GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(usage): scale the streamed Claude utilization from a 0-1 fraction · pingdotgg/t3code@b79b0f0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/usage
    • AccountLimitsService.test.ts
    • accountLimitsNormalize.test.ts
    • accountLimitsNormalize.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/usage/AccountLimitsService.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/usage/AccountLimitsService.test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const claudeUsagePayload = (fiveHour: number, weekly: number) => ({
3838
},
3939
});
4040

41-
/** The streamed single-window Claude event. */
41+
/** The streamed single-window Claude event. `utilization` is a 0-1 fraction. */
4242
const claudeWindowPayload = (utilization: number) => ({
4343
type: "rate_limit_event",
4444
rate_limit_info: {
@@ -167,7 +167,7 @@ it.layer(NodeServices.layer)("account limits service", (it) => {
167167
});
168168
yield* service.ingest({
169169
provider: "claudeAgent",
170-
payload: claudeWindowPayload(87.5),
170+
payload: claudeWindowPayload(0.875),
171171
createdAt: "2026-08-15T12:00:01.000Z",
172172
providerInstanceId: asInstanceId("claude_partner"),
173173
});
Collapse file

‎apps/server/src/usage/accountLimitsNormalize.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/usage/accountLimitsNormalize.test.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ describe("claudeUsageSnapshotFromUnknown", () => {
9898
});
9999

100100
describe("claudeWindowFromRateLimitEvent", () => {
101-
it("maps the binding window with a unix-seconds reset", () => {
101+
it("maps the binding window with a unix-seconds reset, scaling the 0-1 utilization", () => {
102+
// The streamed field carries the response header's fraction, not the
103+
// usage endpoint's percent: 0.875 here is the 87.5 the endpoint reports.
102104
const window = claudeWindowFromRateLimitEvent({
103105
type: "rate_limit_event",
104106
rate_limit_info: {
105107
status: "allowed_warning",
106108
rateLimitType: "five_hour",
107-
utilization: 87.5,
109+
utilization: 0.875,
108110
resetsAt: 1_786_600_800,
109111
},
110112
});
@@ -120,7 +122,7 @@ describe("claudeWindowFromRateLimitEvent", () => {
120122
it("drops hidden window types", () => {
121123
expect(
122124
claudeWindowFromRateLimitEvent({
123-
rate_limit_info: { rateLimitType: "seven_day_opus", utilization: 90 },
125+
rate_limit_info: { rateLimitType: "seven_day_opus", utilization: 0.9 },
124126
}),
125127
).toBeNull();
126128
});
Collapse file

‎apps/server/src/usage/accountLimitsNormalize.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/usage/accountLimitsNormalize.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ function claudeWindowFromLimitEntry(entry: unknown): AccountLimitsWindow | null
234234
* Parses the streamed `rate_limit_event` SDK message into the one window it
235235
* names. Returns null for shapes that are not that message, and for windows
236236
* we hide.
237+
*
238+
* Units differ from the usage response: `rate_limit_info.utilization` mirrors
239+
* the `anthropic-ratelimit-unified-*-utilization` response headers, which are
240+
* a 0-1 fraction (`0.11` while the usage endpoint reports `12.0` for the same
241+
* window at the same moment), so it is scaled here. Passing it through would
242+
* show the binding window - the only one this message names - at 1/100th.
237243
*/
238244
export function claudeWindowFromRateLimitEvent(value: unknown): AccountLimitsWindow | null {
239245
if (!isRecord(value)) return null;
@@ -248,7 +254,7 @@ export function claudeWindowFromRateLimitEvent(value: unknown): AccountLimitsWin
248254
return {
249255
id: meta.id,
250256
label: meta.label,
251-
usedPercent: utilization === null ? 0 : clampPercent(utilization),
257+
usedPercent: utilization === null ? 0 : clampPercent(utilization * 100),
252258
resetsAt: resetsAt === null ? null : isoFromUnixSeconds(resetsAt),
253259
windowMinutes: meta.minutes,
254260
};

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.