Repository navigation
Description
Context
Hosted CI run 42483189496, job unit (4), on PR #3715 at head 12d7f1c6f, failed one test with Safety frame deadline: real WS replay and contiguous updates survive duplicate/reordered delivery without count reduction (test("real WS replay, packages/ui-server/tests/safety-history.test.ts:33). The error comes from the fixture's frame waiter (const until=, packages/ui-server/tests/helpers/safety-history-fixture.ts:62-64), an event-driven listener with a 3,000 ms failure maximum. The PR does not touch the safety-history path.
Reproduced and attributed at main fb999b8baeabbb3a9cb5756a19862eee45467ebf (triage 2026-11-09, Bun 1.4.4 38afee6c8, frozen install, throwaway worktree, one busy loop per core plus six parallel copies of the file):
- Unmodified: 3 of 12 runs failed this test with
error: Safety frame deadlineatsafety-history-fixture.ts:64:70, in about 3.7 s each. The other 13 tests in the file passed. - The frame is not late. It never comes. With the failure maximum raised to 30 s as a diagnostic only, 4 of 18 runs still failed after 30 s. At the 3 s mark the buffered frames were
statusand{"type":"safety_unavailable","version":1,"reason":"gap","requestId":"subscription"}, while the waiter was looking form.type === "safety_update". A longer deadline cannot fix this test. - Tagging each
gapsite in the throwaway copy showed one source in every failing run, the equal-revision projection check inpoll(if(update.toRevision===s.revision&&projectionHash!==s.projectionHash),packages/ui-server/src/governance/safety-history.ts:250-252). Its comment says this is intentional: "Equal durable revisions do not prove equal read state" (line 248). - The sequence in every failing run: the subscription anchors at revision 7 (unresolved 1, pending 0). A poll then delivers
7 → 10withunresolvedCount: 2, pendingCount: 1. That read saw B's durable rows while B's local pending latch was still set.through(2)waits forpendingCount === 0, so it ignores that update (const through=,safety-history.test.ts:41). The next poll reads revision 10 again withpendingCount: 0. The revision is equal and the fingerprint differs, so the server deletes the subscription and sendsgap. No furthersafety_updateis sent on that subscription. - In passing runs the first delivered update was already
7 → 10withpendingCount: 0, then10 → 13.
The race is between a poll's readDelta (private async readDelta, safety-history.ts:190-205) and the test's await f.add("B");f.history.poll(); (safety-history.test.ts:42; const add=async, safety-history-fixture.ts:54-56). subscribe triggers a poll of its own (this.poll() at the end of subscribe, safety-history.ts:207-211). The diagnostics were discarded and no source was changed.
Scope
- Make the test's subscription phase deterministic: no poll may observe a write between its durable commit and the clearing of its local pending latch. For example, let the subscribe-triggered poll settle before the next
add, and make each explicitpoll()run only after that write's local pending state has settled. Use an observable condition, not a sleep, and followdocs/process/test-waits.md. - Optionally, the waiter can fail at once with a clear message when a
safety_unavailableframe arrives for the awaitedrequestId, instead of running out its deadline. That turns this race into a named failure.
Out of scope
- Changing safety-history product semantics: the equal-revision/different-projection
gapclose, pending/loss latches, revision numbering or the WS protocol. If the implementer finds this window also reaches real clients in a way that needs a product change, file that as a separate issue with evidence. - Raising the 3,000 ms failure maximum as the fix, retries, skips or quarantining.
Acceptance criteria
- The PR names the race (a poll observes B with
pendingCount: 1at the same revision a later poll sees withpendingCount: 0, sogapcloses the subscription) and the ordering change that removes it. - Failing-first receipt under the load recipe below: before the fix, at least one run fails this test, with a
safety_unavailable/gapframe recorded or withSafety frame deadline. After the fix, at least 18 runs under the same recipe produce zero failures of this test. - Mutation receipt: removing only the ordering change brings the failure back under the same recipe.
- A mutation that suppresses the awaited
safety_updatestill fails the test with the named deadline (or the new namedsafety_unavailablemessage). -
packages/ui-server/src/governance/safety-history.tsandpackages/ui-server/src/ws/handlers/safety.tsare unchanged.
Verification
for i in $(seq $(nproc)); do (while :; do :; done) & done # kill afterwards
for r in 1 2 3; do for c in 1 2 3 4 5 6; do
bun run test packages/ui-server/tests/safety-history.test.ts -t 'real WS replay' > run-$r-$c.log 2>&1 &
done; wait; doneRecord pass/fail counts before and after, plus both mutation receipts. Also run the whole file once (bun run test packages/ui-server/tests/safety-history.test.ts).
Contract impact
None. Test/fixture ordering only.
Triage 2026-11-09 at main fb999b8ba: reproduced the hosted failure locally (3/12 unmodified loaded runs). A 30 s diagnostic deadline showed the frame never arrives: the server closes the subscription with gap after a poll observes B's transient pending latch. needs: repro is removed. The scope moved from "wait longer" to "remove the write/poll race". #736 is full, and #2753 covers only browser runs, so this stays standalone. P2: wanted, unscheduled.
Activity
[-]ui-server: safety-history WS fixture's fixed 3 s frame deadline fails under CI load[/-][+]ui-server: safety-history WS replay test races a poll against an unsettled write and is closed with gap under load[/+]schlessera commentedon Nov 9, 2026
Triage 2026-11-09 at main
fb999b8ba(Bun 1.4.4, busy loop per core plus six parallel copies):real WS replay…withSafety frame deadline, at the same fixture line as the hosted job.safety_unavailablewithreason: "gap"for the subscription. Tagging thegapsites pinned it to the equal-revision/different-projection close inpoll(safety-history.ts:250-252): one poll delivered7→10withpendingCount: 1(B's local latch still set), the next read revision 10 withpendingCount: 0, and the subscription was closed.needs: repro. Rewrote the scope as a test-ordering fix (productgapsemantics out of scope) with failing-first and mutation receipts, retitled the issue to the actual cause and addedagent-ready. No parent: Epic: Keyless verification completes deterministically and isolates host state #736 is full, and Epic: browser verification is deterministic and attributable #2753 covers only browser runs.schlessera commentedon Nov 10, 2026
Another hosted occurrence: CI run 42890776798, job
unit (1), on the test-health batch PR #3897 (heada4b1b9854c64b772b4d92e7b0b931a2a5078a765, baseepic/3855-test-health).real WS replay and contiguous updates survive duplicate/reordered delivery without count reductionfailed after 15.3 s withSafety frame deadlineatpackages/ui-server/tests/helpers/safety-history-fixture.ts:69. That PR changes onlypackages/ui-backend-claude/testsfiles, none of them on this test's path. Not rerun.test(ui-server): test-health batch e3855-ui-server-03 (#3902)