Skip to content

Commit 53453ba

Browse files
Ashkaant3dotgg
authored andcommitted
fix(server): skip the transcript scan in the Claude usage probe
The probe reads only the plan rate limits, but the SDK's usage request also scans every local transcript to fill `behaviors` unless told not to. With a few GB of transcripts that outlasts the probe's 4 s deadline and every Claude instance reads probeFailed.
1 parent 61a0ec9 commit 53453ba

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,25 @@ it.effect("preserves initialized capabilities when optional usage times out", ()
353353
assert.equal(abortSignal?.aborted, true);
354354
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
355355
);
356+
357+
it.effect("asks for usage without the local transcript scan", () =>
358+
Effect.gen(function* () {
359+
let usageOptions: unknown;
360+
const query = vi.spyOn(ClaudeSdk, "query").mockImplementation(
361+
() =>
362+
({
363+
initializationResult: async () => ({
364+
account: { email: "[email protected]", subscriptionType: "max", tokenSource: "oauth" },
365+
commands: [],
366+
}),
367+
usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET: async (options?: unknown) => {
368+
usageOptions = options;
369+
return { rate_limits_available: true, rate_limits: null };
370+
},
371+
}) as unknown as ReturnType<typeof ClaudeSdk.query>,
372+
);
373+
yield* Effect.addFinalizer(() => Effect.sync(() => query.mockRestore()));
374+
yield* probeClaudeCapabilities(decodeClaudeSettings({ binaryPath: "claude" }));
375+
assert.deepEqual(usageOptions, { skipBehaviors: true });
376+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
377+
);

‎apps/server/src/provider/ClaudeProvider.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ const probeClaudeCapabilities = (
367367
Effect.flatMap(({ q, init }) =>
368368
Effect.gen(function* () {
369369
// Usage has its own deadline so a slow optional request cannot discard initialization.
370+
// Only the rate limits are read, so skip the local transcript scan that fills
371+
// `behaviors`: with a few GB of transcripts it outlasts the deadline.
370372
const usageResult = includeUsage
371373
? yield* Effect.tryPromise(() =>
372-
q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET(),
374+
q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true }),
373375
).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
374376
: undefined;
375377
const usage =

0 commit comments

Comments
 (0)