fix(server): Claude limits show from streamed events when the usage probe fails #49552
Openwillbedust(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/49552/headopened View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -173,9 +199,13 @@173- return undefined;174- }175- const usedPercent = info.utilization * 100;176- const resetsAt = isoFromEpochSeconds(info.resetsAt);177- if (type in WINDOWS) {178- return { windows: [makeWindow(type, usedPercent, resetsAt)] };199+ const unified = Option.getOrUndefined(200+ decodeUnifiedWindows((info as { readonly unifiedWindows?: unknown }).unifiedWindows),201+ );202+ const windows: ServerProviderUsageWindow[] = [];203+ for (const [type, entry] of Object.entries(unified ?? {})) {204+ const window = streamedWindow(type, entry.utilization, entry.resetsAt, names);205+ if (window) windows.push(window);179206 }180- if (type === OVERAGE_INCLUDED_EVENT_TYPE && names.overageIncluded) {181- return { windows: [scopedWindow(names.overageIncluded, usedPercent, resetsAt)] };207+ // Older CLIs stream only the top-level bucket, and only past a warning threshold.208+ const type: string | undefined = info.rateLimitType;209+ if (type && typeof info.utilization === "number") {210+ const window = streamedWindow(type, info.utilization, info.resetsAt, names);211+ if (window && !windows.some((existing) => existing.id === window.id)) windows.push(window);
Pushed18c871a
- @@ -166,13 +192,13 @@192+}193+166194 /** Stream utilization is 0-1. Drop unnamed overage buckets until probed to avoid unreconcilable rows. */167195 export function claudeRateLimitEventToUpdate(168196 info: SDKRateLimitInfo,169197 names: ClaudeScopedLimitNames,170198 ): ProviderUsageLimitsUpdate | undefined {171- const type: string | undefined = info.rateLimitType;172- if (!type || typeof info.utilization !== "number") {173- return undefined;174- }175- const usedPercent = info.utilization * 100;176- const resetsAt = isoFromEpochSeconds(info.resetsAt);177- if (type in WINDOWS) {178- return { windows: [makeWindow(type, usedPercent, resetsAt)] };199+ const unified = Option.getOrUndefined(200+ decodeUnifiedWindows((info as { readonly unifiedWindows?: unknown }).unifiedWindows),201+ );202+ const windows: ServerProviderUsageWindow[] = [];203+ for (const [type, entry] of Object.entries(unified ?? {})) {204+ const window = streamedWindow(
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes