Skip to content

test(copilot): the stand-in quit deadlines carry herdr's agent events for the pane - #3924

Merged
devswha merged 2 commits into
mainfrom
test/copilot-contract-records-pane-events
Nov 15, 2026
Merged

devswha merged 2 commits into
mainfrom
test/copilot-contract-records-pane-events

Conversation

@devswha

@devswha devswha commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Change

When the Copilot stand-in quits in server/copilot.contract.test.ts, two deadlines follow. One waits for the stand-in to leave the pane ("isolated fixture did not exit"); the other waits for herdr to stop naming it ("herdr still names the quit stand-in"). Both errors now also carry the pane's agent events from herdr's events.subscribe, each with its time in ms from the quit (negative before it). In the runs read, herdr's log had no line for the stand-in's exit, but the pane's agent events did (below). So the next failure shows what herdr reported for the pane, which the log tail added in #3920 cannot show.

  • Where the recording opens. The test opens it at its start, long before the quit, and waits there for herdr's acknowledgement (bounded at 2 s, an early-resolving bound, not a fixed sleep). It covers pane.agent_detected (kept for this pane) and pane.agent_status_changed for this pane.
  • When it ends. It closes after the label assertion, or through onTestFinished when the test ends any other way.
  • The quit is placed exactly as on main. :quit follows the foreground-process check at once. Between the two, only const quitAt = performance.now(); was added; nothing is awaited there. (Diff of that span against main: 2a3 > const quitAt = performance.now();.) The flake's cause is unknown and timing-shaped, so a wait there could hide it.
  • First line of the recording. herdr's acknowledgement is recorded as the first line, with its (negative) time. A failure's message therefore shows that the recording covered the quit.
  • Heading. The recording's heading says that events arrive on herdr's poll, so the latest may be missing; an empty or short recording is not proof of absence.
  • Diagnostic only. The recording never fails or passes the test. A subscription error, or herdr closing it, becomes a line. No assertion and no timeout changed.
  • Comments. The log tail's doc comment, the recorder's, and the comment before the quit now state only what was observed in the runs read. They make no claims about herdr's internals.
  • Why a dedicated connection. The test file had no subscription of its own. The bridge's subscription lives inside the server's collector and is not reachable from a test, so this opens one with subscribeEvents, as the omp, api and opencode-prompt contract tests do.

Recorded lines

Forced failure: a scratch copy of the file (not committed) with the label deadline forced to expire. The whole file was run the CI way: bun scripts/check.ts run, HERDR_TEST_MODE=integration, --timeout 15000, Node 22.23.3, herdr 0.9.3, an isolated session. The test threw at 528 after 11.80 s, inside its 20 s timeout:

