fix(codex): name the usage limit and its reset instead of relaying "out of credits" #10473
Mergedvitalyiegorov(GitHub profile, opens in a new tab)merged 1 commit into
main fromrefs/pull/10473/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- docs/user/providers-codex.md lines 70 to 73Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -65,3 +65,9 @@6565 the current session, or permanently. See [Permission modes](./permission-modes.md)6666 for command and file approvals.676768+## Codex says I hit a usage limit69+70+When Codex stops on a usage limit, the thread names the window that ran out and71+when it resets. Send the message again after the reset. On a workspace plan the72+message also says whether your workspace owner needs to add credits or raise the73+spend limit to continue sooner.apps/server/src/provider/Layers/CodexAdapter.ts line 2359OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2339,4 +2350,10 @@23392350 }23402351 }234123522342- const runtimeEvents = mapToRuntimeEvents(event, event.threadId).map((runtimeEvent) => {2353+ if (event.method === "error") {2354+ const errorPayload = readPayload(2355+ EffectCodexSchema.V2ErrorNotification,2356+ event.payload,2357+ );2358+ if (errorPayload?.error.codexErrorInfo === "usageLimitExceeded") {2359+ usageLimitStop = { ...usageLimitStop, providerMessage: errorPayload.error.message };apps/server/src/provider/Layers/codexUsageLimits.ts line 185OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -159,0 +165,21 @@165+ * and the snapshot that does arrives in a separate notification.166+ */167+export interface CodexUsageLimitStop {168+ /** The provider's own sentence, kept as the runtime error's detail. */169+ readonly providerMessage?: string | undefined;170+ readonly rateLimitReachedType?: string | null | undefined;171+ readonly exhaustedWindow?:172+ | {173+ readonly kind: ServerProviderUsageWindow["kind"];174+ readonly resetsAt: string;175+ }176+ | undefined;177+}178+179+/** Picks the window that ran out of a snapshot; the latest reset wins. */180+export function codexUsageLimitStopFromSnapshot(181+ snapshot: CodexRateLimitSnapshot,182+): CodexUsageLimitStop {183+ let exhaustedWindow: CodexUsageLimitStop["exhaustedWindow"];184+ let latestResetMs = Number.NEGATIVE_INFINITY;185+ for (const window of codexRateLimitsToWindows(snapshot)) {
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
- apps/server/src/provider/Layers/CodexAdapter.ts line 2383Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2342,0 +2363,21 @@2363+ EffectCodexSchema.V2ErrorNotification,2364+ event.payload,2365+ );2366+ // The failed `turn/completed` repeats this sentence and is answered2367+ // below; relaying both would show the limit twice.2368+ if (errorPayload?.error.codexErrorInfo === "usageLimitExceeded") return;2369+ }2370+2371+ let usageLimitError: ProviderRuntimeEvent | undefined;2372+ let usageLimitMessage: string | undefined;2373+ if (event.method === "turn/completed") {2374+ const completedPayload = readPayload(2375+ EffectCodexSchema.V2TurnCompletedNotification,2376+ event.payload,2377+ );2378+ const turnError =2379+ completedPayload?.turn.status === "failed"2380+ ? completedPayload.turn.error2381+ : undefined;2382+ if (turnError?.codexErrorInfo === "usageLimitExceeded") {2383+ usageLimitMessage = codexUsageLimitMessage(rateLimits, event.createdAt);
juliusmarminge merged thisd64335b
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed