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

The Claude capabilities probe now asks for usage with skipBehaviors, so it no longer scans every local transcript and misses its 4 s deadline. Takes over #14456.

Co-authored-by: Ashkaan <[email protected]>
This commit is contained in:
Theo BrowneandAshkaan authored and GitHub committed 2026-10-05 21:28:36 -07:00
1 parent 24edd55d94
commit 255ac27d52
2 files changed
+25 -1

No files matched your search

@@ -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)),
);
+3 -1
View File
@@ -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 =