Skip to content

test(machine-herdr-switch-retry): a failed switch asks no real ssh whether the PC is Windows, and a stalled wait restores its spies - #3903

Merged
devswha merged 2 commits into
mainfrom
test/machine-herdr-switch-retry-slow-runner
Nov 15, 2026
Merged

devswha merged 2 commits into
mainfrom
test/machine-herdr-switch-retry-slow-runner

Conversation

@devswha

@devswha devswha commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Why

Hosted Fast checks on #3738 (run 43717080636, job 132820955312) failed in server/machine-herdr-switch-retry.test.ts with "pauses old retries when the link drops before a switch, then the switch is failed": setup did not settle at 5016 ms. The other three cases took 30-75 ms.

Cause

In both "then the switch is failed" cases, the posixHost.inspect stand-in throws "B refused connection". detectHost (server/remote-host.ts) then asks windowsHost.inspect, which the test left unmocked. That runs ssh.runPowerShell, and with SshConnection.start mocked there is no master, so a real ssh -S control ... -T fixture-only powershell ... starts. The job settles only when that process exits, and the product bounds it only by ConnectTimeout=15 and the 90 s run deadline. A local stand-in for ssh recorded two such calls per run, one in each failed case. On the hosted runner the first one outlasted the test's 5 s wait; why that runner's ssh to fixture-only was slow (likely name resolution) was not proven.

There is a second, related flaw. The test's own bounded waits (5 s) are as long as bun's default test timeout (5 s). When bun's timeout wins, the case reports a bare "this test timed out", finally never runs, and its spies stay installed. The next case then fails with RangeError: Maximum call stack size exceeded in the stacked clearTimeout spy.

Change (test only)

  • windowsHost.inspect rejects as it would for a PC that is not Windows. B's own refusal stays the job's error, as the test asserts, and the test starts no external process.
  • The waits share SETTLE_MS. The test's timeout is 4 * SETTLE_MS, so it outlasts its three sequential waits. A stall then reports what it waited for, and finally restores the spies. The bound itself is unchanged: with ssh out of the way, every answer in this fixture is in-process or on loopback (measured 10-40 ms a case).
  • The wait for the switch to reach B's inspection has its own SETTLE_MS deadline ("The switch never asked B"). Without it, a switch that ends before posixHost.inspect leaves await reached.promise pending until the runner's timeout, so finally is skipped. That deadline starts together with run(b)'s, so the test still outlasts its waits in a row.

Timers: the test already holds the product's retry delays (1-60 s) and fires them itself. The other timers stay real; none of them sits on the path being waited for.

Validation

Forcing: an OVIS_SSH stand-in that logs its arguments and sleeps FAKE_SSH_DELAY seconds before failing as an unresolvable host would.

  • Before (origin/main 139759a, FAKE_SSH_DELAY=6): "before ... failed" fails at 5000 ms ("this test timed out after 5000ms"), and "during ... failed" then fails at 11 ms with Maximum call stack size exceeded. With FAKE_SSH_DELAY=0 the stand-in logged 2 ssh calls (... -T fixture-only powershell ...).
  • After, same forcing: 4 pass, 0 ssh calls.
  • bun test --rerun-each 20 ./server/machine-herdr-switch-retry.test.ts unforced: 80 pass, 0 fail.
  • Scratch mutation in server/machines.ts (not committed): a failed switch no longer calls retryLater(existing). Both failed cases go red with "Old PC retries did not resume".
  • Scratch run with the new windowsHost mock removed and the 6 s stand-in: both failed cases report "setup did not settle" at about 5009 ms. No cascade into the next case.
  • bun run check fast: exit 0 in a 2-core heavy slot (typecheck, build, unit tests: 17383 pass, 0 fail). The fixed file also ran on one core beside a busy loop: --rerun-each 5, 20 pass.
  • Second push (394f09a), forced: a scratch change made the switch's SSH start fail before inspect, in the first case only.
    • Before (c6c9bf7): that case ended at the 20 s runner timeout, and the other three failed with Maximum call stack size exceeded.
    • After: it fails at 5025 ms with "The switch never asked B", and the other three pass.
  • bun test --rerun-each 20 on the file at 394f09a: 80 pass, 0 fail. bun run check fast at 394f09a: exit 0 (17383 pass, 0 fail).

