Skip to content

ui-server: the turn-boundary hold deadline test races real time, so a loaded runner fails 'held before the deadline' #4246

Open

Description

@schlessera

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 FailureReplay fails 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

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

  1. added
    type: test
    area: ui-server
    priority: p2
    on Nov 17, 2026
  2. added
    agent-ready
    on Nov 20, 2026
  3. schlessera commented on Nov 21, 2026

    @schlessera
    OwnerAuthor

    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.ts are byte-identical to main b7202e638; #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.

  4. schlessera commented on Nov 22, 2026

    @schlessera
    OwnerAuthor

    Another occurrence: a full CI dispatch of the #4278 integration work (PR #4457, head 7b47c1f78) failed unit (1) on this test. The assertion was held before the deadline at packages/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-serverpriority: p2type: test

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions