Skip to content

fix(terminal): wait for shell readiness on Codex account restart - #9365

Merged
nwparker merged 1 commit into
stablyai:mainfrom
kazu-42:agent/fix-codex-restart-shell-ready
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
kazu-42:agent/fix-codex-restart-shell-ready

Conversation

@kazu-42

@kazu-42 kazu-42 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a race where switching Codex accounts could drop, mangle, or leave unsubmitted the codex command in the restarted terminal pane.

ELI5

When you switch Codex accounts, Orca reopens the terminal and types codex for you. Sometimes it typed too early — before the shell was ready — so the command got garbled. Now it waits until the shell is actually listening.

Root cause & fix

The account-switch restart relaunched panes with startup: { command: 'codex' }, which used the default "fast" delivery (a 300 ms daemon fast-path). Slow prompt integrations like Starship can still be rendering the first prompt past that boundary, so the command could be delivered before the shell accepts input. The fix introduces a shared constant CODEX_ACCOUNT_RESTART_STARTUP = { command: 'codex', startupCommandDelivery: 'shell-ready' } and uses it at the relaunch site — matching the fresh-launch behavior already defined for codex in shared/tui-agent-startup.ts. Ordinary blank Codex launches keep the low-latency fast path.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Test: codex-session-restart.test.ts via npx vitest run --config config/vitest.config.ts src/renderer/src/lib/codex-session-restart.test.ts
  • On branch: Test Files 1 passed (1) | Tests 10 passed (10)
  • Fix files reverted to main (test kept): 1 failed | 9 passed — proving the test locks the fix:
AssertionError: expected undefined to deeply equal
  { command: 'codex', startupCommandDelivery: 'shell-ready' }
  (CODEX_ACCOUNT_RESTART_STARTUP is undefined without the fix)
  • Fix restored → back to green.
  • startupCommandDelivery is a recognized startup field, read in pty-connection.ts and honored by shouldUseShellReadyStartupDelivery in shared/codex-startup-delivery.ts.
  • Lint: npx oxlint TerminalPane.tsx codex-session-restart.ts → exit 0, no warnings/errors.
  • Rebase: clean onto merge-base 7ab601487c; branch diff against it is exactly the 3 PR files, no conflicts.

Trade-offs

The account-switch restart may wait for the remaining shell initialization time before starting Codex. This is intentional — the new process must reliably inherit the selected CODEX_HOME — and transport-specific bounded fallbacks (local, daemon, SSH, remote) still apply, so there is no unbounded wait.

Regression risk

Near-zero. Only the account-switch restart branch changes delivery mode; ordinary blank Codex launches and all non-affected paths are byte-identical. The regression test proves the corrected descriptor and fails when the fix is reverted.

Credit to @kazu-42 for the original fix. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@kazu-42
kazu-42 marked this pull request as ready for review July 20, 2026 17:40
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Codex account restart handling now uses the exported CODEX_ACCOUNT_RESTART_STARTUP configuration, which runs codex with shell-ready startup delivery. The terminal pane restart path uses this shared configuration when reconnecting, and tests verify both its shape and delivery behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections and include the required testing checklist, review summary, security audit, and notes.
✅ 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 summarizes the main change: delaying Codex restart until shell readiness.

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.

@nwparker
nwparker force-pushed the agent/fix-codex-restart-shell-ready branch from 6c4fe1a to b9502f3 Compare July 23, 2026 11:49
@nwparker
nwparker merged commit 53222cc into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much for this, @kazu-42 — wait for shell readiness on Codex account restart. Verified (fail-on-main/pass-on-branch), rebased on latest main, reviewed, and merged. Really appreciate it! 🙏

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.

4 participants