Repository navigation
fix(test): keep metadata-close Gateway ports reserved through startup - #150642
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 3:46 AM ET / 07:46 UTC (Revision 5). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherGateway 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +23, Tests +76. Total +99 across 7 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
2b7c0ed to
950b7ce
Compare
|
Merged via squash.
|
…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.
…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.
…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.
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
GatewayLockErrorcaused byEADDRINUSE.getFreePorthelper before its intended listener could bind./healthz, and reuse of the same port after Gateway close.127.0.0.2was unavailable.#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 onorigin/main; they run increateGatewayKernelbefore HTTP transport creation. This is a separate fairness repair, not anEADDRINUSErecurrence. 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:changedpassed on pre-rebase head2b7c0edc9c082f84466d7ee67f9f137752acb470, including the cleanup-callback lint fix. The authored patch remains identical after rebasing, andgit diff --checkis clean.Previous-head CI run 35187936375 completed blocked only on campaign red-main flake
#56:extensions/slack/src/monitor/provider.interop.test.ts:508, TS2769 (ArrayBuffer | Buffer<ArrayBufferLike>does not match theBuffer.fromoverload).Slack Socket Mode envelope guard requires the SDK acknowledgement sender.The shard otherwise had 2,976 passing tests.The aggregate
openclaw/ci-gatefailed 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#56blocker was fixed on main by #150656.Rebased patch-identically onto main at
7f2637f18d79c0a74e414da629062f65064d1ff4, which includes #150656 (d768ad297d5c38ac2c66bc0b9101abd29a196115).git range-diffreports2b7c0edc9c0 = 950b7ce5d43; there were no conflicts or authored-code changes. The review of record,pr-150642-autoreview.md, is retained.pnpm install --frozen-lockfilepassed. New head:950b7ce5d43df42098d6ca3a3322ff901b984470. Freshpull_requestCI run 35193350398 completed GREEN for head950b7ce5d43df42098d6ca3a3322ff901b984470. The native watcher exited successfully with zero pending checks. One conflict-free rebase was sufficient; no additional rebase or test rerun was needed.