Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/server/src/provider/Drivers/ClaudeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,12 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv, Path.
capacity: 1,
timeToLive: (exit) =>
// Only fresh usage earns the TTL; failures, fallbacks and usage-less probes retry.
// Claude answers available-but-null while it holds back usage reads; retry that too.
Exit.isSuccess(exit) &&
exit.value._tag === "fresh" &&
exit.value.capabilities.usage !== undefined
exit.value.capabilities.usage !== undefined &&
(exit.value.capabilities.usage.rate_limits !== null ||
!exit.value.capabilities.usage.rate_limits_available)
? CAPABILITIES_PROBE_TTL
: Duration.zero,
},
Expand Down
9 changes: 6 additions & 3 deletions apps/server/src/provider/ProviderInstanceRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
);

const makeClaudeCacheFixture = Effect.fnUntraced(function* (
state: "ready" | "signed-out" | "usage-failed",
state: "ready" | "signed-out" | "usage-failed" | "usage-null",
) {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
Expand Down Expand Up @@ -811,6 +811,9 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
sensitive: false,
},
]),
...(state === "usage-null"
? [{ name: "T3_CLAUDE_USAGE_FAILS_AS_NULL", value: "1", sensitive: false }]
: []),
],
config: makeClaudeConfig({
enabled: true,
Expand All @@ -829,11 +832,11 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
};
});

for (const state of ["signed-out", "usage-failed"] as const) {
for (const state of ["signed-out", "usage-failed", "usage-null"] as const) {
it.effect.skipIf(windowsHost)(
state === "signed-out"
? "shows Claude usage on the first refresh after signing back in"
: "retries Claude usage on the first refresh after a failed usage read",
: `retries Claude usage on the first refresh after a ${state === "usage-null" ? "missing" : "failed"} usage read`,
() =>
Effect.gen(function* () {
const fixture = yield* makeClaudeCacheFixture(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ lines.on("line", (line) => {
process.stdout.write(
JSON.stringify({
type: "control_response",
response: { subtype: "error", request_id: message.request_id, error: "usage failed" },
response: process.env.T3_CLAUDE_USAGE_FAILS_AS_NULL
? {
subtype: "success",
request_id: message.request_id,
response: { session: {}, rate_limits_available: true, rate_limits: null },
}
: { subtype: "error", request_id: message.request_id, error: "usage failed" },
}) + "\n",
);
return;
Expand Down
Loading