Skip to content

fix(test): prevent port probes from colliding with fixture reservations - #155228

Merged
steipete merged 1 commit into
mainfrom
upd/test-instance-port-collision
Sep 21, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/test-instance-port-collision

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an EADDRINUSE race between a test fixture's idle reservation and another allocator's temporary port probe. Investigated after run 35649415771, job 106498397182 failed the final config/environment case in openclaw-test-instance.test.ts on #153314's unrelated merge ref.

Related: #150642, which fixed listener handoff in the separate in-process metadata-close fixture.

User Impact

No product runtime or update behavior changes. Test fixtures keep their existing isolated state, Linux non-ephemeral port ranges, derived-port claims, and cleanup contracts. No new configuration, CLI options, dependencies, schemas, retries, or timeouts.

Why This Change Was Made

Numeric-port probes were binding sockets before acquiring the fixture's logical claim. A competing probe could occupy the selected port while its eventual fixture owner tried to reserve it. Both allocation probes and persistent fixture reservations now use the existing exclusive claim owner, with probe claims released after the sockets close. The shared low-level claim operation is factored out to avoid a dependency cycle.

The deterministic regression overlaps two real fixture acquisitions in one worker using independent allocator module copies and event gates. It fails before the repair with EADDRINUSE; the repaired acquisitions both return distinct live reservations. The reproduced second binder is probeTestPort in src/test-utils/ports.ts (pre-fix line 65). The archived job did not record bind PIDs, so the precise historical holder of port 21336 remains unproven.

Evidence

  • Deterministic Linux regression: original source fails with EADDRINUSE in 42 ms; final candidate passes in 35 ms. Bind trace identifies the live contender at src/test-utils/ports.ts:65 on the pre-fix source (PID 5230, worker thread 1, port 15024).
  • 5/5 replays of the original 75-file selector at the archived two-worker setting: 1,350 passed, four expected skips each. Wall times: 112.11, 75.99, 85.62, 91.65, 75.00 seconds. No test exceeded 30 seconds or file exceeded 120 seconds of test time.
  • Allocator, reserved-listener, provider-cleanup, and collision siblings: 33 tests passed. The final regression also passes with --maxWorkers=1: Linux 17.26 s Vitest wall (93% transform), 35 ms test time; macOS 9.58 s wrapper wall, 47 ms test time.
  • All required changed-check steps passed. The initial full selection passed all support-code checks, including core typechecking, 25 core-test partitions, lint, dead-export and import-cycle guards; it found two regression lint errors. Those were corrected without suppressions, and the final node scripts/check-changed.mjs -- test/helpers/openclaw-test-instance.port-collision.test.ts selection passed. Unchanged support-code proof was reused.
  • Final Codex P1 autoreview: scoped-clean, no accepted/actionable findings.

Final remote proof: Blacksmith Testbox tbx_01m32ym03htyd1qcxgsh000yjx, lease workflow, wrapper exit 0. Earlier unchanged-support proof used tbx_01m32vp352efzn7ds32feh1x25, lease workflow. Both used isolated test state and owned listeners. Hosted PR CI timing is pending.

Runtime LOC +0/−0; shared test support +94/−73; regression +76/−0.

Make numeric allocation probes acquire the same exclusive port claims as
persistent test fixtures. Retain claims until probe sockets close so a
competing probe cannot occupy a port during fixture reservation or handoff.

Add a deterministic two-fixture regression that fails with EADDRINUSE on the
previous owner and passes after the repair. Preserve existing port ranges,
derived-port ownership, cleanup, and zero-retry claim behavior.

Related: #150642. Investigated from run 35649415771, job 106498397182 on
#153314's unrelated merge ref. No product runtime or update behavior changes.
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 22:00
@steipete
steipete enabled auto-merge (squash) September 21, 2026 22:06
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 6:05 PM ET / 22:05 UTC.

ClawSweeper review

What this changes

Makes test port probes share exclusive claims with fixture reservations and adds a deterministic overlapping-allocation regression.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main still allows allocation probes to bypass fixture claims. The patch addresses that race without changing product runtime behavior, and no blocking defect was found.

Priority: P2
Reviewed head: 2a919327d36a57435388737ba4c53f4496b3345b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with a meaningful deterministic regression and reported cross-platform validation.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor proof gate does not apply to this maintainer-authored test-support repair. Its captured evidence describes real fixture/socket overlap on Linux and macOS through the changed allocator; no product runtime behavior or authority boundary changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored test-support repair. Its captured evidence describes real fixture/socket overlap on Linux and macOS through the changed allocator; no product runtime behavior or authority boundary changes.
Evidence reviewed 6 items Introduced change and lifecycle: The pinned merge-base-to-head diff extracts the existing claim implementation without changing its lock policy, acquires claims before numeric probes, and releases them after all probe sockets close.
Current main still needs the fix: Current main calls probeTestPort for candidate offsets without acquiring fixture claims. The existing fixture acquires its persistent claim afterward, leaving the described competing-probe window.
Regression matches the changed boundary: The new regression overlaps real fixture acquisitions, gates probe closure with deferred events, verifies both acquisitions succeed on distinct ports, and cleans up both instances. The captured PR body reports pre-fix EADDRINUSE, post-fix Linux/macOS passes, 33 sibling tests, and five original-selector replays; these runs were not repeated during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw’s test port allocator selects local ports for isolated server fixtures. Temporary socket probes and persistent fixture reservations now coordinate through the same file-lock owner.

