Skip to content

test(server): retry the Reserve ingress fixture's start on a port collision - #8659

Merged
lidge-jun merged 3 commits into
devfrom
fix/dev-red2-reserve-ingress-port-race
Nov 13, 2026
Merged

lidge-jun merged 3 commits into
devfrom
fix/dev-red2-reserve-ingress-port-race

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

test 1/5 of dev batch run 43369456647 ran on self-hosted lidge-ocx-07 and failed tests/server/reserve-ingress.test.ts "responses gpt-reserve: public localhost traffic stays public; credential-bearing sibling stays local" with EADDRINUSE on port 39915. tests/helpers/reserve-ingress-fixture.ts (unchanged since September) probes two free ports with findAvailablePort and binds them later in startServer. On a shared runner another process took the probed port in between, so this is a fixture flake with a known mechanism, not a dev regression.

The fixture now picks fresh ports and starts again, up to three attempts, only when the start fails on an address-in-use bind (including the loopback listener's AuxiliaryListenerBindError). This mirrors how the CLI's own start retries isAddrInUse in src/cli/index.ts, and startServer already rolls back the public listener when the loopback bind fails. Before deciding to retry or rethrow, it awaits waitForFailedStartRollback(error) as the CLI does, so a public listener started before a loopback collision has fully stopped. If that rollback rejects, the fixture keeps its home (the error names it) instead of deleting it from under a listener or lease that may still be live, and a teardown failure is reported together with the error that caused it. Any other start error still throws immediately. Test-only.

tests/server/reserve-ingress-fixture-port-race.test.ts covers this deterministically: a public collision and a loopback-listener collision are probed again and start, a collision on every attempt fails after three starts with the bind error, a slow rollback must settle before the next probe, and a rejecting rollback surfaces both errors and keeps the home. Removing the rollback await fails two of these cases, and removing the home guard fails one.

Verification

  • bun test tests/server/reserve-ingress-fixture-port-race.test.ts: 5 pass on this branch; the original three fail on dev's fixture (0 pass, 3 fail). With the related ingress and layout files: 69 pass, 0 fail.
  • Earlier scratch reproduction: hold a TCP port open and make the fixture's first public-port probe return it. On dev's fixture: 0 pass, 1 fail with EADDRINUSE. With this change: 1 pass.
  • bun test tests/server/reserve-ingress.test.ts: 32 pass, 0 fail. bun test tests/server/caller-session-ingress.test.ts (the other user of the fixture): 3 pass, 0 fail.
  • bun run typecheck: exit 0.
  • NOT RUN: the full suite.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Tests
    • Improved test fixture reliability when a port is already in use by retrying startup with fresh ports and waiting for failed-start cleanup before retrying.
    • Added coverage for collisions on both ingress hosts, including cases where startup continues to fail after repeated attempts.
    • Added checks that rollback failures are reported alongside the original startup error and prevent unsafe retries. The fixture home is preserved when cleanup status is uncertain.
    • Updated test-layout mappings for the new port-collision tests.

…lision

test 1/5 of dev batch 43369456647 (self-hosted lidge-ocx-07) failed
"responses gpt-reserve: public localhost traffic stays public" with
EADDRINUSE: the fixture probes two free ports with findAvailablePort and
binds them later in startServer, and on a shared runner another process took
the probed port in between.

Pick fresh ports and start again, up to three attempts, only when the start
fails on an address-in-use bind (including the loopback listener's), as the
CLI's own start retries isAddrInUse. A scratch test holding the probed public
port open fails with EADDRINUSE on the old fixture and passes on this one.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 06:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T06:05:28.184783Z 7a87282 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ingress fixture retries server startup up to three times for address-in-use errors from the primary listener or an auxiliary listener. Each attempt selects fresh distinct ports and rebuilds the configuration. Failed-start rollback and teardown errors are handled explicitly. New tests cover retry, exhaustion, rollback timing, and rollback failure.

Changes: Ingress fixture startup

Layer / File(s) Summary
Retry listener bind collisions
tests/helpers/reserve-ingress-fixture.ts
Each attempt selects fresh distinct ports and saves rebuilt configuration. The fixture waits for failed-start rollback before retrying. Rollback failure produces an AggregateError containing both errors and causes the fixture home to be preserved. Setup failure handling also aggregates teardown errors with the original error.
Verify collision handling and map the test shard
tests/server/reserve-ingress-fixture-port-race.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
Tests cover one-time public and loopback collisions, persistent collisions, rollback timing, and rollback failure. Both test-layout files map the new test to the server shard.

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

Change: Other

Merge Risk: Minimal · up to 14499

This change makes the ingress test fixture more resilient to port collisions and affects only tests. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "test(server): retry the Reserve ingress fixture's start on a port collision" names the primary change. The raw summary says the fixture now retries startup up to three times when a bind fai…
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 Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "test(server): retry the Reserve ingress fixture's start on a port collision" names the primary change. The raw summary says the fixture now retries startup up to three times when a bind fails with address-in-use, with fresh ports per attempt. The added server-shard test file covers the collision and retry paths. The title is specific and matches the changeset. It is concise, has no file list or vague wording, and a teammate scanning history would understand the main change.

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 e98c58c and 14499c4.

Files selected for processing: 2

  • tests/helpers/reserve-ingress-fixture.ts
  • tests/server/reserve-ingress-fixture-port-race.test.ts

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

…ries

Review of #8659: a start whose loopback bind fails has already started the
public listener, and its stop and ledger-lease release settle
asynchronously. Await waitForFailedStartRollback before retrying or
rethrowing, as the CLI's start does, and report a rollback that does not
settle together with the original error.

Adds reserve-ingress-fixture-port-race.test.ts: a public collision and a
loopback-listener collision are probed again and start, and a collision on
every attempt fails after three starts with the bind error. All three fail
on dev's fixture and pass here.
… uncertain

Second review of #8659: when the rollback rejects, the fixture's teardown
removed the home anyway, and a failing teardown could replace the original
error; the collision tests also passed without the rollback being awaited.

The fixture now marks the rollback uncertain, keeps the home (named in the
error) while still restoring process state, and reports a teardown failure
together with the error that caused it. Two cases control the rollback: a
slow one must settle before the next probe, and a rejecting one surfaces
both errors and leaves the home in place. Dropping the await fails both;
dropping the home guard fails the second.
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment (dev integration, MAINTAINERS.md maintainer-integration exception): merging without a second maintainer approval, as part of the DEV-RED repair for dev batch run 43369456647 (test 1/5 (self-hosted lidge-ocx-07)).

  • Exact head: 14499c406e5456586168d5269201d9ddbdc20d36. Every required PR check on this head passed.
  • Fresh independent review on this exact head (gpt-6.1-terra, high): VERDICT: PASS, no findings, after two earlier rounds whose findings (rollback await, regression tests, home kept on uncertain rollback, tests proving the await) were all addressed. Its fresh runs: port-race, ingress and layout tests 69 pass / 0 fail; mutation checks fail as expected; typecheck, structure:check, privacy:scan exit 0.
  • Classification: fixture flake (port probe-to-bind race) in tests/helpers/reserve-ingress-fixture.ts, unchanged since September; bounded retry on address-in-use only, as the CLI's start does. Test-only.
  • No outstanding change requests.

@lidge-jun
lidge-jun merged commit c5010b0 into dev Nov 13, 2026
39 checks passed
@lidge-jun
lidge-jun deleted the fix/dev-red2-reserve-ingress-port-race branch November 13, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant