@devries-cameron20 / t3code Mirror · read-only / commits / 10784e01f8
Fork 0

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 21, 08:30 UTC

fix: expired-session error card asks to pair again and names the rejected request's trace (#38041)

Julius Marminge committed Nov 17, 2026 at 01:57 UTC 10784e01f8b5158ef0f6d61ebd19a8963c45579d
5 files changed +76 -5
apps/server/src/http.test.ts
+38
@@ -234,6 +234,44 @@ describe("untraced requests", () => {
234 expect(serverSpans).toEqual(["GET", "GET", "GET"]);
235 }).pipe(Effect.provide(NodeServices.layer)),
236 );
237 +
238 + it.effect("starts a separate trace for each request, not the server's lifetime trace", () =>
239 + Effect.gen(function* () {
240 + const requestSpans: Array<Tracer.NativeSpan> = [];
241 + const layerTracer = Layer.succeed(
242 + Tracer.Tracer,
243 + Tracer.make({
244 + span: (options) => {
245 + const span = new Tracer.NativeSpan(options);
246 + if (options.kind === "server") requestSpans.push(span);
247 + return span;
248 + },
249 + }),
250 + );
251 + const layerRoutes = Layer.effectDiscard(
252 + Effect.gen(function* () {
253 + const router = yield* HttpRouter.HttpRouter;
254 + yield* router.add("GET", "/api/environment", HttpServerResponse.empty());
255 + }),
256 + );
257 + const services = yield* Layer.build(
258 + HttpRouter.serve(layerRoutes, { disableListenLog: true, disableLogger: true }).pipe(
259 + ServerHttp.withRootRequestSpans,
260 + Layer.provideMerge(NodeHttpServer.layerTest),
261 + ),
262 + ).pipe(Effect.withSpan("server.lifetime"), Effect.provide(layerTracer));
263 + // Without a traceparent header, the server alone decides each request's parent.
264 + const client = Context.get(services, HttpClient.HttpClient);
265 +
266 + for (let i = 0; i < 2; i++) {
267 + yield* client
268 + .execute(HttpClientRequest.get("/api/environment"))
269 + .pipe(Effect.provideService(HttpClient.TracerPropagationEnabled, false));
270 + }
271 + expect(requestSpans.map((span) => span.parent._tag)).toEqual(["None", "None"]);
272 + expect(new Set(requestSpans.map((span) => span.traceId)).size).toBe(2);
273 + }).pipe(Effect.provide(NodeServices.layer)),
274 + );
275 });
276
277 const layerFileResponse = Layer.mergeAll(NodeHttpPlatform.layer, NodeServices.layer);
apps/server/src/http.ts
+14
@@ -9,6 +9,7 @@ import { injectMcpAppCookieBootstrap, injectMcpAppThemeBootstrap } from "@t3tool
9 import { FILE_PREVIEW_SCROLL_SCRIPT } from "@t3tools/shared/htmlRender";
10 import { decodeOtlpTraceRecords } from "@t3tools/shared/observability";
11 import * as ByteSize from "effect/ByteSize";
12 +import * as Context from "effect/Context";
13 import * as Effect from "effect/Effect";
14 import * as FileSystem from "effect/FileSystem";
15 import * as Layer from "effect/Layer";
@@ -16,6 +17,7 @@ import * as Option from "effect/Option";
17 import * as Path from "effect/Path";
18 import * as Schema from "effect/Schema";
19 import * as Stream from "effect/Stream";
20 +import * as Tracer from "effect/Tracer";
21 import { cast, pipe } from "effect/Function";
22 import {
23 HttpClient,
@@ -432,6 +434,18 @@ const layerUntracedRequests = Layer.succeed(HttpMiddleware.TracerDisabledWhen)((
434
435 export const withUntracedRequests = Layer.provide(layerUntracedRequests);
436
437 +// Request spans otherwise parent to the server's lifetime span, so every request shares one trace id.
438 +export const withRootRequestSpans = <A, E, R>(layer: Layer.Layer<A, E, R>) =>
439 + Layer.fromBuild((memoMap, scope) =>
440 + Layer.buildWithMemoMap(layer, memoMap, scope).pipe(
441 + // ParentSpan is optional to every reader, so removing it leaves R satisfied.
442 + Effect.updateContext(
443 + (context: Context.Context<R>) =>
444 + Context.omit(Tracer.ParentSpan)(context) as Context.Context<R>,
445 + ),
446 + ),
447 + );
448 +
449 export const layerAssetRoute = HttpRouter.add(
450 "GET",
451 `${ASSET_ROUTE_PREFIX}/*`,
apps/server/src/server.ts
+2 -1
@@ -32,7 +32,7 @@ import * as HostPowerMonitor from "./background/HostPowerMonitor.ts";
32 import * as NonBlockingSpawner from "./process/NonBlockingSpawner.ts";
33 import * as KeepAwake from "./background/KeepAwake.ts";
34 import * as ServerConfig from "./config.ts";
35 -import { withUntracedRequests } from "./http.ts";
35 +import { withRootRequestSpans, withUntracedRequests } from "./http.ts";
36 import * as ServerHttp from "./http.ts";
37 import {
38 guardHttpResponseWriteErrors,
@@ -1340,6 +1340,7 @@ const layerMakeServer = Layer.unwrap(
1340 routerConfig: HTTP_ROUTER_CONFIG,
1341 }).pipe(
1342 withUntracedRequests,
1343 + withRootRequestSpans,
1344 Layer.tap(() => Deferred.succeed(routesReady, undefined).pipe(Effect.orDie)),
1345 );
1346 const layerServerApplication = Layer.mergeAll(
packages/client-runtime/src/connection/diagnosis.test.ts
+14
@@ -1,3 +1,4 @@
1 +import { EnvironmentAuthInvalidError } from "@t3tools/contracts";
2 import {
3 RelayEnvironmentEndpointUnavailableError,
4 type RelayProtectedError,
@@ -163,6 +164,19 @@ describe("presentConnectionDiagnosis", () => {
164 expect(diagnosis?.steps.join(" ")).toContain("t3 auth connect-device approve K7QM-2XFD");
165 });
166
167 + it("tells a host that refused this device's login to sign in again, not to start T3 Code", () => {
168 + const failure = mapRemoteEnvironmentError(
169 + new EnvironmentAuthInvalidError({
170 + code: "auth_invalid",
171 + reason: "invalid_credential",
172 + traceId: "trace-1",
173 + }),
174 + );
175 + const steps = diagnose(backoff(failure), "direct")?.steps.join(" ");
176 + expect(steps).not.toContain("Make sure T3 Code is running");
177 + expect(steps).toMatch(/pair|sign in/i);
178 + });
179 +
180 it("does not report hops as working when the failure names none", () => {
181 const failure = new ConnectionBlockedError({
182 reason: "authentication",
packages/client-runtime/src/connection/diagnosis.ts
+8 -4
@@ -235,10 +235,14 @@ function steps(host: string, located: Located, failure: ConnectionAttemptError |
235 ]
236 : [`Make sure ${host} is awake and online.`, checkHost];
237 case "server":
238 - return [
239 - `Make sure T3 Code is running on ${host}.`,
240 - "Retry. If it keeps failing, copy the diagnostics.",
241 - ];
238 + return failure?.reason === "authentication"
239 + ? [
240 + `This device's sign-in to ${host} expired or was revoked. Pair it again with a new pairing link from ${host}.`,
241 + ]
242 + : [
243 + `Make sure T3 Code is running on ${host}.`,
244 + "Retry. If it keeps failing, copy the diagnostics.",
245 + ];
246 }
247 }
248