Skip to content

fix(macos): prevent stale remote tunnel recreation - #116172

Merged
vincentkoc merged 1 commit into
mainfrom
perf-macos-runtime-profile-v17
Jul 30, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf-macos-runtime-profile-v17

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where macOS users switching or stopping a remote Gateway connection could have delayed tunnel work recreate an SSH process after the connection lifecycle had already moved on. Concurrent reconnects could also launch duplicate tunnel creation work after restart backoff.

Why This Change Was Made

The remote tunnel actor now carries an explicit lifecycle generation across restart backoff, in-flight creation, and tunnel installation. Stale or cancelled work terminates without installing or recursively recreating a tunnel, while a current caller can safely retire an older create and join the canonical replacement.

User Impact

Remote Gateway reconnects and shutdowns no longer leave behind resurrected or duplicate SSH tunnel processes. Current reconnect work continues normally when another caller already owns the same tunnel creation.

Evidence

  • swift test --package-path apps/macos --build-path apps/macos/.build-local --filter GatewayEndpointStoreTests: 57 passed
  • swiftlint lint --strict --config config/swiftlint.yml apps/macos/Sources/OpenClaw/RemoteTunnelManager.swift apps/macos/Tests/OpenClawIPCTests/GatewayEndpointStoreTests.swift: 0 violations
  • Exact rebased head 105fecb1e75: focused Swift suite passed 57 tests; configured SwiftLint reported 0 violations; git diff --check passed
  • Fresh exact-head autoreview: no accepted or actionable findings
  • The exact-head changed gate was delegated to Blacksmith Testbox, but Testbox timed out during checkout sync before executing. A local fallback was stopped at the Codex-worktree dependency-reconciliation prompt per repository policy; GitHub CI owns the remaining broad gate.

@vincentkoc vincentkoc self-assigned this Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: M maintainer Maintainer-authored PR labels Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 10:25 PM ET / July 30, 2026, 02:25 UTC.

ClawSweeper review

What this changes

The PR adds lifecycle-generation ownership to macOS remote Gateway tunnel creation so cancelled, superseded, and concurrent reconnect work cannot resurrect or duplicate SSH tunnels.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this member-authored, maintainer-labelled macOS availability fix open for explicit maintainer review. The supplied patch and focused Swift coverage target the reported stale-work race, but the timing-sensitive SSH process behavior and exact-head macOS checks remain the material merge checks.

Priority: P2
Reviewed head: 105fecb1e75f4481c134bc1fba80327fc8358221

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The proposed lifecycle model has focused regression coverage and no supplied line-level defect, but final confidence depends on maintainer review of the timing-sensitive actor path and exact-head macOS checks.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a member-authored PR, so the external-contributor real-behavior-proof gate does not apply; the reported focused Swift tests are supplemental evidence, while a direct macOS process trace would still strengthen review confidence.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a member-authored PR, so the external-contributor real-behavior-proof gate does not apply; the reported focused Swift tests are supplemental evidence, while a direct macOS process trace would still strengthen review confidence.
Evidence reviewed 4 items Targeted lifecycle change: The proposed Swift patch adds a lifecycle generation to in-flight tunnel creation and checks it across restart backoff, creation, installation, and retirement paths; its stated purpose is to stop stale work from installing or recreating a tunnel.
Focused regression coverage: The PR adds tests for restart-backoff cancellation propagation and configuration-currentness checks, while the PR body reports 57 focused Gateway endpoint/tunnel tests passing on the exact head.
Prior lifecycle provenance: The related merged tunnel-stabilization work introduced the earlier single-flight and restart-backoff foundation; this PR describes a narrower cross-generation ownership gap in that established path.
Findings None None.
Security None None.

How this fits together

The macOS client uses a remote SSH tunnel to reach a selected Gateway. Endpoint changes, reconnects, health checks, and shutdowns feed the tunnel manager, which must either retain one current tunnel or deliberately retire stale work before the app routes traffic to the Gateway.

flowchart LR
  A[Gateway endpoint state] --> B[Remote tunnel manager]
  C[Reconnect or health check] --> B
  D[Shutdown or endpoint change] --> B
  B --> E[Lifecycle generation check]
  E --> F[Create or join current SSH tunnel]
  E --> G[Cancel stale tunnel work]
  F --> H[Remote Gateway route]
Loading

Before merge

  • Resolve merge risk (P1) - The change governs a race between cancellation, endpoint replacement, restart backoff, and asynchronous SSH creation; focused unit tests cover pieces of the ownership model, but do not directly demonstrate that a stale process cannot be recreated during a real macOS reconnect or shutdown.
  • Resolve merge risk (P1) - The exact-head macOS Swift and dead-code CI lanes were still in progress in the supplied status, so maintainers should use their final results when deciding whether the lifecycle change is ready to land.
  • Complete next step (P2) - The PR is member-authored and carries the protected maintainer label, so its native availability tradeoffs and final exact-head checks require explicit maintainer handling rather than automated repair or cleanup.
Agent review details

Security

None.

PR surface

Docs +1, Other +268. Total +269 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 2 304 36 +268
Total 3 305 36 +269

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Land after exact-head lifecycle validation (recommended)
    Use the completed macOS CI results and a maintainer review of the cancellation/create interleavings before merging this tunnel-availability change.
  2. Request direct process-race evidence
    If maintainers need stronger confidence beyond the focused tests, collect a redacted macOS reconnect or stop trace showing that stale SSH work exits while a current reconnect remains usable.

Technical review

Best possible solution:

Retain a single generation-owned tunnel lifecycle: current reconnect work may join or replace the canonical create, while endpoint changes and shutdown permanently retire stale work before it can install or restart an SSH process.

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

No high-confidence live reproduction is included: the supplied evidence is focused Swift coverage of cancellation and configuration ownership, while the reported failure is a timing-dependent macOS SSH lifecycle race. The source-level path is sufficiently concrete to classify as source reproducible.

Is this the best way to solve the issue?

Unclear. Carrying an explicit lifecycle generation through restart, create, install, and retirement is a coherent way to establish one owner for stale asynchronous work, but maintainers should confirm the complete current actor path and final macOS checks before treating it as the best fix.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against 3672ab6fa15f.

Labels

Label justifications:

  • P2: This is a bounded macOS remote-Gateway availability race that can disrupt reconnects or shutdowns but is not evidenced as an emergency-wide outage.
  • merge-risk: 🚨 availability: Merging changes to SSH tunnel ownership can affect whether macOS clients retain or restore remote Gateway connectivity.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a member-authored PR, so the external-contributor real-behavior-proof gate does not apply; the reported focused Swift tests are supplemental evidence, while a direct macOS process trace would still strengthen review confidence.

Evidence

What I checked:

  • Targeted lifecycle change: The proposed Swift patch adds a lifecycle generation to in-flight tunnel creation and checks it across restart backoff, creation, installation, and retirement paths; its stated purpose is to stop stale work from installing or recreating a tunnel. (apps/macos/Sources/OpenClaw/RemoteTunnelManager.swift:10, 105fecb1e75f)
  • Focused regression coverage: The PR adds tests for restart-backoff cancellation propagation and configuration-currentness checks, while the PR body reports 57 focused Gateway endpoint/tunnel tests passing on the exact head. (apps/macos/Tests/OpenClawIPCTests/GatewayEndpointStoreTests.swift:1226, 105fecb1e75f)
  • Prior lifecycle provenance: The related merged tunnel-stabilization work introduced the earlier single-flight and restart-backoff foundation; this PR describes a narrower cross-generation ownership gap in that established path. (apps/macos/Sources/OpenClaw/RemoteTunnelManager.swift:1, 357891a06334)
  • Review-cycle continuity: The prior ClawSweeper cycle raised no line-level findings and requested a macOS reconnect/shutdown exercise after rebase; the author rebased to the stated exact head and explained why a live race reproduction was not run. (105fecb1e75f)

Likely related people:

  • ngutman: The merged macOS tunnel stabilization work established the restart-backoff and tunnel-management path that this PR refines. (role: introduced tunnel restart and single-flight behavior; confidence: high; commits: 357891a06334; files: apps/macos/Sources/OpenClaw/RemoteTunnelManager.swift)
  • steipete: The merged onboarding and configured-Gateway work carried route-scoped endpoint behavior through the macOS connection flow adjacent to this tunnel lifecycle path. (role: recent adjacent route-safety contributor; confidence: medium; commits: 96f0983a85b5; files: apps/macos/Sources/OpenClaw/RemoteTunnelManager.swift)

Rank-up moves

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

  • Confirm the completed macos-swift and macOS dead-code checks for the exact PR head.
  • If practical, add a redacted reconnect or shutdown process trace showing stale SSH work cannot resurrect a tunnel.

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 (1 earlier review cycle)
  • reviewed 2026-07-30T02:10:27.170Z sha de8364a5a85a188166fdf1e58f34ddf301b4f198 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the perf-macos-runtime-profile-v17 branch from de8364a to 105fecb Compare July 30, 2026 02:20
@vincentkoc
vincentkoc marked this pull request as ready for review July 30, 2026 02:21
@vincentkoc

Copy link
Copy Markdown
Member Author

Rank-up move follow-up:

  • Rebase/current-main merge state: completed. The PR now targets exact head 105fecb1e75 and is mergeable.
  • Live macOS reconnect/stop process trace: skipped for this landing because reproducing the shutdown race would require disrupting the operator's active native app and live Gateway. The exact-head proof instead uses the focused 57-test Swift suite, explicit cancellation/configuration ownership regression cases, configured SwiftLint, fresh autoreview, and PR CI.

Provenance: the restart-backoff tunnel path dates to fix(macos): stabilize bridge tunnels (#676); later create/join and configuration validation behavior was carried forward by subsequent tunnel changes, including #102883. The defect is a cross-generation ownership gap rather than a single recent regression.

@vincentkoc

Copy link
Copy Markdown
Member Author

Final exact-head proof for 105fecb1e75:

  • openclaw/ci-gate: success
  • macos-swift: success
  • macOS and shared-kit dead-code checks: success
  • All PR checks: 26 passing, 0 failing, 0 pending

The optional live reconnect/stop trace remains intentionally skipped for the operator-safety reason documented above.

@vincentkoc
vincentkoc merged commit 5128df0 into main Jul 30, 2026
90 of 96 checks passed
@vincentkoc
vincentkoc deleted the perf-macos-runtime-profile-v17 branch July 30, 2026 02:29
vincentkoc added a commit to zhangguiping-xydt/openclaw that referenced this pull request Jul 30, 2026
* origin/main:
  fix(macos): stop canceled voice wake timers (openclaw#116189)
  fix(macos): coalesce location permission requests (openclaw#116183)
  fix(macos): guard remote tunnel restart ownership (openclaw#116172)
  fix(agents): throw CompactionError when summarization fails (openclaw#115500)
  fix(test): isolate ACP startup output stream (openclaw#116076)
  fix(agents): deny all tools when scheduled authority names a removed account (openclaw#115932)
  fix(test): stop collecting Vydra test helpers (openclaw#116139)
  fix(discord): preserve webhook deadline errors (openclaw#116155)
  fix(test): isolate Google embedding batch timeout (openclaw#116161)
  fix(cron): stop replaying old schedule slots after a cron job is edited (openclaw#115779)
  fix(plugins): report request timeouts for stalled response bodies (openclaw#116166)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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