fix(server): type the account rate-limit runtime payload #5473
Closedvasars2024-hub(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/5473/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Layers/CodexAdapter.ts lines 469 to 469OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -438,0 +449,21 @@449+ usedPercent: window.usedPercent,450+ ...(window.resetsAt != null ? { resetsAt: window.resetsAt } : {}),451+ ...(window.windowDurationMins != null ? { windowDurationMins: window.windowDurationMins } : {}),452+ };453+}454+455+/**456+ * Normalizes a Codex rate-limit snapshot onto the canonical payload. Codex457+ * reports two windows at once and signals exhaustion out of band, via458+ * `rateLimitReachedType`, rather than as a status on the windows themselves.459+ */460+function rateLimitsPayloadFromNotification(461+ snapshot: EffectCodexSchema.V2AccountRateLimitsUpdatedNotification__RateLimitSnapshot,462+): AccountRateLimitsUpdatedPayload {463+ const windows = [464+ rateLimitWindow("primary", snapshot.primary ?? null),465+ rateLimitWindow("secondary", snapshot.secondary ?? null),466+ ].filter((window) => window !== undefined);467+468+ return {469+ status: snapshot.rateLimitReachedType != null ? "rejected" : "allowed",@@ -1393,3 +1428,3 @@13931428 }1394142913951430 if (event.method === "account/rateLimits/updated") {
- @@ -1502,0 +1512,21 @@1512+ * Normalizes the SDK rate-limit snapshot onto the canonical payload. Claude1513+ * reports the one window currently governing the account rather than a full1514+ * set, so `windows` holds at most one entry, and none at all when the SDK1515+ * sends a bare status. `utilization` is a 0-100 percentage, matching the1516+ * `rate_limits` windows the SDK documents on its usage response.1517+ */1518+function rateLimitsPayloadFromSdk(info: SDKRateLimitInfo): AccountRateLimitsUpdatedPayload {1519+ const window =1520+ info.rateLimitType !== undefined && info.utilization !== undefined1521+ ? {1522+ kind: info.rateLimitType,1523+ usedPercent: info.utilization,1524+ ...(info.resetsAt !== undefined ? { resetsAt: info.resetsAt } : {}),1525+ }1526+ : undefined;1527+1528+ return {1529+ status: CLAUDE_RATE_LIMIT_STATUS[info.status],1530+ windows: window ? [window] : [],1531+ };1532+}apps/server/src/provider/Layers/CodexAdapter.ts line 478Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -438,0 +451,21 @@451+ ...(window.windowDurationMins != null ? { windowDurationMins: window.windowDurationMins } : {}),452+ };453+}454+455+/**456+ * Normalizes a Codex rate-limit snapshot onto the canonical payload. Codex457+ * reports two windows at once and signals exhaustion out of band, via458+ * `rateLimitReachedType`, rather than as a status on the windows themselves.459+ */460+function rateLimitsPayloadFromNotification(461+ snapshot: EffectCodexSchema.V2AccountRateLimitsUpdatedNotification__RateLimitSnapshot,462+): AccountRateLimitsUpdatedPayload {463+ const windows = [464+ rateLimitWindow("primary", snapshot.primary ?? null),465+ rateLimitWindow("secondary", snapshot.secondary ?? null),466+ ].filter((window) => window !== undefined);467+468+ return {469+ status: snapshot.rateLimitReachedType != null ? "rejected" : "allowed",470+ windows,471+ };apps/server/src/provider/Layers/CodexAdapter.ts line 478Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -438,0 +451,21 @@451+ ...(window.windowDurationMins != null ? { windowDurationMins: window.windowDurationMins } : {}),452+ };453+}454+455+/**456+ * Normalizes a Codex rate-limit snapshot onto the canonical payload. Codex457+ * reports two windows at once and signals exhaustion out of band, via458+ * `rateLimitReachedType`, rather than as a status on the windows themselves.459+ */460+function rateLimitsPayloadFromNotification(461+ snapshot: EffectCodexSchema.V2AccountRateLimitsUpdatedNotification__RateLimitSnapshot,462+): AccountRateLimitsUpdatedPayload {463+ const windows = [464+ rateLimitWindow("primary", snapshot.primary ?? null),465+ rateLimitWindow("secondary", snapshot.secondary ?? null),466+ ].filter((window) => window !== undefined);467+468+ return {469+ status: snapshot.rateLimitReachedType != null ? "rejected" : "allowed",470+ windows,471+ };
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
56835ea5-b2be-42b2-9671-12b5c35cd708You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share