Skip to content

fix(test): gateway loopback LAN proof flakes in parallel CI - #121389

Merged
steipete merged 1 commit into
mainfrom
fix/gateway-loopback-ephemeral-port
Aug 10, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/gateway-loopback-ephemeral-port

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where the gateway loopback/LAN QA proof could fail with GatewayLockError when parallel CI processes selected the same deterministic test-port block.

Observed on unrelated #121331 in Actions run 31347484644, attempt 1, where the LAN phase exhausted bind retries on 0.0.0.0:56008.

Why This Change Was Made

The producer now uses the OS-ephemeral free-port helper for each gateway phase, probing on 0.0.0.0 so the selected port is free across IPv4 interfaces. The shared helper keeps its existing loopback default for all current callers, and the producer retains its isolated state directory and awaited gateway shutdown between phases and in final cleanup.

The deterministic gateway block allocator remains appropriate for tests that consume derived port + N listeners; this producer disables those sidecars and does not need a block.

User Impact

No product behavior changes. Parallel CI is less likely to fail an unrelated PR because a sibling process selected the same gateway test port.

Evidence

  • Failure proof: attempt 1 of run 31347484644 failed only gateway-loopback-lan-access.test.ts with EADDRINUSE on the second deterministic block offset (56008); attempt 2 passed unchanged.
  • Focused repeat: 10/10 isolated-Linux-network-namespace runs passed, totaling 30/30 assertions for real loopback isolation, LAN reachability, HTTP/WS health, token auth, and teardown.
    • Focused command per iteration: node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-loopback-lan-access.test.ts
  • pnpm check:changed -- src/test-utils/ports.ts test/e2e/qa-lab/runtime/gateway-loopback-lan-access.ts passed all selected format, guard, typecheck, lint, dead-code, and import-cycle checks via the documented local fallback (Testbox/Crabbox was unavailable in the orb).
  • TruffleHog pre-review scan: clean.
  • Independent source review: no blocking findings.

AI-assisted: yes. The implementation, failure logs, allocator ownership, network behavior, and validation results were manually inspected.

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 10, 2026 03:58
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 10, 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 Aug 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 12:05 AM ET / 04:05 UTC.

ClawSweeper review

What this changes

The PR makes the gateway loopback/LAN QA producer obtain ephemeral ports reserved across IPv4 interfaces rather than choose a deterministic multi-port gateway block.

Regression provenance

Possible regression — suspected (failure trace; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: this is a maintainer-owned, protected test-infrastructure fix for a credible parallel-CI port race. Source supports the intended boundary, but final Codex-policy approval is blocked because the required sibling ../codex source is absent and cannot be fetched in this read-only, DNS-restricted environment.

Priority: P3
Reviewed head: c212b062740c878b63aaa7416721dfecf252760b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral test-stability patch with credible source alignment; final policy-gated review remains incomplete in this environment.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This is maintainer-owned test infrastructure; the external-contributor proof gate does not apply, and the PR body additionally reports repeated real gateway-producer runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-owned test infrastructure; the external-contributor proof gate does not apply, and the PR body additionally reports repeated real gateway-producer runs.
Evidence reviewed 6 items PR port-selection change: The branch adds an optional bind host to the shared free-port helper and retains 127.0.0.1 as the default for existing callers.
Affected producer has no derived listeners: Both proof phases now request a wildcard-IPv4 ephemeral port, while gateway startup explicitly defers sidecars; the deterministic multi-port allocator is not needed by this producer.
Gateway LAN contract: The LAN bind mode resolves to 0.0.0.0, matching the wildcard address used to select the test port.
Findings None None.
Security None None.

How this fits together

The gateway network QA producer starts isolated loopback and LAN gateway instances, then probes HTTP and authenticated WebSocket behavior. Its chosen port feeds gateway startup and the resulting checks produce CI evidence artifacts.

flowchart TD
  A[Isolated QA environment] --> B[Port selection]
  B --> C[Gateway startup]
  C --> D{Loopback or LAN bind}
  D --> E[HTTP and WebSocket probes]
  E --> F[QA evidence and CI result]
Loading

Before merge

  • Resolve merge risk (P1) - Final Codex-policy approval remains unavailable until a reviewer can inspect the required sibling ../codex source; this environment cannot fetch it or missing promisor history because DNS resolution fails.
  • Complete next step (P2) - The protected maintainer PR needs final policy-compliant review and exact-head CI rather than an automated repair branch.
Agent review details

Security

None.

PR surface

Source 0, Tests 0. Total 0 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 3 3 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 5 5 0

Review metrics

Metric Value Why it matters
Production versus test LOC production 0; test support +2/-2; QA proof +3/-3 The patch is net-neutral and changes only test infrastructure and its focused QA producer.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the host-aware ephemeral-port selection for this single-listener QA producer, then complete final review in an environment with the required Codex source and exact-head CI.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the host-aware ephemeral-port selection for this single-listener QA producer, then complete final review in an environment with the required Codex source and exact-head CI.

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

No live reproduction was run in this read-only review, but the current deterministic allocator and the producer’s concurrent lifecycle make the reported parallel-process collision source-reproducible.

Is this the best way to solve the issue?

Unclear: the proposed boundary is technically well matched to a sidecar-free LAN listener, but repository policy prevents a final Codex verdict until the required sibling source is available.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 232281fc74f7.

Labels

Label changes:

  • add P3: This reduces CI flakiness without changing shipped gateway behavior or user workflows.
  • 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: This is maintainer-owned test infrastructure; the external-contributor proof gate does not apply, and the PR body additionally reports repeated real gateway-producer runs.

Label justifications:

  • P3: This reduces CI flakiness without changing shipped gateway behavior or user workflows.
  • 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: This is maintainer-owned test infrastructure; the external-contributor proof gate does not apply, and the PR body additionally reports repeated real gateway-producer runs.

Evidence

What I checked:

  • PR port-selection change: The branch adds an optional bind host to the shared free-port helper and retains 127.0.0.1 as the default for existing callers. (src/test-utils/ports.ts:18, c212b062740c)
  • Affected producer has no derived listeners: Both proof phases now request a wildcard-IPv4 ephemeral port, while gateway startup explicitly defers sidecars; the deterministic multi-port allocator is not needed by this producer. (test/e2e/qa-lab/runtime/gateway-loopback-lan-access.ts:368, c212b062740c)
  • Gateway LAN contract: The LAN bind mode resolves to 0.0.0.0, matching the wildcard address used to select the test port. (src/gateway/net.ts:294, 232281fc74f7)
  • Existing regression boundary: The existing focused test invokes the full producer and asserts loopback isolation, LAN reachability, token authentication, and environment restoration. (test/e2e/qa-lab/runtime/gateway-loopback-lan-access.test.ts:39, 232281fc74f7)
  • Feature history: The deterministic allocator’s process-spread behavior dates to Peter Steinberger’s gateway-test stabilization work; the shared helper was later consolidated by Dallin Romney. (src/test-utils/ports.ts:44, fc5a231e9578)
  • Codex policy gate unavailable: The required sibling Codex checkout is absent; fetching missing partial-clone history and cloning it both fail because DNS cannot resolve github.com.

Likely related people:

  • steipete: Authored the deterministic port-block spreading work that defines the allocator behavior this PR deliberately bypasses. (role: gateway test-stability contributor; confidence: high; commits: fc5a231e9578, 208398973baf; files: src/test-utils/ports.ts, src/gateway/test-helpers.e2e.ts)
  • Dallin Romney: Authored the later consolidation of the shared free-port utility used by this patch. (role: shared test-utility contributor; confidence: medium; commits: 7b2c51573f40; files: src/test-utils/ports.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete final review where sibling ../codex source is available and exact-head CI has finished.

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 self-assigned this Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready verification for c212b062740c878b63aaa7416721dfecf252760b:

  • Root cause / owner fix: the QA producer used a deterministic, process-local gateway port block even though it starts only one listener and no port + N sidecars. Sibling CI processes could select the same block; run 31347484644, attempt 1 failed the LAN phase on 0.0.0.0:56008 and the unchanged retry passed. The producer now asks the OS for an ephemeral port on 0.0.0.0 for each phase, retains isolated OPENCLAW_STATE_DIR, and awaits owned gateway shutdown. Existing getFreePort() callers retain the 127.0.0.1 default. Production LOC delta: 0; test support +2/-2; QA proof +3/-3.
  • Focused before/after proof: node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-loopback-lan-access.test.ts passed 10/10 bounded repetitions (30/30 assertions) in fresh Linux network namespaces with loopback plus a dummy 10.200.0.1/24 LAN interface.
  • Changed-surface checks: pnpm check:changed -- src/test-utils/ports.ts test/e2e/qa-lab/runtime/gateway-loopback-lan-access.ts, git diff --check, and TruffleHog passed.
  • Hosted exact-head CI: openclaw/ci-gate run 31354084177 passed. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 121389 passed at 2026-08-10T05:00:53Z in hosted_exact_or_recent_parent mode; no separate Testbox lease was created because exact-head hosted CI already satisfied the gate.
  • Known proof gap: direct orb networking mirrors loopback listeners onto 169.254.0.21, so the isolation assertion was validated in fresh network namespaces rather than on the orb network itself.

Latest ClawSweeper rank-up move disposition: exact-head CI is complete. Sibling Codex source inspection is not applicable because this patch does not touch or depend on Codex code, protocol, or runtime; the changed surfaces are the test-only Node net helper and gateway QA producer. ClawSweeper reported no actionable code or security findings.

@steipete
steipete merged commit d6ee4c3 into main Aug 10, 2026
183 of 185 checks passed
@steipete
steipete deleted the fix/gateway-loopback-ephemeral-port branch August 10, 2026 05:10

Copy link
Copy Markdown
Contributor 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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

2 participants