Skipped: bun run check full and the integration/browser suites (test-only change to one unit test file).

…ether the PC is Windows, and a stalled wait restores its spies

When B's inspection fails, detectHost asks windowsHost.inspect next. The test
left that unmocked, so each "then the switch is failed" case ran a real
`ssh ... -T fixture-only powershell ...` and waited for it to exit. On a
GitHub-hosted runner that ssh outlasted the 5 s deadline (run 43717080636).
windowsHost.inspect now rejects as a non-Windows PC does, so B's own refusal
stays the job's error.

The test's 5 s waits also tied bun's default 5 s test timeout. When bun won,
the case reported a bare timeout and skipped `finally`, so its spies stayed
installed and the next case overflowed the stack in the stacked clearTimeout
spy. The test now outlasts its three waits in a row, so a stalled wait names
what it waited for and the spies are restored.
@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
    • Expanded automated coverage for switch-retry behavior across POSIX and Windows hosts, including failed-switch handling and retry resumption.
    • Added consistent time limits to keep these checks bounded and predictable.

The switch-retry test now mocks Windows host inspection, uses a shared 5-second wait limit for setup and retry-resumption deadlines, and sets the test timeout to four times that limit.

Changes: Switch-retry test

Layer / File(s) Summary
Bound failed-switch retry test timing
server/machine-herdr-switch-retry.test.ts
The test mocks Windows host inspection to reject. Setup and retry-resumption deadlines use the shared 5-second limit, and the test timeout is four times that limit.

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

Change: Other

Merge Risk: Minimal · up to c6c9b

This change makes a test more deterministic by avoiding a real SSH process and bounding its waits. It has no production impact and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the test file and describes two concrete fixes: a failed switch no longer asks real ssh about Windows, and a stalled wait restores its spies. Both match the test-only changes in the su…
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 cause (an unmocked windowsHost.inspect starts a real ssh process) and the fix (reject window…
Full details: Title check

Explanation

The title names the test file and describes two concrete fixes: a failed switch no longer asks real ssh about Windows, and a stalled wait restores its spies. Both match the test-only changes in the summary and objectives. It is long (131 characters, 20 words) and dense, but it is specific and related to the main change.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section explains the cause (an unmocked windowsHost.inspect starts a real ssh process) and the fix (reject windowsHost.inspect, shared SETTLE_MS waits, a 4x test timeout, and a new deadline for the switch reaching B). The Validation section lists the forced-failure runs, the rerun-each 20 results, bun run check fast, and the skipped suites with reasons. The template asks for a linked issue for features; this is a test-only fix, so no issue link is required. The description is complete.

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 139759a and c6c9bf7.

Files selected for processing: 1

  • server/machine-herdr-switch-retry.test.ts

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

A switch that ended before it inspected B (run(b) settles as failed) left
`await reached.promise` pending until the runner's test timeout, so
`finally` never ran and the next case broke on the spies left installed.
The wait now gets its own SETTLE_MS deadline and says "The switch never
asked B". It starts with run(b)'s own deadline, so the test's timeout still
outlasts its waits in a row.
@devswha
devswha merged commit 63d0191 into main Nov 15, 2026
21 of 22 checks passed
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 394f09a65882 as 63d019129e9c on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: test-only.

Test-only, one file. Two faults in the test, both reproduced by its author by forcing (a stand-in ssh that sleeps 6 s): the unmocked windowsHost.inspect started a real ssh in both "then the switch is failed" cases, and the test's own 5 s waits equalled bun's 5 s test timeout, so finally never ran and the next case crashed. At this head no ssh is started and the test timeout is four times its settle wait; unforced 80 of 80.

The first review found that the wait for the switch to ask B had no deadline of its own, so a switch failing earlier ran to the runner timeout and skipped finally; 394f09a bounds it inside try/finally, and its author forced that path (it now fails at about 5 s with a clear message and the other cases pass).

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

@devswha
devswha deleted the test/machine-herdr-switch-retry-slow-runner branch November 15, 2026 14:54
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