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

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

fix(server): stop caching failed or signed-out Claude usage probes (#15836)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 05:14 UTC 6e45544850e41c989e704e99c1d3315584f03d55
3 files changed +118 -4
apps/server/src/provider/Drivers/ClaudeDriver.ts
+9 -2
@@ -238,8 +238,10 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv, Path.
238 {
239 capacity: 1,
240 timeToLive: (exit) =>
241 - // Only a fresh probe earns the TTL; a failure or its fallback retries on the next check.
242 - Exit.isSuccess(exit) && exit.value._tag === "fresh"
241 + // Only fresh usage earns the TTL; failures, fallbacks and usage-less probes retry.
242 + Exit.isSuccess(exit) &&
243 + exit.value._tag === "fresh" &&
244 + exit.value.capabilities.usage !== undefined
245 ? CAPABILITIES_PROBE_TTL
246 : Duration.zero,
247 },
@@ -272,6 +274,11 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv, Path.
274 ),
275 ),
276 ),
277 + Effect.tap((provider) =>
278 + provider.auth.status === "unauthenticated"
279 + ? Cache.invalidateAll(capabilitiesProbeCache)
280 + : Effect.void,
281 + ),
282 Effect.map(stampIdentity),
283 ),
284 ),
apps/server/src/provider/ProviderInstanceRegistry.test.ts
+84
@@ -666,6 +666,90 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
666 }),
667 );
668
669 + const makeClaudeCacheFixture = Effect.fnUntraced(function* (
670 + state: "ready" | "signed-out" | "usage-failed",
671 + ) {
672 + const fs = yield* FileSystem.FileSystem;
673 + const path = yield* Path.Path;
674 + const fixtures = yield* makeTildeProviderFixtures();
675 + const recovered = path.join(fixtures.claudeHomePath, "recovered");
676 + const probeLog = path.join(fixtures.claudeHomePath, "probes.log");
677 + const instanceId = ProviderInstanceId.make("claude_cache");
678 + const { registry } = yield* makeProviderInstanceRegistry({
679 + drivers: [ClaudeDriver],
680 + configMap: {
681 + [instanceId]: {
682 + driver: ProviderDriverKind.make("claudeAgent"),
683 + enabled: true,
684 + environment: [
685 + { name: "T3_CLAUDE_PROBE_LOG", value: probeLog, sensitive: false },
686 + ...(state === "ready"
687 + ? []
688 + : [
689 + {
690 + name:
691 + state === "signed-out"
692 + ? "T3_CLAUDE_LOGIN_MARKER"
693 + : "T3_CLAUDE_USAGE_FAILS_UNTIL",
694 + value: recovered,
695 + sensitive: false,
696 + },
697 + ]),
698 + ],
699 + config: makeClaudeConfig({
700 + enabled: true,
701 + binaryPath: fixtures.claudeBinaryPath,
702 + homePath: fixtures.claudeHomePath,
703 + }),
704 + },
705 + },
706 + });
707 + const instance = yield* registry.getInstance(instanceId);
708 + expect(instance).toBeDefined();
709 + return {
710 + refresh: instance!.snapshot.refresh,
711 + recover: fs.writeFileString(recovered, ""),
712 + probeLog: fs.readFileString(probeLog),
713 + };
714 + });
715 +
716 + it.effect.skipIf(windowsHost)("reuses Claude's successful usage probe on refresh", () =>
717 + Effect.gen(function* () {
718 + const fixture = yield* makeClaudeCacheFixture("ready");
719 + const first = yield* fixture.refresh;
720 + const second = yield* fixture.refresh;
721 + expect(first.usageLimits?.windows.map((window) => window.id)).toEqual(["five_hour"]);
722 + expect(second.usageLimits).toEqual(first.usageLimits);
723 + expect(yield* fixture.probeLog).toBe("probe\n");
724 + }).pipe(Effect.provide(layerTest)),
725 + );
726 +
727 + for (const state of ["signed-out", "usage-failed"] as const) {
728 + it.effect.skipIf(windowsHost)(
729 + state === "signed-out"
730 + ? "shows Claude usage on the first refresh after signing back in"
731 + : "retries Claude usage on the first refresh after a failed usage read",
732 + () =>
733 + Effect.gen(function* () {
734 + const fixture = yield* makeClaudeCacheFixture(state);
735 + const before = yield* fixture.refresh;
736 + if (state === "signed-out") {
737 + expect(before.auth.status).toBe("unauthenticated");
738 + expect(before.usageLimits).toBeUndefined();
739 + } else {
740 + expect(before.auth.status).toBe("authenticated");
741 + expect(before.usageLimits?.unavailable?.reason).toBe("probeFailed");
742 + }
743 +
744 + yield* fixture.recover;
745 + const after = yield* fixture.refresh;
746 + expect(after.auth.status).toBe("authenticated");
747 + expect(after.usageLimits?.unavailable).toBeUndefined();
748 + expect(after.usageLimits?.windows.map((window) => window.id)).toEqual(["five_hour"]);
749 + }).pipe(Effect.provide(layerTest)),
750 + );
751 + }
752 +
753 it.live(
754 "shadows instances whose driver is not registered in this build without failing boot",
755 () =>
apps/server/src/provider/testing/ProviderInstanceRegistryLive.fixture.mjs
+25 -2
@@ -10,13 +10,34 @@ if (process.argv.includes("--version")) {
10 process.stdout.write("claude 2.1.219\n");
11 process.exit(0);
12 }
13 +const loginMarker = process.env.T3_CLAUDE_LOGIN_MARKER;
14 +const signedOut = loginMarker !== undefined && !NodeFS.existsSync(loginMarker);
15 +if (process.env.T3_CLAUDE_PROBE_LOG)
16 + NodeFS.appendFileSync(process.env.T3_CLAUDE_PROBE_LOG, "probe\n");
17 const lines = NodeReadline.createInterface({ input: process.stdin });
18 lines.on("line", (line) => {
19 const message = JSON.parse(line);
20 if (message.type !== "control_request") return;
21 + if (message.request?.subtype === "get_usage" && signedOut) {
22 + process.stdout.write(
23 + JSON.stringify({
24 + type: "control_response",
25 + response: {
26 + subtype: "success",
27 + request_id: message.request_id,
28 + response: { session: {}, rate_limits_available: false, rate_limits: null },
29 + },
30 + }) + "\n",
31 + );
32 + return;
33 + }
34 if (message.request?.subtype === "get_usage") {
35 const marker = process.env.T3_CLAUDE_RESET_MARKER;
19 - if (process.env.T3_CLAUDE_USAGE_FAILS_AFTER_CLAIM && marker && NodeFS.existsSync(marker)) {
36 + const usageFailsUntil = process.env.T3_CLAUDE_USAGE_FAILS_UNTIL;
37 + if (
38 + (usageFailsUntil && !NodeFS.existsSync(usageFailsUntil)) ||
39 + (process.env.T3_CLAUDE_USAGE_FAILS_AFTER_CLAIM && marker && NodeFS.existsSync(marker))
40 + ) {
41 process.stdout.write(
42 JSON.stringify({
43 type: "control_response",
@@ -60,7 +81,9 @@ lines.on("line", (line) => {
81 models: [],
82 output_style: "default",
83 available_output_styles: ["default"],
63 - account: { email: "test@example.com", subscriptionType: "pro", tokenSource: "oauth" },
84 + account: signedOut
85 + ? { tokenSource: "none", apiProvider: "firstParty" }
86 + : { email: "test@example.com", subscriptionType: "pro", tokenSource: "oauth" },
87 },
88 },
89 }) + "\n",