error: herdr still names the quit stand-in: {"pid":2835152,"state":"gone","front":[[2835139,["/bin/bash","--noprofile","--norc"]]],"status":"unknown"}; pane.release_agent answered {"type":"ok"}
herdr agent events for w2:p1, ms from the quit (they arrive on herdr's poll: the latest may be missing):
-1711 herdr acknowledged the subscription
320 pane_agent_detected {"agent":"copilot","final_status":"idle","pane_id":"w2:p1","released":true,"type":"pane_agent_detected","workspace_id":"w2"}
621 pane.agent_status_changed {"agent_status":"unknown","pane_id":"w2:p1","workspace_id":"w2"}
herdr log:
...

On a passing whole-file run of the previous commit (a61f4ff, same run setup), a printing scratch copy recorded 201 pane_agent_detected {... "released":true ...} for the quit stand-in. herdr sent no event for this pane before the quit in any of these runs, which is why the only negative line is the acknowledgement.

Why these events, from herdr's source (read from herdr v0.9.3, not verified by the reviewer)

  • The exit is not logged. An exit is reported with ReportProcessExit, which returns changed = false (src/pane.rs:504-507). agent changed is logged only under if changed (src/pane.rs:2917).
  • The exit does emit an event. A process exit sets agent_released (src/terminal/state.rs:384), and emit_pane_state_update emits pane.agent_detected with released (src/app/api.rs:665).
  • Delivery lags. Subscription events go out on a 100 ms poll (CONNECTION_POLL_INTERVAL, src/api/server.rs:29 and 953). In a passing run the test may see the label go before the event arrives.
  • No pane filter. pane.agent_detected takes no pane filter in its subscription (src/api/subscriptions.rs:158), so the handler keeps only this pane's.
  • A lost delivery is logged. An undelivered state change logs failed to deliver StateChanged event (src/pane.rs:266).
  • A delivered exit is always applied for Copilot. Both early returns in set_detected_state_with_screen_signals_at require !process_exited (src/terminal/state.rs:850 and 414).

What a failing run will now show

  • herdr's detection never reported the exit. No "released":true line after the quit, and no failed to deliver StateChanged event warning in the log tail.
  • The exit was reported but not delivered to the pane's state. That warning appears in the log tail.
  • The exit was applied and the label came back. A "released":true line, then a later pane_agent_detected naming copilot without "released":true, at its time from the quit.

The deadline at 523 carries the same recording.

Review points answered

  • The quit's placement (t87). As above: nothing is awaited between the foreground-process check and :quit.
  • dori's LOW on the 2 s wait. The subscription's set-up and its 2 s bound now happen at the test's start, so they no longer come out of the time after the quit.
  • dori's LOW on the empty recording. The heading of every recording says that events arrive on herdr's poll and the latest may be missing.
  • The test timeout. No timeout was raised. The early wait can cost at most 2 s at the start of a test with a 20 s timeout; nothing asserts on it. The LOW on test(copilot): the stand-in quit deadlines say what herdr logged #3920 about the 20 s timeout (a stand-in that left only near the end of the first 10 s deadline) stands as it was; this change adds no time after the quit.

Validation

  • server/copilot.contract.test.ts at 3706fcf, the whole file, 10 times the CI way in a 2-core heavy slot (~/.ovis-toolchain/heavy-run.sh; Node 22.23.3, herdr 0.9.3): the test this PR changes passed 10/10 (2.27 to 2.54 s). 9 runs passed all 8 tests. In one run (w2), another test failed: "retries failed Copilot page reads only while fresh ownership and file generation still agree", Copilot cursor was not ready: 200 {"source":"scrollback","turns":[]} at line 631. Its stand-in (pane 7) was detected at 19:13:19.794, then pane 7 and pane 2 were both re-detected from None at 19:13:20.405, and the cursor never became ready within its 5 s. That test also failed on CI on 2026-11-12 (job 131032697803, at another assertion) before this PR existed. The recording in this PR is closed when the previous test ends, so it is not open during that test. I count it as a separate flake and did not look into it further.
  • Lint (this repo's lint is the conventions tests): HERDR_TEST_MODE=unit bun test server/conventions.test.ts: exit 0.
  • bun run typecheck: exit 0.
  • bun run check fast on 3706fcf: exit 0.
  • Forced failure (scratch copy, not committed): above.
  • Not run: bun run check full. The flake itself was not reproduced; this PR changes only what its next failure prints.

… for the pane

The two deadlines after the Copilot stand-in quits now carry the pane's
agent events from herdr's events.subscribe (pane.agent_detected and
pane.agent_status_changed), recorded from before the quit until the
assertion ends, each with its time from the quit. herdr 0.9.3 reports a
process exit with no log line; it does emit pane_agent_detected with
"released":true, so a failure now shows whether herdr ever reported the
exit, and whether the label came back after it.

The log tail's doc comment no longer says the log tells why an agent was
kept or dropped: it shows detection changes and warnings, not an exit.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved diagnostics for agent exit-detection test failures by capturing relevant events and logs.

The quit contract test now records pane agent-detection and status events while checking process exit and agent-label removal. If either check times out, the test includes the event timeline with pane state and herdr logs.

Changes: Quit Detection

Layer / File(s) Summary
Capture events during quit detection
server/copilot.contract.test.ts
The test subscribes to matching pane events before sending the quit command. Timeout errors include the recorded event timeline, pane state, and herdr logs. A finally block closes the subscription.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: yuuuxie

Merge Risk: Minimal · previous review a61f4

This change adds extra diagnostics to a contract test and does not alter production behavior or test assertions. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the test change and the subject of the change: the stand-in quit deadlines now include herdr agent events for the pane. The raw summary and objectives confirm the change adds pane agen…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template. It has a Change section that explains the problem, the new diagnostic output, the recording lifecycle, and why the test uses a dedicated connection. It…
Full details: Title check

Explanation

The title names the test change and the subject of the change: the stand-in quit deadlines now include herdr agent events for the pane. The raw summary and objectives confirm the change adds pane agent-detection and status event recording to the quit deadline errors. The title is specific and matches the main change, though it is slightly long at 82 characters and somewhat awkwardly phrased.

Full details: Description check

Explanation

The description follows the repository template. It has a Change section that explains the problem, the new diagnostic output, the recording lifecycle, and why the test uses a dedicated connection. It also has a Validation section that lists the checks run (conventions test, typecheck, check fast, whole-file contract test runs, and a forced-failure scratch run) and states that check full was not run. The description is detailed and specific. The template asks for a linked issue for features; this is a test diagnostic change, so that requirement does not apply strictly. The description cites PR #3920 and dori's review points but does not link a tracking issue for the flake.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6127e39 and a61f4ff.

Files selected for processing: 1

  • server/copilot.contract.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

…where main quits

The subscription that records the pane's agent events now opens at the
start of the test and is acknowledged there, long before the quit; it
closes after the label assertion, or when the test ends. :quit follows the
foreground-process check at once again, as on main: only the quit's time
is taken between them, so the recording adds no wait at the moment the
flake is timing-shaped. herdr's acknowledgement is the recording's first
line, before the quit.

The comments now say what was observed in the runs read rather than
herdr's internals, and the recording's heading says that events arrive on
herdr's poll, so the latest may be missing.
@devswha
devswha merged commit 016cb60 into main Nov 15, 2026
21 of 22 checks passed
@devswha
devswha deleted the test/copilot-contract-records-pane-events branch November 15, 2026 19:46
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 3706fcf22c69 as 016cb6084e1b on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: the owner's test-only pull request (one file, server/copilot.contract.test.ts): one reviewer by facts.md.

Merge pass note for #3924 at 3706fcf (test-only, one file: server/copilot.contract.test.ts).

One reviewer (Codex, by the skill's rule for the owner's test-only pull request), two rounds. Round one asked for one change: the subscription that records herdr's agent events was opened and awaited right before the stand-in's quit, which could hide the timing flake it is meant to catch. At this head it opens on the test's first line, and between the foreground check and the send of ":quit" the only added line is const quitAt = performance.now(); (checked side by side against main).

Diagnostic only: no assertion or deadline changed against main. Left open, as notes:

  • the wait for the subscription's acknowledgement (up to 2 s) still comes out of the test's unchanged 20 s timeout; on passing runs the test ends in about 2.1 to 2.5 s (seven green CI jobs and ten local runs, the author's reading), so it cannot matter there; the author raises the timeout by the 2 s in its next change to the file, for the failing path;
  • the failure message says events arrive on herdr's poll; the recording alone does not show that;
  • whether an extra subscriber changes herdr's behaviour for the pane is not known from this repository.
    The cause of the flake stays UNKNOWN; this change only makes the next failure say more. A different test of the same file failed once in ten of the author's runs and had failed on CI on 2026-11-12, before this pull request.

devswha added a commit that referenced this pull request Nov 15, 2026
…and the recording says only that later events may not have arrived (#3927)

## Change

Two changes to one test in `server/copilot.contract.test.ts`, "binds
only the reported UUID to the foreground process's home and rejects old
cursors after a switch". Both were asked for by the merge pass on #3924.
No deadline and no assertion changed.

- **Timeout 20 s -> 30 s.** The test's worst failing path is the 2 s
wait for herdr's acknowledgement at its start (since #3924), then what
the test does before the quit, then the two 10 s deadlines after the
quit. On that path the test's own 20 s timeout fired before the
deadline's error, and that error carries the recording.
- **The recording's heading.** It said events "arrive on herdr's poll",
which the recording itself does not show. It now says only `(later
events may not have arrived yet)`.

### The arithmetic

| Part | Time |
|---|---|
| wait for the acknowledgement (its bound) | 2.0 s |
| test start -> `:quit`, measured on passing runs (a printing scratch
copy, the CI way, three whole-file runs) | 1.64 / 1.83 / 1.69 s, taken
as 1.9 s |
| first deadline (the stand-in leaves the pane) | 10.0 s |
| second deadline (herdr stops naming it) | 10.0 s |
| **sum** | **23.9 s** |

On top of that sum, each deadline needs one more loop turn (an RPC and a
50 ms sleep) and the error itself needs two RPCs and a log read. The
forced run below took 23.88 s, which matches the sum. At 20 s the
timeout fired 3.9 s early. 30 s leaves about 6 s for a slower runner,
and it is the timeout the test just above this one in the same file
already uses. Passing runs are unaffected: 2.04 to 2.61 s in the ten
runs below.

### Forced failure, before and after

A scratch copy of the file (not committed) changes three things. The
acknowledgement is held back, so the full 2 s bound runs out. The first
deadline's loop keeps waiting until 50 ms before its deadline, so the
stand-in leaves only at the end of the first 10 s. The second deadline's
condition is forced to stay true, so that deadline expires. Each run was
the whole file, the CI way, in a 2-core heavy slot (Node 22.23.3, herdr
0.9.3).

**After (this branch):** the test fails with the deadline's error and
its recording after 23.88 s, inside the 30 s timeout:

```text
error: herdr still names the quit stand-in: {"pid":4027051,"state":"gone","front":[[4027043,["/bin/bash","--noprofile","--norc"]]],"status":"idle"}; pane.release_agent answered {"type":"ok"}
herdr agent events for w2:p1, ms from the quit (later events may not have arrived yet):
-3893 herdr acknowledged the subscription (scratch: held back, not settled)
-1894 herdr did not start the subscription within 2 s
124 pane_agent_detected {"agent":"copilot","final_status":"idle","pane_id":"w2:p1","released":true,"type":"pane_agent_detected","workspace_id":"w2"}
herdr log:
...
(fail) binds only the reported UUID to the foreground process's home and rejects old cursors after a switch [23885.76ms]
```

**Before (main's file, same forcing):** the test failed on its own
timeout. The deadline's error came about 4 s later, as an "Unhandled
error between tests" printed after later tests had already started, so
it was attributed to no test:

```text
(fail) binds only the reported UUID to the foreground process's home and rejects old cursors after a switch [20000.27ms]
  ^ this test timed out after 20000ms.
...
# Unhandled error between tests
error: herdr still names the quit stand-in: {"pid":3993307,"state":"gone","front":[[3993302,["/bin/bash","--noprofile","--norc"]]],"status":"unknown"}; pane.release_agent answered {"type":"ok"}
herdr agent events for w2:p1, ms from the quit (they arrive on herdr's poll: the latest may be missing):
...
 7 pass
 1 fail
 1 error
```

The brief's literal forcing (only the acknowledgement held back and the
second deadline forced; the stand-in leaves at once) ends in the
deadline's error on both files, after 13.62 s on main and 13.59 s here.
That path never reached 20 s, so it was not the one at risk.

## Validation

- `server/copilot.contract.test.ts`, the whole file, at 45f5e5c1c (this
commit on 016cb60; the branch was then rebased onto c9084e0, whose
#3923 touches only install and plugin-launcher files, so the test file
and everything it imports are the same), run 10 times the CI way in a
2-core slot of `~/.ovis-toolchain/heavy-run.sh`
(`HERDR_TEST_MODE=integration bun scripts/check.ts run bun test
--timeout 15000 ./server/copilot.contract.test.ts`, Node 22.23.3, herdr
0.9.3): **10/10 runs passed all 8 tests**. The changed test took 2.04 to
2.61 s. "retries failed Copilot page reads..." passed in all ten runs.
- Forced failure before and after, plus the timing measurement: scratch
copies, not committed (above).
- `bun run typecheck`: exit 0.
- Lint (the conventions tests): `HERDR_TEST_MODE=unit bun test
server/conventions.test.ts`: 16 pass, exit 0.
- `bun run check fast` (in the heavy slot): exit 0 at 45f5e5c1c (530 s;
local Node v24.18.0, with the check's warning that CI uses Node 22), and
exit 0 again at the rebased head 0fc2a54 (517 s).
- **Not run:** `bun run check full`, the browser lanes, and the other
integration files. This change touches only one test file's timeout and
one message string.
devswha added a commit that referenced this pull request Nov 16, 2026
…ilot, and two self-started herdrs keep their sockets in /tmp (#3932)

Three integration files fail on a host with Node 24, or with a deep
TMPDIR, though CI (runner image: herdr 0.9.3, Node 22, TMPDIR=/tmp)
passes them. herdr's version is not the cause: the runner image with
only its herdr swapped for 0.9.5 passes them. This changes the tests
only.

### `server/copilot.contract.test.ts`: on Node 24 only, the stand-in
takes the name `copilot`
herdr takes a `node <script>` process for the script's agent only while
the process is called `node` (`/proc/<pid>/stat` comm). Node 24 names
its main thread `MainThread`, so herdr never labels `node copilot.js`
there. `beforeAll` then fails with `isolated Copilot stand-in not
detected`.

The test now asks `node` once, before it writes the stand-in, what such
a process is called (`node -e` reading `/proc/self/comm`, Linux only, as
the fixture is). Where the answer is `node`, it writes main's stand-in
unchanged. Otherwise it puts two lines before it: `import {
writeFileSync as nameStandIn } from "node:fs";` and
`nameStandIn("/proc/self/comm", "copilot");`. That gives the process the
name `copilot`, as the real CLI's native binary has. Only the name
changes: the command line stays as typed. `process.title` would have
overwritten the command line, and the test and the product read it. The
handoff child runs the same file. herdr 0.9.3 and 0.9.5 label a renamed
stand-in 257-260 ms after it is typed (5 runs each on Node 22 and Node
24), well inside the test's 10 s wait.

Earlier heads of this PR first used `exec -a copilot` in a subshell
(bash only, and it changed the fixture on CI), then a check of
`/proc/self/comm` inside the stand-in (an extra read on CI). This head
drops both.

### `scripts/phone-setup.contract.test.ts` and the bridge test in
`server/compiled-server.contract.test.ts`: herdr's sockets go in `/tmp`
Both tests start a herdr whose session directory is under `tmpdir()`.
The longest socket, `herdr-client.sock`, is 111 bytes under
`~/.cache/ovis-tmp/<name>/tmp/...` (the TMPDIR AGENTS.md asks for on the
maintainer's PC) and 128 bytes for the phone test. herdr then exits at
start with `local socket name length exceeds capacity of sun_path of
sockaddr_un` (herdr 0.9.3 and 0.9.5 alike). The tests saw `Phone QA
server did not start`, or a bridge whose `/api/health` answered 502 or
whose `remote --discover` returned `[]`.

Their herdr config now lives in `/tmp`, as
`server/reattach.contract.test.ts` already does. Phone setup's root is
removed in `onTestFinished`, so an assertion that fails before the `try`
leaves no folder behind. The bridge test's home is removed in
`afterAll`, after the bridge has exited.

### What this does NOT change
- On CI (Node 22) the Copilot stand-in file is main's, byte for byte,
and it is launched with main's line: no subshell, no renaming, no extra
read. I took the stand-in each test wrote during a real run of the whole
file in `herdr-ci-runner:local` as is (Node 22.23.3, herdr 0.9.3), from
main f6ad182 and from this head:
  ```
  $ cmp main-node22.js head-node22.js && echo identical
  identical
d79b625bbd53204f5c0f08298423b9e0e511a560fa6461f153e3ba7f7a1c1d04
main-node22.js
d79b625bbd53204f5c0f08298423b9e0e511a560fa6461f153e3ba7f7a1c1d04
head-node22.js
main-node22: comm=node cmdline=node <root>/copilot.js
12aa83d8-48bc-41f2-a498-7055c5c44a01
head-node22: comm=node cmdline=node <root>/copilot.js
12aa83d8-48bc-41f2-a498-7055c5c44a01
  ```
`startFixture`'s launch line (`COPILOT_HOME=${home} node ${executable}
${session}...`), the `:quit` handler and the handoff child's spawn are
unchanged from main. So the quit flake at about :528 stays observable on
CI, the agent events #3924 records describe the same fixture, and
herdr's `node <script>` detection of Copilot stays exercised there.
- With Node 24 in the same image, main's stand-in (the same file, sha256
`d79b625b...`) runs as `comm=MainThread`, and the file fails. This
head's (`469d7e7b...`, main's plus the two lines) runs as `comm=copilot`
with the same command line, and the file passes.

## Validation
Each file runs alone the CI way: `env CHECK_DIR=$PWD/.ci/h bun run check
run -- env HERDR_TEST_MODE=integration bun test --timeout 15000
./<file>`. Runs went through `~/.ovis-toolchain/heavy-run.sh` (2-core
slots). Container runs used `herdr-ci-runner:local` as its runner user,
with the local merge gate's flags.

This head:

| Where | copilot.contract (whole file) | compiled-server.contract |
phone-setup.contract |
|---|---|---|---|
| image as is (herdr 0.9.3, Node 22) | 10/10 | - | - |
| image + Node 24 only | 5/5 | - | - |
| host (herdr 0.9.5, Node 24, the long TMPDIR
`~/.cache/ovis-tmp/<name>/t`) | 5/5 | 5/5 | 5/5 |

Time of "binds only the reported UUID to the foreground process's home
and rejects old cursors after a switch" (the test holding the quit
deadline):

| Where | runs | min | median | max |
|---|---|---|---|---|
| main 9de1a32, image as is | 5 | 2.08 s | 2.28 s | 2.32 s |
| this head, image as is | 10 | 1.93 s | 2.34 s | 2.91 s (one run; next
highest 2.58 s) |
| this head, image + Node 24 | 5 | 1.94 s | 2.22 s | 2.43 s |
| this head, host | 5 | 2.08 s | 2.38 s | 2.44 s |
| earlier heads, image as is | 15 + 10 | 1.98 s | 2.35 / 2.34 s | 2.75 /
3.07 s |

The image and host runs of this head ran at the same time, in two slots.

Before this PR (main): host 0/2 for each of the three files, image +
Node 24 copilot 0/2.

- `bun run check fast` (host, through heavy-run.sh, on this head): exit
0. Workflow syntax, generated types and themes, typecheck, build and
unit tests (482 s) all `ok`.
- Skipped: the full integration suite and the browser lanes (only these
three test files change), macOS.

Not changed here: `server/reattach.contract.test.ts` fails on the
maintainer's PC only, because `~/.local/bin/herdr` there is a guard
script that execs `herdr-real`, and the test's `pgrep '^[^ ]*herdr
terminal attach'` does not match that name. That is the PC's wrapper,
not the test.
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