Skip to content

test(copilot): wait through a switch's 409 and scrollback answers, not read every answer as a transcript - #2385

Merged
devswha merged 2 commits into
mainfrom
test/copilot-switch-poll
Oct 29, 2026
Merged

devswha merged 2 commits into
mainfrom
test/copilot-switch-poll

Conversation

@devswha

@devswha devswha commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Found by the flake-hunt lane: server/copilot.contract.test.ts "reads a resumed CLI without marker or report and follows foreground switches rather than stale reports" failed with TypeError: undefined is not an object (evaluating '(await read()).turns[0]') in its switch polls three times in the 417 CI runs from 2026-10-28 03:26Z to 2026-10-29 18:22Z (jobs 122685036108, 122847698843, 123297359877), including after #2224. Each passed on a rerun.

Cause (test flake)

The Copilot stand-in logs a switch as two lines: Unregistering, then Registering. A conversation read resolves ownership, reads the page, and checks ownership again (server/conversation.ts, about lines 1682-1686). A read whose two checks straddle the switch rightly answers HTTP 409 {"error":{"code":"history_changed"}}, which has no turns. A read between the two lines rightly answers scrollback. The test's polls treated every answer as a conversation and read turns[0] off the 409 body.

Reproduced: a scratch spy appended a real Registering line during a read, forcing the straddle. The old test failed 3/3 with CI's TypeError, and the new one passed 3/3 while it saw the real 409s. A 400 ms gap between the two lines alone did not reproduce it (3/3 passed).

Change

  • read() returns nothing for a non-200 answer and keeps the last answer for the timeout message.
  • waitForTranscript(text, previousHistory?) waits for HTTP 200, source copilot-transcript and the expected first turn (and a new history_id when asked). Every switch poll uses it.
  • After the peer pane starts, both panes are polled until they fail closed to scrollback, rather than read once. herdr names the peer before it logs its own Registering line.
  • The sibling test "retries failed Copilot page reads only while fresh ownership and file generation still agree" waits for a 200 with a cursor before arming each injected read failure. It prints every answer it waits past.

Proof

These runs used CI's herdr 0.9.3 and Node 22, with checksum-verified binaries under the run's own tools directory. As #2224 notes, this file cannot run on herdr 0.9.5 with Node 24.

  • Fail-first: with the forced straddle, the old test failed 3/3 and the new one passed 3/3.
  • Plain runs of the whole file: the final head passed 4 of 5 runs, 5 tests each. Earlier heads passed 3 of 3 and 3 of 3.
  • The one failure is the separate finding below, in the sibling test.
  • Local checks: bun run check fast ok.

Test-only.

Not fixed here: the sibling test's cursor wait (reproduced, cause unknown)

The sibling test's last loop failed on CI twice (jobs 122661979002, 122801012396; before.cursor undefined, then line 448). Locally it failed once in five runs with the new wait. The server answered 200 {"source":"scrollback","turns":[]} for the whole 5 s after the transcript file was replaced and the session registered again.

A read-only analysis ruled out the timestamp cache and the generation map: a registration with identical timestamps is picked up at once. It could not name the cause, because ConnectionDiagnostics suppresses repeat failures for 30 s and the underlying ConversationUnavailable reason is never logged. The wait added here prints each answer it skips, so the next CI failure says what it saw. Because the wait only retries until a cursor shows, a real regression there still fails, now as a timeout with its answers printed.

Reviews

  • omo-native-code-reviewer: APPROVE (WATCH). Both MEDIUMs were taken.
    • MEDIUM-1: the peer's single scrollback read had the same startup race. It now polls both panes.
    • MEDIUM-2: the cursor wait could hide an unknown failure. It now prints every answer it waits past, and the test's own first read uses it too.
    • LOWs noted: two asserts after waitForTranscript repeat what it guarantees.
  • Test-only, so no Codex review (notes/pr-policy.md).

Second commit: the quit wait at line 320 (red on main)

"binds only the reported UUID to the foreground process's home and rejects old cursors after a switch" failed at :320 ("isolated fixture did not exit") on every main push since c5851e7 and on several PRs, #2385 itself included.

Cause: after :quit the test waited 10 s for herdr's agent label on the pane to stop saying copilot. The label is not the exit: the test itself reported the Copilot session for that pane (pane.report_agent_session, source herdr:copilot), and on the CI runner the label outlasted the 10 s. startFixture then waited on the same label for the next stand-in.

Change:

  • The test waits for the stand-in's own pid to leave the pane's foreground.
  • It then releases the session it reported (pane.release_agent, as Copilot's own hook would at its exit), waits for the label to go, and starts the next stand-in by its own process.
  • A timeout now prints the pid's state, the foreground, the label and its session, so CI says which signal never came.

Proof:

  • Local: on CI's herdr 0.9.3 and Node 22, the case passed 4/4, run as two pairs side by side in two checkouts, and the whole file passed 5/5.
  • Local checks: bun run check fast ok.
  • Not reproduced: the stuck label. Here herdr cleared it 150 to 320 ms after the exit, and a report repeated just after :quit did not hold it. So there is no local fail-first for that part, and this PR's CI run is the first real test of it.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 37 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8f84c26 and 8a44db5.

Files selected for processing: 2
  • changelog.d/copilot-switch-poll-readiness.md
  • server/copilot.contract.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…t read every answer as a transcript

A conversation read checks ownership before and after reading the page: one
whose checks straddle the stand-in's Unregistering/Registering lines answers
409 history_changed, which has no turns, and the switch polls read turns[0]
off it (TypeError, three times in 417 CI runs, also after #2224). Poll for an
HTTP 200 copilot-transcript answer with the expected first turn, keeping the
last answer for the timeout message; poll both panes to scrollback after the
peer starts; and have the read-retry test wait for a cursor before arming
each injected failure, printing every answer it waits past (that test's CI
failures had no logged cause).

Fail-first with a scratch spy forcing the straddle: old 3/3 TypeError, new
3/3 pass. Plain runs on CI's herdr 0.9.3 and Node 22: 4/5 at this head (the
fifth is the read-retry test's open finding); bun run check fast ok.
@devswha
devswha force-pushed the test/copilot-switch-poll branch from a00f156 to 28ea384 Compare October 29, 2026 20:25
…ease the session the test reported

"binds only the reported UUID ..." quit its stand-in and then waited for
herdr's agent label on the pane to stop saying copilot, with 10 s to do it.
The label is not the exit: the test itself reported the Copilot session for
that pane (report_agent_session, source herdr:copilot), and on the CI runner
the label outlasted the 10 s ("isolated fixture did not exit", every main
push since c5851e7 and several PRs), while startFixture then waited on the
same label for the next stand-in.

Wait for the stand-in's own pid to leave the pane's foreground, release the
session the test reported (pane.release_agent, as Copilot's hook does at its
exit), wait for the label to go, and start the next stand-in by its own
process. A timeout now prints the pid's state, the foreground, the label and
its session, so CI says which signal never came.

Local, on CI's herdr 0.9.3 and Node 22: the case passed 4/4 (two pairs side
by side in two checkouts) and the whole file 5/5; bun run check fast ok. The
stuck label itself did not reproduce here (herdr cleared it 150-320 ms after
the exit), so there is no local fail-first for that part.
@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Review of 8a44db5 (omo-native-code-reviewer): APPROVE (WATCH)

CI on this head: Integration tests pass. The line-320 case took 2389 ms (job 123739245177); it failed at 12.6 s before. The whole copilot file took 7.8 s.

The reviewer confirmed:

  • The server never calls report_agent or release_agent. The release undoes only the test's own herdr:copilot reports, the same way pending-input.contract.test.ts undoes its manual report.
  • The server behaviour under test is still asserted: stale IDs after the switch before the quit, and session B, the wrong header, the missing file and the symlink after the restart.
  • The argv match is exact (executable path and session ID).
  • The loops are bounded.

How each finding was resolved:

  • MEDIUM-1: the release sends no seq, and the untrusted-source report is never released.
    • Not pushed, because this CI run is green and a push restarts it. If the release ever does nothing, the case fails with "herdr still names the quit stand-in" and prints the session's source; it cannot pass falsely.
    • A follow-up adding seq is ready and kept for that case.
  • LOW-1: the not-exited error doesn't show the stand-in's unrecognized input. Kept in the same follow-up: the tail of input.txt in the error.
  • LOW-2: three 10 s waits under a 20 s case timeout. Kept in the same follow-up: a 45 s case timeout.
  • LOW-3: style (the /proc stat parse, and startFixture's error detail). Left as is.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merging 8a44db5. Test-only: server/copilot.contract.test.ts waits, with deadlines, through a switch's transient answers (a 409 while ownership changes, or scrollback) instead of reading each answer as the transcript, and fixes the case that failed main twice ('isolated fixture did not exit'): it now waits for the quit stand-in's own process to leave the pane rather than herdr's agent label (which can outlast it), releases the session the test reported as Copilot's hook would, and every timeout prints what it saw. Diff read by the merge pass; no CodeRabbit review needed.

@devswha
devswha merged commit d945786 into main Oct 29, 2026
20 checks passed
@devswha
devswha deleted the test/copilot-switch-poll branch October 29, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant