Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): T3 Connect no longer stays down after a network change #19335

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19335/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

After a network change, T3 Connect could stay down for hours. cloudflared resolves Cloudflare's edge addresses only at startup. When those addresses stop routing (VPN, WARP, or ZTNA clients that hand out session-scoped IPs), it keeps running with zero connections. T3 restarted the connector only when the process exited or when the edge rejected the tunnel, so it never recovered on its own.

Fix

  • Spawn cloudflared with --metrics 127.0.0.1:0 and read the bound port from its Starting metrics server on ... log line.
  • Poll /ready every 30s. After 6 HTTP 503s in a row (about 3 minutes), kill the connector. The existing supervisor restarts it, and the new process resolves the edge again. The exit path also sends the existing relay recovery request.
  • Only an explicit 503 counts. A 200 clears the streak. Failed requests, timeouts, and other statuses are ignored, so a healthy tunnel is never restarted.
  • Each restart that never reaches a 200 doubles the threshold, up to about 30 minutes. A host that is really offline does not restart every few minutes.
  • If the metrics line never appears, nothing is polled, which keeps today's behavior.

Proof

  • New test in ManagedEndpointRuntime.test.ts uses TestClock with a scripted /ready. Five 503s, a failed request, and a 200 do not restart the connector. Six 503s in a row restart it. The replacement needs twelve 503s. The test fails on main. Removing the doubling or the reset on 200 also makes it fail.
  • Real process, cloudflared 2026.10.0, fake token, TUNNEL_EDGE=192.0.2.1:7844 (unroutable). This reproduces the issue's failed to dial to edge with quic: timeout: no recent network activity loop.
    • main: the same connector PID ran for 4 minutes with 47 dial timeouts and was never restarted.
    • this branch: at 3:00 it logged Relay client has no tunnel connection; restarting it, and the supervisor started a fresh connector.
  • Checked by hand that cloudflared 2026.5.2 and 2026.10.0 both print the metrics line with --metrics 127.0.0.1:0, that /ready returns {"status":503,"readyConnections":0} with zero connections, and that SIGTERM exits at once.
  • vpr typecheck (apps/server), vp lint, and vp fmt --check on the changed files pass.

Not proven end to end: a real tunnel that registers and then loses its routes. The restart path is the same one the proof exercised.

Fixes #16258

Reviewed with sol-loop: 1 round with GPT-6.1-Sol.

Model and harness: Claude Opus 5.5 in Claude Code via T3 Code.

🤖 Generated with Claude Code

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

    2. juliusmarminge added labelsmacroscope-review

    3. Approvability

      Verdict: Approved at 3fe724f

      Macroscope's review found this PR approvable — This is a focused Cloudflare connector recovery fix that adds a loopback readiness watchdog with conservative retry and restart thresholds, backed by tests covering the failure and recovery sequences. The production impact is limited to restarting a stale connector after sustained explicit readiness failures, with no schema, security, billing, deployment, or static-analysis changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. 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: 4b9f736d-b9af-44de-ade2-20226f6e7be2
      📥 Commits

      Reviewing files that changed from the base of the PR and between d10621de5f8f7e3af4831be04c0564a4ae65eade and 3fe724f5ce4f6c49da7dd41fb54a80f13bfb63f5.

      📒 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. 2 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.

      📝 Walkthrough

      The managed endpoint runtime now starts the relay client with a loopback metrics listener, reads its address, and polls /ready. Consecutive HTTP 503 responses trigger connector termination with an increasing threshold; HTTP 200 resets the threshold. Tests cover response handling and restart behavior.

      Changes: Connector readiness and restart

      Layer / File(s)Summary
      Expose the connector metrics endpoint
      apps/server/src/cloud/ManagedEndpointRuntime.ts
      The runtime requests a metrics listener on a random loopback port and captures its address from connector output.
      Poll readiness and restart stale connectors
      apps/server/src/cloud/ManagedEndpointRuntime.ts, apps/server/src/cloud/ManagedEndpointRuntime.test.ts
      The runtime polls /ready every 30 seconds. HTTP 503 responses count toward the restart threshold; HTTP 200 resets the count and threshold. Failed requests and other statuses do not count. Tests cover the response handling, connector restarts, and launch arguments.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 3fe72

      The change adds a readiness watchdog that restarts a stale connector after sustained 503 responses. No merge-blocking issue was identified in the supplied changes.

      Pre-merge checks: Passed 4
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Description checkPassedThe description explains the problem, implementation, scope, verification steps, limitations, linked issue, and agent details. It matches the required template closely.
      Title checkPassedThe title is concise, uses conventional commit format, and clearly identifies the server fix for T3 Connect recovery after a network change.
      Linked Issues checkPassedIssue [#16258] requires a loopback metrics listener, readiness polling every 30 seconds, counting only consecutive HTTP 503 responses, restart at six checks, threshold doubling up to 60 checks, and re…
      Out of Scope Changes checkPassedThe changes are limited to ManagedEndpointRuntime.ts and its test. The command-line metrics option, readiness watcher, restart behavior, and test helpers directly implement issue [#16258]. No unrela…
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    5. 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 KiB+31 B (+0.6%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB+31 B (+2.6%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB+41 B (+0.2%)29.3 KiB✅
      ClaudeLive turn messages12+1 (+100.0%)8✅

      Baseline: d10621d · PR result: 3fe724f · 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.

Sign in to join this conversation.