Expand description
The log position a write folds, carried into the store the way the tenant
is (TenantContext): a task-local, so no write
method’s signature changes.
§Why a store needs it
A processor records each event in the task’s log and then stores the state it leads to. A subscriber on another replica, with no live queue to read from, starts its stream from the stored task and replays the log after the position that task reflects. Read the task, and it cannot know that position: the log’s end may hold an event the task does not reflect yet (it was logged and not yet stored), and an event replayed that the task already reflects arrives twice. Until 2026-10-15 the subscription read the log’s end and then the task, and lost the first case silently (audit register R69).
So a store that keeps a log records, atomically with each write made
inside AppliedPosition::scope, the position that write folds, and
returns it with the task from
TaskStore::get_with_position.
A write outside a scope keeps the position already stored: a new task’s
first save and the handler’s own status writes change no logged event’s
effect. A write inside one stores its position even when that is lower
than the stored one, which is how a continuation’s save says it
overwrote events folded after its read (below).
What the position does not cover:
- The lost update of a stale write from another replica. A
continuation’s save replaces the stored artifacts and metadata with the
ones its send read, so an event another replica folded after that read
is gone from the task. Until 2026-10-20 the save was unscoped and kept
the position that fold stored, so the position claimed an event the
task had lost and a subscriber starting from it lost it too
(
tests/stale_write_position). The save now records the position of the read it was built from (handler/messaging/basis.rs, which also says why a new turn’s numbering survives the lower position), so a subscriber that starts before the continuing turn’s first fold replays the event. From that fold on the position is past it again and the task still lacks it: the lost update itself, which only a compare-and-set write would refuse. The other unscoped task writes overwrite no folded event a stream starts from: a cancel writes the status alone and leaves the task terminal, which no subscription starts from, and a processor’s own (an executor’s panic, an error event) writes the snapshot its turn’s folds built, which reflects the position its last fold stored unless another replica’s turn writes the task at the same time (single-writer admission does not cross replicas,tests/multi_replica.rs). - A replica on an earlier release. Its writes leave the position where it was, so until every replica writes it the position can trail the task and a subscription replays events the snapshot already holds: duplicates, not losses. Its continuation saves keep the stored position, as every release before 2026-10-20 did (the first entry).
- A failed append. The fold is stored with the position of an event the log does not hold, so the position can be past the log’s end. A new turn is numbered after the later of the two, so no position names two events.
§Implementing it in a custom store
Read AppliedPosition::current at the start of every write method, before
anything is spawned (a task-local does not cross tokio::spawn), and store
it with the write in one atomic step, even when it is lower than the
stored one; keep the stored position when it is None. Then override
get_with_position to read the task and the position together. A store that does neither keeps the trait’s default,
None, and a subscription falls back to reading the log’s end.
Structs§
- Applied
Position - The log position the current write folds, if any; see the module documentation.