@devries-cameron20 / t3code-1 / commits / 6b7766143d
Fork 0

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

fix(server): T3 Connect retries a link rejected for an expired proof (#18621)

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>

fixfon committed Oct 18, 2026 at 22:11 UTC 6b7766143d3f4eba5ad6c02da8e02cc3aa4931fa
3 files changed +91 -5
apps/server/src/cloud/CloudLink.lifecycle.test.ts
+52 -5
@@ -1213,10 +1213,20 @@ describe("releaseManagedTunnelOnShutdown", () => {
1213 });
1214
1215 it.effect.each([
1216 - { status: 401, rejection: "unauthorized" },
1217 - { status: 403, rejection: "forbidden" },
1218 - { status: 409, rejection: "rejected" },
1219 - ])("preserves a permanent $status relay recovery failure", ({ status, rejection }) => {
1216 + { status: 401, body: {}, rejection: "unauthorized" },
1217 + {
1218 + status: 401,
1219 + body: {
1220 + _tag: "RelayAuthInvalidError",
1221 + code: "auth_invalid",
1222 + reason: "invalid_bearer",
1223 + traceId: "trace-revoked",
1224 + },
1225 + rejection: "unauthorized",
1226 + },
1227 + { status: 403, body: {}, rejection: "forbidden" },
1228 + { status: 409, body: {}, rejection: "rejected" },
1229 + ])("preserves a permanent $status relay recovery failure", ({ status, body, rejection }) => {
1230 const { store } = makeMemorySecretStore([
1231 [CLOUD_ENDPOINT_RUNTIME_CONFIG, "old-config"],
1232 [RELAY_URL_SECRET, "https://relay.example.test"],
@@ -1239,7 +1249,44 @@ describe("releaseManagedTunnelOnShutdown", () => {
1249 store,
1250 applyConfigCalls,
1251 requests,
1242 - respond: () => Response.json({}, { status }),
1252 + respond: () => Response.json(body, { status }),
1253 + }),
1254 + );
1255 + });
1256 +
1257 + // A proof signed with a skewed boot clock is rejected as expired. The next
1258 + // attempt mints a new proof, so startup reconcile must keep retrying it.
1259 + it.effect("retries a relay link proof rejected as expired", () => {
1260 + const { store } = makeMemorySecretStore([
1261 + [CLOUD_ENDPOINT_RUNTIME_CONFIG, "old-config"],
1262 + [RELAY_URL_SECRET, "https://relay.example.test"],
1263 + [CLOUD_LINKED_USER_ID, "user-123"],
1264 + [RELAY_ENVIRONMENT_CREDENTIAL_SECRET, "environment-credential"],
1265 + ]);
1266 + const applyConfigCalls: Array<unknown> = [];
1267 + const requests: Array<HttpClientRequest.HttpClientRequest> = [];
1268 +
1269 + return Effect.gen(function* () {
1270 + const link = yield* CloudLink.CloudLink;
1271 + const error = yield* Effect.flip(link.recoverManagedTunnel("http://127.0.0.1:3773"));
1272 +
1273 + expect(error).toMatchObject({ _tag: "RelayRequestError", rejection: "unavailable" });
1274 + expect(error.message).toContain("Trace ID: trace-expired");
1275 + expect(CloudLink.shouldRetryCloudLink(error)).toBe(true);
1276 + }).pipe(
1277 + provideReleaseHarness({
1278 + store,
1279 + applyConfigCalls,
1280 + requests,
1281 + respond: () =>
1282 + Response.json(
1283 + {
1284 + _tag: "RelayEnvironmentLinkProofExpiredError",
1285 + code: "environment_link_proof_expired",
1286 + traceId: "trace-expired",
1287 + },
1288 + { status: 401 },
1289 + ),
1290 }),
1291 );
1292 });
apps/server/src/cloud/relayResponse.test.ts
+28
@@ -76,6 +76,34 @@ it.effect("makes revoked authorization actionable and non-retryable", () =>
76 }),
77 );
78
79 +it.effect("retries an expired link proof but not a revoked bearer, both 401", () =>
80 + Effect.gen(function* () {
81 + const expired = yield* filterRelayResponse(
82 + response(401, {
83 + _tag: "RelayEnvironmentLinkProofExpiredError",
84 + code: "environment_link_proof_expired",
85 + traceId: "trace-expired",
86 + }),
87 + ).pipe(Effect.mapError(relayRequestError), Effect.flip);
88 + const revoked = yield* filterRelayResponse(
89 + response(401, {
90 + _tag: "RelayAuthInvalidError",
91 + code: "auth_invalid",
92 + reason: "invalid_bearer",
93 + traceId: "trace-auth",
94 + }),
95 + ).pipe(Effect.mapError(relayRequestError), Effect.flip);
96 +
97 + expect(expired).toMatchObject({ _tag: "RelayRequestError", rejection: "unavailable" });
98 + expect(expired.message).toContain("Relay environment link proof expired");
99 + expect(expired.message).toContain("date and time");
100 + expect(expired.message).toContain("Trace ID: trace-expired");
101 + expect(shouldRetryRelayRequest(expired)).toBe(true);
102 + expect(revoked).toMatchObject({ rejection: "unauthorized" });
103 + expect(shouldRetryRelayRequest(revoked)).toBe(false);
104 + }),
105 +);
106 +
107 it.effect("reports an unrecognized access denial without printing its response body", () =>
108 Effect.gen(function* () {
109 const error = yield* filterRelayResponse(
apps/server/src/cloud/relayResponse.ts
+11
@@ -63,6 +63,17 @@ export const filterRelayResponse = Effect.fn("cloud.filter_relay_response")(func
63 ? `T3 Connect: ${decoded.value.message}. ${recoveryHint(decoded.value)} Trace ID: ${decoded.value.traceId}.`
64 : `T3 Connect relay returned HTTP ${response.status} without a recognized error response. Check relay access and any proxy or firewall restrictions, then restart T3 Code.${requestId}`;
65
66 + // The only 401 that clears itself: a proof signed with a skewed clock (a host
67 + // that booted before NTP) expires on arrival, and the next attempt signs a new
68 + // one. It is recognized only from a schema-decoded relay body. Every other
69 + // 401, including a revoked bearer or an undecodable body, stays permanent.
70 + if (
71 + response.status === 401 &&
72 + Option.isSome(decoded) &&
73 + decoded.value._tag === "RelayEnvironmentLinkProofExpiredError"
74 + ) {
75 + return yield* new RelayRequestError({ rejection: "unavailable", description });
76 + }
77 if (response.status === 401) {
78 return yield* new RelayRequestError({ rejection: "unauthorized", description });
79 }