The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
feat(relay): watch tunnel cleanup on the relay dashboard and warnings (#22105)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 19, 2026 at 20:44 UTC
2d88519c2f4881df224aa00fcf958ebc86aa55c7
2 files changed
+53
docs/operations/relay-observability.md
+9
@@ -147,6 +147,15 @@ account limit.
147
**Traffic dropped.** The Worker is down, a deploy broke it, or spans stopped reaching Axiom. Check
148
`https://relay.t3.codes/health` first.
149
150
+**Tunnel cleanup stopped / tunnel deletions failing.** Warnings for the five-minute reaper that deletes
151
+idle Cloudflare tunnels. "Stopped" counts sweeps that finished, so it also fires when every sweep
152
+fails; a sweep fails when listing tunnels does, usually behind Cloudflare 429s. Idle tunnels are
153
+billed until the reaper catches up, which the "Idle tunnels in Cloudflare" chart shows. A failed
154
+sweep records no counts, so while sweeps fail the chart stops at the last good one; check the tunnel
155
+list in the Cloudflare dashboard for current numbers. For failed
156
+deletions, read the relay's "Failed to delete an inactive managed tunnel" warnings. To pause cleanup,
157
+see [Managed tunnel cleanup rollout](release.md#managed-tunnel-cleanup-rollout).
158
+
159
**Links degraded / database slow.** Warnings for slow degradation. Link failures above 20% over six
160
hours have so far meant provisioning running into the 9 s deadline, with Postgres latency as the
161
usual cause.
infra/relay/src/monitoring.ts
+44
@@ -14,6 +14,11 @@ const LINK_ROUTE = `"/v1/client/environment-links"`;
14
const TUNNEL_ROUTES = `"/v1/environments/:environmentId/tunnel", "/v1/environments/:environmentId/tunnel/recovery"`;
15
const CLOUDFLARE_API = `['attributes.url.full'] startswith "https://api.cloudflare.com"`;
16
const STATUS = `toint(['attributes.http.response.status_code'])`;
17
+// The tunnel reaper records its counters on this span every five minutes,
18
+// including while cleanup is off.
19
+const SWEEP = `name == "relay.managed_endpoint_reaper.sweep"`;
20
+const sweepCounter = (field: string) =>
21
+ `toint(['attributes.custom']['relay.managed_endpoint_reaper.${field}'])`;
22
23
// Status codes, not span errors: a request cut off by the relay deadline ends
24
// as an interrupted span with no error flag, but still answers 504.
@@ -173,6 +178,33 @@ const relayMonitors: ReadonlyArray<RelayMonitor> = [
178
rangeMinutes: 15,
179
triggerFromNRuns: 2,
180
},
181
+ {
182
+ id: "RelayTunnelCleanupStoppedMonitor",
183
+ severity: "warn",
184
+ name: "T3 Connect relay: tunnel cleanup stopped",
185
+ description:
186
+ "Tunnel cleanup sweeps that finished in 30 min. Healthy: 6. The cron is not running, or every sweep fails, as during the 2026-10-19 Cloudflare 429s when listing tunnels timed out. Idle tunnels pile up and are billed meanwhile.",
187
+ query: (dataset) =>
188
+ `['${dataset}']\n| where ${SWEEP} and error != true\n| summarize sweeps = count()`,
189
+ operator: "Below",
190
+ threshold: 1,
191
+ rangeMinutes: 30,
192
+ triggerFromNRuns: 2,
193
+ alertOnNoData: true,
194
+ },
195
+ {
196
+ id: "RelayTunnelCleanupFailingMonitor",
197
+ severity: "warn",
198
+ name: "T3 Connect relay: tunnel deletions failing",
199
+ description:
200
+ "Cloudflare tunnel deletions that failed in 30 min. Healthy: 0; the worst 30 min so far had 3. The relay logs a warning with the Cloudflare error for each.",
201
+ query: (dataset) =>
202
+ `['${dataset}']\n| where ${SWEEP}\n| summarize failed = sum(${sweepCounter("failed")})`,
203
+ operator: "Above",
204
+ threshold: 10,
205
+ rangeMinutes: 30,
206
+ triggerFromNRuns: 2,
207
+ },
208
];
209
210
interface QueryChart {
@@ -230,6 +262,18 @@ const relayDashboardCharts = (dataset: string): ReadonlyArray<QueryChart> => {
262
"Push delivery jobs",
263
`${source}\n| where name in ("relay.apns_deliveries.process_signed_job", "relay.fcm.process")\n| summarize delivered = countif(error != true), failed = countif(error == true) by bin_auto(_time), service = iff(name == "relay.fcm.process", "fcm", "apns")`,
264
),
265
+ timeSeries(
266
+ "tunnel-cleanup",
267
+ "Tunnel cleanup per sweep",
268
+ `${source}\n| where ${SWEEP}\n| summarize deleted = sum(${sweepCounter("deleted")}), deleted_legacy = sum(${sweepCounter("deletedLegacy")}), would_delete = sum(${sweepCounter("wouldDelete")}), would_delete_legacy = sum(${sweepCounter("wouldDeleteLegacy")}), failed = sum(${sweepCounter("failed")}), sweeps_failed = countif(error == true) by bin_auto(_time)`,
269
+ ),
270
+ // Cloudflare's own counts for this stage, including tunnels the reaper
271
+ // skips, so this is the idle tunnels still billed.
272
+ timeSeries(
273
+ "tunnel-backlog",
274
+ "Idle tunnels in Cloudflare",
275
+ `${source}\n| where ${SWEEP}\n| summarize down = max(${sweepCounter("totalDown")}), never_connected = max(${sweepCounter("totalInactive")}) by bin_auto(_time)`,
276
+ ),
277
timeSeries(
278
"server-errors",
279
"5xx by route",