Add Luna Reserve usage fallback to the TUI (#42372)

## Why

When ordinary included usage is exhausted, eligible users need a way to keep working with the backend-provided Luna Reserve quota and return to their previous model once ordinary usage recovers.

## What changed

- Automatically switch eligible TUI tasks to Luna Reserve after an authoritative account usage read, preserving the prior model and reasoning effort per task.
- Restrict model selection while on Reserve to its supported reasoning levels, keep queued turns on the accepted model, and restore the saved model after a fresh read confirms recovery.
- Surface Reserve usage in the composer and `/status`, and expose `normalModelSlug` in app-server rate-limit snapshots so clients can use the associated model's display metadata without changing the request model.
- Poll account limits more frequently near exhaustion and retain compatibility with app servers that only accept the legacy null request parameters.

## Testing

- Added coverage for Reserve entry, queued-turn handling, task reconstruction, recovery authorization, account changes, model selection, usage rendering, and banner dismissal.

GitOrigin-RevId: 46a435e9531051f8cec3f6a46c4b9f7cfa479747
This commit is contained in:
dhruvgupta-oai authored and copyberry committed 2026-09-02 21:50:51 +00:00
1 parent 76f47103fe
commit 5037919777
76 files changed
+1907 -135

No files matched your search

@@ -1,11 +1,9 @@
---
source: tui/src/chatwidget/tests/backend_banners_tests.rs
assertion_line: 50
expression: "render_bottom_popup(&chat, 70)"
expression: "normalize_snapshot_paths(render_bottom_popup(&chat, 70))"
---
Selected model usage exhausted
Ask your owner for credits or switch to another model.
› 1. Notify owner
Press a number to choose
@@ -0,0 +1,12 @@
---
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
expression: "normalize_snapshot_paths(render_bottom_popup(&chat, 90))"
---
You’re now using Luna, a faster model for simpler tasks.
Add credits or upgrade to continue using the most advanced models.
1. Add credits
› 2. Upgrade
3. Continue with Luna Reserve
Press enter to confirm or esc to continue working
@@ -0,0 +1,8 @@
---
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
expression: "render_bottom_popup(&chat, 34)"
---
› Ask Codex to do anything
Luna Reserve default · /tmp/pro…
@@ -0,0 +1,10 @@
---
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
expression: rendered
---
• Working (0s • esc to interrupt)
› x
tab to queue message 100% context left
@@ -0,0 +1,8 @@
---
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
expression: rendered
---
› Ask Codex to do anything
Luna Reserve default · /tmp/project
@@ -0,0 +1,12 @@
---
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
expression: "normalize_snapshot_paths(render_bottom_popup(&chat, 80))"
---
You’re now using Luna, a faster model for simpler tasks.
Add credits or upgrade to continue using the most advanced models.
› 1. Add credits
2. Upgrade
3. Continue with Luna Reserve
Press enter to confirm or esc to continue working