Skip to content

fix(server): a zero Codex credit cap no longer delays usage-limit recovery on seat-based plans - #35025

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-34974-a1794473966
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-34974-a1794473966

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

codexUsageLimitResetAt treated the individual credit-cap window at 100% as blocking even when plan windows (primary/secondary) were present, unlike exhaustedUsageWindow's seat-based rule in packages/shared/src/usageLimits.ts. CodexAdapterV2's failureResetAt therefore attached the monthly credit reset to usage_limit failures, and emitRootTerminal's awaitsReset check skipped the account read that would find the plan reset, so UsageLimitRecoveryWorker waited for the monthly renewal. The helper now drops the individual window from the exhausted set whenever a plan window exists (the same rule exhaustedUsageWindow uses), so the plan window's reset drives recovery. Free and Go plans with only the credit cap behave as before. One-file change of a few lines. No new regex or parser.

Fixes #34974

Reproduction on main

On origin/main b68aedf (fresh worktree, vp i) I ran the reporter's repro.sh unchanged, taken from the issue body. It is a Vite+ test that replays Codex app-server frames through the real CodexAdapterV2, provider-event ingestion, orchestrator, SQLite projections and the production limitRecoveryCommand. It passed with 'DEFECT PRESENT'. Plan room with the cap: helperReset, the stored failure resetAt and the shell usageLimitResetAt are all 2026-12-01 (monthly credit reset), no account/rateLimits/read is sent, and recovery returns nothing 1 ms after the plan reset (2026-11-11T05:00Z) and message.dispatch only after the credit reset. Primary at 100% with the cap: also stores 2026-12-01 and waits past the plan reset. The no-cap controls store the plan reset and dispatch right after it. The successful-turn and manual-continuation controls behave correctly. I then added a case to codexUsageLimits.test.ts (team plan, primary at 100%, individualLimit remainingPercent 0). It fails on main: Expected 2026-07-14T03:33:20.000Z (primary reset), Received 2026-12-01T00:00:00.000Z.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

vp test run apps/server/src/provider/codexUsageLimits.test.ts: on the repro base, 1 failed / 15 passed (expected 2026-07-14T03:33:20.000Z, received 2026-12-01). With the fix, 16/16 passed. vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and test (2 files) all passed.

Not in this change

  • codexUsageLimitResetAt and exhaustedUsageWindow each carry their own copy of the seat-based credit-cap rule; they could share one helper, but that is a refactor beyond this fix.

AI-assisted; verified with the tests and tools listed above.

…ge-limit reset

Fails on main: codexUsageLimitResetAt returns the monthly credit reset
instead of the plan window's reset (repro for #34974).

AI-assisted; verified with the tests and tools listed above.
…overy on seat-based plans

The credit cap blocks only plans without plan windows, matching exhaustedUsageWindow.

AI-assisted; verified with the tests and tools listed above.
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 12, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 8ca9669

Macroscope's review found this PR approvable — Codex usage-limit recovery now follows plan-window resets instead of an unrelated exhausted credit cap when plan windows exist. This aligns recovery with the existing blocking rule without changing quotas, billing, or resume preferences.

You can add or adjust custom eligibility rules. Learn more.

@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Baseline: b68aedf · PR result: 8ca9669 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The reset-time calculation now excludes an exhausted individual credit limit when plan windows exist. Tests cover cases where the primary plan window is exhausted or has remaining allowance.

Changes: Codex reset selection

Layer / File(s) Summary
Select plan reset time
apps/server/src/provider/codexUsageLimits.ts, apps/server/src/provider/codexUsageLimits.test.ts
The reset-time calculation excludes the exhausted individual credit limit when plan windows exist. Tests verify that the primary window’s reset time is used when it is exhausted, and that the result is null when it is not exhausted.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: t3dotgg, yash-singh1

Merge Risk: Minimal · up to 8ca96

