Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): recover a deleted tunnel when Cloudflare says "Tunnel not found" #16648

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/16648/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

When 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


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. Approvability

      Verdict: Approved at a894e20

      Macroscope'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).
    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 517188b · PR result: a894e20 · Source CI: success

      Scenario 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.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/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.ts
      The matcher recognizes additional errors in tunnel-registration output, including Tunnel not found. Tests confirm that the same message in Failed to serve tunnel connection output does not match.
      Timed registration recovery
      apps/server/src/cloud/ManagedEndpointRuntime.ts, apps/server/src/cloud/ManagedEndpointRuntime.test.ts
      Each 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 unconnected

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to a894e

      No actionable merge-blocking issue was established. The recovery change is mergeable after normal checks.

      🚥 Pre-merge checks | ✅ 4
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly identifies the server fix for recovery when Cloudflare reports that a tunnel was not found.
      Description check✅ PassedThe 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.
    6. juliusmarminge merged this740bda4

    7. juliusmarminge closed this

Sign in to join this conversation.