Skip to content

Show Codex model capacity failures as red agent status - #28231

Merged
nwparker merged 3 commits into
mainfrom
nwparker/detect-at-capcity-codex
Oct 13, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/detect-at-capcity-codex

Conversation

@nwparker

@nwparker nwparker commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​474 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​474
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​331 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​321

ELI5

When Codex says the selected model is at capacity, Orca now replaces the agent's running spinner with its existing red failure indicator. Sending another prompt restores the running state.

What Changed

Recognize Codex's native capacity notice in live terminal output, verify it is the latest notice above the composer, and publish a failed main-agent turn into the execution host's existing hook status store. Preserve prompt, model, session identity and child work; keep the failure through a later Stop or child update, and clear it on the next prompt. Terminal status deduplication now respects an explicitly supplied main-agent verdict.

Why

Codex can finish an overloaded request without the completion hook Orca needs, leaving a misleading spinner. The bounded detector reuses Orca's escape scanner, headless terminal and status pipeline. It abandons unrelated warning text immediately and normalizes only bounded candidate fragments; command recognition is cached per emulator and invalidated when the startup command changes. This avoids another poller, process scan, or sidebar-only state. Source inspection covered Codex's ServerOverloaded error and its TUI turn-finalization path in ~/projects/codex.

Linked Issue

Requested directly by a maintainer; no linked issue.

Visual Proof

Hidden Electron instance, real PTY, replay of a captured Codex capacity response in a folder project. Before: working. After: red failure indicator and the capacity message in the left sidebar. Retrying restored Working.

Before: running agent
After: capacity failure

Testing

  • Manually tested on macOS through Playwright CDP against a hidden Electron instance from this worktree.
  • Automated tests added: 115 passing tests across eight focused suites. Includes real Codex 0.162.1 inline and 40-column fullscreen captures, single-character chunk splits, wrapping, quoted text, old history, synchronized frames, retry, subagents, queued-output races, same-millisecond turn boundaries, shell-launched first notices, combined ANSI modes, and SSH ownership.
  • pnpm tc and pnpm run check:code-quality:changed passed; changed files formatted with oxfmt.
  • Electron main/preload/renderer compiled successfully during validation. Full release build and full lint remain for CI.
  • Reproducible detector benchmark: ORCA_BACKGROUND_LAUNCH=1 node --import tsx config/scripts/codex-capacity-status-benchmark.ts. Ordinary output causes zero screen/status reads; command classification occurs once per unchanged launch. No new polling or subprocesses.
  • Captures used isolated Codex homes and a local HTTP 503 server_is_overloaded server; both passed the transcript secret scan.

Performance

Same local macOS machine, Node 24, median of five warmed runs. Baseline is commit 2cd76e307da; these numbers measure detection work rather than total Electron CPU or IPC/render time.

Workload Before After
Captured 3.7 KB TUI sequence 143 µs/chunk 45 µs/chunk
Ordinary warning footer 5.84 µs/chunk 0.31 µs/chunk
1 MiB output following an unrelated warning 1.69 ms/chunk 0.10 ms/chunk
Unrelated terminal, 4 KB ordinary output 1.15 µs/chunk 0.025 µs/chunk
Plain Codex output, 4 KB about 0.1 µs/chunk about 0.1 µs/chunk

At 100 captured TUI chunks per second, 45 µs/chunk extrapolates to roughly 0.45% of one CPU core per terminal for detection alone. The rare 40-column/24-row screen read measured about 0.5 µs; parsing and validating the complete captured failure took about 43 µs. Synthetic marker-flood input is included in the benchmark and regression tests.

Source inspection confirmed that the normal Codex TUI sets persist_extended_history: false, error records require extended rollout history, and Stop hooks have no provider error code. A provider error hook would be the preferable upstream signal. Switching ordinary terminal sessions to a controlled app-server transport would be a separate launch architecture change.

Review

Adversarial review found and fixed three issues:

  • P1 — Missed first notice in a shell-launched session. The lazy tracker could start after the synchronized redraw opened, inspect a half-painted screen, and discard the notice. It now consults the emulator's actual synchronized-output mode after the ordered write. Regression tests replay the real 40-column capture through the complete detector in 1/7/64/full-size chunks.
  • P2 — Combined ANSI modes bypassed the redraw guard. The scanner only recognized a standalone 2026 parameter. It now recognizes 2026 in a mode list; tests prove zero screen reads until the combined redraw closes.
  • P2 — Same-millisecond turn/output ordering was treated as safe. The timestamp guard now yields when the turn starts at or after the output timestamp. The equal-timestamp case is covered.

Remaining heuristic limits are explicit: tool output that exactly imitates the native capacity notice immediately above the composer can produce a false failure. Terminal bytes alone cannot prove the provider error code. Conversely, a genuine notice arriving in the same millisecond as a new turn is conservatively skipped rather than risking marking the newer turn failed. A structured provider error hook would remove these ambiguities.

