Skip to content

Commit 6bbff17

Browse files
fixfonclaude
andcommitted
fix(server): a Claude account with no rate-limit data no longer stays unsupported
The Claude usage probe marked an account `unsupported` whenever `get_usage` returned no `rate_limits`, including when `rate_limits_available` was true. The CLI sends that shape when its own usage fetch fails, so a subscription account was locked out of Limits with no bar and no notice, and streamed rate_limit_event windows were discarded. Only `rate_limits_available: false` is now `unsupported`; the other shape is `probeFailed`, which shows "Could not read limits." and recovers on the next probe or streamed window. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent a01c48f commit 6bbff17

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ describe("claudeUsageResponseToLimits", () => {
9595
).toEqual({ checkedAt, windows: [], unavailable: { reason: "unsupported" } });
9696
});
9797

98+
it("reports a subscription account whose usage read came back empty as a failed probe", () => {
99+
// The CLI sets `rate_limits` to null when its own usage fetch fails, while
100+
// `rate_limits_available` stays true for an account that has limits.
101+
const { limits, names } = claudeUsageResponseToLimits({
102+
checkedAt,
103+
response: { rate_limits_available: true, rate_limits: null },
104+
});
105+
expect(limits).toEqual({ checkedAt, windows: [], unavailable: { reason: "probeFailed" } });
106+
expect(names).toEqual(noNames);
107+
});
108+
98109
it("skips a window the endpoint reports without a utilization", () => {
99110
expect(
100111
claudeUsageResponseToLimits({

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,15 @@ export function claudeUsageResponseToLimits(input: {
160160
}): { readonly limits: ServerProviderUsageLimits; readonly names: ClaudeScopedLimitNames } {
161161
const { response, checkedAt } = input;
162162
if (!response.rate_limits_available || !response.rate_limits) {
163+
// `unsupported` is a lock: it hides the account from Limits and ignores
164+
// streamed windows. Only `rate_limits_available: false` earns it. The CLI
165+
// also sends `rate_limits: null` beside `true` when its own usage fetch
166+
// failed, which is transient, so the next probe or event can recover.
163167
return {
164-
limits: makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" }),
168+
limits: makeUnavailableUsageLimits({
169+
checkedAt,
170+
reason: response.rate_limits_available ? "probeFailed" : "unsupported",
171+
}),
165172
names: { overageIncluded: undefined },
166173
};
167174
}

0 commit comments

Comments
 (0)