Repository navigation
Description
Part of #2963. The test oracle can fail when the product deadline behaves correctly.
Context
Found while landing PR #4198 (#4154). Its confirmation run 44195552641 on head c74cf05764a26493bdd5bc97c32e54079ae26dac failed one unit test, in job 134436702331:
(fail) a teardown that never finishes releases the hold at the boundary deadline [51.12ms]
error: held before the deadline
Expected: false
at packages/ui-server/tests/turn-boundary-hold.test.ts:51:63
PR #4198 changes nothing in packages/ui-server/src/ws/turn-failures.ts or this test. Every other unit test in that run passed, along with the PR's own heavy feedback run on its previous head. No failed job was rerun.
Cause
The test (packages/ui-server/tests/turn-boundary-hold.test.ts:46-56) builds FailureReplay with boundaryReadMs = 50. The hold resolves on a real setTimeout(resolve, this.boundaryReadMs) (const hold, packages/ui-server/src/ws/turn-failures.ts:181-182). The first assertion then calls settlesSoon(held), which performs up to 20 real Bun.sleep(1) calls and expects the hold to still be pending. Each sleep is at least 1 ms and, on a loaded runner, often more. Once begin, resulted and those sleeps together pass 50 ms, the hold has correctly released at its deadline, and the "held before the deadline" assertion fails. The recorded test time of 51.12 ms is consistent with this. The product's 10-second default (BOUNDARY_READ_MS) is not involved.
This is a test-timing flake in the harness, not a product regression.
Scope
Make the test prove the same two claims without racing real time: the session stays held while the deadline has not passed, and it is released by the deadline without a finish and without recording a boundary. Control the clock the hold uses (inject a timer, or use the repo's existing fake-timer approach), or make the "still held" check independent of how long the sleeps take. Don't weaken either assertion or drop the test.
Acceptance criteria
- The test asserts "held before the deadline" and "released by the deadline without a finish" on a clock it controls, so CPU load cannot reorder them.
- A mutation receipt: removing the deadline timer in
FailureReplayfails the release assertion, and making the hold release immediately fails the held assertion. Both are restored, and both receipts are in the PR. - The test passes repeatedly under the changed-test determinism gate.
Out of scope
- Changing the product's
BOUNDARY_READ_MSor the hold semantics from ui-server: a history read during turn teardown replays the answer without its turn id #3803.
Verification
Run bun run test packages/ui-server/tests/turn-boundary-hold.test.ts and retain the two restored mutations described above. Verify changed-test repetitions in the selected determinism job.
On main bd751d434, Bun 1.4.4, the named case passed. In an isolated checkout, lengthening only the test helper's polling sleep from 1 ms to 4 ms triggered held before the deadline (expected false, received true, exit 1). Restoring the helper passed again. This induced delay reproduces the ordering failure with production timing and hold code intact.
Contract impact
Internal test only. The production deadline and hold behavior remain within the existing contract.
2026-11-20 triage — Recorded the controlled timing failure and the verification path.
Activity
schlessera commentedon Nov 21, 2026
Additional occurrence in PR #4425 confirmation run 44916413812, unit (2), job 136883304951: the deadline case failed in 53.42 ms. The test and
packages/ui-server/src/ws/turn-failures.tsare byte-identical to mainb7202e638; #4425 changes neither. This matches the real-time race and main reproduction already documented here. The unrelated failed assertions earlier in that serial worker do not alter the timer implementation; the worker continued and the polling sleeps still race the 50 ms hold. No failed job or flaky test was rerun. This issue remains unscheduled.schlessera commentedon Nov 22, 2026
Another occurrence: a full CI dispatch of the #4278 integration work (PR #4457, head
7b47c1f78) failedunit (1)on this test. The assertion washeld before the deadlineatpackages/ui-server/tests/turn-boundary-hold.test.ts:51(expected false, got true; 51.87 ms). Run: https://github.com/schlessera/brain-kit/actions/runs/45034521236. That change doesn't touch this file or the turn-replay hold, and the test passed in the four dispatches before it.