Seat-based Codex accounts with a zero-credit cap now recover at the plan reset instead of waiting for the credit reset. Existing behavior is preserved for plans with only a credit cap. No merge-blocking risk is evident.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#34974] The head diff changes only codexUsageLimitResetAt in apps/server/src/provider/codexUsageLimits.ts. When any non-individual window exists, the individual credit-cap window is dropped from the … Provide evidence that, at the reviewed head, CodexAdapterV2 and emitRootTerminal use the plan reset in both cases: plan room with a zero credit cap, and primary exhausted with a zero credit cap. Show that the account/rateLimits/read is sent…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the change: a zero Codex credit cap no longer delays usage-limit recovery on seat-based plans. The raw summary and objectives confirm the change excludes the exhausted individual credi…
Description check Passed The description follows the template structure: Problem, Change, Scope, Verification, and a closing AI-assistance note. The problem and root cause are explained in detail. The change is described (a o…
Out of Scope Changes check Passed The head diff has two files. The source change in codexUsageLimitResetAt adds a hasPlanWindows check and filters the individual window only when plan windows exist. This directly implements the issue …
Full details: Title check

Explanation

The title names the change: a zero Codex credit cap no longer delays usage-limit recovery on seat-based plans. The raw summary and objectives confirm the change excludes the exhausted individual credit window when a plan window exists, so the title matches the main change. It uses a conventional commit prefix and is specific. It is 94 characters, which is long but still a single readable sentence.

Full details: Description check

Explanation

The description follows the template structure: Problem, Change, Scope, Verification, and a closing AI-assistance note. The problem and root cause are explained in detail. The change is described (a one-file helper update) and the scope links issue #34974. Verification lists specific focused test runs with observed results (1 failed / 15 passed on the repro base, 16/16 with the fix) and the check:changed steps. The Evidence section says before/after evidence is still being captured and states that it must be filled before merge. Because that is a required item for UI-related changes and the section is open, this gap should be resolved before merge. The rest of the description is substantially complete, so the check passes.

Full details: Out of Scope Changes check

Explanation

The head diff has two files. The source change in codexUsageLimitResetAt adds a hasPlanWindows check and filters the individual window only when plan windows exist. This directly implements the issue requirement. The test file adds one test that exercises this helper. The PR description's note about a refactor to share the seat-based rule is listed as excluded and is not in the diff. No unrelated changes were found in the reviewed diffs. The adapter and worker files that the PR description mentions are not changed by this PR, so no out-of-scope change was found in them.

Full details: Linked Issues check

Explanation

[#34974] The head diff changes only codexUsageLimitResetAt in apps/server/src/provider/codexUsageLimits.ts. When any non-individual window exists, the individual credit-cap window is dropped from the exhausted set. The new test covers two cases. Case 1: team plan, primary at 100%, credit cap at 0%. The result is the primary reset (2026-07-14T03:33:20.000Z). Case 2: primary at 0%, credit cap at 0%. The result is null. This meets the helper-level requirement that the plan window drives the reset. Credit-cap-only accounts with no plan windows keep the existing rule. The issue also requires that recovery uses the plan reset in the adapter. That path includes CodexAdapterV2 failureResetAt and the emitRootTerminal awaitsReset check, which are not in this diff. The requirement to preserve the account/rateLimits/read path when plan room is shown depends on that code. The PR reports a repro on main, but the real-app before and after evidence is not yet captured. No verified head-state evidence shows the adapter now performs the read and dispatches at the plan reset.

Resolution

Provide evidence that, at the reviewed head, CodexAdapterV2 and emitRootTerminal use the plan reset in both cases: plan room with a zero credit cap, and primary exhausted with a zero credit cap. Show that the account/rateLimits/read is sent when the snapshot shows plan room. Provide the captured before and after results from the repro, or an adapter-level test that verifies these paths at head.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ee90bdc and 8ca9669.

Files selected for processing: 2

  • apps/server/src/provider/codexUsageLimits.test.ts
  • apps/server/src/provider/codexUsageLimits.ts

Limit details: You’ve used all 10 included reviews currently available.

@juliusmarminge

Copy link
Copy Markdown
Member Author

The automated pipeline stopped on this pull request and will not merge it:

the fix is written and reviewed, but proving it needs something no worker has:

  • Permanent blocker: manual real-app verification requires first-party ChatGPT OAuth usage-limit and renewal flows, explicitly unavailable on this VM. The scenario replay agent uses generic ACP and cannot create the Codex usage-limit failure state; the supplied test-harness reproduction is not admissible evidence. Both verdict flags are false because neither side was observed.

It stays open for a person to finish or close.

@someone6783

Copy link
Copy Markdown

Note

🤖 Claude Opus 5.5 responding on behalf of @someone6783

Real-app confirmation of the defect this PR fixes, on T3 Code desktop 0.1.3 (Linux), which does not include this change. Two ChatGPT workspace seats, each signed into Codex. I could not check the "after" state because this branch is not built here.

Usage → Limits at the time (both seats):

Window Seat A Seat B
Session 0% left, resets in 1h 31m 0% left, resets in 2h 35m
Weekly 66% used 76% used
Monthly credit limit 0% left, resets in 4d 18h 0% left, resets in 4d 18h

Four threads stopped on a Codex usage limit, two per seat:

Thread Banner Matches
Seat A, thread 1 Resumes 2:53 pm session reset ✅
Seat B, thread 1 Resumes 3:58 pm session reset ✅
Seat A, thread 2 Resumes 1/12 8:00 am (1 Dec, en-AU) monthly credit reset ❌
Seat B, thread 2 Resumes 1/12 8:00 am monthly credit reset ❌

The weekly windows still had room, so the session reset is the correct resume time. The two ❌ threads would wait about 4.5 days for no reason.

The fact that the same seat produces both outcomes fits the root cause described above. failureResetAt reads the per-session rateLimitSnapshot (CodexAdapterV2.ts, created empty per session). A session whose snapshot already held individualLimit at remainingPercent: 0 got the credit reset from codexUsageLimitResetAt. A session whose snapshot didn't hold it got the session reset. The account/rateLimits/updated handler then skips items that already have a resetAt, so the wrong value is never corrected. Dropping the individual window when a plan window exists, as this PR does, makes both paths agree on the session reset.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A zero-credit Codex cap delays usage-limit recovery until the monthly credit reset

2 participants