Skip to content

ui-server: the recovery read reports a turn as running after its result is published, so a reload announces the finished turn again #3994

Open

Description

@schlessera

Context

A reload shortly after a turn finishes can announce that turn's completion a second time. The tracker rule is that a tracker restored on load is a baseline and says nothing (createTrackerAnnouncer, packages/ui-react/src/lib/tracker-announcer.ts:36, D52 §3), and mounted trackers > …: drawn in the strip or the pane, announced once, opened and cleared from there asserts it ("a reload announces nothing", packages/ui-react/tests/tracker-runtime.test.ts:284).

Sightings.

Cause, reproduced on demand (2026-11-14). Local host, d64f893b5, Bun 1.4.4, Chromium 153. One throwaway line makes the fixture backend return late after it has emitted its result (after bridge.emit({ type: "result", … }), packages/ui-react/tests/tracker-runtime.test.ts:77), which is what a real backend does while its process winds down.

Backend returns after its result Cases Recovery read just before the reload
at once (unchanged) 6 of 6 pass state: "terminal", outcome: "success", endedAt set
3,000 ms later 6 of 6 fail at a reload announces nothing, Received: "The voyage home is done." state: "running", outcome: null, endedAt: null

The page had already announced the completion from the live result frame, at least 300 ms before that read.

  • The recovery read reports every registered turn that has started as running, whether or not its result is out (liveRequests, packages/ui-server/src/ws/recovery.ts:77-96).
  • Snapshot-on-connect already makes the distinction: a registered turn with a result is reported idle (const finishSnapshot, packages/ui-server/src/ws/connection.ts:169-177).
  • The reloaded page takes running as its baseline. When the host releases the turn, the tracker changes to done, which the announcer rightly treats as a change (const changed, packages/ui-react/src/lib/tracker-announcer.ts:55).

So the announcer and the test are right, and the host's answer is stale for as long as the backend takes to return. On an idle host that is a few milliseconds, which is why the case usually passes.

Scope

Make the recovery read report a turn whose result has been published as ended, with that result's outcome, even while the host still holds the turn. Keep the controlled late return as a permanent case in the tracker runtime file.

Out of scope

  • The announcer's rules and the reload assertion. A wait in the test for the host to release the turn is not a fix: the reader would still hear the announcement twice.
  • The shape of the recovery read. Only which state it reports in this window changes.
  • Queued follow-ups and pending interactions in the recovery read, snapshot-on-connect, and how long a backend may take to return.

Acceptance criteria

  • A case in tracker-runtime.test.ts has the fixture backend return late after its result. On main it fails at a reload announces nothing with Received: "The voyage home is done.". With the fix it passes. The PR records both runs.
  • A host-level test reads the recovery for a session whose registered turn has published a result and has not returned. It reports a terminal state with the result's outcome, not running. Reverting the fix fails that assertion.
  • A registered turn with no result yet still reads running, and a queued request still reads queued.
  • The existing tracker and parallel-session runtime cases pass with no assertion or wait changed.

Verification

BRAIN_REQUIRE_CHROME=1 bun run test packages/ui-react/tests/tracker-runtime.test.ts
bun run test packages/ui-server/tests
bun run check:pr --base origin/main

No API key or network is needed.

Contract impact

None expected: no field is added, removed or retyped. Check the recovery read's entry in docs/integration-contract.md before merging; if it states when a turn stops reading running, update it in the same commit with the CONTRACT: prefix.

Found during the needs: repro triage of 2026-11-13. Related: #3834 has the same trigger (a page connecting while the host still holds a finished turn) with a fixture cause.

Activity

  1. added
    type: fix
    area: ui-server
    area: ui-react
    priority: p2
    agent-ready
    on Nov 14, 2026
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-reactarea: ui-serverpriority: p2type: fix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions