fix(server): recover a deleted tunnel when Cloudflare says "Tunnel not found" #16648
main fromrefs/pull/16648/head·merged by juliusmarminge View on GitHubWhen the relay deletes an idle tunnel, the host's connector is supposed to notice the rejection and ask for a replacement at the same hostname. It only recognized three exact messages, and Cloudflare now answers a deleted tunnel with Unauthorized: Tunnel not found. A user's host retried that dead tunnel 503 times instead of recovering. Turning on relay cleanup on 2026-10-06 made this path common, so cleanup is back in dry-run until this ships.
- Any
Unauthorized:registration error now counts as a rejection, alongside the unprefixed messages seen so far. Recovery still waits for four rejections in a row, which absorbs the brief rejections while a new tunnel's token propagates. - A connector that has not registered a connection three minutes after starting requests recovery anyway, and again every three minutes until it connects. When the tunnel is still live the relay hands back the same tunnel, so the connector is left running. This covers the next wording change and any other way a tunnel dies silently.
Tests: the reported line is now matched, and a new TestClock test covers the fallback. Reverting either change fails its test.
Built with Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code Fixes #16399
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Approved at
a894e20Macroscope's review found this PR approvable — This is a contained Cloudflare tunnel recovery fix: it recognizes the newer rejection message and adds a scoped, three-minute fallback for connectors that never register. Existing connected behavior remains unchanged, and the fallback plus message matching are covered by focused tests.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
517188b· PR result:a894e20· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
aed96348-95d4-405c-b0b4-7800be43a8b3
📥 Commits
Reviewing files that changed from the base of the PR and between 517188b3caa135bc09ec0a4f93474ef17c8b5c4f and a894e20b9efa203484d6782f7a5450069c5c237a.
📒 Files selected for processing (2)
apps/server/src/cloud/ManagedEndpointRuntime.test.tsapps/server/src/cloud/ManagedEndpointRuntime.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
📝 Walkthrough
Walkthrough#
The runtime now recognizes additional tunnel-registration rejection messages. It also monitors new connectors and queues recovery every three minutes until a connection is registered.
Changes#
Managed endpoint recovery
Layer / File(s) Summary Tunnel rejection matching
apps/server/src/cloud/ManagedEndpointRuntime.ts,apps/server/src/cloud/ManagedEndpointRuntime.test.tsThe matcher recognizes additional errors in tunnel-registration output, including Tunnel not found. Tests confirm that the same message inFailed to serve tunnel connectionoutput does not match.Timed registration recovery
apps/server/src/cloud/ManagedEndpointRuntime.ts,apps/server/src/cloud/ManagedEndpointRuntime.test.tsEach connector starts with an unconnected state. The runtime queues recovery every three minutes until the connector registers a connection. Tests cover repeated recovery for an unconnected connector and no recovery after connection registration. Priority: ⬆️ High
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant ManagedEndpointRuntime participant RegistrationWatcher participant ActiveConnector participant RecoveryQueue ManagedEndpointRuntime->>RegistrationWatcher: Start watcher for connector RegistrationWatcher->>ActiveConnector: Check connection status after three minutes ActiveConnector-->>RegistrationWatcher: Return connected status RegistrationWatcher->>RecoveryQueue: Queue recovery if unconnectedSuggested reviewers:
t3dotggMerge Risk: ⚪ Minimal · up to
a894eNo actionable merge-blocking issue was established. The recovery change is mergeable after normal checks.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly identifies the server fix for recovery when Cloudflare reports that a tunnel was not found. Description check ✅ Passed The description explains the problem, the recovery changes, and the related tests. It does not use the template headings or clearly state why the change qualifies without prior maintainer approval, an… ✨ Finishing Touches
📝 Generate docstrings
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge merged this740bda4
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes