Skip to content

ui-react: the answer-delivery fixture counts another session's replayed exchange, so a case can read 2 cards after the host's receipt #3834

Open

Description

@schlessera

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. afterEach cancels 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:

  1. 2026-11-10, ask_user_list online, full local proof for ui-sdk, ui-server: classify unrecoverable staging refusals as recovery, and show unresolved journal records to the owner #3826 at 003333e02.
  2. 2026-11-13, ask_user online, about 42 minutes into a whole-repository run at main 631bbae2c.
  3. 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. activeCardRequestIds already 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_IDENTITY exists 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 with Received: 2.

Out of scope

  • Snapshot-on-connect, history publication, the client's buffer creation and anything else under packages/ui-server/src or packages/ui-react/src. The replay is intended.
  • The once-only settlement assertions, the ANSWERED assertion, 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 with Expected: 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_IDENTITY is 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.ts

Run 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

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

  1. added
    type: fix
    area: ui-react
    needs: repro
    priority: p2
    on Nov 10, 2026
  2. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    2026-11-10 triage at main 7f1c15837: citations hold (cards() assertion at packages/ui-react/tests/answer-delivery-runtime.test.ts:541, cards at packages/ui-react/tests/fixtures/answer-delivery-client.ts:56-59). Added priority: p2: one full-run duplicate count with a passing focused control, not seen on main CI. needs: repro stays until the request/buffer trace exists, so not agent-ready.

  3. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    Test-health audit, 2026-11-10 (push #3855, shard e3855-ui-react-01). Bounded reproduction attempt; no fix and no attribution is claimed.

    • Commit: epic-branch b71c6e4fe, plus test-only edits to the same file that do not touch the asserted path (see below).
    • Command: 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.
    • Result: answer-delivery-runtime stable, 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) became filter(...)).toEqual([]), so a stray frame is printed. Behaviour and waits are unchanged. Still unreproduced, so needs: repro stays.

  4. schlessera commented on Nov 13, 2026

    @schlessera
    OwnerAuthor

    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:

    Runs of the file Cases run Failures
    4 96 0

    Recurrence sweep. I read the failed-step log of every failed product job on main CI from 2026-10-28 to 2026-11-13: 84 jobs across 300 runs. card says Answered only after the host's receipt appears 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.

  5. schlessera commented on Nov 13, 2026

    @schlessera
    OwnerAuthor

    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):

    packages/ui-react/tests/answer-delivery-runtime.test.ts:
    541 |  expect(await page.evaluate(() => (window as unknown as { __answers: { cards(): number } }).__answers.cards())).toBe(1);
    error: expect(received).toBe(expected)
    Expected: 1
    Received: 2
    (fail) answer delivery in a real browser > ask_user: online, the card says Answered only after the host's receipt, and the backend gets it once [2436.43ms]
    

    What this adds.

    • A second sighting, a different question form. The first was ask_user_list; this is ask_user. The other three forms' online cases passed in the same run, as did the rest of the file (23 of 24).
    • The same shape. Lines 538 to 540 passed: one backend settlement, the expected result, and the card reading ANSWERED. Only the fixture's count of stored ask exchanges was 2.
    • It is not load. The one-minute load was between 2 and 3 on 4 CPUs when it failed. My isolated runs, which never failed, ran under more pressure (4 busy loops).
    • What differed is the process, not the machine. This file ran as part of one bun test over 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: repro stays.

  6. schlessera commented on Nov 14, 2026

    @schlessera
    OwnerAuthor

    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.

    1. A case ends and closes its browser context while the host still has that case's turn registered.
    2. The next case's page connects. With exactly one turn registered, the host's snapshot-on-connect announces that session to the new socket and then sends its history (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.
    3. The client keeps a history replay for a session it has no buffer for, and creates the buffer (if (msg.type === "session_history") return frameSessionId;, packages/ui-react/src/ws-client/inbound.ts:326).
    4. The fixture's 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_IDENTITY holds a finished turn, opens a fresh context and waits for cards() === 1 from 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 existing resultGate, then the online case's steps verbatim in a fresh context.

    Previous case's turn Frames the new socket gets before its own turn Buffers at the assertion cards()
    released 1.5 s before the next page connects server_hello, status own session only 1, passes
    still registered at connect, released just after server_hello, session_info, …, session_history, status odysseus-answers-1: toolu_ask_user_1; odysseus-answers-2: toolu_ask_user_2 2, fails

    The failing row is this issue's signature exactly:

    expect(await page.evaluate(() => (window as unknown as { __answers: { cards(): number } }).__answers.cards())).toBe(1);
    error: expect(received).toBe(expected)
    Expected: 1
    Received: 2
    

    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.

    • Request IDs, buffers, rendered count: above. Two request IDs, one per session buffer, one rendered card.
    • Does it persist? Yes, and correctly. The second buffer is the previous session's replayed history. It was still there at every sample until the case ended. Nothing is duplicated inside the case's own session.
    • Product or fixture? Fixture. The count spans sessions, and cases share one host without waiting for it to release the previous turn.

    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_IDENTITY connects 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, changed type: fix to type: test, added agent-ready.

  7. changed the title [-]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[/+] on Nov 14, 2026
  8. added
    type: test
    agent-ready
    and removed
    type: fix
    needs: repro
    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-reactpriority: p2type: test

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions