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, 07:00 UTC
fix(server): T3 Connect keeps a log file of its tunnel connector (#24485)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
Victor Vogel committed
Nov 1, 2026 at 15:59 UTC
80a5ffa4ae582cf0a64c52c7c12eae503fbcf731
6 files changed
+174
-1
apps/server/src/cloud/ManagedEndpointRuntime.test.ts
+105
-1
@@ -6,12 +6,15 @@ import * as Duration from "effect/Duration";
6
import * as Effect from "effect/Effect";
7
import * as Exit from "effect/Exit";
8
import * as Fiber from "effect/Fiber";
9
+import * as FileSystem from "effect/FileSystem";
10
import * as Layer from "effect/Layer";
11
import * as Logger from "effect/Logger";
12
import * as Option from "effect/Option";
13
+import * as Path from "effect/Path";
14
import * as PlatformError from "effect/PlatformError";
15
import * as Queue from "effect/Queue";
16
import * as References from "effect/References";
17
+import * as Schema from "effect/Schema";
18
import * as Sink from "effect/Sink";
19
import * as Stream from "effect/Stream";
20
import * as TestClock from "effect/testing/TestClock";
@@ -42,6 +45,15 @@ const layerRelayClientAvailable = Layer.succeed(
45
46
const unusedHttpClient = HttpClient.make(() => Effect.die("unused"));
47
48
+const decodeLogEntry = Schema.decodeUnknownSync(
49
+ Schema.fromJsonString(
50
+ Schema.Struct({
51
+ level: Schema.String,
52
+ message: Schema.Tuple([Schema.String, Schema.Unknown]),
53
+ }),
54
+ ),
55
+);
56
+
57
const emptySecretStoreLayer = Layer.mock(ServerSecretStore.ServerSecretStore)({
58
get: () => Effect.succeedNone,
59
set: () => Effect.void,
@@ -59,7 +71,8 @@ const runtimeDependencies = (
71
Layer.succeed(HttpClient.HttpClient, httpClient),
72
relayClientLayer,
73
secretStoreLayer,
62
- );
74
+ ServerConfig.layerTest(process.cwd(), { prefix: "t3-managed-endpoint-" }),
75
+ ).pipe(Layer.provideMerge(NodeServices.layer));
76
77
const buildCloudManagedEndpointRuntime = (
78
spawner: ReturnType<typeof ChildProcessSpawner.make>,
@@ -543,6 +556,97 @@ describe("CloudManagedEndpointRuntime", () => {
556
}),
557
);
558
559
+ it.effect("keeps redacted connector logs bounded even when rotation fails", () =>
560
+ Effect.gen(function* () {
561
+ const fs = yield* FileSystem.FileSystem;
562
+ const path = yield* Path.Path;
563
+ for (const rotationBlocked of [false, true]) {
564
+ const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-relay-client-log-" });
565
+ const logPath = path.join(baseDir, "userdata", "logs", "relay-client.ndjson");
566
+ const existingLog = "x".repeat(1024 * 1024);
567
+ if (rotationBlocked) {
568
+ yield* fs.makeDirectory(`${logPath}.2`, { recursive: true });
569
+ yield* fs.writeFileString(`${logPath}.2/blocked`, "blocks rotation");
570
+ yield* fs.writeFileString(logPath, existingLog);
571
+ }
572
+ const warnings: unknown[] = [];
573
+ const logger = Logger.make(({ message }) => {
574
+ if (Array.isArray(message) && message[0] === "Relay client log unavailable") {
575
+ warnings.push(message);
576
+ }
577
+ });
578
+ const fixture = yield* makeTransportSpawner();
579
+ yield* Effect.gen(function* () {
580
+ const context = yield* Layer.build(
581
+ ManagedEndpointRuntime.layer.pipe(
582
+ Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir)),
583
+ Layer.provide(runtimeDependencies(fixture.spawner)),
584
+ ),
585
+ );
586
+ const runtime = yield* Effect.service(
587
+ ManagedEndpointRuntime.CloudManagedEndpointRuntime,
588
+ ).pipe(Effect.provide(context));
589
+ yield* runtime.applyConfig({ ...tunnelConfig, connectorToken: "connector-secret" });
590
+ yield* fixture.observe(
591
+ runtime,
592
+ 0,
593
+ '2026-10-16T20:29:40Z ERR Failed to serve tunnel connection error="rejected connector-secret" connIndex=0\n',
594
+ );
595
+ }).pipe(Effect.scoped, Effect.withLogger(logger));
596
+
597
+ const log = yield* fs.readFileString(logPath);
598
+ if (rotationBlocked) {
599
+ expect(log.length).toBe(existingLog.length);
600
+ expect(warnings).toHaveLength(1);
601
+ continue;
602
+ }
603
+ const entries = log
604
+ .trim()
605
+ .split("\n")
606
+ .map((line) => decodeLogEntry(line));
607
+ expect(entries.map((entry) => [entry.level, entry.message[0]])).toEqual([
608
+ ["INFO", "Relay client process started; waiting for tunnel connection"],
609
+ ["WARN", "Relay client reported a transport warning"],
610
+ ["INFO", "Relay client tunnel connection registered"],
611
+ ["INFO", "Relay client stopped"],
612
+ ]);
613
+ expect(log).toContain("rejected <redacted>");
614
+ expect(log).not.toContain("connector-secret");
615
+ const oversizedFixture = yield* makeTransportSpawner();
616
+ yield* Effect.gen(function* () {
617
+ const context = yield* Layer.build(
618
+ ManagedEndpointRuntime.layer.pipe(
619
+ Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir)),
620
+ Layer.provide(runtimeDependencies(oversizedFixture.spawner)),
621
+ ),
622
+ );
623
+ const runtime = yield* Effect.service(
624
+ ManagedEndpointRuntime.CloudManagedEndpointRuntime,
625
+ ).pipe(Effect.provide(context));
626
+ yield* runtime.applyConfig(tunnelConfig);
627
+ yield* oversizedFixture.observe(runtime, 0, "ERR " + "界".repeat(1024 * 1024) + "\n");
628
+ }).pipe(Effect.scoped);
629
+ const files = yield* fs.readDirectory(path.dirname(logPath));
630
+ const allEntries = [];
631
+ for (const file of files.filter((name) => name.startsWith("relay-client.ndjson"))) {
632
+ const contents = yield* fs.readFileString(path.join(path.dirname(logPath), file));
633
+ expect(Buffer.byteLength(contents)).toBeLessThanOrEqual(1024 * 1024);
634
+ allEntries.push(
635
+ ...contents
636
+ .trim()
637
+ .split("\n")
638
+ .map((line) => decodeLogEntry(line)),
639
+ );
640
+ }
641
+ expect(
642
+ allEntries.some(
643
+ (entry) => entry.message[0] === "Relay client log entry omitted: exceeds 1 MiB",
644
+ ),
645
+ ).toBe(true);
646
+ }
647
+ }).pipe(Effect.provide(NodeServices.layer)),
648
+ );
649
+
650
it.effect("discards a pending fallback when its connector is replaced or removed", () =>
651
Effect.gen(function* () {
652
for (const nextConfig of [{ ...tunnelConfig, connectorToken: "replacement" }, null]) {
apps/server/src/cloud/ManagedEndpointRuntime.ts
+60
@@ -1,4 +1,5 @@
1
import type { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay";
2
+import { RotatingFileSink } from "@t3tools/shared/logging";
3
import * as RelayClient from "@t3tools/shared/relayClient";
4
import * as Clock from "effect/Clock";
5
import * as Context from "effect/Context";
@@ -7,7 +8,9 @@ import * as Duration from "effect/Duration";
8
import * as Effect from "effect/Effect";
9
import * as Exit from "effect/Exit";
10
import * as Layer from "effect/Layer";
11
+import * as Logger from "effect/Logger";
12
import * as Option from "effect/Option";
13
+import * as Path from "effect/Path";
14
import * as Queue from "effect/Queue";
15
import * as Ref from "effect/Ref";
16
import * as Result from "effect/Result";
@@ -20,6 +23,7 @@ import * as ChildProcess from "effect/process/ChildProcess";
23
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
24
25
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
26
+import * as ServerConfig from "../config.ts";
27
import * as ManagedLimits from "../policy/managedLimits.ts";
28
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
29
@@ -123,6 +127,7 @@ const encodeHttp2Fallback = Schema.encodeSync(Http2Fallback);
127
// than this, so a crash-looping connector or an offline host does not redownload
128
// on every reconcile.
129
const RELAY_CLIENT_INSTALL_RETRY_INTERVAL_MS = 10 * 60_000;
130
+export const RELAY_CLIENT_LOG_FILE = "relay-client.ndjson";
131
132
/** Preserve user-chosen PATH binaries and overrides; CLI downloads require consent. */
133
function needsPinnedRelayClient(executable: RelayClient.RelayClientStatus): boolean {
@@ -227,6 +232,60 @@ export const make = Effect.gen(function* () {
232
const quicStallsRef = yield* Ref.make<ReadonlyArray<number>>([]);
233
let reconcileConfig: CloudManagedEndpointRuntime["Service"]["applyConfig"];
234
235
+ const { logsDir } = yield* ServerConfig.ServerConfig;
236
+ const path = yield* Path.Path;
237
+ const relayClientLogPath = path.join(logsDir, RELAY_CLIENT_LOG_FILE);
238
+ // Synchronous appends avoid a flush timer for this low-volume log.
239
+ const fallbackLoggers = yield* Effect.service(Logger.CurrentLoggers);
240
+ let writeFailureReported = false;
241
+ const relayClientLog = yield* Effect.try(
242
+ () =>
243
+ new RotatingFileSink({
244
+ filePath: relayClientLogPath,
245
+ maxBytes: 1024 * 1024,
246
+ maxFiles: 2,
247
+ throwOnError: true,
248
+ }),
249
+ ).pipe(
250
+ Effect.map((sink) =>
251
+ Logger.make((options) => {
252
+ try {
253
+ const entry = Logger.formatJson.log(options);
254
+ const bytes = Buffer.byteLength(entry) + 1;
255
+ sink.write(
256
+ bytes <= 1024 * 1024
257
+ ? `${entry}\n`
258
+ : `${JSON.stringify({
259
+ timestamp: options.date.toISOString(),
260
+ level: options.logLevel.toUpperCase(),
261
+ message: ["Relay client log entry omitted: exceeds 1 MiB", { bytes }],
262
+ })}\n`,
263
+ );
264
+ } catch {
265
+ if (!writeFailureReported) {
266
+ writeFailureReported = true;
267
+ for (const logger of fallbackLoggers) {
268
+ logger.log({
269
+ ...options,
270
+ logLevel: "Warn",
271
+ message: ["Relay client log unavailable", { filePath: relayClientLogPath }],
272
+ });
273
+ }
274
+ }
275
+ }
276
+ }),
277
+ ),
278
+ Effect.catch((error) =>
279
+ Effect.logWarning("Relay client log unavailable", {
280
+ filePath: relayClientLogPath,
281
+ cause: error,
282
+ }).pipe(Effect.as(undefined)),
283
+ ),
284
+ );
285
+ // Forked connector fibers inherit this logger after the applyConfig span ends.
286
+ const withRelayClientLog = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
287
+ relayClientLog ? Effect.withLogger(effect, relayClientLog) : effect;
288
+
289
const stopActive = Effect.gen(function* () {
290
const active = yield* Ref.getAndSet(activeRef, null);
291
yield* stopConnector(active);
@@ -760,6 +819,7 @@ export const make = Effect.gen(function* () {
819
return yield* reconcileConfig(config);
820
}),
821
),
822
+ withRelayClientLog,
823
);
824
825
const readMetrics = <S extends Schema.Decoder<unknown>>(url: string, schema: S) =>
apps/server/src/triage/triagePrompt.test.ts
+1
@@ -72,6 +72,7 @@ const contextInput = {
72
logsDir: "/home/u/.t3/userdata/logs",
73
serviceLogPath: "/home/u/.t3/userdata/logs/boot-service.log",
74
desktopBackendLogGlob: "/home/u/.t3/userdata/logs/server-child*.log*",
75
+ relayClientLogPath: "/home/u/.t3/userdata/logs/relay-client.ndjson",
76
serverTracePath: "/home/u/.t3/userdata/logs/server.trace.ndjson",
77
providerEventLogPath: "/home/u/.t3/userdata/logs/provider/events.log",
78
terminalLogsDir: "/home/u/.t3/userdata/logs/terminals",
apps/server/src/triage/triagePrompt.ts
+2
@@ -217,6 +217,7 @@ export interface TriageContextInput {
217
readonly logsDir: string;
218
readonly serviceLogPath: string;
219
readonly desktopBackendLogGlob: string;
220
+ readonly relayClientLogPath: string;
221
readonly serverTracePath: string;
222
readonly providerEventLogPath: string;
223
readonly terminalLogsDir: string;
@@ -302,6 +303,7 @@ ${input.entry.kind === "app" ? IN_APP_SECTION : ""}${input.sourceClone === undef
303
- Logs dir: ${input.paths.logsDir}
304
- Service log (systemd/launchd service installs only): ${input.paths.serviceLogPath}
305
- Desktop backend logs (glob; one file per backend plus rotated copies; written only when a backend crashes or fails to start): ${input.paths.desktopBackendLogGlob}
306
+- T3 Connect tunnel log (ndjson; what the server logged about its cloudflared connector, with rotated copies \`.1\` and \`.2\`): ${input.paths.relayClientLogPath}
307
- Server trace (ndjson): ${input.paths.serverTracePath}
308
- Provider event log: ${input.paths.providerEventLogPath}
309
- Terminal logs: ${input.paths.terminalLogsDir}
apps/server/src/triage/triageSession.ts
+2
@@ -10,6 +10,7 @@ import * as Option from "effect/Option";
10
import * as Path from "effect/Path";
11
12
import * as BootService from "../cloud/bootService.ts";
13
+import * as ManagedEndpointRuntime from "../cloud/ManagedEndpointRuntime.ts";
14
import type * as ServerConfig from "../config.ts";
15
import { isProcessAlive, readPersistedServerRuntimeState } from "../serverRuntimeState.ts";
16
import {
@@ -80,6 +81,7 @@ export const writeTriageSession = Effect.fn("triage.writeTriageSession")(functio
81
logsDir: paths.logsDir,
82
serviceLogPath: path.join(paths.logsDir, BootService.BOOT_SERVICE_LOG_FILE),
83
desktopBackendLogGlob: path.join(paths.logsDir, "server-child*.log*"),
84
+ relayClientLogPath: path.join(paths.logsDir, ManagedEndpointRuntime.RELAY_CLIENT_LOG_FILE),
85
serverTracePath: paths.serverTracePath,
86
providerEventLogPath: paths.providerEventLogPath,
87
terminalLogsDir: paths.terminalLogsDir,
docs/user/t3-connect-troubleshooting.md
+4
@@ -151,3 +151,7 @@ If none of this helps, open an issue on
151
- The text from **Copy diagnostics** in the environment's **Details**.
152
- The output of `t3 connect status` on the host.
153
- The trace ID, if one is shown.
154
+- If the tunnel dropped earlier, the host's tunnel log, `relay-client.ndjson`
155
+ in the logs folder (`~/.t3/userdata/logs` by default). It records when the
156
+ tunnel connected, warned, exited, and restarted, with the tunnel token
157
+ removed.