Skip to content

fix(gateway): avoid Tailscale crash loops after upgrades - #126069

Merged
joshavant merged 2 commits into
mainfrom
fix/tailscale-legacy-route-upgrade
Aug 19, 2026
Merged

joshavant merged 2 commits into
mainfrom
fix/tailscale-legacy-route-upgrade

Conversation

@joshavant

@joshavant joshavant commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #125390

What Problem This Solves

Fixes an issue where users upgrading an existing managed Tailscale Serve or Funnel deployment could enter a gateway restart loop when a persistent HTTPS route already owned port 443.

Why This Change Was Made

Gateway startup now treats Tailscale's port-443 listener collision as an ownership conflict and exits with configuration status 78. OpenClaw does not parse the existing route shape to infer ownership and never removes it automatically: a legacy OpenClaw route and an operator-managed route can be identical.

The startup error tells operators to inspect the route and either remove the confirmed legacy root handler explicitly or keep the external route and disable managed Tailscale ingress. This preserves lifecycle-owned managed routes without taking ownership of unrelated Tailscale configuration.

User Impact

Upgrades with a stale persistent route stop once with an actionable migration message instead of entering a systemd restart loop. Operator-managed routes remain untouched, including a persistent root route whose shape exactly matches an older OpenClaw route.

Evidence

  • Captured the regression before the fix with persistent Serve and Funnel routes followed by the current foreground claim; both failed with Tailscale's listener already exists for port 443 error.
  • Process-boundary regression coverage proves that identical persistent Serve and Funnel routes are left byte-for-byte unchanged and startup returns the ownership-conflict guidance.
  • The same fixture proves that an independent Tailscale Service remains unchanged while the managed foreground claim succeeds.
  • Focused validation: 61 tests across Gateway Tailscale startup, Tailscale command handling, and supervised startup exit behavior.
  • node scripts/check-changed.mjs
  • pnpm build
  • pnpm check:docs
  • Off-host Tailscale 1.102.2 proof established the real port-443 collision contract and configuration-exit behavior. The automatic-removal success logs in the earlier evidence comment describe the superseded revision and are not claimed for the current HEAD.
  • All live proof ran on disposable remote systems. The development host's Tailscale configuration was not read or changed; remote routes, nodes, and leases were cleaned up afterward.

Production delta is +35 lines: a typed ownership-conflict error, collision translation at the Tailscale claim boundary, and supervised exit-status mapping. Test/support delta is +122 lines; docs delta is +1 line.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 8:04 PM ET / August 19, 2026, 00:04 UTC.

ClawSweeper review

What this changes

The PR turns a persistent Tailscale HTTPS port-443 collision into an actionable configuration exit while leaving the existing route untouched.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open for explicit maintainer approval: the repair safely preserves ambiguous routes and stops the managed systemd retry loop, but it deliberately changes upgrade recovery policy and the PR is protected with maintainer.

Priority: P1
Reviewed head: d02e799feb745c0bf11323fe0330263764753f52
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with credible real behavior evidence, pending explicit upgrade-policy approval and exact-head checks.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Redacted disposable-host terminal evidence shows the current non-mutating collision path returns exit 78 and leaves route state unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Redacted disposable-host terminal evidence shows the current non-mutating collision path returns exit 78 and leaves route state unchanged.
Evidence reviewed 8 items Current-main behavior: Current main converts a failed route-owner process into a generic error, so the startup exit resolver returns 1 rather than the configuration exit used by systemd prevention.
Conflict translation: The PR recognizes the observed Tailscale listener-collision diagnostic at the route-owner boundary and creates a typed ownership-conflict error.
Supervisor integration: The Gateway command maps that typed error to exit 78, and generated systemd units already declare RestartPreventExitStatus=78.
Findings None None.
Security None None.

How this fits together

Gateway startup asks the local Tailscale CLI to hold a foreground Serve or Funnel route for an isolated Gateway listener. A persistent route can reject that claim; this change carries that failure to the supervised Gateway process and operator recovery guidance.

flowchart LR
  A[Gateway startup] --> B[Foreground Tailscale claim]
  B --> C{Port 443 available?}
  C -->|yes| D[Managed route active]
  C -->|persistent route conflict| E[Ownership conflict]
  E --> F[Configuration exit 78]
  F --> G[Systemd stops restart loop]
  E --> H[Operator reviews route]
Loading

Decision needed

Question Recommendation
Should OpenClaw intentionally fail closed with exit 78 and require targeted operator cleanup when a persistent route is indistinguishable from an operator-managed route? Approve fail-closed migration: Keep the non-mutating conflict exit and documented targeted recovery path.

Why: Automatically removing the matching route would take ownership of configuration that current documentation says may be externally managed.

Before merge

  • Resolve merge risk (P1) - The new diagnostic match is proven against Tailscale 1.102.2; older or future CLI versions that phrase the port-443 collision differently would still take the generic exit-1 path.
  • Resolve merge risk (P1) - Exit 78 stops the loop for generated systemd units with RestartPreventExitStatus=78; custom units without that directive may still restart.
  • Resolve merge risk (P1) - The bug fix adds 34 production lines; the typed error is justified as the cross-process signal needed by the supervisor, but the positive production delta merits maintainer review.
  • Complete next step (P2) - The protected maintainer label and deliberate upgrade-policy choice require explicit owner approval; no narrow mechanical repair remains.
Agent review details

Security

None.

PR surface

Source +34, Tests +122, Docs +1. Total +157 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 34 0 +34
Tests 3 122 0 +122
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 157 0 +157

Review metrics

Metric Value Why it matters
Production versus test delta production +34, tests/test support +122, docs +1 The production addition carries a typed conflict through the worker and supervisor; the larger test support covers Serve and Funnel collision behavior.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/server-tailscale-upgrade.test.ts, serialized state: src/gateway/server-tailscale-upgrade.test.ts, serialized state: test/fixtures/tailscale-legacy-route-fixture.mjs. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #125390
Summary: This PR is the candidate fix for the persistent Tailscale port-443 upgrade collision.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Approve the non-mutating upgrade path (recommended)
    Accept exit 78 plus manual targeted cleanup because OpenClaw cannot safely prove ownership of an identical persistent route.
  2. Require broader version proof
    Pause for contract evidence across the supported Tailscale CLI range if the diagnostic-text dependency is not acceptable.

Technical review

Best possible solution:

Approve the non-mutating ownership boundary, document targeted operator recovery, and merge only after exact-head checks verify the refreshed branch.

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

Yes, source-reproducible: the fixture models the persistent listener collision and proves current main lacks the exit-78 translation; the contributor also supplied a redacted off-host run. A direct local execution was not possible in this read-only environment.

Is this the best way to solve the issue?

Yes, subject to maintainer approval of the upgrade policy. Automatically removing a shape match would violate the documented external-route ownership boundary, while the proposed error preserves state and gives a targeted recovery path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 10610d9f639e.

Labels

Label changes:

  • 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. Sufficient (terminal): Redacted disposable-host terminal evidence shows the current non-mutating collision path returns exit 78 and leaves route state unchanged.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported upgrade path prevents a systemd-managed Gateway from starting and repeatedly restarts it until recovery.
  • merge-risk: 🚨 compatibility: Existing managed Tailscale installations with persistent port-443 routes now stop deliberately and require operator recovery rather than retrying startup.
  • 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. Sufficient (terminal): Redacted disposable-host terminal evidence shows the current non-mutating collision path returns exit 78 and leaves route state unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. Redacted disposable-host terminal evidence shows the current non-mutating collision path returns exit 78 and leaves route state unchanged.

Evidence

What I checked:

  • Current-main behavior: Current main converts a failed route-owner process into a generic error, so the startup exit resolver returns 1 rather than the configuration exit used by systemd prevention. (src/infra/tailscale.ts:240, 10610d9f639e)
  • Conflict translation: The PR recognizes the observed Tailscale listener-collision diagnostic at the route-owner boundary and creates a typed ownership-conflict error. (src/infra/tailscale.ts:241, d02e799feb74)
  • Supervisor integration: The Gateway command maps that typed error to exit 78, and generated systemd units already declare RestartPreventExitStatus=78. (src/cli/gateway-cli/run.ts:480, d02e799feb74)
  • Ownership invariant regression: The new process-boundary fixture covers Serve and Funnel routes with the indistinguishable legacy proxy shape, expects the ownership error, and verifies byte-identical route state. (src/gateway/server-tailscale-upgrade.test.ts:34, d02e799feb74)
  • Existing external-route contract: Current documentation explicitly supports externally managed Serve and Funnel routes and says OpenClaw does not own or clean them up, supporting the decision not to infer ownership from matching route shape. Public docs: docs/gateway/tailscale.md. (docs/gateway/tailscale.md:109, 10610d9f639e)
  • Real after-fix proof: The PR discussion records a redacted disposable-host collision run with exit 78 and byte-identical persistent state; its revision note explicitly separates superseded automatic-removal evidence from the current non-mutating head. (d02e799feb74)

Likely related people:

  • Peter Steinberger: Recent history and the Tailscale-file shortlog show extensive maintenance of the integration and its shared infrastructure. (role: recent area contributor; confidence: high; commits: c5a74b494968, a6f4de4a669d; files: src/infra/tailscale.ts, src/daemon/systemd-unit.ts)
  • TUARAN: Introduced the recent retry handling around Serve startup, an adjacent lifecycle path. (role: prior Tailscale reliability contributor; confidence: medium; commits: 3a5b2764f8a5; files: src/infra/tailscale.ts)
  • RenzoMXD: Earlier work preserved externally managed Funnel routes, directly related to the ownership boundary in this PR. (role: adjacent external-route contributor; confidence: medium; commits: 60f1b1f8d9e8; files: src/infra/tailscale.ts, src/gateway/server-tailscale.ts)

Rank-up moves

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

  • Obtain maintainer approval for the fail-closed migration policy.
  • Refresh against current main and wait for exact-head required checks to finish.

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 (2 earlier review cycles)
  • reviewed 2026-08-18T23:17:24.063Z sha 1cbb16e :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T23:35:20.672Z sha 1cbb16e :: found issues before merge. :: [P1] Do not treat a matching persistent route as OpenClaw-owned

@joshavant

Copy link
Copy Markdown
Collaborator Author

Retained, redacted external-contract evidence from the disposable off-host run described in the PR body follows. Hostnames, tailnet identifiers, foreground session IDs, and the private managed-backend port are removed.

$ tailscale version
1.102.2

# Legacy Serve state created by the older OpenClaw build
$ tailscale serve status --json
{
  "TCP": { "443": { "HTTPS": true } },
  "Web": {
    "<redacted-host>.ts.net:443": {
      "Handlers": { "/": { "Proxy": "http://127.0.0.1:18789/" } }
    }
  }
}

# First startup with this branch
[tailscale] removed legacy persistent Tailscale serve route before claiming foreground ownership
gateway_exit=0

$ tailscale serve status --json
{
  "Foreground": {
    "<redacted-session>": {
      "TCP": { "443": { "HTTPS": true } },
      "Web": {
        "<redacted-host>.ts.net:443": {
          "Handlers": { "/": { "Proxy": "http://127.0.0.1:<managed-backend-port>/" } }
        }
      }
    }
  }
}

# Independent tailnet peer
$ curl -sS -o /dev/null -w '%{http_code}\n' https://<redacted-host>.ts.net/healthz
200

The Funnel run had the same legacy TCP/Web shape plus:

"AllowFunnel": { "<redacted-host>.ts.net:443": true }

Its first patched startup logged removed legacy persistent Tailscale funnel route before claiming foreground ownership and exited 0. An independent public verifier, after disconnecting its own Tailscale client, received HTTP 200 from https://<redacted-host>.ts.net/healthz.

The non-mutation case used a root proxy target of http://127.0.0.1:9000/:

gateway_exit=78
Tailscale HTTPS port 443 is already owned by a route that OpenClaw cannot safely migrate. Inspect `tailscale serve status`; remove or reconfigure that route manually, then restart the Gateway.
route_before_vs_after=byte-identical

The upstream contract was also checked directly at tag v1.102.2: foreground routes are stored under ServeConfig.Foreground; a new foreground listener colliding with persistent TCP 443 returns listener already exists for port 443; and the CLI's targeted --https=443 --set-path=/ off path removes that handler without clearing the device's whole Serve configuration. Sources: ipn/serve.go, ipn/ipnlocal/serve.go, and cmd/tailscale/cli/serve_v2.go.

All Tailscale state in this proof existed only on disposable remote nodes. Those routes and nodes were cleared/logged out and all four remote leases were released. The development host's Tailscale configuration was never read or changed.

@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 18, 2026
@joshavant

Copy link
Copy Markdown
Collaborator Author

Revision note for the off-host evidence above: the automatic route-removal behavior and success logs belong to superseded HEAD 1cbb16e77c9. Current HEAD d02e799feb7 does not infer ownership from route shape and never issues a Tailscale cleanup command during startup. It leaves an identical persistent Serve/Funnel route unchanged and exits with status 78 plus explicit operator guidance; the current process-boundary regression covers that exact indistinguishable route shape.

@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 19, 2026
@joshavant
joshavant merged commit 8d6cbee into main Aug 19, 2026
228 of 238 checks passed
@joshavant
joshavant deleted the fix/tailscale-legacy-route-upgrade branch August 19, 2026 00:14
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
…6069)

* fix(gateway): migrate legacy Tailscale routes on upgrade

* fix(gateway): preserve unattributable Tailscale routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: Upgrade leaves stale Tailscale :443 route and gateway crash-loops

1 participant