Skip to content

test(pc-install): stand-in servers' addresses are ports the system gives no other test - #3670

Merged
devswha merged 1 commit into
mainfrom
fix/pc-install-restore-flake
Nov 11, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/pc-install-restore-flake

Conversation

@devswha

@devswha devswha commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Change

Test-only fix for an intermittent failure in server/pc-install.test.ts, "starting a stopped server again as it was > starts nothing when its address is taken by a live server, and keeps its log this account's alone" (:1079, expect(await linked.exited).not.toBe(0)), seen in a local bun run check fast run on a busy host. The same cause can fail two neighbouring tests in that describe block.

Cause

The test's freePort() asked the system for a port (port 0), released it and kept only the number. While the test runs, another port: 0 listener or an outgoing connection can be given that same number: in check fast, another test file running in parallel; in the neighbouring test "probes its own PORT…", that test's own relay, which takes a port right after freePort(). The restore then finds its address taken and answers taken, so its log is never written as the test expects.

The stand-in server never listens on its port and never reopens its log, so a slow-dying server is not the cause.

Fix

freePort becomes quietPort() from scripts/quiet-port.ts, the helper #3604 added for this exact problem: a free port outside the range the system hands out for port 0, so nothing else is given that number. One file, +7/-8. No assertion, wait or timeout changed. The product's taken check is unchanged, since refusing an address that is in use is correct.

Validation

  • With a scratch process that keeps taking port: 0 listeners on 127.0.0.1 and letting them go, 8 test processes at a time, batches alternating: main's file failed 5 of 80 runs (this test 3×, its two neighbours once each), each time with a restore that said taken; the fixed file failed 0 of 80. Without that churn, main's file failed 1 of 120.
  • CI: 0 hits in the last 200 CI runs (174 Fast checks jobs), so this matters for local check fast and the merge gate on a busy host.
  • bun run check fast: pass (16129 pass, 0 fail) on main 1e1e57a.
  • Not run: check full. No changelog fragment: test-only.

…ves no other test

## Why

`bun run check fast` on 2026-11-11 failed "starting a stopped server again
as it was > starts nothing when its address is taken by a live server, and
keeps its log this account's alone" at `expect(await linked.exited).not.toBe(0)`.

That restore can exit 0 only by printing `taken`: its log is a link, which
the launcher's `O_NOFOLLOW` open refuses with exit 1 every time. The stand-in
server never listens, and the server killed just before it does not listen
or reopen its log either. So something else was on the address.
`freePort()` took a port with port 0 and let it go. The next `port: 0` server
can be given that port: another test file's in `check`, an outgoing
connection, or this file's own relay in "probes its own PORT, not its
registration's port", which takes one with port 0 right after `freePort()`.
The restore's probe then finds the address in use and says `taken`.

## What

`freePort` in `server/pc-install.test.ts` is `quietPort()` from
`scripts/quiet-port.ts` (#3604): a free port outside the range the system
hands out for port 0, so no port-0 server or outgoing connection can be on
it. Test-only. No assertion, wait or timeout changed, and the product's
`taken` probe is unchanged: it is right to refuse an address in use.

## Proof

On this PC, the whole file run 8 at a time, beside a process that keeps
taking ports with port 0 on 127.0.0.1 and letting them go a few ms later
(64 at once), batches of the two alternating:

| File | Runs | Failed |
|---|---|---|
| `main`'s file | 80 | 5 (this test 3x, "probes its own PORT" 1x, "copies a server's program" 1x, all a restore that said `taken`) |
| this branch | 80 | 0 |

Without that load, `main`'s file failed 1 in 120 runs here ("probes its own
PORT", `said` was `taken`). In the last 200 CI runs, no Fast checks job
failed in this file.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Updated the installation test setup to use a shared method for selecting available ports. The tests continue to use those ports as before, with no change to installation behavior or other user-facing functionality.

The test suite replaces its local helper, which opened and closed a temporary server to obtain a port, with the shared quietPort value.

Changes: Test port allocation

Layer / File(s) Summary
Use quietPort for test ports
server/pc-install.test.ts
The test file imports quietPort and uses it as the shared freePort value instead of creating a temporary server. Existing tests continue to use freePort.

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

Change: Other

Possibly related PRs

Merge Risk: Minimal · up to 2a60a

This change only affects how a test chooses its port, with no product behavior change. It is intended to reduce intermittent test failures and is low risk to merge.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title identifies the test-only pc-install change and explains that stand-in servers use ports outside the system's normal port allocation range.
Description check Passed The description explains the intermittent failure, its cause, the quietPort() fix, validation results, skipped checks, and the absence of a changelog entry for this test-only change.
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: 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 1e1e57a and 2a60a2c.

Files selected for processing: 1

  • server/pc-install.test.ts

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

@devswha
devswha merged commit 43c9787 into main Nov 11, 2026
21 checks passed
@devswha

devswha commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 2a60a2c4c1ab as 43c9787fffa3 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: test-only PR (one unit test file).

Test-only PR (server/pc-install.test.ts), so one reviewer: Codex Terra, CLEAR.

It closes a port race in that unit test: the stand-in servers' addresses are now ports the system hands to no other test in the process. The author's runs under port churn: 5 of 80 failed on main, 0 of 80 with the fix.

Left, LOW (Codex, not run), sent to the author's lane: the ports are tracked per process only, so a test file in another process can still take the same one.

@devswha
devswha deleted the fix/pc-install-restore-flake branch November 11, 2026 13:22
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