Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions apps/server/src/provider/claudeUsageLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ describe("claudeUsageResponseToLimits", () => {
).toEqual({ checkedAt, windows: [], unavailable: { reason: "unsupported" } });
});

it("reports a subscription account whose usage read came back empty as a failed probe", () => {
// The CLI sets `rate_limits` to null when its own usage fetch fails, while
// `rate_limits_available` stays true for an account that has limits.
const { limits, names } = claudeUsageResponseToLimits({
checkedAt,
response: { rate_limits_available: true, rate_limits: null },
});
expect(limits).toEqual({ checkedAt, windows: [], unavailable: { reason: "probeFailed" } });
expect(names).toEqual(noNames);
});

it("skips a window the endpoint reports without a utilization", () => {
expect(
claudeUsageResponseToLimits({
Expand Down
9 changes: 8 additions & 1 deletion apps/server/src/provider/claudeUsageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,15 @@ export function claudeUsageResponseToLimits(input: {
}): { readonly limits: ServerProviderUsageLimits; readonly names: ClaudeScopedLimitNames } {
const { response, checkedAt } = input;
if (!response.rate_limits_available || !response.rate_limits) {
// `unsupported` is a lock: it hides the account from Limits and ignores
// streamed windows. Only `rate_limits_available: false` earns it. The CLI
// also sends `rate_limits: null` beside `true` when its own usage fetch
// failed, which is transient, so the next probe or event can recover.
return {
limits: makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" }),
limits: makeUnavailableUsageLimits({
checkedAt,
reason: response.rate_limits_available ? "probeFailed" : "unsupported",
}),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
names: { overageIncluded: undefined },
};
}
Expand Down
Loading