flowchart TD
  A[Test requests port block] --> B[Select candidate ports]
  B --> C[Acquire exclusive claims]
  C -->|Already claimed| B
  C --> D[Probe local sockets]
  D --> E[Close probes and release claims]
  E --> F[Fixture claims and reserves ports]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +97. Total +97 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 4 170 73 +97
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 170 73 +97

Review metrics

Metric Value Why it matters
Regression execution cost Reported test time: Linux 35 ms; macOS 47 ms The event-gated regression exercises real reservations without adding sleeps or booting Gateway processes.

Technical review

Best possible solution:

Keep probe and fixture exclusion under one claim owner, with socket closure preceding claim release and deterministic coverage of overlapping acquisitions.

Do we have a high-confidence way to reproduce the issue?

Yes: source establishes the unclaimed-probe window, and the supplied regression deterministically overlaps that probe with fixture acquisition. The PR reports a before/after failure and pass; this review did not execute it.

Is this the best way to solve the issue?

Yes: extending the existing exclusive claim owner closes the race without adding retries, timeouts, or a competing reservation mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1fab25b37f95.

Labels

Label changes:

  • add P2: This repairs a concrete shared test-fixture race with bounded operational impact and no product runtime change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored test-support repair. Its captured evidence describes real fixture/socket overlap on Linux and macOS through the changed allocator; no product runtime behavior or authority boundary changes.

Label justifications:

  • P2: This repairs a concrete shared test-fixture race with bounded operational impact and no product runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored test-support repair. Its captured evidence describes real fixture/socket overlap on Linux and macOS through the changed allocator; no product runtime behavior or authority boundary changes.

Evidence

What I checked:

  • Introduced change and lifecycle: The pinned merge-base-to-head diff extracts the existing claim implementation without changing its lock policy, acquires claims before numeric probes, and releases them after all probe sockets close. (src/test-utils/ports.ts:82, 2a919327d36a)
  • Current main still needs the fix: Current main calls probeTestPort for candidate offsets without acquiring fixture claims. The existing fixture acquires its persistent claim afterward, leaving the described competing-probe window. (src/test-utils/ports.ts:79, 1fab25b37f95)
  • Regression matches the changed boundary: The new regression overlaps real fixture acquisitions, gates probe closure with deferred events, verifies both acquisitions succeed on distinct ports, and cleans up both instances. The captured PR body reports pre-fix EADDRINUSE, post-fix Linux/macOS passes, 33 sibling tests, and five original-selector replays; these runs were not repeated during this read-only review. (test/helpers/openclaw-test-instance.port-collision.test.ts:9, 2a919327d36a)
  • Dependency exclusivity contract: The target’s file-lock-manager adapter delegates to @openclaw/fs-safe 0.18.0. npm package metadata identifies openclaw/fs-safe as its repository. Inspection of the published package confirms globally shared manager state and that reentrancy requires an explicit matching reentrantOwner, which these claims do not provide. Published distribution source was inspected; no dependency commit SHA was established. (dist/sidecar-lock-acquire.js)
  • Related work is distinct: The supplied GitHub context verifies fix(test): keep metadata-close Gateway ports reserved through startup #150642 merged a listener-handoff fix for the metadata-close fixture. That does not eliminate the numeric allocator’s unclaimed probes. fix(doctor): explain archived registry warnings after updates #153314 supplied the failing CI context but changes Doctor diagnostics, not this allocator.
  • Area history and inspection limits: Available current-main history repeatedly identifies Peter Steinberger on allocator and fixture maintenance, including the safe-port and loopback reliability work. Deeper blame and latest-release source inspection encountered unavailable historical objects; no introduction or shipped-fix claim is made. (src/test-utils/ports.ts, f1cd636fc88d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit c3ae72c into main Sep 21, 2026
217 checks passed
@steipete
steipete deleted the upd/test-instance-port-collision branch September 21, 2026 22:24
steipete added a commit that referenced this pull request Sep 22, 2026
Compose initial TCP and HTTP reservations over the canonical claim owner
extracted in #155228, retaining its claim-aware allocation probes. Retry only
an automatic initial bind that reports EADDRINUSE after joined rollback;
keep explicit and published ports, later reacquisition, cancellation and
cleanup failures pinned to their existing contracts.

Integrate #155209 without replacing its published ancestry. Current-main
controls reproduce both real initial-bind failures. The composed candidate
passes all 123 cases across seven files and all 34 selected checks, including
25 core-test type graphs. Fresh P2 review has no actionable findings.

The recorded #155098 group passed once on the available 4-CPU Testbox with
its normal two-worker fallback. That result does not reproduce the original
eight-worker topology or establish the historical competing socket owner;
earlier zero-close acquisition failures also remain unattributed.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…ns (openclaw#155228)

Make numeric allocation probes acquire the same exclusive port claims as
persistent test fixtures. Retain claims until probe sockets close so a
competing probe cannot occupy a port during fixture reservation or handoff.

Add a deterministic two-fixture regression that fails with EADDRINUSE on the
previous owner and passes after the repair. Preserve existing port ranges,
derived-port ownership, cleanup, and zero-retry claim behavior.

Related: openclaw#150642. Investigated from run 35649415771, job 106498397182 on
openclaw#153314's unrelated merge ref. No product runtime or update behavior changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant