Skip to main content

nothing_below_an_observed_position_appears_later

Function nothing_below_an_observed_position_appears_later 

pub async fn nothing_below_an_observed_position_appears_later<F: Fixture>(
    open: impl AsyncFn() -> F,
) -> RuleOutcome
Expand description

Nothing becomes visible below a position a reader has already observed.

ES-10 states it: once any reader has observed an event at position P, no subsequent read against that store may yield an event at a position ≤ P that was not already visible. It is the property that makes AppendCondition::after mean anything — is_violated_by compares position values, so a caller conditioning on after: 100 while 99 is still invisible gets no violation and no error, and the consistency boundary silently stops enforcing.

§The shape, and why it is single-threaded

Two append futures are created from one handle and neither is polled by being created: an async fn body runs nothing until its first poll. That is what puts two appends genuinely in flight with no executor, no Send bound and no clock — CF-33 forbids a clock in a rule, and a wall-clock deadline in a conformance rule is a flake in a conformance rule. The alternative on the table was a Send + Sync sub-trait to bind parallel rules on; it was not needed, and CF-13 records that.

The schedule is A, B, B, A, and plain alternation is not a substitute. An adapter that allocates its position before committing but commits in allocation order is indistinguishable from a correct one; the reversal on resumption is what models the slow transaction that took a low number and published it late.

§Why MemoryEventStore passes it trivially, and why that is right

Its append body contains no .await at all, so the first poll runs it to completion and there is no interleaving to have. The rule is not weaker for that: a store with no window cannot have a window bug, and the schedule below skips a future that has already finished rather than polling it again.

§A requirement this rule adds, which no clause states

observe below runs a full read at four points where one or both append futures are pinned, entered and unfinished. So passing this rule requires that a read issued while an append on the same handle is suspended completes. ES-36 states the append-versus-append direction and a_live_read_stream_does_not_block_an_append the read-then-append one; neither states this, and ES-36’s prose records that.

If your adapter hangs here, that is the reason. An adapter holding one exclusive resource across its append’s suspension point — a pooled connection, a futures::lock::Mutex, a Durable Object storage transaction — blocks the read on what the suspended append still holds, and the suspended future cannot be re-polled because this rule is inside the read on the same stack. CF-33 forbids a clock in a rule, so there is deliberately no watchdog to turn that into a message: it is a hung job naming no rule, which is why the diagnosis is written here.

§What it rejects

A Postgres adapter allocating positions with nextval() outside the transaction — a number taken before the work and released at commit, so a transaction that started earlier can become visible later. PreCommitPositionStore in tests/mutation_coverage/mutants.rs is that store, compiled and registered: polled A, B, B, A it publishes B’s row first, a reader sees B’s higher position, and then A’s lower one appears underneath it. It is the one mutant in the registry whose bug is a faithful model of a real database rather than an implementation slip.

§The schedule changed at phase 10; the name and the clause did not

It used to poll the two writers A, B, B, A — two polls each — and that made the rule’s strength depend on a property no Fixture can express: how many polls the adapter’s append needs. ADR-0013 recorded the gap when it lifted ES-10 to [FROZEN], and spec/SPECIFICATION.md named the instrument that would settle it and assigned it to phase 10 — “if it fires, the rule changes and this clause does not.”

It fired. PollPaddedPositionStore is PreCommitPositionStore with one extra Pending in its append: the same defect, one more poll. Under the old schedule it passed.

The padding is measured, not chosen — ADR-0013 refused to let an author pick it and waited for an adapter with real I/O. happenstance-postgres’s append measures at 3 polls against a live server, the unpadded mutant takes 2, so the padding is 1.

What changed: the slow writer is polled once, to take its number; the fast writer is then driven to completion rather than polled a fixed number of times. That asks for what the rule needs — the fast writer has committed — rather than for a proxy that happens to imply it when a store suspends exactly once.

§What this rule still cannot see

An adapter whose append hands its work to a runtime advances off-poll, so no poll-based schedule decides when its transaction commits. happenstance-postgres is that shape, and a deliberately naive arm of it passes this rule even after the change. Padding a poll-driven state machine cannot model a store that is not poll-driven, so the decorator above cannot reach it either. That limitation belongs to ADR-0024 and is recorded rather than papered over.