Skip to content

fix(server): route exhausted Codex quota to Luna Reserve - #22003

Open
juliusmarminge wants to merge 3 commits into
mainfrom
codex-08b/reserve-routing
Open

juliusmarminge wants to merge 3 commits into
mainfrom
codex-08b/reserve-routing

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Ordinary Luna turns keep failing after Codex exhausts ordinary quota, even when the account has Luna Reserve. After a usage-limit failure, the adapter now reads Reserve-capable quota state before the next turn and sends gpt-reserve only for the matching normal model. Both the regular turn model and collaboration settings use that wire model; the selected model and reasoning effort stay unchanged.

Quota state belongs to the provider instance, survives session release, and clears only on authoritative recovery. Reads time out after three seconds and back off for thirty seconds on failure; ordinary sessions never read quota. Authentication-required clears Reserve until a later quota failure rearms it. A child-only quota failure also arms the next root turn.

Rebuilt from @juliusmarminge’s #14214 against current main. The dependent layer keeps Reserve subagent models visible. The original helper-only tests and repeated transcripts were replaced with behavior tests in the existing adapter suite and one orchestrator replay.

Verification: six adapter routing cases and one integrated ordinary → quota failure → Reserve → recovery replay; the unchanged adapter failed the replay at the expected missing quota read. After integrating current main, the full adapter plus fixture/schema checks pass (187 cases), as do focused lint and server typecheck. The fixture is hand-ported protocol proof, not a live Reserve recording.

Live limitation: Codex 0.163.0 returned -32600 authentication required to the Reserve-capable account read on this machine. An eligible account must still verify live activation/recovery. macOS, Windows, iOS, Android, and Electron were not run. This changes the server adapter only; no client or wire contracts change. The first goal turn uses the same start path; Codex-owned autonomous goal continuations keep the settings they started with and do not independently refresh recovery.

Independent review: one fresh round by Claude Opus 5.5 and Codex gpt-6-sol; no code blockers. Review and land both layers together.

Model/harness: Codex gpt-6.1-sol in T3 Code; tests by Codex gpt-6-astra.

Other layer: #22004.

Fixes #11274

@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Oct 19, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 19, 2026
@github-actions github-actions Bot added the size:L 100-499 changed lines (additions + deletions). label Oct 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — Eligible Luna turns now automatically use Reserve after ordinary quota exhaustion, while the selected model stays unchanged. A human needs to authorize this change in default fallback behavior.

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

@github-actions

github-actions Bot commented Oct 19, 2026 •

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: 31bf2f7 · PR result: b843b3d · 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 Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Codex adapter now reads account rate-limit data to track Luna Reserve availability and recovery. When Reserve applies to the selected model, turn startup sends gpt-reserve as the wire model. Replay tests cover routing, read failures, recovery, and session behavior.

Changes: Luna Reserve routing

Layer / File(s) Summary
Reserve detection and refresh
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
The adapter extracts Reserve and recovery state from rate-limit data. It serializes Reserve reads, applies a 3-second timeout and a 30-second failure backoff, and arms refreshes after qualifying usage-limit failures.
Turn model selection
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
The turn parameter builder accepts an optional wire model. The adapter uses gpt-reserve when Reserve applies; otherwise it uses the selected model.
Adapter replay coverage
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
The replay harness supports successive session transcripts and exposes adapter.openSession. Tests cover Reserve routing, recovery evidence, usage-read failures, cross-session state, and child-turn quota failures.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: t3dotgg

Merge Risk: Minimal · up to b843b

The change routes exhausted Codex quota to Luna Reserve with bounded reads and backoff. No concrete defects were identified. Live verification on an eligible account is still pending.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: routing exhausted Codex quota to Luna Reserve. It uses a suitable conventional commit format.
Description check Passed The description is substantially complete. It explains the problem, implementation, scope, verification results, test limitations, linked issue and dependent pull request, and model/harness details. T…
Linked Issues check Passed Issue #11274 requires Reserve eligibility detection, supportsLunaReserve: true, gpt-reserve routing, preserved visible model and reasoning settings, and recovery to the normal model. `CodexAdapter…
Out of Scope Changes check Passed The reviewed changes are limited to CodexAdapterV2.ts and its adapter tests. The implementation, replay harness updates, and automated cases directly support issue #11274. No unrelated product area …
Full details: Description check

Explanation

The description is substantially complete. It explains the problem, implementation, scope, verification results, test limitations, linked issue and dependent pull request, and model/harness details. The content is not separated under the template headings, but all required information is present.

Full details: Linked Issues check

Explanation

Issue #11274 requires Reserve eligibility detection, supportsLunaReserve: true, gpt-reserve routing, preserved visible model and reasoning settings, and recovery to the normal model. CodexAdapterV2 reads account rate limits after a usage-limit failure, decodes ordinaryUsageAllowed and the luna_reserve banner, tracks state on the provider instance, and routes matching turns through gpt-reserve. buildCodexTurnStartParams applies the wire model to both turn/start.model and collaboration settings without changing model selection or reasoning effort. Confirmed recovery clears Reserve state. The added replay tests cover routing, recovery, read failures, session sharing, and child quota failures.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to CodexAdapterV2.ts and its adapter tests. The implementation, replay harness updates, and automated cases directly support issue #11274. No unrelated product area or client contract changes are shown.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
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 5998703 and b843b3d.

Files selected for processing: 2

  • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts

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

@juliusmarminge juliusmarminge changed the title codex 08b/reserve routing fix(server): route exhausted Codex quota to Luna Reserve Oct 20, 2026
juliusmarminge and others added 2 commits November 11, 2026 05:57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The adapter tests already pin each turn's wire model through exhaustion,
Reserve, and recovery. The synthesized transcript added no coverage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member Author

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

the proof has no capture anyone can open:

  • Permanent blocker: first-party ChatGPT OAuth usage, limit, and renewal flows are unavailable on this VM; the reproduction requires exhausted ordinary quota with available Reserve.
  • The scenario runner explicitly excludes provider-specific behavior and usage-limit starting states; generic replay cannot establish this proof.
  • Reserve routing, preservation of the visible selection and reasoning effort, and return to ordinary routing after quota recovery remain unverified.

It stays open for a person to finish or close.

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

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex Luna Reserve fallback is missing from orchestrator v2

1 participant