Repository navigation
Description
Context
packages/ui-react/tests/answer-delivery-runtime.test.ts intermittently fails its online case at expect(... __answers.cards()).toBe(1) with Received: 2 (line 541), after the backend-settled-once, expected-result and ANSWERED assertions have passed.
Cause, reproduced on demand (receipt, 2026-11-14):
- When a page connects while exactly one turn is registered with the host, snapshot-on-connect sends that session's history to the new socket (
const runningTurns,packages/ui-server/src/ws/connection.ts:146-185). The running set is host-wide. - The client creates a buffer for a replayed session it has not opened (
if (msg.type === "session_history") return frameSessionId;,packages/ui-react/src/ws-client/inbound.ts:326). - The fixture's
cards()counts ask exchanges across every buffer (cards,packages/ui-react/tests/fixtures/answer-delivery-client.ts:56-59). - Every case shares one host.
afterEachcancels active turns but does not wait for the host to release them (afterEach,packages/ui-react/tests/answer-delivery-runtime.test.ts:174-176).
So when the previous case's turn is still registered as the next case's page connects, the next page holds the previous session's answered exchange in a second buffer, and the count is 2. The page renders one card and the case's own session holds one exchange. This is intended product behaviour: ASK_RETURNS_NEW_CARD_IDENTITY relies on the same replay (test, packages/ui-react/tests/answer-delivery-runtime.test.ts:744-777). The defect is in the fixture: its count spans sessions.
Sightings. Three, all inside long single-process runs, none on hosted main CI from 2026-10-28 to 2026-11-13:
- 2026-11-10,
ask_user_listonline, full local proof for ui-sdk, ui-server: classify unrecoverable staging refusals as recovery, and show unresolved journal records to the owner #3826 at003333e02. - 2026-11-13,
ask_useronline, about 42 minutes into a whole-repository run at main631bbae2c. - 2026-11-14, the controlled reproduction at main
631bbae2c.
Scope
Make the file's exchange-count assertions say what they mean: this case's session holds exactly its own exchange.
- Five assertions count across buffers and are exposed: lines 458, 541, 580, 789 and 844 (
cards()). Assert each on the session the case owns.activeCardRequestIdsalready reads only the active session (activeCardRequestIds,packages/ui-react/tests/fixtures/answer-delivery-client.ts:60-64); comparing it with the expected request IDs is stricter than a count. - Keep line 761 counting across buffers. That wait is the replay
ASK_RETURNS_NEW_CARD_IDENTITYexists to observe. - Add the controlled ordering as a permanent case: the previous case's finished backend is held with the file's existing
resultGate, the next page connects, the gate is released, and the online steps run. On main this case fails at the count withReceived: 2.
Out of scope
- Snapshot-on-connect, history publication, the client's buffer creation and anything else under
packages/ui-server/srcorpackages/ui-react/src. The replay is intended. - The once-only settlement assertions, the
ANSWEREDassertion, the real-browser cases, timeouts and provider admission. None is weakened or removed. - Waiting out the host's teardown between cases as the only repair. It hides the count's meaning and leaves the assertions wrong for the replay they can legitimately meet.
- Staging and journal recovery from ui-sdk, ui-server: classify unrecoverable staging refusals as recovery, and show unresolved journal records to the owner #3826.
Acceptance criteria
- A new controlled case holds the previous turn until the next page has received the previous session's
session_info, releases it, runs the online steps and passes. Before the assertion change it fails at the count withExpected: 1,Received: 2. The PR records both runs. - In that case, the next page holds two session buffers when its count is asserted, and the assertion still passes. The PR shows the buffer identities.
- The assertions at lines 458, 541, 580, 789 and 844 no longer count across sessions. Each still fails when its own session holds an extra or a missing exchange: one mutation that adds a second exchange to the active session fails the online case on that assertion, and restoring it passes.
-
ASK_RETURNS_NEW_CARD_IDENTITYis unchanged and passes. - The whole file passes with real Chrome.
Verification
BRAIN_REQUIRE_CHROME=1 bun run test packages/ui-react/tests/answer-delivery-runtime.test.tsRun it with an explicitly empty provider-key environment; no API key or network is needed. Record the failing-first run of the new case, the mutation and its restoration, and bun run check:pr --base origin/main.
Contract impact
None. Test and fixture only.
History
- Found during ui-sdk, ui-server: classify unrecoverable staging refusals as recovery, and show unresolved journal records to the owner #3826; filed 2026-11-10 as an attribution task with
needs: repro. - 2026-11-10: focused control and a test-health audit run passed, unreproduced.
- 2026-11-13: closed as not planned after 96 isolated cases passed, then reopened the same day when a whole-repository run failed the
ask_userform. - 2026-11-14: reproduced on demand and attributed.
Triage 2026-11-14 at main d64f893b5: rewrote the body around the demonstrated cause and a fixture-only fix. Removed needs: repro, changed type: fix to type: test, added agent-ready. priority: p2 unchanged; no milestone.
Activity
schlessera commentedon Nov 10, 2026
2026-11-10 triage at main
7f1c15837: citations hold (cards()assertion atpackages/ui-react/tests/answer-delivery-runtime.test.ts:541,cardsatpackages/ui-react/tests/fixtures/answer-delivery-client.ts:56-59). Addedpriority: p2: one full-run duplicate count with a passing focused control, not seen on main CI.needs: reprostays until the request/buffer trace exists, so notagent-ready.schlessera commentedon Nov 10, 2026
Test-health audit, 2026-11-10 (push #3855, shard
e3855-ui-react-01). Bounded reproduction attempt; no fix and no attribution is claimed.b71c6e4fe, plus test-only edits to the same file that do not touch the asserted path (see below).BRAIN_REQUIRE_CHROME=1 bun scripts/test-health.ts measure packages/ui-react/tests/answer-delivery-runtime.test.ts packages/ui-react/tests/approval-recovery-runtime.test.ts packages/ui-react/tests/association-signout-runtime.test.ts --runs 2, run on a shared host while other workers were running suites.answer-delivery-runtimestable, 2 of 2 green, median about 211 s per run including the fixture build. No storage-refusal timeout, and no duplicate exchange count.An earlier shuffled, combined baseline of all five cluster-2 runtime files hit its 2-hour harness limit before it finished. That limit is the harness's, and says nothing about this test.
The audit changed only how this file reports failures: four frame checks of the form
some(...)).toBe(false)becamefilter(...)).toEqual([]), so a stray frame is printed. Behaviour and waits are unchanged. Still unreproduced, soneeds: reprostays.schlessera commentedon Nov 13, 2026
Closing as not planned (maintainer-requested triage, 2026-11-13). One local sighting on 2026-11-10 during a full local proof, with every user-visible assertion passing: the card read Answered and the backend settled once. The same case had passed in an earlier full run on identical source.
New attempt under load. Main
631bbae2c, a 4-CPU Ubuntu 24.04 VM, real Chrome, the whole file (24 cases) beside 4 busy loops:Recurrence sweep. I read the failed-step log of every failed product job on main
CIfrom 2026-10-28 to 2026-11-13: 84 jobs across 300 runs.card says Answered only after the host's receiptappears in eleven of those logs, four cases each, always as a pass.The open question here was whether the count of 2 was a transient overlap between session buffers or a persistent duplicate. Nothing since has shown a second exchange, and the one sighting did not capture which. With a single observation and no user-visible effect, I am closing it rather than leaving it open on a guess.
On recurrence: file a new issue with the two request IDs, the buffer each was read from, and the rendered card count, so the overlap and the duplicate can be told apart.
schlessera commentedon Nov 13, 2026
Reopening: I closed this an hour too early. The same signature just reproduced on main (2026-11-13).
My close above rested on 4 isolated runs of the file (96 cases, 0 failures) and a clean hosted record. A different experiment then hit it, in a whole-repository run on the same kind of VM (4-CPU Ubuntu 24.04, Chrome 151, main
631bbae2c):What this adds.
ask_user_list; this isask_user. The other three forms' online cases passed in the same run, as did the rest of the file (23 of 24).ANSWERED. Only the fixture's count of stored ask exchanges was 2.bun testover the whole repository, about 42 minutes in, after roughly 700 other test files in the same process. Isolated, it passed 96 of 96. So order or accumulated process state is the lead, where I had been testing for timing.One condition to state plainly: a foreign process was holding the default maintenance ledger during that run (it was the census for #3019). I have no reason to think the ledger reaches this case, since the busy refusal does not appear in this file's output, but it was not a clean-room run.
Still unknown, and now worth the effort: whether the 2 is a transient overlap between session buffers or a persistent duplicate. The assertion reads
cards()once, at the instant the card turns Answered. Sampling it for a second or two after a failure, with the request IDs and the buffer each exchange sits in, separates the two.How to look for it: run the file inside a larger single-process run rather than alone. The first sighting was also a full local proof, not an isolated run.
needs: reprostays.schlessera commentedon Nov 14, 2026
Reproduced on demand and attributed (2026-11-14). The 2 is two different exchanges in two session buffers. It is not a duplicate card.
What happens.
const runningTurns,packages/ui-server/src/ws/connection.ts:146-185). The running set is host-wide, so the new page gets a session it never started.if (msg.type === "session_history") return frameSessionId;,packages/ui-react/src/ws-client/inbound.ts:326).cards()counts ask exchanges across every buffer (cards,packages/ui-react/tests/fixtures/answer-delivery-client.ts:56-59). The previous case's answered exchange and this case's own make 2.The suite already depends on step 2 and 3 on purpose:
ASK_RETURNS_NEW_CARD_IDENTITYholds a finished turn, opens a fresh context and waits forcards() === 1from the replay alone (packages/ui-react/tests/answer-delivery-runtime.test.ts:744-777). The online case reaches the same state by accident when the previous turn is still registered.Controlled receipt. Main
631bbae2c, local host, Bun 1.4.4, Chromium 153 headless (the browser's own sandbox switched off, which this host needs). One throwaway case added to the unchanged file: the previous case's online steps with its finished backend held by the file's existingresultGate, then the online case's steps verbatim in a fresh context.cards()server_hello,statusserver_hello,session_info, …,session_history,statusodysseus-answers-1:toolu_ask_user_1;odysseus-answers-2:toolu_ask_user_2The failing row is this issue's signature exactly:
The three assertions before it pass, as in both sightings. At the failing instant the page renders one
[data-answer-delivery="answered"]card, the active session is the case's own, and its buffer holds one exchange with the expected request ID.Answers to the acceptance criteria.
Why isolated loops never hit it. The window is the host's turn teardown after the backend returns. It is a few milliseconds in a fresh process. Both sightings were in long single-process runs (a full local proof, and about 42 minutes into a whole-repository run), where that teardown is slower. My 96 isolated cases under CPU load did not widen it. That is also why my close on 2026-11-13 was wrong.
One thing I did not chase. In two variants where the previous turn stayed held for the whole case, the host announced the session (
session_info) but sent no history until the turn was released, so the count stayed 1.ASK_RETURNS_NEW_CARD_IDENTITYconnects sooner after the answer and gets the history at once. The difference does not change the attribution, since the natural failure has the turn released shortly after connect.Exposure. Five assertions in the file count across buffers the same way: lines 458, 541, 580, 789 and 844. Line 761 is the deliberate replay wait and must keep counting across buffers.
The body now carries the fix scope. Removed
needs: repro, changedtype: fixtotype: test, addedagent-ready.[-]ui-react: attribute intermittent duplicate answer exchange count after host receipt[/-][+]ui-react: the answer-delivery fixture counts another session's replayed exchange, so a case can read 2 cards after the host's receipt[/+]