Skip to content

test(ssh-integration): a failed request to a PC's route also says how /api/machines shows that PC then - #3933

Merged
devswha merged 2 commits into
mainfrom
test/ssh-integration-failure-names-pc-state
Nov 16, 2026
Merged

devswha merged 2 commits into
mainfrom
test/ssh-integration-failure-names-pc-state

Conversation

@devswha

@devswha devswha commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

What this adds

scripts/ssh-integration.ts only, and only for diagnosis. When a request to one PC's route (/api/machines/<uuid>, followed by /, ? or nothing) fails, api()'s assertion message now also says:

  • how GET /api/machines shows that PC at that moment: its state and error;
  • how long after a setup job last said connected the failure came (a timestamp taken in setup() when it sees connected).

How it stays out of the way:

  • Only on failure. The extra read happens only after the request has already failed, so a passing run does not do it and nothing about its timing changes.
  • The original comes first. The failed request's own status and text are read and put in the message before the extra read starts.
  • Bounded. The extra read has one 2 s deadline (AbortSignal.timeout(2000)) for both the answer and its body. If /api/machines does not answer, or stalls in its body, the message says /api/machines could not be read (The operation timed out.) and the assertion fires about 2 s later than it would have.
  • Nothing else changes. No assertion, deadline, wait, sleep, retry or step order.

Not changed, and older than this PR: the failed request's own await r.text() has no deadline. A server that sent the error status and then stalled its body would hold that read the same way. The passing path's r.json() is the same.

The messages, forced

Both come from scratch copies of the server (never committed) in the self-hosted runner image.

1. Injected loss. One connection loss right after an update's setup job says connected, the state of the red run below:

AssertionError: /api/machines/f545b71e-570b-42b4-92f0-f9657ab88bc4/session: 503 {"error":{"code":"machine_offline","message":"This PC is disconnected"}}
  this PC in /api/machines now: {"state":"reconnecting","error":"injected loss after connected"}, 1 ms after a setup job last said connected

When the loss cut the session request in mid-flight, the same line followed a 504 machine_timeout instead (2 of 3 runs).

2. Injected loss, plus /api/machines never answering. It was also run with a body that never ends; the message is the same.

AssertionError: /api/machines/543c3add-3823-4397-aede-f2d087d982ca/session: 503 {"error":{"code":"machine_offline","message":"This PC is disconnected"}}
  /api/machines could not be read (The operation timed out.), 1 ms after a setup job last said connected

The message came 2.09-2.18 s after setup connected in all 6 such runs (3 with no answer, 3 with a stalled body), and the script ended 0.02 s later.

Before this PR, these failures printed only the first line.

What a next occurrence will be able to say

Line 196 (the session read right after the bridge update) went red once in 28 hosted attempts on #3922 (run 43768827926, attempt 1) with only 503 machine_offline. Next time the second line will say:

  • which state the PC was in: reconnecting (a lost connection, waiting for its own retry), disconnected or error. If it says connected, the PC was already back by the time of the extra read.
  • which way the connection was lost, from the error that lost() in server/machines.ts records:
    • SSH bridge connection interrupted: the PC's status socket closed;
    • SSH connection ended: the SSH master exited;
    • Remote herdr unavailable (<status>) or a fetch error: a roster read through the bridge failed;
    • or an action-required message.
  • how soon after the connect it came: in milliseconds.

The same applies to a failed PATCH or DELETE of /api/machines/<id> and to the PC's other routes.

Background

A CI-supervisor investigation of that red run concluded the following:

  • The product's order is correct. setup() sets the machine's state to connected inside observe() (server/machines.ts:2240) before the job's phase (:1372), on the same connection generation, with a cancel check in between.
  • A test wait does not help. With the forced loss above, waiting for state === "connected" before the read (as line 177 does) still failed with the same 503 in 1 of 5 runs: the drop can land between any check and the read.
  • What it was: a real drop of a freshly made connection. In the red run the same PC had dropped a fresh connection 0.6 s earlier too, in the restart step; no other attempt shows that. Its trigger is unknown.

This PR does not change that. It makes the next occurrence name it.

A separate observation, not fixed here

refresh() returns without reading when an older refresh is still in flight (server/machines.ts:2197, if (runtime.refreshing) { runtime.refreshQueued = true; return; }). In that case observe() (:2238-2240) marks the PC connected without a read through the new connection. No instrumented run hit it: in a bridge update the old connection's reads fail as soon as its SSH master is killed. It is left as is.

Validation

All in the self-hosted runner image herdr-ci-runner:local (runner user, no privileges, as the local merge gate starts it), key-only flow: bun install --frozen-lockfile && bun run build && bun run scripts/build-remote-bundle.ts, then bun run scripts/ssh-integration.ts.

  • Injected loss (scratch server): 3 runs, each failing at the session read with message 1 (state reconnecting, the injected error, 1-4 ms).
  • Injected loss plus a stalled /api/machines (scratch server): 3 runs where it never answers and 3 where its body never ends. Each failed with message 2 within 2.2 s of setup connected. Whole runs took 13.5-13.9 s, against 11.5-12.2 s for the injected loss alone.
  • Unchanged server: the script 20 times, 0 failures.
  • Bun behaviour: a separate probe on Bun 1.4.2 confirmed that the fetch's AbortSignal.timeout also rejects a body read that stalls after the headers (500 ms deadline: 500 ms), not only a request that gets no answer (501 ms).
  • Typecheck: bun run typecheck passed, but it does not include scripts/ssh-integration.ts. That file was also typechecked directly with tsc -p against a scratch config extending tsconfig.json: 0 errors in it (the only errors were in shared/vendor/paseo-e2ee, which scripts/typecheck.ts checks under its own config).
  • Check fast: bun run check fast passed.
  • Not run locally: the password mode of this script (SSH_TEST_PASSWORD=1, needs sudo; GitHub's ssh job runs it, and it passed on this PR's first head 4c98cc8), bun run check full, the Windows and macOS jobs.

… /api/machines shows that PC then

When a request under /api/machines/<id>/ fails, api()'s assertion message now also
carries that PC's state and error as /api/machines reports them right then, and how
long after a setup job last said connected the failure came. The extra read runs only
in the failing branch of the message, so a passing run is unchanged.

The one red run of line 196 (503 machine_offline right after a bridge update, run
43768827926) said nothing about why the PC was offline; the next one will say which
state it was in and how its connection was lost.
@coderabbitai

coderabbitai Bot commented Nov 16, 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
    • Integration test failures for machine routes now include the machine’s reported state and error, or indicate when the machine is absent or diagnostic data could not be retrieved.
    • Failure messages also report elapsed time since the most recently observed connected phase, or note when no connected phase was observed.
    • Requests to non-machine routes retain their existing failure details.

The SSH integration test records when setup last reaches the connected phase. Failed requests on matching machine routes now include machine state and timing diagnostics.

Changes: SSH integration diagnostics

Layer / File(s) Summary
Connected timing and failure diagnostics
scripts/ssh-integration.ts
The setup polling loop records the time of each observed connected phase. Failed requests on matching machine routes append the machine’s state and error, or report that it is absent or the diagnostic fetch failed. The diagnostic also reports elapsed time since the last connected phase, or that none was observed.

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

Change: Other

Merge Risk: Minimal · previous review 4c98c

This change adds failure diagnostics to the SSH integration test script and does not affect production behavior. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: a failed request to a PC's route now also reports how /api/machines shows that PC. It matches the diagnostic added in scripts/ssh-integration.ts and the stated objective. I…
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 template's two sections, Change and Validation. The Change section explains the problem, the diagnostic added to the assertion message, the bounding behaviour, and the scop…
Full details: Title check

Explanation

The title names the change: a failed request to a PC's route now also reports how /api/machines shows that PC. It matches the diagnostic added in scripts/ssh-integration.ts and the stated objective. It is long (102 characters) and wordy, but it is specific and clear.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section explains the problem, the diagnostic added to the assertion message, the bounding behaviour, and the scope. It also cites the motivating failure. The Validation section lists the commands and runs with results, plus the checks not run locally (password mode, check full, Windows and macOS jobs). The template asks for a linked issue for features, but this is a diagnostic change to a test script, not a feature, and the PR references PR #3922 and run 43768827926 as the motivating failure. The description is thorough and mostly complete. The template's contract-test note is not applicable because the change touches no HTTP/WS handler.

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 794b030 and 4c98cc8.

Files selected for processing: 1

  • scripts/ssh-integration.ts

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

…a PC's own route

The read of /api/machines that a failed PC request adds to its message now has one 2 s
deadline for its answer and its body, so a server in a bad way at that moment cannot
stall the failure until CI's timeout: the message then says /api/machines could not be
read. The failed request's own status and text are read first, before that read.

A failed PATCH or DELETE of /api/machines/<id> (no slash after the id, or a query) gets
the diagnostic too.
@devswha
devswha merged commit a761ccd into main Nov 16, 2026
21 of 22 checks passed
@devswha

devswha commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 7c6235e07c69 as a761ccde32f7 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: the owner's test-only pull request (one integration script, diagnostic output only): one reviewer by facts.md.

Merge pass note for #3933 at 7c6235e (test-only: scripts/ssh-integration.ts).

One reviewer (Codex, by the skill's rule for the owner's test-only pull request), two rounds, by reading; the integration script was not run in the review.
Why: this script's step after "cancellation before installation" failed once on a GitHub-hosted runner with "This PC is disconnected" right after a correct connect; the cause was a real drop of the fresh connection, not found and not reproduced locally. The change adds output only: when a request to a PC's route fails, the message also says how /api/machines shows that PC then (its state and error) and how long ago a setup job last said connected.
The first head's diagnostic read had no deadline and could have hidden the failure it explains; now the failure's own status and text are built first and the read is bounded at two seconds. No wait, retry or changed assertion; the passing path makes no added request.

@devswha
devswha deleted the test/ssh-integration-failure-names-pc-state branch November 16, 2026 01:45
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