Skip to content

fix(test): keep metadata-close Gateway ports reserved through startup - #150642

Merged
steipete merged 1 commit into
mainfrom
upd/flake-server-close-port-reservation
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/flake-server-close-port-reservation

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes intermittent Gateway startup failures in the metadata-close tests when another process takes a probed port before the Gateway binds it.

Related: #150427. The failure was observed in checks-node-compact-small-18 on that PR's merge ref; that PR was not the cause.

User Impact

No user-visible behavior or update behavior changes. This removes an unreserved-port race from the shared metadata-close fixture and all three of its test callers.

Why This Change Was Made

The fixture now allocates and holds the actual HTTP listener before startup. A narrow internal transport seam adopts that listener without closing or rebinding it, so the kernel still receives the real port for its configuration and bookkeeping. The fixture closes reservations on failed startup or cleanup; normal Gateway shutdown closes the adopted listener. Explicit same-endpoint restart tests retain their fixed-port contract.

This changes no timeouts, configuration, CLI options, schemas, or dependencies. The existing production bind/retry path remains in use for ordinary startup.

Evidence

  • Deterministic pre-fix failure: a competing listener claims Gateway B's probed port after Gateway A starts; real startup throws GatewayLockError caused by EADDRINUSE.
  • Linux / Node 24.21: a separate process deterministically claimed a port returned by the real getFreePort helper before its intended listener could bind.
  • Post-fix boundary regression verifies exclusive reservation, successful /healthz, and reuse of the same port after Gateway close.
  • macOS focused fixture proof: 4 files, 15 tests passed.
  • Linux focused fixture proof: 4 files, 15 tests passed on Node 24.19; the final macOS collision regression also passed on Node 24.21 after the cleanup-callback lint correction.
  • HTTP/transport sibling proof: 59 passed, 1 expected macOS skip because 127.0.0.2 was unavailable.
  • Exact 43-file shard (747 tests per run): macOS 4/4 passed; Linux 5/6 passed, then stopped at the first failure. The sole miss was campaign red-main flake #57: src/gateway/server-kernel.startup-fairness.test.ts:85, “services queued I/O after preparing shutdown (cancel: false)”. It observed ["shutdown prepared", "core startup", "I/O"] instead of ["shutdown prepared", "I/O", "core startup"]. At the time of that proof, the test and zero-delay timer were unchanged on origin/main; they run in createGatewayKernel before HTTP transport creation. This is a separate fairness repair, not an EADDRINUSE recurrence. The maintainer accepted the combined proof above for this port-reservation surface; the failure was not retried or hidden.

Production LOC: +33/−10. Tests and test support: +90/−14. All proof used isolated test state and owned listeners.

Codex branch autoreview: --mode branch --base origin/main --max-priority P1, scoped-clean, no accepted/actionable findings. Review artifact: l544-review-branch.md (earlier uncommitted review: l544-review-scoped.md).

pnpm check:changed passed on pre-rebase head 2b7c0edc9c082f84466d7ee67f9f137752acb470, including the cleanup-callback lint fix. The authored patch remains identical after rebasing, and git diff --check is clean.

Previous-head CI run 35187936375 completed blocked only on campaign red-main flake #56:

  • check-test-types: extensions/slack/src/monitor/provider.interop.test.ts:508, TS2769 (ArrayBuffer | Buffer<ArrayBufferLike> does not match the Buffer.from overload).
  • checks-node-changed-extensions-bundle-28: 87 Slack tests failed with Slack Socket Mode envelope guard requires the SDK acknowledgement sender. The shard otherwise had 2,976 passing tests.

The aggregate openclaw/ci-gate failed because those two job families failed. All other executed CI jobs passed: 136 passed, 17 skipped, with no additional independent failures. That previous head’s final full check rollup had zero pending checks. The run is retained as failed evidence and was not rerun. Its #56 blocker was fixed on main by #150656.

Rebased patch-identically onto main at 7f2637f18d79c0a74e414da629062f65064d1ff4, which includes #150656 (d768ad297d5c38ac2c66bc0b9101abd29a196115). git range-diff reports 2b7c0edc9c0 = 950b7ce5d43; there were no conflicts or authored-code changes. The review of record, pr-150642-autoreview.md, is retained. pnpm install --frozen-lockfile passed. New head: 950b7ce5d43df42098d6ca3a3322ff901b984470. Fresh pull_request CI run 35193350398 completed GREEN for head 950b7ce5d43df42098d6ca3a3322ff901b984470. The native watcher exited successfully with zero pending checks. One conflict-free rebase was sufficient; no additional rebase or test rerun was needed.

@clawsweeper

clawsweeper Bot commented Sep 17, 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 gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 17, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 3:46 AM ET / 07:46 UTC (Revision 5).

ClawSweeper review

What this changes

