Repository navigation
test(copilot): a stand-in's command is done once it is also at rest again - #3602
Conversation
…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]>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Local merge gate: FAIL
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
Reruns:
Total 494s. |
Local merge gate: PASS
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
Total 512s. |
Merge passMerged head
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. |
…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]>
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): expectedcopilot-transcript, receivedscrollback, 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 stateD). 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 (stateSin/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/tmpis tmpfs, where fsync never waits):main+ a scratch patch that keeps the stand-in in write+fsync for 400 ms after its:api-allowacknowledgementcopilot_process_set_unprovedmain+ the stand-in equally long busy on the CPU instead (stateR)main+ the peer's stand-in held the same wayNot 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 onmain).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.tsin the CI runner image: 25 of 25 green with the temp folder on tmpfs, 15 of 15 on ext4 (8 pass, 0 fail each).Not in this PR
copilotTranscriptPath,server/conversation.ts). It fails closed.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>/cmdlineitself when herdr lists a process without argv, asserver/copilot-foreground.tsalready does.startFixturereturns 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