Skip to content

fix(ci): prevent idle gateway fixture port collisions - #140747

Merged
vincentkoc merged 1 commit into
mainfrom
fix/ci-idle-gateway-port-reservation
Sep 7, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/ci-idle-gateway-port-reservation

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Related: #140632

What Problem This Solves

Resolves a problem where parallel CI fixtures could claim an isolated Gateway's automatically selected port while that Gateway was being prepared, stopped for Doctor work, or restarted after a startup refusal.

Why This Change Was Made

The test instance now reserves its automatically allocated loopback port throughout idle phases, releases it immediately before spawning, and reacquires the same port only after verified child teardown. Terminal cleanup releases the reservation independently of process cleanup and never reopens it. Acquisition rollback preserves the original failure while still attempting both state and socket cleanup.

Caller-supplied ports remain caller-owned. Existing convergence retries, deadlines, process ownership checks, runtime storage behavior, and CI parallelism are unchanged. The release-to-child-bind handoff is still non-atomic; this closes long idle ownership gaps, not every possible port race.

Review disposition: the remaining handoff race predates this patch. The selected mitigation is to repair idle ownership now and retain the broader collision issue for controlled concurrent verification. This is the bounded maintainer-reviewed scope, not a claim of complete race elimination.

User Impact

More reliable parallel Gateway lifecycle proofs without serializing CI or masking startup failures. No end-user runtime behavior changes.

Evidence

  • Before the fix, real competing listeners acquired the instance port after creation, during held entrypoint preparation, after terminal refusal, and after verified stop. The new regression assertions failed at those boundaries.
  • The focused helper suites pass: 57 tests, with the native Windows-only case skipped on macOS. Coverage includes refusal, CLI work, repeated same-port restarts, connection disposal, reacquisition failure diagnostics, acquisition rollback, retained failed process ownership, explicit ports, and terminal cleanup.
  • Independent P1/P2 review found no actionable defects. Subsequent edits are mechanical lint corrections.
  • Targeted formatting, lint, script lint, coercion and ownership guards pass. The local changed-check gate reached test typechecking but was blocked by its shared-dependency checkout restriction. All three hosted test-typecheck jobs passed on the exact head in ready CI.
  • The matching-artifact SQLite lifecycle proof passed in build-artifacts: RUN_SQLITE_SESSION_LIFECYCLE=true, with the unchanged built-CLI test passing in 34.1 seconds. No local build was substituted.
  • Windows job 2 passed the actual helper suite, including the new reservation cases and the native inherited-stderr ownership test that was skipped on macOS. Windows job 1 also passed.
  • Ready CI completed successfully on its first attempt at 8d9052c5697caab0847b48a4777b3fede1300970. The draft-only skipped run is not used as evidence.

The linked issue stays open: the original concurrent SQLite/Discord collision sequence has not been reproduced end to end.

@clawsweeper

clawsweeper Bot commented Sep 7, 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.

@vincentkoc vincentkoc self-assigned this Sep 7, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 7, 2026 03:50
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 7, 2026
@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 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 6, 2026, 11:58 PM ET / September 7, 2026, 03:58 UTC.

ClawSweeper review

What this changes

Reserve automatically selected Gateway test ports during preparation and stopped phases, with socket cleanup and regression coverage for failures and restarts.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this is a useful, bounded fixture repair absent from current main and the latest release. No actionable introduced defect was found. The maintainer-authored PR also remains protected from automatic closure.

Priority: P2
Reviewed head: 8d9052c5697caab0847b48a4777b3fede1300970

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with meaningful failure-path coverage and no blocking correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR. The changed fixture owner has reported real-socket regression coverage; matching-artifact SQLite and Windows validation remain ordinary CI checks, and the original concurrent failure is not claimed resolved.
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 MEMBER-authored PR. The changed fixture owner has reported real-socket regression coverage; matching-artifact SQLite and Windows validation remain ordinary CI checks, and the original concurrent failure is not claimed resolved.
Evidence reviewed 8 items Pinned patch ownership: The host-verified merge-base-to-head patch changes only the shared instance helper and its two test files. The verified test merge contains those same changes against its main parent; unrelated endpoint drift is excluded.
Current main still has the idle ownership gap: Current main closes its ephemeral listener before returning the selected port. The reviewed patch adds reservation ownership across preparation, verified stops, and startup failures.
Latest-release comparison: The supplied latest release, v2026.9.2, also closes the ephemeral listener immediately; it does not contain this reservation behavior.
Findings None None.
Security None None.

How this fits together

The shared Gateway test helper creates isolated state and launches processes used by integration and CI proofs. Its port and process lifecycle determines whether parallel fixtures can run without interfering with each other.

flowchart TD
 A[Test requests an instance] --> B{Caller supplies port?}
 B -->|Yes| C[Caller owns port]
 B -->|No| D[Reserve idle loopback port]
 D --> E[Release socket and launch Gateway]
 C --> E
 E --> F[Verify child teardown]
 F -->|Reusable instance| D
 F -->|Terminal cleanup| G[Release resources and state]
Loading

Before merge

  • Resolve merge risk (P1) - The existing release-to-child-bind race remains non-atomic, so this repair does not establish that every collision in the original concurrent CI sequence is eliminated.
Agent review details

Security

None.

PR surface

Tests +230. Total +230 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 267 37 +230
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 267 37 +230

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep idle-port ownership in the shared fixture lifecycle and retain the broader collision issue until its concurrent execution is verified.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep idle-port ownership in the shared fixture lifecycle and retain the broader collision issue until its concurrent execution is verified.

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

Yes for the idle-port gap: current source releases the listener before preparation, allowing a competing listener to bind. This review did not execute that path or reproduce the original concurrent SQLite/Discord sequence.

Is this the best way to solve the issue?

Yes. Holding the reservation in the existing fixture owner is a focused repair that preserves explicit-port ownership, teardown checks, retry limits, and CI parallelism.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: Repairs an observed parallel-CI fixture collision with a bounded test-infrastructure impact.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 MEMBER-authored PR. The changed fixture owner has reported real-socket regression coverage; matching-artifact SQLite and Windows validation remain ordinary CI checks, and the original concurrent failure is not claimed resolved.

Label justifications:

  • P2: Repairs an observed parallel-CI fixture collision with a bounded test-infrastructure impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 MEMBER-authored PR. The changed fixture owner has reported real-socket regression coverage; matching-artifact SQLite and Windows validation remain ordinary CI checks, and the original concurrent failure is not claimed resolved.

Evidence

What I checked:

  • Pinned patch ownership: The host-verified merge-base-to-head patch changes only the shared instance helper and its two test files. The verified test merge contains those same changes against its main parent; unrelated endpoint drift is excluded. (8d9052c5697c)
  • Current main still has the idle ownership gap: Current main closes its ephemeral listener before returning the selected port. The reviewed patch adds reservation ownership across preparation, verified stops, and startup failures. (test/helpers/openclaw-test-instance.ts:234, de0b6849e19e)
  • Latest-release comparison: The supplied latest release, v2026.9.2, also closes the ephemeral listener immediately; it does not contain this reservation behavior. (test/helpers/openclaw-test-instance.ts:234, 3928bad9badf)
  • Lifecycle and failure handling: The complete helper preserves serialized lifecycle operations and verified process teardown. Reservation release precedes spawn; terminal cleanup disables reacquisition and attempts socket release even when another cleanup phase fails. Explicit ports remain caller-owned. (test/helpers/openclaw-test-instance.ts:567, 8d9052c5697c)
  • Behavioral regression coverage: Inspected tests use real competing TCP listeners and spawned fixture processes to cover idle reservation, refusal, restart, probe disposal, reacquisition failure, explicit ports, and terminal release. Acquisition tests also verify socket rollback when state cleanup fails. The captured PR body reports 57 passing tests and one Windows-only skip on macOS; no tests were executed during this read-only review. (test/helpers/openclaw-test-instance.test.ts:412, 8d9052c5697c)
  • Consumer boundary and related issue: The SQLite proof creates this helper, expects a startup refusal, runs Doctor, and restarts the same Gateway. The supplied discussion at [Bug]: Concurrent SQLite and Discord built proofs can collide on a gateway port #140632 records an actual concurrent CI collision. The PR explicitly leaves that issue open because its original execution sequence has not been reproduced end to end. (test/helpers/sqlite-sessions-transcripts-flip-proof.ts:104, 8d9052c5697c)

Likely related people:

  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: 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.

@vincentkoc

Copy link
Copy Markdown
Member Author

The remaining handoff risk is pre-existing and was explicitly accepted in the bounded implementation review: repair the long idle ownership gaps while retaining #140632 for controlled concurrent verification. This PR does not claim complete race elimination or close that issue. The PR body now records that disposition explicitly.

The matching-artifact SQLite lifecycle test and all three hosted test-typecheck jobs have passed at 8d9052c5697caab0847b48a4777b3fede1300970 in https://github.com/openclaw/openclaw/actions/runs/34081004347. Windows and the final CI aggregate are still pending.

@vincentkoc
vincentkoc merged commit 77eaf46 into main Sep 7, 2026
184 checks passed
@vincentkoc
vincentkoc deleted the fix/ci-idle-gateway-port-reservation branch September 7, 2026 04:08
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

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