Skip to content

Commit 6849abf

Browse files
committed
Tighten Codex usage payload detection
1 parent ca2150f commit 6849abf

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

apps/server/src/provider/codexUsage.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ describe("normalizeCodexUsageSnapshot", () => {
7676
]);
7777
});
7878

79+
it("does not treat wrapped payload metadata as a direct bucket", () => {
80+
const snapshot = normalizeCodexUsageSnapshot({
81+
providerInstanceId: instanceId,
82+
source: "read",
83+
payload: {
84+
planType: "plus",
85+
rateLimitReachedType: "secondary",
86+
rateLimits: {
87+
primary: { usedPercent: 60, windowDurationMins: 300 },
88+
},
89+
},
90+
});
91+
92+
expect(snapshot?.windows).toEqual([
93+
{
94+
kind: "five-hour",
95+
usedPercent: 60,
96+
remainingPercent: 40,
97+
resetsAt: null,
98+
windowDurationMins: 300,
99+
},
100+
]);
101+
expect(snapshot?.rateLimitReachedType).toBeNull();
102+
});
103+
79104
it("accepts a direct rate-limit snapshot payload", () => {
80105
const snapshot = normalizeCodexUsageSnapshot({
81106
providerInstanceId: instanceId,

apps/server/src/provider/codexUsage.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,7 @@ function normalizeWindow(
116116
}
117117

118118
function isRateLimitBucketPayload(payload: RateLimitPayload): boolean {
119-
return (
120-
"primary" in payload ||
121-
"secondary" in payload ||
122-
"limitId" in payload ||
123-
"limitName" in payload ||
124-
"credits" in payload ||
125-
"planType" in payload ||
126-
"rateLimitReachedType" in payload
127-
);
119+
return "primary" in payload || "secondary" in payload;
128120
}
129121

130122
function selectCodexBucket(payload: RateLimitPayload): RateLimitBucket | null {

0 commit comments

Comments
 (0)