Skip to content

fix(native-chat): do not exit Chat UI on false agent-title after send - #10102

Open
innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/native-chat-suppress-false-exit-on-send
Open

innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/native-chat-suppress-false-exit-on-send

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Description

An ordinary natural-language send from Codex Chat UI could flip the pane back to Terminal, showing the hosted codex … command line. Composer ordinary sends never call onSwitchToTerminal; the more likely path is a false agent-exit from a brief shell-like OSC title while the first PTY write is accepted, which routes through handleConfirmedAgentExit → exitChat.

This PR suppresses that programmatic Chat→Terminal handoff for a short window after an optimistic chat send (and while pending sends remain), and records renderer breadcrumbs when exit is suppressed vs applied so post-hoc triage can see the branch (#10098 requested).

Evidence

  • Hypothesis matches [Bug]: Codex Chat UI ordinary message unexpectedly switches to Terminal #10098 source notes (ordinary send path does not switch; TerminalPane exitChat does).
  • Unit tests:
    pnpm exec vitest run --config config/vitest.config.ts \
      src/renderer/src/components/native-chat/native-chat-pending.test.ts \
      src/renderer/src/components/native-chat/native-chat-leaf-routing.test.ts \
      src/renderer/src/components/native-chat/native-chat-exit-suppress.test.ts
    66/66 passed
  • Coverage: grace after prune; pending still suppress; sibling pane isolation; suppress keeps mounted leaf; suppress does not block real leaf-removed exit.

ELI5

After you hit send in Chat UI, Orca briefly listens for “did the agent quit?”. Sometimes the terminal title flickers and Orca thought it quit, so it yanked you into the raw terminal. Now it waits a few seconds after a chat send before trusting that signal.

User-regression-tradeoffs

  • Intentional picker / /model handoffs still use onSwitchToTerminal and are unchanged.
  • If the agent truly exits during the 5s post-send grace, Chat UI may stay open until grace ends (or until the leaf unmounts). Preferable to mid-send Terminal thrash; real process death still clears agent rows via process trackers.
  • Breadcrumbs are best-effort crash evidence only.

Checklist notes

  • Cross-platform: pure renderer logic (macOS report; same path all platforms).
  • SSH/remote: paneKey-scoped; works for remote-hosted PTYs the same way.
  • Agents/integrations: any Chat UI agent with optimistic send + title exit path (Codex is the reported case).
  • Performance: O(pending scopes) map scan on agent-exit only.
  • UI: no layout change.
  • Security: no new network surface.

Fixes #10098

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

Adds pane-scoped native-chat exit suppression based on pending entries and a five-second optimistic-send grace period. Extends leaf routing to preserve a mounted chat leaf during confirmed agent exit when suppression is active, while still exiting if the leaf is absent. Integrates the guard into terminal-pane routing and records breadcrumbs for suppressed exits and chat-to-terminal handoffs. Adds tests covering suppression timing, pane isolation, and routing outcomes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative but does not follow the required template and omits several mandatory sections. Add the missing template sections and fill them out: Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)

Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: preventing Chat UI from exiting after a false agent-title signal.
Linked Issues check ✅ Passed The PR addresses #10098 by suppressing false agent-exit handoffs after sends, preserving explicit handoffs, and adding regression tests and breadcrumbs.
Out of Scope Changes check ✅ Passed The changes stay within native-chat routing, suppression, breadcrumbs, and tests, with no unrelated scope introduced.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 27a2016e-34ee-42b8-b434-be95e0818c39

📥 Commits

Reviewing files that changed from the base of the PR and between c445f26 and 96c836dfb31e4ca5b9d5a97eda42f10accd41b16.

📒 Files selected for processing (7)
  • src/renderer/src/components/native-chat/native-chat-exit-suppress.test.ts
  • src/renderer/src/components/native-chat/native-chat-exit-suppress.ts
  • src/renderer/src/components/native-chat/native-chat-leaf-routing.test.ts
  • src/renderer/src/components/native-chat/native-chat-leaf-routing.ts
  • src/renderer/src/components/native-chat/native-chat-pending.test.ts
  • src/renderer/src/components/native-chat/native-chat-pending.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx

@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (96c836dfb)

Address CodeRabbit: suppress before sibling route, pre-route breadcrumb leaf, post-grace re-eval of confirmed exit.

@innocarpe
innocarpe force-pushed the fix/native-chat-suppress-false-exit-on-send branch from a9f6b5b to 2cc109c Compare July 24, 2026 09:06
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (2cc109cdb)

Clean rebase onto upstream/main (no conflicts). Keeps false agent-title exit-suppress + review feedback; now current with main.

@AmethystLiang
AmethystLiang requested a review from OrcaWin July 24, 2026 16:51
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@innocarpe
innocarpe force-pushed the fix/native-chat-suppress-false-exit-on-send branch from 2cc109c to a287b49 Compare October 22, 2026 02:35
@innocarpe
innocarpe force-pushed the fix/native-chat-suppress-false-exit-on-send branch from a287b49 to c9424ba Compare October 29, 2026 10:52
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects Native Chat exit routing in terminal panes.

Fix the delayed exit callback before merging; it can still close Chat after the agent recovers.

Findings

  1. P1 Chat closes after recovery ▶
  2. P2 Closed panes keep memory ▶

Summary

Adds a pane-specific guard against title-based Chat exits after a send.

  • Native Chat stays open through a brief agent-title exit after a send.

Acknowledgment: innocarpe explicitly made suppression continue while pending sends remain. That behavior was not reported as a separate finding.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Chat send] --> B[Record pane send time]
  C[Title reports agent exit] --> D{Recent send or pending entry?}
  D -->|Yes| E[Keep mounted chat leaf]
  E --> F[Wait for retry timer]
  F --> C
  D -->|No| G[Apply confirmed exit route]
  G --> H[Switch to Terminal or eligible sibling]
Loading

Reviews (1) · Last reviewed commit: "fix(native-chat): address exit-suppress ..." · Reviewed by Greptile

Comment on lines +219 to +222
pendingConfirmedExitTimerRef.current = setTimeout(() => {
pendingConfirmedExitTimerRef.current = null
onAgentExitedRef.current(leafId)
}, remainingMs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Chat closes after recovery

If a shell-like title briefly appears after a send, this timer replays that exit even after the agent title recovers. Once pending sends clear and the grace ends, handleConfirmedAgentExit still passes chatLeafHasConfirmedAgentExit: true. With the same active leaf, that forces Chat back to Terminal despite the agent still running.

Recheck current exit evidence before applying the delayed route, or cancel the timer when the agent recovers.

Comment on lines +7 to +10
const lastOptimisticSendAtByPaneKey = new Map<string, number>()

export function recordNativeChatOptimisticSendForExitGuard(paneKey: string, sentAt: number): void {
lastOptimisticSendAtByPaneKey.set(paneKey, sentAt)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Closed panes keep memory

lastOptimisticSendAtByPaneKey keeps every pane that has ever sent a message. Expired entries and closed panes are never removed; only the test helper clears the map. Long-running sessions that open and close chat panes therefore keep growing this map.

Bound it like pendingSendCache, or remove expired entries during normal use.

@innocarpe
innocarpe force-pushed the fix/native-chat-suppress-false-exit-on-send branch from c9424ba to f83adf9 Compare November 2, 2026 13:01
Ordinary Codex Chat UI sends can race a brief shell-like OSC title and
trip handleConfirmedAgentExit → exitChat, switching to Terminal mid-turn.

Suppress that handoff while optimistic sends are pending or within a
short post-send grace window, and record breadcrumbs when exit is
suppressed vs applied for post-hoc triage.

Fixes stablyai#10098
- Apply send-grace suppression before eligible-sibling retarget
- Breadcrumb the pre-route chat leaf on terminal handoff
- Re-evaluate confirmed agent exit after the grace window ends
@innocarpe
innocarpe force-pushed the fix/native-chat-suppress-false-exit-on-send branch from f83adf9 to 758cce0 Compare November 10, 2026 07:25
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (758cce0e25)

Rebased onto current upstream/main. A recent Chat UI send still suppresses a false agent-title exit, including sibling retarget, and the grace window rechecks the exit. Related tests: 17 passed.

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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex Chat UI ordinary message unexpectedly switches to Terminal

3 participants