Skip to content

test(copilot): a stand-in's command is done once it is also at rest again - #3602

Merged
devswha merged 1 commit into
mainfrom
test/copilot-contract-flake
Nov 10, 2026
Merged

devswha merged 1 commit into
mainfrom
test/copilot-contract-flake

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Why

server/copilot.contract.test.ts "reads the live API without a report, follows warm switches, and fails closed on API loss or conflicts" failed once on a GitHub-hosted Integration run (42814392706, attempt 2): expected copilot-transcript, received scrollback, after 1683 ms, green on the rerun. #3189 was the same failure at another read of this test.

The stand-in Copilot acknowledges each :api-* command on its main thread with a temp write and a rename. The acknowledgement is visible to the test before that rename has returned, and the rest of the rename can wait on the disk (process state D). herdr reads no argv from a process in that state (process_state_allows_remote_memory_read, the same in herdr 0.9.3 to 0.9.5), and the server takes two argv-less answers in a row as no Copilot in front (copilot_process_set_unproved) and answers from the terminal. command() returned as soon as the acknowledgement showed, and the test asserts on one read.

What

command() leaves its existing loop when the acknowledgement shows and the stand-in's main thread is asleep in its event loop again (state S in /proc/<pid>/stat). The deadline (4 s) and the step (20 ms) are unchanged; no sleep, retry or assertion was added, changed or removed. Test-only; the test is Linux-only already.

Proof

In the CI runner image (herdr-ci-runner:local, herdr 0.9.3), with the temp folder on ext4 (the image's /tmp is tmpfs, where fsync never waits):

Run Result
main + a scratch patch that keeps the stand-in in write+fsync for 400 ms after its :api-allow acknowledgement 20 of 20 fail at CI's assertion, with copilot_process_set_unproved
this branch + the same patch 20 of 20 pass
main + the stand-in equally long busy on the CPU instead (state R) 20 of 20 pass: the failure needs the disk wait, not slowness
main + the peer's stand-in held the same way 9 of 10 fail (the conflict read answers the transcript)
this branch + the same 10 of 10 pass
unforced, asking herdr as soon as an acknowledgement shows, 20000 rounds 8 first answers without argv, 4 without argv twice
unforced, asking once the stand-in is at rest, 20000 rounds 0

Not shown: that the CI instance itself was copilot_process_set_unproved. Its log has one failure line per pane per 30 s, so the fallback at the failing read was not printed; this is the only fast, transient scrollback answer that could be produced at that read. The unforced failure of the whole test was not seen here (0 of 40 on main).

Validation

  • bun run check fast: pass on this head (14804 unit tests pass, 0 fail).
  • bun run check run -- env HERDR_TEST_MODE=integration bun test --timeout 15000 ./server/copilot.contract.test.ts in the CI runner image: 25 of 25 green with the temp folder on tmpfs, 15 of 15 on ext4 (8 pass, 0 fail each).
  • The forced runs above.
  • Skipped: the rest of the integration suite and the browser suites (one integration test file changed, no product code). No changelog fragment: nothing a user notices.

Not in this PR

  • Product: a Copilot whose main thread waits on the disk across both asks falls back to the terminal for one refresh (copilotTranscriptPath, server/conversation.ts). It fails closed.
  • Product: a peer pane is asked once, so a peer in a disk wait gives no claim and a session conflict is missed for one read (gatherPeerClaims). fix(copilot): a herdr answer without Copilot's argv is asked again, not taken as Copilot gone #3189 listed it as a follow-up. For both, the server could read /proc/<pid>/cmdline itself when herdr lists a process without argv, as server/copilot-foreground.ts already does.
  • Test: startFixture returns on herdr's label, not on the stand-in's own "fixture ready" line. Today the label comes 420 to 610 ms after the stand-in is ready, so the reads right after it are covered by that margin only.

🤖 Generated with Claude Code

…gain

The stand-in acknowledges each :api-* command with a temp write and a rename on its main thread.
The acknowledgement shows before that rename has returned, and the rest of the rename can wait on
the disk (state D). herdr reads no argv from a process in that state, and the server takes two
such answers in a row as no Copilot in front, so the read right after an acknowledgement could
answer scrollback (run 42814392706). command() now leaves its loop when the acknowledgement
shows and the stand-in's main thread is asleep in its event loop.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved foreground API test reliability by waiting for both the expected acknowledgement and the fixture process to become idle, with a timeout if either condition is not met.

The foreground API contract test now waits for both the expected acknowledgement and the fixture process to reach Linux /proc state S. The wait times out after four seconds if either condition is unmet.

Changes: Foreground API test

Layer / File(s) Summary
Acknowledgement and process wait
server/copilot.contract.test.ts
The test adds an atRest check for process state S. The command helper waits for that state and the expected acknowledgement, and updates its timeout error.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Possibly related PRs

  • devswha/ovis#2666: Adds the foreground API and its stand-in contract test, which this change updates.

Suggested reviewers: yuuuxie

Merge Risk: Minimal · up to afb7f

The Linux test now waits for acknowledgement and a sleeping process. No merge-blocking risk is established.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly describes the test change: wait for the stand-in to return to rest before treating its command as complete.
Description check Passed The description explains the problem and resulting behavior, and reports validation results, contract-test coverage, and skipped suites. Its Why and What sections provide the required Change informati…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Description check

Explanation

The description explains the problem and resulting behavior, and reports validation results, contract-test coverage, and skipped suites. Its Why and What sections provide the required Change information.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
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 00284cd and afb7f33.

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 commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate: FAIL

Local merge gate: FAIL #3602 merge=d0ff8fd9abfe head=afb7f3385beb main=4fb64e692c1f on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 in 494s, reruns=1

The Linux suites of the required checks (Fast checks, Integration and browser), run on main 4fb64e6 with this PR's head afb7f33 merged in (local merge d0ff8fd9abfe, not pushed), as groups side by side in the self-hosted CI runner image on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 (30% busy before the start, host load 38.54; shards=4 unit_workers=8 browser_main_workers=2 browser_other_workers=16). Scope: full. Native Windows install and the macOS checks are not part of this gate.

Step Command Result Seconds Counts
fast-install bun install --frozen-lockfile pass 0 -
release-guards bun scripts/release-guards.ts --base 4fb64e692c1f pass 0 -
fast bun run check fast fail (exit 1) 170 tests 15008 pass / 2 fail; check steps 5 ok / 2 failed
integration-install bun install --frozen-lockfile pass 0 -
integration bun run check integration pass 202 tests 1389 pass / 0 fail; check steps 3 ok / 0 failed
browser-main-install bun install --frozen-lockfile pass 0 -
browser-main-build bun run build pass 10 -
browser-main BROWSER_SCRIPTS=ui-regression,ui-contexts-regression bun run check run -- bun scripts/ci-browser-parallel.ts pass 340 browser scripts 2/2 passed
browser-other-install bun install --frozen-lockfile pass 0 -
browser-other-build bun run build && bun run build:shell pass 14 -
browser-other BROWSER_EXCLUDE=<those two> bun run check run -- bun scripts/ci-browser-parallel.ts pass 471 browser scripts 202/202 passed

Reruns:

  • browser scripts/copilot-chat-browser-qa.ts failed, then passed on its automatic second run

Total 494s.

@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate: PASS

Local merge gate: PASS #3602 merge=d1dea685d23d head=afb7f3385beb main=4a563f715cc5 on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 in 512s, reruns=0

The Linux suites of the required checks (Fast checks, Integration and browser), run on main 4a563f7 with this PR's head afb7f33 merged in (local merge d1dea685d23d, not pushed), as groups side by side in the self-hosted CI runner image on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 (17% busy before the start, host load 65.70; shards=4 unit_workers=8 browser_main_workers=2 browser_other_workers=16). Scope: full. Native Windows install and the macOS checks are not part of this gate.

Step Command Result Seconds Counts
fast-install bun install --frozen-lockfile pass 0 -
release-guards bun scripts/release-guards.ts --base 4a563f715cc5 pass 0 -
fast bun run check fast pass 171 tests 15046 pass / 0 fail; check steps 6 ok / 0 failed
integration-install bun install --frozen-lockfile pass 0 -
integration bun run check integration pass 203 tests 1389 pass / 0 fail; check steps 3 ok / 0 failed
browser-main-install bun install --frozen-lockfile pass 0 -
browser-main-build bun run build pass 12 -
browser-main BROWSER_SCRIPTS=ui-regression,ui-contexts-regression bun run check run -- bun scripts/ci-browser-parallel.ts pass 335 browser scripts 2/2 passed
browser-other-install bun install --frozen-lockfile pass 0 -
browser-other-build bun run build && bun run build:shell pass 17 -
browser-other BROWSER_EXCLUDE=<those two> bun run check run -- bun scripts/ci-browser-parallel.ts pass 485 browser scripts 203/203 passed

Total 512s.

@devswha
devswha merged commit ac7b503 into main Nov 10, 2026
21 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head afb7f3385beb as ac7b503ddd21 on the local merge gate, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: owner's test-only PR: one contract test.

Test-only: one reviewer (Codex Terra), CLEAR. Fixes the copilot.contract flake seen on #3450's run.

@devswha
devswha deleted the test/copilot-contract-flake branch November 10, 2026 18:19
devswha added a commit that referenced this pull request Nov 10, 2026
…s no other test (#3604)

## Why

#3602's local merge gate failed Fast checks on two tests of
`server/machine-core-choice.test.ts` that its diff does not touch:
"chooses the PC's own core server: server error later" (`Expected:
"Bearer aaaa…"`, `Received: null` at the relay's check of the request's
token, with `GET - /api/health failed`) and, in its wake, "server error
after proof" (`Executable not found in $PATH: "ssh"`).

That test's relay stands on a port the system handed out (the server
under test takes one with port 0 for its tunnel) and checks the token of
every request it gets. The server under test never asks a tunnel for
`/api/health` without the token, so the request came from another
process.

`scripts/plugin.test.ts` was running beside it (51.7 s in that lane). It
took a port with port 0, let it go and handed it to `scripts/plugin.ts`
as `PORT`. The plugin asks that port for `/api/health`, with no token,
for as long as it waits for a server: seconds. Every other unit file's
servers are on ports the system hands out the same way, in the same
container, so one that was given the plugin's port got the plugin's
question.

Which process sent the request in the gate run is not in its log; the
plugin tests are the only ones found that ask a port they do not hold
for `/api/health` without a token.

## What

`scripts/quiet-port.ts`: a free loopback port outside the ports the
system hands out for port 0, so no port-0 server can be on it. The range
is read from the host (`ip_local_port_range`; where it cannot be read,
every port from 32768 up counts, which covers macOS and Windows), and
the port is picked from a stretch of at least a thousand that holds none
of them, from 20000 up when that fits. A process is never given the same
port twice. `scripts/plugin.test.ts` (four places) and
`scripts/plugin-phone.test.ts` hand the plugin such a port.

Test-only. No assertion, wait or timeout changed, and
`server/machine-core-choice.test.ts` still checks every request's token.

## Proof

In the CI runner image (`herdr-ci-runner:local`):

| Run | Result |
|---|---|
| `main`'s `machine-core-choice.test.ts` + one tokenless `GET
/api/health` sent to its relay during "server error later" (scratch
patch) | the gate's two failures with the gate's messages, `42 pass, 2
fail` |
| `main`'s plugin tests beside 4000 listeners that keep taking ports
with port 0 and letting them go | 9 tokenless `GET /api/health` arrived
at those listeners, on 2 ports; two plugin tests failed themselves
("starts at the same moment", their port taken by a listener) |
| this branch, the same listeners | 0 arrived; those two tests pass |

## Validation

- `bun run check fast`: pass on this head (15015 unit tests pass, 0
fail).
- `bun test ./scripts/quiet-port.test.ts ./scripts/plugin.test.ts
./scripts/plugin-phone.test.ts`: 56 pass on this PC.
- The listener runs above were made on the first commit; the second
changes only where the port is picked from (on this host and in the
image, 20000 to 32767).
- Skipped: `bun run check full`, the integration and browser suites (two
unit test files and a test helper, no product code). No changelog
fragment: nothing a user notices.
- In the bare container used for the listener runs, one plugin test
("run the release the app updated to as link") fails on `main` and on
this branch alike (`This PC is already in an Ovis account`); it passes
under `bun run check fast` and is not about ports.

## Not in this PR

- `scripts/windows-plugin.test.ts:180` takes its port the same way (it
runs on Windows only, in a job of its own).
- Tests that send one request to a port they just let go
(`server/push.test.ts:1208`, `server/bridge.test.ts:327`,
`server/ssh.test.ts:236`, `server/relay/direct.contract.test.ts:361`,
`scripts/check.test.ts:200`): one request within a moment of the
release, where the plugin asks for seconds.
- `server/updater.test.ts` has its own picker from #3590 (10000 to
19999, fixed); `quietPort()` stays above it wherever the host's range
allows.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
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