Skip to content

ui-server: a history read during turn teardown replays the answer without its turn id #3803

Closed

Description

@schlessera

Context

Found in #3155's image-originals slice. It predates that slice: it reproduces on main with a plain-text composer original.

A turn's boundary, the link from an assistant row to its turnId, is recorded in finish, after host teardown (finish, packages/ui-server/src/ws/turn-failures.ts:165-171). History replays attach boundaries in attachTurnBoundaries (packages/ui-server/src/ws/session-work.ts:111-130). A client can read the history again as soon as the turn's result arrives, while teardown is still running. That replay runs before the boundary exists, so the answer it ends replays without its turnId, and nothing replays it again. Recorded and replayed prefix digests match; the cause is ordering, not the digest.

Evidence (packages/ui-react/tests/parallel-sessions-runtime.test.ts, "1279 desktop: A and B stream side by side", which fails when the last assistant row has no turnId, around :781):

Tree, follow-up Runs Fails
main, follow-up carrying a plain-text composer original 3 3
main, original scene (legacy inline image) 3 1 (at :810)
#3155 image branch, follow-up carrying an image original 5 4

A follow-up that carries attachmentRefs takes longer to tear down, which widens the window.

Scope

  • History reads of a session wait for its turn's boundary between the turn's result and its finish, bounded by the existing 10,000 ms BOUNDARY_READ_MS so a teardown that never ends cannot hold history indefinitely.
  • Cover both ordinary bridge and direct backend result emission paths. Keep the hold owned by the concrete host/session, release it on normal completion and failure/cleanup, and preserve authorization checks while publishing history.
  • Keep the current assistant-position/prefix-digest matching. A hold coordinates existing metadata; it must not manufacture a boundary for an older or unrelated answer.

Out of scope

  • Changing prefix digests or recorded positions.
  • Client changes.

Acceptance criteria

  • A ui-server test fails first on the current tree: a history read issued after a turn's result but before its finish returns the answer with its turnId. A candidate test exists (packages/ui-server/tests/ws-turn-failure-replay.test.ts, "Received: undefined" on both backends before the fix).
  • The parallel-sessions-runtime case above passes repeatedly on main with a composer-original follow-up.
  • A mutation that removes the hold fails the named test.
  • A held session cannot block an unrelated session. The existing boundary deadline releases a stalled result-to-finish hold without a leaked pending entry or timer; cancellation and cleanup remain bounded.
  • Existing no-answer, truncated/edited transcript and stale-result controls keep rejecting a false boundary. No client change or automatic history/effect replay is introduced.

A candidate fix with that test is on branch fix/turn-boundary-replay-race (fa6b976f1, from main). FailureReplay gains resulted(sessionId), which tracks a hold on the session's history until the turn's finish, bounded by BOUNDARY_READ_MS, and the bridge or backend entry calls it when the result goes out. Review it and run the full proof before landing.

Verification

bun run test for the ui-server turn-failure and replay tests, and the real-Chrome parallel-sessions-runtime file, built first with bun run build --jobs=2.

Contract impact

None: no wire, HTTP or MCP shape changes.

Bounded failing-first verification — 2026-11-09

On a detached checkout of 9c7eb25825fdad5f4485db0df472188805edb450, frozen dependencies and Bun 1.4.4 (38afee6c8), triage copied only the candidate test file from fa6b976f13550afd2893cb0239ffcfa4bd60d41e to ignored tmp/triage/3803-boundary.test.ts, adapting its relative imports. No production code was copied or changed. The fixture, real host replay path and the actual Claude/Pi history normalizers ran through the repository wrapper and offline network preload; backend transcript transport is scripted, with no provider call.

bun run test ./tmp/triage/3803-boundary.test.ts -t 'a resume between'

Exit 1: 0 pass / 2 fail / 30 filtered, four assertions. Both backend cases reached the intended the answer carries its turn assertion: the result had a turn ID and the replayed last assistant had undefined. They completed in 175.58 ms / 116.45 ms. This independently establishes the controlled result-before-finish race; it is not a module-load failure, a real-provider result or a rerun of the reported browser-rate table. The cited production files are byte-identical at inspected main 4b8db90dee643cd67ef6acc7c122294f262d92ec; its only intervening change is #3802's notification test clock.

Readiness and ownership

The ordinary brief is complete and the failure is reproduced; add agent-ready, preserve p2 and no milestone. The candidate branch is evidence for review, not merged or qualified behavior, and no assignment is made. Keep standalone: #3150/#3155 own attachment delivery, while this also fails with a plain-text original; #578 owns offline transitions, #1344 owns schema parsing, and #1345 owns extension API conformance. None owns this full host teardown-order correction. Discovery in the attachment slice is not epic membership or an implementation dependency.

Triage 2026-11-09 at main 4b8db90dee643cd67ef6acc7c122294f262d92ec: Verified the source anchors and candidate boundary, reproduced the intended assertion on both host paths, and specified bounded/session-isolated cleanup proof. Existing digests, client behavior, priority and unscheduled state are preserved; no implementation or browser qualification is claimed.

Activity

  1. added
    type: fix
    area: ui-server
    priority: p2
    agent-ready
    on Nov 9, 2026
  2. schlessera commented on Nov 9, 2026

    @schlessera
    OwnerAuthor

    Hosted occurrence: #3805 candidate proof, run 42657353591, job unit (2), head 2922f3c69. Case: parallel-sessions-runtime "1440 desktop, light, fine pointer, reduced motion: A and B stream side by side…". It hit TimeoutError at parallel-sessions-runtime.test.ts:781, waiting for "Scroll to latest", which is the step that needs the last assistant row's turnId. Same failure as above. The follow-up in this scene carries an image original. Per the maintainer's ruling this does not block #3805: it is documented there and a fresh confirmation is requested, with no rerun of the failed job.

  3. self-assigned this
    on Nov 10, 2026
  4. added this to the 0.45.0 milestone on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ui-serverpriority: p2type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions