fix(server): T3 Connect no longer stays down after a network change #19335
main fromrefs/pull/19335/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubAfter 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:0and read the bound port from itsStarting metrics server on ...log line. - Poll
/readyevery 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.tsuses 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'sfailed to dial to edge with quic: timeout: no recent network activityloop.- 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/readyreturns{"status":503,"readyConnections":0}with zero connections, and that SIGTERM exits at once. vpr typecheck(apps/server),vp lint, andvp fmt --checkon 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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Approved at
3fe724fMacroscope'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).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.tsapps/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.tsThe 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.tsThe runtime polls /readyevery 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:
4-
Passed checks: 4 passed-
Check name Status Explanation Description check The description explains the problem, implementation, scope, verification steps, limitations, linked issue, and agent details. It matches the required template closely. Title check The title is concise, uses conventional commit format, and clearly identifies the server fix for T3 Connect recovery after a network change. Linked Issues check Issue [ #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 check The changes are limited to ManagedEndpointRuntime.tsand 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
-
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 +31 B (+0.6%) 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 +31 B (+2.6%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB +41 B (+0.2%) 29.3 KiB ✅ Claude Live turn messages 1 2 +1 (+100.0%) 8 ✅ Baseline:
d10621d· PR result:3fe724f· 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.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes