Repository navigation
fix(tailscale): release managed routes after Gateway crashes - #139261
Conversation
Keep the IPC cleanup worker alive when the Gateway process group is killed, so its detached foreground claimant exits and a replacement can bind the same port. Handle IPC loss during worker startup and rely on native Promise settlement instead of duplicate startup state. Related: #126445, #126457. Preserve this prevention repair pending the ownership decision for foreground orphans left by pre-fix Gateways; no automatic reclamation of ambiguous existing foreground routes is added. Co-authored-by: PollyBot13 <[email protected]>
|
🦞👀 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: blocked before merge. Reviewed September 5, 2026, 2:13 PM ET / 18:13 UTC. ClawSweeper reviewWhat this changesKeeps the Tailscale cleanup worker alive after a Gateway process-group crash so it can release the managed route, with regression coverage for cleanup and port reacquisition. Merge readiness⛔ Blocked before merge - 3 items remain Keep open: current main still has the process-group lifecycle defect, and this focused repair has no blocking correctness findings. Priority: P1 Review scores
Verification
How this fits togetherManaged Tailscale Serve and Funnel expose the Gateway through a foreground CLI process. A cleanup worker owns that process and releases its route when Gateway communication closes. flowchart TD
A[Gateway starts managed exposure] --> B[Cleanup worker in separate process group]
B --> C[Foreground Tailscale claimant]
C --> D[Gateway HTTPS route]
E[Gateway exits or crashes] --> F[IPC connection closes]
F --> B
B --> G[Stop claimant and release route]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -1, Tests +107. Total +106 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep crash cleanup in the existing route owner, with automatic release of newly managed claims and explicit operator recovery for already-orphaned legacy claims. Do we have a high-confidence way to reproduce the issue? Yes, source-backed: kill the Gateway's POSIX process group while it holds a managed route; current main also loses the cleanup worker while its detached claimant survives. This read-only review did not execute that scenario. Is this the best way to solve the issue? Yes: repairing the existing process owner addresses hard crashes directly without changing launchd drain policy or terminating ambiguously owned historical processes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bd381bffb29d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready review for d42ae5d: the PR body now contains the fresh Crabbox before/after trace, exact Gateway/build/test commands, source identities and proof limitations. The real Linux Gateway comparison reproduced the pre-fix PPID-1 claimant and replacement exit 78. The fixed worker/claimant exited within 31 ms, and replacement Gateway plus same-port route health passed within 1.976 seconds. This uses a synthetic PATH Tailscale CLI with real IPC/process/socket behavior; it is not authenticated tailnet/TLS or native launchd Gateway proof. All 55 focused tests and both runtime builds passed. The Testbox lease was stopped and cleanup verified: https://github.com/openclaw/openclaw/actions/runs/33982892355. Independent Codex autoreview is scoped-clean at P0–P2. Exact-head CI is successful with 130 passing checks, 51 intentional skips and no pending/failing checks: https://github.com/openclaw/openclaw/actions/runs/33983015562. The latest ClawSweeper proof request and rank-up move are addressed in the body. The serialized-state flag is inapplicable: the |
|
Merged via squash.
|
* commit '911d7d5b0c107f7274f2415ca9655dcc6105f0e8': (867 commits) fix(skills): deliver pending Workshop approval controls (#139248) fix(gateway): deliver loopback ask_user prompts to the originating channel (#138831) docs: keep root agent instructions focused on repository policy (#139258) fix(matrix): exclude archived state roots from scans and selection (#112329) perf(agents): prepare exact tool names once per catalog batch (#139267) fix: preserve Swarm progress and simplify owner plumbing (#139269) fix(tailscale): release claims after gateway process-group exit (#139261) refactor(cli): simplify lazy command registration (#139108) test(ui): retain synthetic widget failure evidence (#139229) fix(buzz): keep implicit replies at thread root (#138879) test(diagnostics): await graceful Gateway shutdown before cleanup (#139247) fix(ci): unblock releases with different tooling package managers (#139259) feat(ui): add social preview links for private sessions (#139250) fix(codex): retain failed conversations for guarded continuation (#139246) chore(ui): refresh control ui locales (#139200) fix(ci): run browser checks for real-gateway inputs (#139256) fix(llama-cpp): reconcile managed router state before requests (#136363) chore(i18n): refresh native locales (#139237) refactor(worker): unify inference payload handling (#139245) refactor(terminal): replay wrapped prefixes in one pass (#139240) ...
…claw#139261) Keep the IPC cleanup worker alive when the Gateway process group is killed, so its detached foreground claimant exits and a replacement can bind the same port. Handle IPC loss during worker startup and rely on native Promise settlement instead of duplicate startup state. Related: openclaw#126445, openclaw#126457. Preserve this prevention repair pending the ownership decision for foreground orphans left by pre-fix Gateways; no automatic reclamation of ambiguous existing foreground routes is added. Co-authored-by: PollyBot13 <[email protected]>
What Problem This Solves
Fixes an issue where a macOS Gateway killed during restart could leave its foreground Tailscale claimant alive. That stale claimant kept HTTPS port 443 occupied, so replacement Gateways failed to start and entered a restart loop.
Closes #126445. Supersedes #126457 with a focused repair to process ownership, preserving @PollyBot13's report and contribution.
Why This Change Was Made
The cleanup worker now has its own POSIX process group, allowing it to observe Gateway IPC loss and terminate the foreground claimant even when the Gateway's entire process group is killed. It also handles IPC loss before its listeners are installed. Normal cleanup still waits for the claimant to exit; redundant startup Promise-settlement bookkeeping is removed.
This repairs the existing documented promise that losing the Gateway releases its managed route. It does not change launchd shutdown budgets or introduce the original PR's unreadable-timeout immediate-exit policy. It prevents new orphans; foreground claims left by pre-fix Gateways still require the operator to stop their confirmed owning process, because unrelated foreground routes cannot safely be identified from a port or process name alone.
User Impact
A replacement Gateway can reclaim its Tailscale route after the previous Gateway is killed. Windows retains its current process behavior. No configuration, database, protocol, or dependency changes.
Evidence
Exact head:
d42ae5d4803578c714e3c96ef4b01d605672a867; tree04fe99ddc4971fd5d178d8d02bc77a603bcb0950. Both remote source checkouts had no tracked diff after their builds.blacksmith-testbox, leasetbx_01m1sbvw4vd9z61aznp28td9wn, backing lease workflow. Node 24.19.0, pnpm 12.3.4, Linux 6.6.141 x86_64. The leased command passed; lease cleanup can mark its backing workflow cancelled.pnpm install --offline --frozen-lockfileand built withnode --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime.node scripts/run-vitest.mjs src/infra/tailscale-parent-loss.process.test.ts src/infra/tailscale-route-owner.worker.test.ts src/infra/tailscale.test.ts src/gateway/server-tailscale.test.ts. Prior macOS owner/process proof passed 7 tests; the pre-fix group-kill regression failed because the claimant survived.Real Gateway before/after
The probe ran the built
openclaw.mjs gateway runCLI with isolated state/config and a synthetic PATHtailscaleexecutable owning a real loopback TCP proxy. It exercised the production claim owner withoutVITESTor test-only runtime overrides. This is real Gateway/process/socket proof, not authenticated Tailscale or HTTPS proof; neither Tailscale binary was installed on the runner. It directly tests the changed POSIX ownership boundary. Local macOS process tests and the documented launchd job-group cleanup contract cover the platform-specific premise; a full native launchd Gateway run was not performed in this lane.Before:
e09a265b11112623addd4de2167ee6b34cd82719.After:
d42ae5d4803578c714e3c96ef4b01d605672a867.The Gateway commands, from their respective checkout roots, were:
Each scenario killed the original Gateway's process group with SIGKILL, then launched a replacement with the same Gateway and route ports for that scenario.
ok:trueok:trueEADDRINUSE; old claimant remainedThe temporary remote checkouts, state, configs, listeners and proof processes were removed. The command and wrapper returned success; the lease was stopped and its completed state verified. Evidence report SHA-256:
b037576f3ffeb99b24c42dcb2d8d7f6ba0ee73454b714be8b098c32f6b82a1c5.Review follow-through and upgrade scope
The latest ClawSweeper review identified no code findings. Its requested real-Gateway before/after evidence and rank-up move are satisfied above. Its serialized-state flag is a false positive: the existing
{ argv }IPC payload is unchanged; this diff changes a spawn option, removes a redundant local boolean, and handles already-closed IPC. No stored representation, schema, migration, or config changes exist. Stablev2026.9.1contains the same process-group mismatch; newly started upgraded Gateways use the repaired owner. The maintainer explicitly selected prevention with operator-assisted recovery for historical ambiguous claims.Follow-up identified during review: foreground-conflict diagnostics currently suggest a background route removal command; they should distinguish foreground ownership and direct operators to stop the confirmed owning CLI. Automatic termination of ambiguous historical claims remains out of scope.