Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): T3 Connect switches to HTTP/2 when cloudflared keeps failing its first QUIC registration #48218

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/48218/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

When cloudflared's first QUIC tunnel registration kept timing out (for example while UDP is blocked or the edge is degraded), cloudflared exited before its own HTTP/2 fallback could run. T3 Connect then restarted it with protocol=auto forever, and the tunnel never came up. T3 now counts these startup registration timeouts. After three in a row with no successful registration, it switches the managed cloudflared to --protocol http2 and remembers that choice, the same way it already does for repeated QUIC stalls.

Fixes pingdotgg/t3code#48208

Reproduction on main

Commit 7b7ca65f9a (origin/main), Linux VM, server CLI (t3 serve) linked to the T3 Connect test stage with the managed cloudflared 2026.10.4 and no TUNNEL_TRANSPORT_PROTOCOL set. Steps: t3 connect login --headless and t3 connect link with a fresh --base-dir; started t3 serve in its own systemd scope; dropped UDP 7844 only for that scope with iptables (TCP 7844 untouched).

Run 1 (OUTPUT drop after the first 3 packets of each QUIC flow): the first cloudflared (protocol auto) logged ERR Register tunnel error from server side error="rpc: connection closed", then ERR initial tunnel connection failed error="control stream error: rpc: connection closed", and exited with code 1 after 8 s. T3 counted no QUIC stall, logged no HTTP/2 switch, and restarted it with protocol: auto. This is the reporter's sequence. In my run the second process got fast sendmsg: operation not permitted errors, so cloudflared fell back to http2 on its own within 28 s, and T3 persisted that (#34167).

Run 2 (silent inbound drop, fallback state cleared): cloudflared logged timeout: no recent network activity and fell back to http2 on its own within 6 s.

So the T3 side of the report shows in a real run: an exit during initial registration counts toward nothing and the next start uses auto again. The endless loop also needs the edge to fail registration on every attempt, as it did during the reporter's Cloudflare outage, and I could not force that. Failing test on branch factory/repro-48208 (14acfeba62), in apps/server/src/cloud/ManagedEndpointRuntime.test.ts, "falls back to HTTP/2 when QUIC registration keeps timing out at startup": it feeds the reporter's two log lines followed by exit 1, ten times in a row, and on main the eleventh spawn still has no --protocol http2.

Evidence

Evidence\n\nSteps on both commits: run the managed cloudflared supervisor with ten repeated startup registration failures (rpc: connection closed / context deadline exceeded), advance restart backoff, and inspect the next spawn.\n\n| Before — base 7b7ca65f | After — fix cb19792b |\n| --- | --- |\n| base runtime capture shows the next process still starts without --protocol http2 (the received args are --metrics 127.0.0.1:0 run). | head runtime capture passes after the supervisor starts HTTP/2 and persists it. |\n\nDriver/test source: issue-48208-repro.test.ts

Not shown:

  • The reporter's exact live Cloudflare outage and packet-filtered cloudflared process were unavailable in this VM; evidence uses T3 Code's managed-runtime harness with the reporter's captured cloudflared log sequence, so edge-level networking was not independently re-created.

Tests

  • vp test run src/cloud/ManagedEndpointRuntime.test.ts -t "QUIC registration keeps timing out" without the fix: 1 failed (reproduces the bug)
  • vp test run src/cloud/ManagedEndpointRuntime.test.ts with the fix: 32 passed
  • vp run typecheck (apps/server): no errors
  • vp run check:changed: fmt, lint, knip, typecheck and tests all pass
  • CI on cb19792: all 8 required checks passed

Not in this change

  • The threshold of 3 startup failures is a new constant (QUIC_STARTUP_FAILURES_BEFORE_HTTP2); its value was not tuned against real outages.
  • Not verified end to end against the T3 Connect test stage: forcing the edge to fail registration on every attempt could not be reproduced.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

    1. tanstack-source added labelsbug

    2. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — T3 Connect now automatically selects HTTP/2 after three QUIC startup-registration failures, preserving the fallback across restarts while respecting explicit transport choices. This changes default transport-recovery behavior and requires human confirmation of that product choice.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. 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 decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (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.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.5 KiB92.5 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded78.3 KiB78.3 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows75750 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded79.2 KiB79.2 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows75750 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: 7eba80e · PR result: cb19792 · 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.

    4. juliusmarminge merged this9a08ffb

    5. juliusmarminge closed this

Sign in to join this conversation.