Checked execution-host ownership, prompt/model/session preservation, failure retention through child activity and Stop, retry recovery, stale output, frame boundaries, cache invalidation, large output and marker floods. No new polling, process scans, wire fields or stream opcodes. Physical Linux/Windows/SSH validation remains a stated gap; remote ownership and relay restatements are covered by unit tests.

Agent skill upstream boundary

  • Not applicable; no upstream skill source was copied.

Reliability Contract

Invariant (agent-session.provider-ownership): only the execution host reports the capacity failure, a newer turn cannot be closed by queued old output, and subagent activity does not erase the failed root. The original capacity failure and this performance audit motivate the checks. The oracle is replay of captured Codex bytes through the runtime plus shared-store tests, with deterministic zero-read and command-classification counts. There is an accepted gap for a dedicated capacity entry in the reliability manifest; the focused gate is ORCA_BACKGROUND_LAUNCH=1 pnpm test src/shared/codex-capacity-notice.test.ts src/main/runtime/codex-capacity-terminal-status.test.ts src/main/agent-hooks/server-codex-capacity.test.ts; five neighboring suites also passed. Captured fixtures and the benchmark JSON output provide diagnostic artifacts.

Local runtime/store behavior is covered on macOS; remote ownership and relay restatements are covered by unit tests. Daemon lifecycle, WSL launch/path handling, and mobile/relay transport are unaffected by this optimization. Physical Linux/Windows/SSH validation remains a stated gap.

Notes

No new dependencies or styling. Trackers live in a WeakMap keyed by terminal emulator, and the text carry is bounded. Folder projects and git worktrees use the same terminal ingress.

Checklist

  • Small and focused
  • Explained the user-facing before/after, mechanism and approach
  • Before/after screenshots attached
  • Self-reviewed for correctness, security and performance
  • Cross-platform, SSH, folder projects and compatibility considered
  • Focused tests, typecheck and changed-code lint passed; CI covers full lint and release build

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 974b95f0-b33c-4bd5-addd-25018efcde08
📥 Commits

Reviewing files that changed from the base of the PR and between 597d99d and a0f0b48.

📒 Files selected for processing (5)
  • src/main/daemon/headless-emulator.ts
  • src/main/runtime/codex-capacity-terminal-status.test.ts
  • src/main/runtime/codex-capacity-terminal-status.ts
  • src/shared/codex-capacity-notice.test.ts
  • src/shared/codex-capacity-notice.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

📝 Walkthrough

The change detects Codex capacity notices in terminal output and creates a completed Codex status with a failed main-agent outcome. Terminal observation runs before Freebuff status observation. Terminal and server status handling preserve or reconcile main-agent failure status under specified conditions. Added tests, captured terminal fixtures, and a benchmark cover notice detection and status handling.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to a0f0b

The change is mergeable with owner awareness: in a narrow shell-reuse case, later output repeating the capacity notice can incorrectly turn the agent status red.

Pre-merge checks · Passed 3 · Failed 2

Failed Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description covers the required user impact, implementation, rationale, visual proof, testing, review notes, compatibility considerations, and checklist. However, it does not provide the required … Add an actual linked issue under “Linked Issue” using “Fixes #” or another valid issue reference. Add the AI Disclosure section, or explicitly state the applicable internal-contributor exception if permitted by repository poli…
Passed Passed checks (3 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the primary change: showing Codex model-capacity failures as a red agent status.
Full details: Description check

Explanation

The description covers the required user impact, implementation, rationale, visual proof, testing, review notes, compatibility considerations, and checklist. However, it does not provide the required linked issue and does not include the AI Disclosure section.

Resolution

Add an actual linked issue under “Linked Issue” using “Fixes #<issue-number>” or another valid issue reference. Add the AI Disclosure section, or explicitly state the applicable internal-contributor exception if permitted by repository policy.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ed488b5-dc3d-4180-809f-988660f12b76
📥 Commits

Reviewing files that changed from the base of the PR and between e9285f0 and 2cd76e3.

📒 Files selected for processing (12)
  • src/main/agent-hooks/server-codex-capacity.test.ts
  • src/main/agent-hooks/server/server-ingest-terminal.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/main/runtime/__fixtures__/codex-model-capacity-fullscreen.meta.json
  • src/main/runtime/__fixtures__/codex-model-capacity-fullscreen.txt
  • src/main/runtime/__fixtures__/codex-model-capacity.meta.json
  • src/main/runtime/__fixtures__/codex-model-capacity.txt
  • src/main/runtime/codex-capacity-terminal-status.test.ts
  • src/main/runtime/codex-capacity-terminal-status.ts
  • src/main/runtime/orca-runtime-maybe-hydrate-headless-from-renderer.ts
  • src/shared/agent-terminal-status-equivalence.ts
  • src/shared/codex-capacity-notice.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit 9e52645 into main Oct 13, 2026
38 of 40 checks passed
OrcaWin added a commit that referenced this pull request Oct 13, 2026
…nce (#28286)

#28231 added the codex-model-capacity-fullscreen PTY capture without an entry in the replay
test's known-divergence table, so every PR's test shard fails on main (expected 0, got 12).
The serializer is untouched; the divergence is the same restore limitation the table records.

Co-authored-by: m4air <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant