Skip to content

fix(ui-server): hold a session's history reads until its turn's boundary is recorded - #3899

Merged
schlessera merged 5 commits into
mainfrom
fix/3803-turn-boundary-hold
Nov 10, 2026
Merged

schlessera merged 5 commits into
mainfrom
fix/3803-turn-boundary-hold

Conversation

@schlessera

@schlessera schlessera commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Closes #3803
Refs #3884

What changed

A history read of a session issued between its turn's result and the end of host teardown (finish) now waits for that turn's boundary. Before, such a read ran before the boundary was recorded, so the answer replayed without its turnId. Nothing replayed it again, so the session's tracker could never be observed as seen.

The hold is tracked per session in FailureReplay, the same way failure and boundary writes are already tracked. It starts when the turn's own result goes out (onTurnResult → resulted). It ends in finish, including on failure, or at the existing BOUNDARY_READ_MS deadline, whichever comes first.

This is the declared fix for red-main incident #3884. Main went red on parallel-sessions-runtime at #3805's merge b77987afb. That slice made every image an attachment ref, which widened this pre-existing teardown window. The incident has the evidence and the decision.

Why this shape

#3803's scope: coordinate the existing boundary metadata instead of changing prefix digests or positions, and make no client change. The hold manufactures nothing. A stalled teardown releases at the deadline without recording a boundary. An unrelated session is never held.

The deadline became a constructor option (default unchanged) only so the deadline test runs in milliseconds.

Proof

bun run check:pr --base origin/main

Failing-first, mutations and the runtime case:

  • Failing-first. ws-turn-failure-replay.test.ts "a resume between a turn's result and its end waits for the turn's boundary" fails on both backends with main's packages/ui-server/src (Expected: <turnId>, Received: undefined). It passes with the fix (32 pass).
  • Mutation: drop the hold (this.track(sid, hold) removed). Both cases fail again. Restored.
  • Two new unit tests in turn-boundary-hold.test.ts:
    • An unrelated session's read is not held, this session's waits until finish, and no pending entry remains. A mutation making wait include every session fails "another session reads at once".
    • A teardown that never finishes releases at the deadline, with no pending entry and no made-up boundary. A mutation removing the deadline race fails "released by the deadline without a finish".
    • Both mutations restored.
  • Runtime case under load. parallel-sessions-runtime "1440 desktop, light, fine pointer…" ran with 10 busy loops on a 16-core host:
    • b77987afb: 3 failures in 14 runs.
    • Parent b6c330a60: 0 failures in 5 runs.
    • This branch: 0 failures in 14 runs (12 pass each).
  • Citations. Three citations moved by this change are updated (emission.ts:273, emission.ts:203-229, turn-failures.ts:67-94). check-citations reports none of them.
{
  "version": 1,
  "kind": "brain-check-pr-receipt",
  "head": "1917da1c711fb0de6bcc773aaa96b02614393241",
  "base": "origin/main",
  "mode": "focused",
  "startedAt": "2026-11-10T20:42:24.652Z",
  "finishedAt": "2026-11-10T20:44:24.014Z",
  "checks": [
    {
      "name": "all lint and leakage gates",
      "categories": [
        "changeset"
      ],
      "outcome": "passed",
      "elapsedMs": 28378.931565
    },
    {
      "name": "environment documentation",
      "categories": [
        "changeset"
      ],
      "outcome": "passed",
      "elapsedMs": 207.19922399999632
    },
    {
      "name": "pending changeset package names",
      "categories": [
        "changeset"
      ],
      "outcome": "passed",
      "elapsedMs": 162.6990850000002
    },
    {
      "name": "contribution changeset",
      "categories": [
        "changeset"
      ],
      "outcome": "passed",
      "elapsedMs": 28.339718000002904
    },
    {
      "name": "affected fast invariants",
      "categories": [
        "verify",
        "unit"
      ],
      "outcome": "passed",
      "elapsedMs": 90565.778922
    }
  ]
}
  • Strict typecheck fix. The first hosted verify run failed strict types: the cherry-picked test read result.turnId, which ServerResultMessage does not declare. The test now reads the stamped id through a typed guard, the pattern claude-cancellation.test.ts uses. tsc --noEmit and bun run build pass locally on 1917da1c7.

Checklist

Anything left open

The other two failures in #3884 (runtime_host, safety-history) are outside this change and outside #3805. The recovery main run has to pass them as they stand.

🤖 Generated with Claude Code

schlessera and others added 4 commits November 10, 2026 19:57
…ary is recorded

A client can read history again the moment a turn's result arrives, while
host teardown still runs. That replay happened before the turn boundary
was recorded, so the answer replayed without its turn id and nothing
replayed it again. Reads of that session now wait for the turn's finish,
bounded by BOUNDARY_READ_MS.

Not landed ahead of #3155's image PR (maintainer ruling); see the issue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s at the boundary deadline (#3803)

The result-to-finish hold is keyed by session and raced against the
boundary deadline. Two unit tests pin both: an unrelated session's history
read is never held, and a teardown that never finishes releases the hold
with no pending entry left and no boundary made up. The deadline is a
constructor option so the second test runs in milliseconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 10, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. labels Nov 10, 2026
@schlessera
schlessera marked this pull request as draft November 10, 2026 20:09
@schlessera
schlessera marked this pull request as ready for review November 10, 2026 20:09
…ped guard (#3803)

ServerResultMessage declares no turnId; servers stamp it on every frame.
Strict typecheck refused the direct property read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant