Skip to content

test(copilot): the stand-in quit deadlines say what herdr logged - #3920

Merged
devswha merged 1 commit into
mainfrom
test/copilot-contract-release-explains-itself
Nov 15, 2026
Merged

devswha merged 1 commit into
mainfrom
test/copilot-contract-release-explains-itself

Conversation

@devswha

@devswha devswha commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Change

server/copilot.contract.test.ts sometimes fails at its post-quit deadline ("herdr still names the quit stand-in", main runs 43740263064 and 43697933558, also on an idle runner). The quit stand-in is gone and bash is in front, but herdr still labels the pane copilot, with status idle and the reported session still attached, 10 to 14.7 s after the quit. The message did not say why. This change makes the next failure explain itself, and fixes nothing it cannot prove.

  • Both deadlines after the quit (the stand-in leaving the pane and herdr dropping its label) now append the test herdr's own log (herdr-server.log beside the session socket), its last 25 lines without the per-request ones. That log records herdr's detection transitions for the pane (agent changed ...). It cannot show the exit itself: herdr 0.9.3 publishes a process exit without logging it (ReportProcessExit returns changed = false, src/pane.rs:504-507, and agent changed is logged only under if changed, src/pane.rs:2917). A passing run, in CI and locally, therefore logs no previous_agent=Some(GithubCopilot) agent=None for this pane; only the next stand-in's Some→Some replacement appears. (Corrected after review: an earlier version of this text called that agent=None line herdr seeing the exit, which was wrong.) The label deadline also gives the answer of pane.release_agent.
  • The comment before the quit said the release forgets the reported session. In herdr 0.9.3 it does not. pane.release_agent from herdr:copilot answers {"type":"ok"} and is ignored: AppEvent::HookAgentReleased returns no update for an official source (is_official_agent_source, src/app/actions.rs at v0.9.3). Only herdr's detection of the process exit drops the label and that session. The comment now says so. The call stays, as the release Copilot's own hook sends.

What was found while looking for the cause:

  • The release does nothing for this pane, checked live on herdr 0.9.3. Sent while the stand-in ran, it answered ok and changed neither the label nor the session. With the release removed, the test passes, and the label and session leave together 88 to 264 ms after the quit, when herdr's detection reports the exit. Sending the release again on each poll (proposed earlier) would therefore change nothing.
  • Hypotheses forced on purpose did not reproduce the failure:
    • A late pane.report_agent_session for the quit session, right after the exit, did not hold the label.
    • herdr's detection-manifest auto-update was forced to land in the gap between the exit and herdr's next detection tick. It resets each copilot pane's detection loop, normally about 10 s after a fresh server starts. The forcing used a fake curl and an exit hook in the stand-in through NODE_OPTIONS, delayed 0, 30, 60 and 120 ms; the test file itself was not modified. The reset reached the pane and the label still cleared. So the cause stays unknown, and there is no fix here.

Validation

All runs used Node 22.23.3 and the pinned herdr 0.9.3, each on its own isolated herdr session (bun scripts/check.ts run, HERDR_TEST_MODE=integration, --timeout 15000).

  • server/copilot.contract.test.ts with this change, 10 times unforced the CI way, in a 2-core heavy slot (commit 144a872c, before rebasing onto 6750f40; same file): all 8 tests passed every time (15.7 to 17.8 s per file). One of the ten exited 1 only because check.ts reported "source changed during the check" (the commit was made while it ran). One more run on the rebased head 180a9e6: pass.
  • Both new messages checked by failing each deadline on purpose in scratch copies of the file (not committed): each printed the state, the release answer (label deadline only) and the filtered herdr log tail.
  • Before this change: the unmodified file passed under every forcing above. The failure at 528 has not been reproduced locally, so there is no forced before/after pair.
  • bun run check fast on 180a9e6, Node 22.23.3, in a heavy slot: exit 0.
  • Skipped: bun run check full (test-only change to one integration file).

When herdr still names the quit Copilot stand-in (or the stand-in never
leaves the pane), the error now carries the test herdr's own log tail,
without its per-request lines, and the answer of pane.release_agent.

herdr 0.9.3 answers a release from herdr:copilot and ignores it: only its
detection of the process exit drops the label and the reported session.
The comment that credited the release with forgetting the session says so.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved timeout diagnostics in contract tests by including recent server log output and the agent-release response.
    • Updated test comments to clarify how process exit is detected.

The contract test adds a helper that reads recent herdr log lines. Timeout diagnostics now include the log tail, and the agent-label timeout includes the response from pane.release_agent. Comments describe herdr’s process-exit detection.

Changes: Copilot contract test diagnostics

Layer / File(s) Summary
Log-tail timeout diagnostics
server/copilot.contract.test.ts
The test reads the last 25 nonempty herdr log lines, excluding per-request API entries. Both timeout errors include the log tail. The agent-label timeout also includes the pane.release_agent response. Comments describe process-exit detection as the mechanism that drops the reported session label.

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

Change: Other

Suggested reviewers: yuuuxie

Merge Risk: Minimal · up to 180a9

This adds extra diagnostic output to a test's timeout messages and does not change production behavior. The only remaining uncertainty is how useful the log tail will be when the test fails.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the test change (copilot contract test) and the diagnostic purpose, which matches the PR: both post-quit deadlines now include the herdr log tail and the release response. It is specif…
Description check Passed The description follows the template's two sections, Change and Validation. The Change section states the problem, the resulting behavior, and the herdr 0.9.3 findings. The Validation section lists th…
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.
Full details: Title check

Explanation

The title names the test change (copilot contract test) and the diagnostic purpose, which matches the PR: both post-quit deadlines now include the herdr log tail and the release response. It is specific and concise, though it is somewhat indirect about the mechanism.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section states the problem, the resulting behavior, and the herdr 0.9.3 findings. The Validation section lists the commands run, Node version, runs, and skipped checks, and it covers the test-only scope. No linked issue is given, but this is a test-only diagnostic change, so the template's feature-issue requirement does not apply. The template's changelog reference is not addressed, and the PR does not say whether a changelog.d entry is needed.

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 6750f40 and 180a9e6.

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; 6 remain after this review.

@devswha
devswha merged commit 6127e39 into main Nov 15, 2026
21 checks passed
@devswha
devswha deleted the test/copilot-contract-release-explains-itself branch November 15, 2026 18:39
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 180a9e68e25c as 6127e3926da5 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: test-only.

Test-only, one file: server/copilot.contract.test.ts. It does not fix the failure at line 528 ("herdr still names the quit stand-in") that turned main red once on 2026-11-16; it makes the next one explain itself: the errors at the two quit deadlines now carry the tail of the test herdr's server log and the answer of pane.release_agent, and a wrong comment is corrected. The cause was established from the failing run's own herdr log: herdr 0.9.3 did not detect the stand-in's exit for at least 22 s on an idle runner, and a release from herdr:copilot is ignored though it answers ok, so re-sending it would do nothing. Until herdr is looked at, a red line 528 on main is that miss: rerun the job. The one review read the change and did not run it.

Review reports: ~/.cache/ovis-tmp/reports/

@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

A correction to the merge comment above. It said the cause of the failure at line 528 was established from the failing run's herdr log (herdr not detecting the stand-in's exit, and a release from herdr:copilot being ignored). That inference does not hold: a PASSING run's herdr log lacks the same line, and there the label is gone within half a second of the release with nothing logged. What stands: two failing runs on main in which the label was kept for more than 10 s, cause unknown. This pull request is unaffected: it only adds the log tail and the release's answer to the error, which is what the next failure needs. Until the cause is known, a red line 528 on main is treated as that flake: the failed job is rerun.

devswha added a commit that referenced this pull request Nov 15, 2026
… for the pane (#3924)

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

```text
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 #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.
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