Cod3xDocs
guide

Paid For With Blood — Generations for Deferred Work

CellPresence work was valid when sent and stale when it returned.

The wound

S3maphore's CellPresence/update pipeline crossed script contexts and cell transitions. Deferred work could complete after a newer transition had already made the result irrelevant.

A cell ID check alone was not a sufficiently strong identity for every in-flight operation.

What changed

Commit b148ee31 added:

  • a presence generation;
  • a playback epoch;
  • generation data on presence messages;
  • epoch/cell data on track-change messages;
  • rejection of results that no longer matched the current generation.

The important operation is not incrementing an integer. It is attaching authority to the work.

The rule

Delayed work must be able to prove that it still belongs to the state that requested it.

Use generations/epochs/tokens when:

  • a newer request supersedes an older one;
  • cell transitions can invalidate replies;
  • playback/UI state can change while work is queued;
  • events or callbacks cross enough time that current state may differ.

Do not solve stale work only by checking one coincidental field. Give the request an identity.

Source: S3ctors S3cret St4sh commit b148ee31.

Implementation at that revision: playlistState.lua. Current production source: playlistState.lua on main.