Skip to content

Commit 56dce6a

Browse files
committed
fix(provider-usage): ignore unsupported provider snapshots
- return null for cursor and opencode usage derivation - keep claudeagent and codex snapshot detection unchanged
1 parent d091a09 commit 56dce6a

2 files changed

Lines changed: 66 additions & 4 deletions

File tree

apps/web/src/lib/providerUsage.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,62 @@ describe("providerUsage", () => {
274274

275275
expect(snapshot).toBeNull();
276276
});
277+
278+
it("returns null for cursor provider even when Claude/Codex events are present", () => {
279+
const snapshot = deriveLatestProviderUsageSnapshot(
280+
[
281+
makeActivity("activity-1", {
282+
type: "rate_limit_event",
283+
rate_limit_info: {
284+
status: "allowed_warning",
285+
resetsAt: 1776582000,
286+
rateLimitType: "five_hour",
287+
utilization: 0.83,
288+
},
289+
}),
290+
makeActivity("activity-2", {
291+
rateLimits: {
292+
limitId: "codex",
293+
primary: {
294+
usedPercent: 12,
295+
windowDurationMins: 300,
296+
resetsAt: 1776587601,
297+
},
298+
},
299+
}),
300+
],
301+
{ provider: "cursor" },
302+
);
303+
304+
expect(snapshot).toBeNull();
305+
});
306+
307+
it("returns null for opencode provider even when Claude/Codex events are present", () => {
308+
const snapshot = deriveLatestProviderUsageSnapshot(
309+
[
310+
makeActivity("activity-1", {
311+
type: "rate_limit_event",
312+
rate_limit_info: {
313+
status: "allowed_warning",
314+
resetsAt: 1776582000,
315+
rateLimitType: "five_hour",
316+
utilization: 0.83,
317+
},
318+
}),
319+
makeActivity("activity-2", {
320+
rateLimits: {
321+
limitId: "codex",
322+
primary: {
323+
usedPercent: 12,
324+
windowDurationMins: 300,
325+
resetsAt: 1776587601,
326+
},
327+
},
328+
}),
329+
],
330+
{ provider: "opencode" },
331+
);
332+
333+
expect(snapshot).toBeNull();
334+
});
277335
});

apps/web/src/lib/providerUsage.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ type ProviderUsageDerivationOptions = {
3636
readonly provider?: ProviderKind | null;
3737
};
3838

39-
const PROVIDER_LABEL_BY_KIND: Partial<Record<ProviderKind, string>> = {
39+
const PROVIDER_LABEL_BY_KIND: Record<ProviderKind, string | null> = {
4040
claudeAgent: "Claude",
4141
codex: "Codex",
42+
cursor: null,
43+
opencode: null,
4244
};
4345

4446
// ---------------------------------------------------------------------------
@@ -287,12 +289,14 @@ export function deriveLatestProviderUsageSnapshot(
287289
activities: ReadonlyArray<OrchestrationThreadActivity>,
288290
options: ProviderUsageDerivationOptions = {},
289291
): ProviderUsageSnapshot | null {
292+
if (options.provider && PROVIDER_LABEL_BY_KIND[options.provider] === null) {
293+
return null;
294+
}
295+
290296
const windowsByLabel = new Map<string, RateLimitWindow>();
291297
let providerLabel: string | null = null;
292298
let latestUpdatedAt: string | null = null;
293-
const requestedProviderLabel = options.provider
294-
? (PROVIDER_LABEL_BY_KIND[options.provider] ?? null)
295-
: null;
299+
const requestedProviderLabel = options.provider ? PROVIDER_LABEL_BY_KIND[options.provider] : null;
296300

297301
// Walk backwards so the first match for each label wins (most recent).
298302
for (let index = activities.length - 1; index >= 0; index -= 1) {

0 commit comments

Comments
 (0)