Skip to content
TypeScript

fix(server): Claude limits load again for users with large transcript histories (#16358)

Theo Browne255ac27d5200
diff --git a/apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts b/apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts
index 27b503a3c21..8147a43b05a 100644
--- a/apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts
+++ b/apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts
@@ -353,3 +353,25 @@ it.effect("preserves initialized capabilities when optional usage times out", ()
assert.equal(abortSignal?.aborted, true);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
+
+it.effect("asks for usage without the local transcript scan", () =>
+ Effect.gen(function* () {
+ let usageOptions: unknown;
+ const query = vi.spyOn(ClaudeSdk, "query").mockImplementation(
+ () =>
+ ({
+ initializationResult: async () => ({
+ account: { email: "[email protected]", subscriptionType: "max", tokenSource: "oauth" },
+ commands: [],
+ }),
+ usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET: async (options?: unknown) => {
+ usageOptions = options;
+ return { rate_limits_available: true, rate_limits: null };
+ },
+ }) as unknown as ReturnType<typeof ClaudeSdk.query>,
+ );
+ yield* Effect.addFinalizer(() => Effect.sync(() => query.mockRestore()));
+ yield* probeClaudeCapabilities(decodeClaudeSettings({ binaryPath: "claude" }));
+ assert.deepEqual(usageOptions, { skipBehaviors: true });
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
+);
diff --git a/apps/server/src/provider/ClaudeProvider.ts b/apps/server/src/provider/ClaudeProvider.ts
index 560982f974f..37945bbb79a 100644
--- a/apps/server/src/provider/ClaudeProvider.ts
+++ b/apps/server/src/provider/ClaudeProvider.ts
@@ -367,9 +367,11 @@ const probeClaudeCapabilities = (
Effect.flatMap(({ q, init }) =>
Effect.gen(function* () {
// Usage has its own deadline so a slow optional request cannot discard initialization.
+ // Only the rate limits are read, so skip the local transcript scan that fills
+ // `behaviors`: with a few GB of transcripts it outlasts the deadline.
const usageResult = includeUsage
? yield* Effect.tryPromise(() =>
- q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET(),
+ q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true }),
).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
: undefined;
const usage =