Skip to content

fix(terminal): filter focus reports after Codex history resume - #9259

Merged
brennanb2025 merged 2 commits into
stablyai:mainfrom
OrcaWin:OrcaWin/fix-codex-resume-terminal
Jul 18, 2026
Merged

brennanb2025 merged 2 commits into
stablyai:mainfrom
OrcaWin:OrcaWin/fix-codex-resume-terminal

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Prevents native Windows Codex history resumes from leaving literal [I, [[I, or [O focus-report fragments in the idle composer.

The existing Windows guard was armed by an agent done status. A session resumed from Agent Session History can open directly on a completed Codex composer with focus reporting enabled but no pane status row, so ESC[O / ESC[I could still reach ConPTY. This change recognizes the explicit Codex sidebar-resume startup metadata and arms the same guard until the resumed session starts working again.

Screenshots

No visual change.

Electron validation exercised the visible Agent Session History resume flow and a real focus handoff between the history search and resumed terminal. The completed Codex composer remained clean with focus reporting enabled and no agent-status row.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Additional focused validation:

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts — 449 passed
  • pnpm run typecheck:web
  • pnpm exec oxlint src/renderer/src/components/terminal-pane/pty-connection.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • Electron CDP validation on native Windows ConPTY

AI Review Report

Reviewed the existing startup input ordering fix and the native Windows post-turn focus-report suppression path. The main risk was over-broadly suppressing legitimate focus events for normal shells, Cursor, WSL, SSH, or runtime-hosted terminals. The implementation is restricted to native Windows ConPTY, explicit sidebar resume requests, and Codex startup metadata with no authoritative initial status. Existing working-state transitions restore focus reports.

Cross-platform compatibility was explicitly checked. The change does not alter shortcuts, labels, paths, Git commands, shell selection, macOS/Linux behavior, SSH, WSL, or remote-runtime transport behavior. The full PTY connection test file includes the neighboring remote-safety and non-Codex focus-report coverage.

Security Audit

No new command execution, path handling, authentication, dependency, or IPC surface was introduced. The filter accepts only xterm's exact focus-in and focus-out control sequences and uses existing trusted startup telemetry. Ordinary keyboard input and terminal query replies remain unchanged.

Notes

The behavioral change is intentionally Windows ConPTY-specific. The pre-fix failure was reproduced deterministically at the PTY transport boundary; the visible corruption itself is timing-sensitive.

Reliability Evidence

  • Invariant (terminal-input.focus-report-ownership): an idle native-Windows Codex history resume must not forward exact xterm focus-in/out reports as composer input; non-Codex resumes and fresh Codex launches must continue receiving them.
  • Failure source: the reported Agent Session History resume path can open a completed Codex composer with ?1004h active and no pane status row, allowing literal [I / [O fragments through ConPTY.
  • Oracle: the PTY transport tests assert exact filtered and forwarded byte sequences, preserve ordinary input, and prove suppression clears when Codex starts working. The focused file passes 449 tests.
  • Gate: accepted gap — there is no dedicated config/reliability-gates.jsonc entry for this narrow focus-report invariant. The manifest validator passes, and the deterministic renderer-unit oracle is recorded here until a stable native-Windows Electron gate is added.
  • Provider/platform coverage: local Windows ConPTY is covered. WSL, SSH, remote-runtime, mobile/relay, macOS, and Linux are unaffected by the existing native-ConPTY predicate and neighboring remote-safety tests.
  • Performance budget: no polling, timers, subprocesses, IPC, provider calls, broad scans, or new subscriptions were added. Classification is constant work once at pane connection; the existing input path retains two exact-string comparisons.
  • Diagnostics: a regression is visible as the exact focus bytes observed by the mock transport together with the pane startup metadata and agent-status transition.
  • Residual gap: the real Windows focus handoff was validated manually and is covered by the PR's Windows terminal CI, but no dedicated automated Electron focus-report gate exists yet.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Windows ConPTY pane initialization now detects Codex sidebar resume sessions without an initial agent status and enables suppression of native focus-report escape sequences while idle. Tests verify that \x1b[O and \x1b[I are suppressed initially and that focus input is forwarded after the pane’s agent status changes to working. Additional coverage confirms forwarding remains enabled for Claude history resume and fresh Codex launch scenarios.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 is concise and accurately summarizes the Windows Codex focus-report filtering change.
Description check ✅ Passed The description matches the template and includes summary, screenshots, testing, review, security, and notes.

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.

@brennanb2025
brennanb2025 merged commit cb9c42d into stablyai:main Jul 18, 2026
3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#9259)

* fix(terminal): filter focus reports after Codex history resume

* test(terminal): preserve focus reports outside Codex resume

---------

Co-authored-by: Brennan Benson <[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.

2 participants