The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): a slow host no longer shows settings as read-only (#25526)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Yordis Prieto committed
Oct 26, 2026 at 18:27 UTC
024e593a635670a01187da6607508eceb88c0da0
2 files changed
+99
-10
packages/client-runtime/src/state/environmentHttpAuth.test.ts
+75
@@ -13,9 +13,13 @@ import {
13
type OrchestrationV2ThreadHistoryPage,
14
} from "@t3tools/contracts";
15
import * as Effect from "effect/Effect";
16
+import * as Exit from "effect/Exit";
17
+import * as Fiber from "effect/Fiber";
18
import * as Layer from "effect/Layer";
19
import * as Option from "effect/Option";
20
+import * as Queue from "effect/Queue";
21
import * as Schema from "effect/Schema";
22
+import * as TestClock from "effect/testing/TestClock";
23
import type { HttpClient } from "effect/http";
24
25
import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
@@ -170,6 +174,14 @@ function makeHarness(reply: (requestNumber: number) => Response | Promise<Respon
174
};
175
}
176
177
+// Resolves "settled" instead of hanging when the load finishes without sending another request.
178
+function nextRequestOrSettled(requests: Queue.Queue<number>, load: Fiber.Fiber<unknown, unknown>) {
179
+ return Effect.raceFirst(
180
+ Queue.take(requests).pipe(Effect.as("sent" as const)),
181
+ Fiber.await(load).pipe(Effect.as("settled" as const)),
182
+ );
183
+}
184
+
185
type HttpInput = ReturnType<typeof makeHarness>["input"];
186
const LOADERS: ReadonlyArray<{
187
readonly name: string;
@@ -521,6 +533,69 @@ describe("authenticated environment HTTP requests", () => {
533
}),
534
);
535
536
+ it.effect(
537
+ "waits longer for session permissions after the environment is too slow to answer",
538
+ () =>
539
+ Effect.gen(function* () {
540
+ const requests = yield* Queue.unbounded<number>();
541
+ let answer: () => void = () => {};
542
+ const answered = new Promise<void>((resolve) => {
543
+ answer = resolve;
544
+ });
545
+ const harness = makeHarness((requestNumber) => {
546
+ Queue.offerUnsafe(requests, requestNumber);
547
+ return requestNumber === 1
548
+ ? new Promise<Response>(() => {})
549
+ : answered.then(() => Response.json(SESSION));
550
+ });
551
+ const load = yield* fetchEnvironmentSessionState({
552
+ prepared: { ...PREPARED, httpAuthorization: { _tag: "Bearer", token: "bearer-token" } },
553
+ signer: Option.none(),
554
+ timeoutMs: 1_000,
555
+ }).pipe(Effect.provide(harness.httpLayer), Effect.forkChild({ startImmediately: true }));
556
+
557
+ yield* Queue.take(requests);
558
+ yield* TestClock.adjust("1 second");
559
+ expect(yield* nextRequestOrSettled(requests, load)).toBe("sent");
560
+ yield* TestClock.adjust("1500 millis");
561
+ answer();
562
+
563
+ expect(yield* Fiber.await(load)).toStrictEqual(Exit.succeed(SESSION));
564
+ expect(harness.calls).toHaveLength(2);
565
+ }),
566
+ );
567
+
568
+ it.effect("gives up on session permissions once a 60 second wait also times out", () =>
569
+ Effect.gen(function* () {
570
+ const requests = yield* Queue.unbounded<number>();
571
+ const harness = makeHarness((requestNumber) => {
572
+ Queue.offerUnsafe(requests, requestNumber);
573
+ return new Promise<Response>(() => {});
574
+ });
575
+ const load = yield* fetchEnvironmentSessionState({
576
+ prepared: { ...PREPARED, httpAuthorization: { _tag: "Bearer", token: "bearer-token" } },
577
+ signer: Option.none(),
578
+ timeoutMs: 15_000,
579
+ }).pipe(Effect.provide(harness.httpLayer), Effect.forkChild({ startImmediately: true }));
580
+
581
+ yield* Queue.take(requests);
582
+ yield* TestClock.adjust("15 seconds");
583
+ expect(yield* nextRequestOrSettled(requests, load)).toBe("sent");
584
+ yield* TestClock.adjust("30 seconds");
585
+ expect(yield* nextRequestOrSettled(requests, load)).toBe("sent");
586
+ yield* TestClock.adjust("60 seconds");
587
+ const exit = yield* Fiber.await(load);
588
+
589
+ expect(exit).toMatchObject({
590
+ _tag: "Failure",
591
+ cause: {
592
+ reasons: [{ error: { _tag: "RemoteEnvironmentAuthTimeoutError", timeoutMs: 60_000 } }],
593
+ },
594
+ });
595
+ expect(harness.calls).toHaveLength(3);
596
+ }),
597
+ );
598
+
599
it.effect("reports persistent session rejection instead of showing missing permissions", () =>
600
Effect.gen(function* () {
601
const harness = makeHarness(() => Response.json(UNAUTHENTICATED_SESSION));
packages/client-runtime/src/state/session.ts
+24
-10
@@ -12,6 +12,7 @@ import * as EnvironmentRegistry from "../connection/registry.ts";
12
import type { PreparedConnection } from "../connection/model.ts";
13
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
14
import * as ManagedRelay from "../relay/managedRelay.ts";
15
+import type { RemoteEnvironmentRequestError } from "../rpc/http.ts";
16
import { safeErrorLogAttributes } from "../errors/safeLog.ts";
17
import { executeAuthenticatedEnvironmentHttpRequest } from "./environmentHttpAuth.ts";
18
import { followStreamInEnvironment } from "./environmentStreams.ts";
@@ -36,6 +37,7 @@ function initialConfigOption<E>(
37
}
38
39
const DEFAULT_SESSION_STATE_TIMEOUT_MS = 6_000;
40
+const MAX_SESSION_STATE_TIMEOUT_MS = 60_000;
41
42
export const fetchEnvironmentSessionState = Effect.fn(
43
"clientRuntime.state.fetchEnvironmentSessionState",
@@ -47,16 +49,28 @@ export const fetchEnvironmentSessionState = Effect.fn(
49
>;
50
readonly timeoutMs?: number;
51
}) {
50
- return yield* executeAuthenticatedEnvironmentHttpRequest({
51
- ...input,
52
- group: "auth",
53
- method: "GET",
54
- url: (urls) => urls.session(),
55
- timeoutMs: input.timeoutMs ?? DEFAULT_SESSION_STATE_TIMEOUT_MS,
56
- request: ({ client, headers }) => client.session({ headers }),
57
- // This endpoint returns 200 with authenticated:false for expired credentials.
58
- isUnauthorizedResponse: (response) => !response.authenticated,
59
- });
52
+ const request = (
53
+ timeoutMs: number,
54
+ ): Effect.Effect<AuthSessionState, RemoteEnvironmentRequestError, HttpClient.HttpClient> =>
55
+ executeAuthenticatedEnvironmentHttpRequest({
56
+ ...input,
57
+ group: "auth",
58
+ method: "GET",
59
+ url: (urls) => urls.session(),
60
+ timeoutMs,
61
+ request: ({ client, headers }) => client.session({ headers }),
62
+ // This endpoint returns 200 with authenticated:false for expired credentials.
63
+ isUnauthorizedResponse: (response) => !response.authenticated,
64
+ }).pipe(
65
+ // A timeout says nothing about grants; failing would show a busy host as read-only.
66
+ Effect.catchTags({
67
+ RemoteEnvironmentAuthTimeoutError: (error) => {
68
+ const nextTimeoutMs = Math.min(timeoutMs * 2, MAX_SESSION_STATE_TIMEOUT_MS);
69
+ return nextTimeoutMs > timeoutMs ? request(nextTimeoutMs) : Effect.fail(error);
70
+ },
71
+ }),
72
+ );
73
+ return yield* request(input.timeoutMs ?? DEFAULT_SESSION_STATE_TIMEOUT_MS);
74
});
75
76
function makeEnvironmentSessionAtoms<R, E>(