The PR keeps Gateway test ports bound throughout startup, lets the HTTP transport adopt those listeners, and verifies port exclusion, health responses, and release after shutdown.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main still leaves these fixture ports unreserved. No actionable correctness or security defect was found, and the exact-head CI run succeeded.

Priority: P3
Reviewed head: 950b7ce5d43df42098d6ca3a3322ff901b984470

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful socket-boundary coverage, reported cross-platform validation, successful exact-head CI, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied maintainer classification exempts this internal repair from the external-contributor proof gate; supporting evidence exercises real loopback reservation, Gateway /healthz, and shutdown reuse on Linux and macOS.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer classification exempts this internal repair from the external-contributor proof gate; supporting evidence exercises real loopback reservation, Gateway /healthz, and shutdown reuse on Linux and macOS.
Evidence reviewed 7 items Current main still contains the race: Current-main metadata tests call getFreePort before starting the fixture, and the fixture has no retained listener. The helper closes its probing server before returning the port, leaving a competing bind possible.
Listener adoption preserves the production owner: The transport accepts only an already-bound matching HTTP loopback endpoint, registers it in the normal server collection, and skips binding only that listener. Ordinary listeners retain the existing bind/retry path; request routing and shutdown remain with their existing owners.
Boundary regression and captured validation: The complete supplied PR body reports deterministic pre-fix port theft and after-fix Linux/macOS checks. The new regression uses a real competing TCP listener, fetches /healthz through the adopted Gateway listener, and binds the same port after shutdown. These observations match the changed fixture and transport boundary; this review did not execute tests.
Findings None None.
Security None None.

How this fits together

Gateway lifecycle tests start real HTTP servers to check plugin metadata and cleanup behavior. The shared fixture allocates their endpoints, while the Gateway transport installs request handlers and owns normal listener shutdown.

flowchart TD
  A[Lifecycle test] --> B[Reserve loopback listener]
  B --> C[Start Gateway kernel]
  C --> D[Validate and adopt listener]
  D --> E[Serve HTTP requests]
  E --> F[Gateway shutdown releases port]
  C --> G[Failed startup releases reservation]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +23, Tests +76. Total +99 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 33 10 +23
Tests 5 90 14 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 123 24 +99

Review metrics

Metric Value Why it matters
Production versus test growth Production +33/−10; tests and test support +90/−14 The production growth supplies guarded adoption of an existing listener so the real Gateway retains its configured port without a release-and-rebind gap.

Technical review

Best possible solution:

Keep listener ownership continuous from fixture allocation through Gateway shutdown, with ordinary production binding and retry behavior unchanged.

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

Yes: current source releases the probed port before Gateway startup, allowing a competing listener to claim it. The PR records that deterministic failure; this read-only review did not rerun it.

Is this the best way to solve the issue?

Yes: adopting the actual reserved listener removes the handoff gap while preserving the kernel's real port and the existing routing and shutdown owners.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This improves test reliability without changing end-user behavior, configuration, or upgrade requirements.
  • 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 supplied maintainer classification exempts this internal repair from the external-contributor proof gate; supporting evidence exercises real loopback reservation, Gateway /healthz, and shutdown reuse on Linux and macOS.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-17T05:55:43.245Z sha 2b7c0ed :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T06:08:37.153Z sha 2b7c0ed :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T06:33:55.273Z sha 2b7c0ed :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T07:20:55.101Z sha 950b7ce :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 17, 2026 05:59
@steipete
steipete force-pushed the upd/flake-server-close-port-reservation branch from 2b7c0ed to 950b7ce Compare September 17, 2026 07:11
@steipete
steipete merged commit 3a1a5e1 into main Sep 17, 2026
217 checks passed
@steipete
steipete deleted the upd/flake-server-close-port-reservation branch September 17, 2026 08:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…nclaw#150642)

Keep metadata-close Gateway listeners reserved from allocation through startup, preventing intermittent GatewayLockError/EADDRINUSE when another process claims a probed port. The shared fixture transfers the actual HTTP listener to the existing transport and shutdown owners, migrates all three callers, and closes reservations on failed startup or cleanup.

Ordinary Gateway startup retains the existing bind/retry path. There are no user-visible or update behavior changes, new options, schema changes, dependency changes, or timeout increases.

Related: openclaw#150427, whose CI exposed the fixture race but did not cause it.

Validation: deterministic collision, real health response, and shutdown port-release regression; focused Linux/macOS fixture proof; HTTP/transport sibling coverage; exact-head CI run 35193350398 green with zero pending checks. Historical unrelated failures remain documented in the PR and were not rerun. Recorded Codex autoreview and exact-head ClawSweeper review found no actionable defects.
steipete added a commit that referenced this pull request Sep 21, 2026
…ns (#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: #150642. Investigated from run 35649415771, job 106498397182 on
#153314's unrelated merge ref. No product runtime or update behavior changes.
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

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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