Skip to content

Commit 6ff4f59

Browse files
ntindleclaude
andcommitted
fix(server): a repeated Muse report still moves its checked time forward
With `replace`, a report whose windows had not changed returned the published limits as they were, so `checkedAt` kept the older report's time. Limits picks an account's freshest report across environments by `checkedAt`, so this environment's newer report could lose to an older one from another. Only an exact repeat, with the same time, is a no-op now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 43f8a1d commit 6ff4f59

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎packages/provider-core/src/server/usageLimits.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,25 @@ describe("applyUsageLimitsUpdate", () => {
8080
replace: true,
8181
}),
8282
).toEqual({ checkedAt: "2026-09-03T15:00:00.000Z", windows: [restarted] });
83-
// The same whole state again publishes nothing new.
83+
// The same report again publishes nothing new.
8484
expect(
8585
applyUsageLimitsUpdate({
8686
previous: published,
87-
checkedAt: "2026-09-03T12:00:05.000Z",
87+
checkedAt,
8888
update: { windows: [session, weekly] },
8989
replace: true,
9090
}),
9191
).toBe(published);
92+
// A later report with the same windows publishes its time, so this account's
93+
// report still counts as the freshest when Limits merges environments.
94+
expect(
95+
applyUsageLimitsUpdate({
96+
previous: published,
97+
checkedAt: "2026-09-03T12:00:05.000Z",
98+
update: { windows: [session, weekly] },
99+
replace: true,
100+
}),
101+
).toEqual({ ...published, checkedAt: "2026-09-03T12:00:05.000Z" });
92102
});
93103

94104
it("preserves reset credits when a streamed window update changes usage", () => {

‎packages/provider-core/src/server/usageLimits.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ export function applyUsageLimitsUpdate(input: {
7878
: new Map(published);
7979
// Codex sends this notification beside every token-usage tick, almost
8080
// always with unchanged numbers. Decide "nothing changed" per window on
81-
// the way through so the no-op case never allocates a new snapshot.
82-
let changed = replace && update.windows.length !== published.size;
81+
// the way through so the no-op case never allocates a new snapshot. A
82+
// whole-state report that only moves the time is still news: Limits picks
83+
// the freshest report for an account across environments by `checkedAt`.
84+
let changed =
85+
replace &&
86+
(update.windows.length !== published.size || input.checkedAt !== previous?.checkedAt);
8387
for (const window of update.windows) {
8488
const existing = published.get(window.id);
8589
const next: ServerProviderUsageWindow = {

0 commit comments

Comments
 (0)