@devries-cameron20 / t3code-1 / commits / 97c2cff897
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): retain relay unregister events at normal log level (#21650)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 30, 2026 at 15:28 UTC 97c2cff89737b24e61742a7c1f13a1b62715c641
2 files changed +110 -2
apps/server/src/cloud/ManagedEndpointRuntime.test.ts
+101
@@ -5,9 +5,11 @@ import * as Effect from "effect/Effect";
5 import * as Exit from "effect/Exit";
6 import * as Fiber from "effect/Fiber";
7 import * as Layer from "effect/Layer";
8 +import * as Logger from "effect/Logger";
9 import * as Option from "effect/Option";
10 import * as PlatformError from "effect/PlatformError";
11 import * as Queue from "effect/Queue";
12 +import * as References from "effect/References";
13 import * as Sink from "effect/Sink";
14 import * as Stream from "effect/Stream";
15 import * as TestClock from "effect/testing/TestClock";
@@ -148,6 +150,28 @@ describe("CloudManagedEndpointRuntime", () => {
150 ).toBe("warning");
151 });
152
153 + it("classifies connection unregistration apart from registration and routine output", () => {
154 + expect(
155 + ManagedEndpointRuntime.classifyRelayClientOutput(
156 + "2026-10-06T00:00:00Z INF Unregistered tunnel connection connIndex=0 event=0 ip=198.41.200.23",
157 + ),
158 + ).toBe("unregistered");
159 + for (const level of ["ERR", "WRN", "FTL", "PNC"]) {
160 + expect(
161 + ManagedEndpointRuntime.classifyRelayClientOutput(
162 + `2026-10-06T00:00:00Z ${level} Unregistered tunnel connection connIndex=0`,
163 + ),
164 + ).toBe("warning");
165 + }
166 + for (const line of [
167 + "2026-10-06T00:00:00Z INF Initiating graceful shutdown due to signal terminated ...",
168 + "2026-10-06T00:00:00Z INF Starting metrics server on 127.0.0.1:20241/metrics",
169 + "2026-10-06T00:00:00Z DBG Unregistered tunnel connection connIndex=0",
170 + ]) {
171 + expect(ManagedEndpointRuntime.classifyRelayClientOutput(line)).toBe("debug");
172 + }
173 + });
174 +
175 it("recognizes tunnel authorization failures without matching ordinary transport errors", () => {
176 expect(
177 ManagedEndpointRuntime.isRejectedRelayClientTunnelOutput(
@@ -203,6 +227,83 @@ describe("CloudManagedEndpointRuntime", () => {
227 }),
228 );
229
230 + it.effect("logs a connection unregistration at info with the connector token redacted", () => {
231 + const logs: Array<{ readonly level: string; readonly message: unknown }> = [];
232 + const unregistrationLogged = Deferred.makeUnsafe<void>();
233 + const logger = Logger.make(({ logLevel, message }) => {
234 + logs.push({ level: logLevel, message });
235 + if (Array.isArray(message) && message[0] === "Relay client tunnel connection unregistered") {
236 + Deferred.doneUnsafe(unregistrationLogged, Effect.void);
237 + }
238 + });
239 +
240 + return Effect.gen(function* () {
241 + const config = {
242 + providerKind: "cloudflare_tunnel" as const,
243 + connectorToken: "secret-connector-token",
244 + tunnelId: "tunnel-1",
245 + };
246 + const encoder = new TextEncoder();
247 + const output = yield* Queue.unbounded<Uint8Array>();
248 + const spawner = ChildProcessSpawner.make(() =>
249 + Effect.gen(function* () {
250 + const handle = makeHandle({
251 + pid: 701,
252 + onKill: () => {},
253 + output: Stream.fromQueue(output),
254 + });
255 + yield* Effect.addFinalizer(() => handle.kill().pipe(Effect.ignore));
256 + return handle;
257 + }),
258 + );
259 + const runtime = yield* buildCloudManagedEndpointRuntime(spawner);
260 + yield* runtime.applyConfig(config);
261 + yield* Queue.offer(
262 + output,
263 + encoder.encode(
264 + "2026-10-06T00:00:00Z INF Unregistered tunnel connection connIndex=0 token=secret-connector-token\n",
265 + ),
266 + );
267 + yield* Deferred.await(unregistrationLogged);
268 +
269 + // An unregistration is not a registration, so the registration timeout still recovers.
270 + yield* TestClock.adjust(Duration.minutes(3));
271 + expect(Option.getOrNull(yield* Stream.runHead(runtime.recoveryRequests))).toEqual(config);
272 +
273 + yield* Queue.offer(
274 + output,
275 + encoder.encode(
276 + "2026-10-06T00:00:01Z INF Starting metrics server on 127.0.0.1:20241/metrics\n" +
277 + "2026-10-06T00:00:01Z INF Registered tunnel connection connIndex=0\n",
278 + ),
279 + );
280 + yield* Stream.runHead(runtime.tunnelConnected);
281 +
282 + const relayLogs = logs.filter(
283 + ({ message }) =>
284 + Array.isArray(message) && String(message[0]).startsWith("Relay client tunnel"),
285 + );
286 + expect(relayLogs.map(({ level, message }) => [level, (message as unknown[])[0]])).toEqual([
287 + ["Info", "Relay client tunnel connection unregistered"],
288 + ["Info", "Relay client tunnel connection registered"],
289 + ]);
290 + expect((relayLogs[0]!.message as unknown[])[1]).toMatchObject({
291 + output:
292 + "2026-10-06T00:00:00Z INF Unregistered tunnel connection connIndex=0 token=<redacted>",
293 + });
294 + const logged = JSON.stringify(logs.map(({ message }) => message));
295 + expect(logged).not.toContain("secret-connector-token");
296 + expect(logged).not.toContain("Starting metrics server");
297 + }).pipe(
298 + Effect.provide(
299 + Layer.merge(
300 + Logger.layer([logger], { mergeWithExisting: false }),
301 + Layer.succeed(References.MinimumLogLevel, "Info"),
302 + ),
303 + ),
304 + );
305 + });
306 +
307 const tunnelConfig = {
308 providerKind: "cloudflare_tunnel" as const,
309 connectorToken: "token",
apps/server/src/cloud/ManagedEndpointRuntime.ts
+9 -2
@@ -124,12 +124,17 @@ function needsPinnedRelayClient(executable: RelayClient.RelayClientStatus): bool
124 );
125 }
126
127 -export function classifyRelayClientOutput(line: string): "connected" | "warning" | "debug" {
127 +export function classifyRelayClientOutput(
128 + line: string,
129 +): "connected" | "unregistered" | "warning" | "debug" {
130 if (/\bRegistered tunnel connection\b/iu.test(line)) {
131 return "connected";
132 }
133 // cloudflared uses zerolog FTL/PNC for fatal/panic; classify them above debug too.
132 - return /\b(?:ERR|WRN|FTL|PNC)\b/u.test(line) ? "warning" : "debug";
134 + if (/\b(?:ERR|WRN|FTL|PNC)\b/u.test(line)) {
135 + return "warning";
136 + }
137 + return /\bINF\b.*\bUnregistered tunnel connection\b/u.test(line) ? "unregistered" : "debug";
138 }
139
140 /** Edge rejection wording varies; any Unauthorized registration error counts. */
@@ -513,6 +518,8 @@ export const make = Effect.gen(function* () {
518 ),
519 Effect.asVoid,
520 );
521 + case "unregistered":
522 + return Effect.logInfo("Relay client tunnel connection unregistered", attributes);
523 case "warning":
524 if (/\btimeout: no recent network activity\b/u.test(line)) {
525 return noteQuicStall(connector).pipe(