Skip to content

fix(chat): preserve Chat through startup and unverifiable foreground reads - #22708

Open
lurunzi wants to merge 1 commit into
stablyai:mainfrom
lurunzi:fix/chat-exit-evidence-20260924
Open

lurunzi wants to merge 1 commit into
stablyai:mainfrom
lurunzi:fix/chat-exit-evidence-20260924

Conversation

@lurunzi

@lurunzi lurunzi commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

ELI5

Chat should stay open while Orca is still finding its agent or cannot verify the foreground process.

What Changed

The execution host emits a title-derived agent-exited fact only after its current controller positively identifies a shell. Missing, empty, wrapper-only or replaced-controller results preserve the exit candidate for a later trustworthy observation.

The renderer also keeps a requested Chat mode unbound while an initial pane's eligibility hydrates. It still exits for a confirmed agent exit or removal of a previously bound pane; it never binds the composer to a plain shell.

Why

A failed observation is not evidence of process exit. These two small changes preserve the existing host-owned lifecycle and renderer routing model instead of adding a client status cache or inventing a second lifecycle producer.

Linked Issue

Fixes #22707

Visual Proof

Pending: rendered startup/reconnect before/after evidence. This is a draft; source tests are not a desktop interaction recording.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Windows: 60 focused runtime exit/side-effect cases and 18 renderer routing cases passed. After switching the five new exit cases to upstream-supported Codex, all five passed again. Startup coverage uses Grok. Other runtime cases were excluded by the test-name filter (1,267 skipped in the combined run; 1,307 in the five-case rerun), so this is not a full-suite pass. Node/web typechecks, changed-code quality and lint-staged passed. No live SSH/WSL, macOS/Linux, packaging or rendered Electron checks.

AI Disclosure

Prepared and verified with Codex. Delegated attempts were blocked by account quota and produced no code.

Review

Host/controller provenance, reconnect races, unavailable capabilities, later positive shell evidence and existing pane-close behavior are covered. No Cursor/Antigravity Chat foundation or mobile implementation is included.

Agent skill upstream boundary

  • Not applicable; no skill-installer source or data copied.

Notes

Six files, no wire-format changes. Startup routing remains independent of git worktree versus folder-workspace identity.

Checklist

  • Small and focused
  • Explained before/after, mechanism and choice
  • Before/after recording attached
  • Self-reviewed
  • Cross-platform and SSH ownership considered
  • Full lint, typecheck, test and build pass; focused checks only

Keep pending startup routes unbound during owner hydration, and require a current positive shell observation before publishing title-derived exit facts.

Co-authored-by: Codex <noreply@openai.com>
@lurunzi
lurunzi force-pushed the fix/chat-exit-evidence-20260924 branch from aaca3e1 to af0b73e Compare October 16, 2026 18:31
@lurunzi
lurunzi marked this pull request as ready for review October 16, 2026 18:31
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Runtime exit detection now rejects unavailable, empty, or stale foreground-process results as exit evidence. A later shell observation can still produce an exit fact. During startup, chat routing remains active without a bound leaf when agent exit is unconfirmed. Added tests cover runtime evidence and startup routing cases.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to af0b7

Chat can still close while a wrapper process such as SSH or WSL is in the foreground. A pending Chat request that has not yet bound to a pane can also stay open after the agent has exited. Resolve both issues before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: preserving Chat during startup and unverifiable foreground-process reads.
Description check Passed The description is complete and covers the required sections, linked issue, user impact, implementation, rationale, testing scope, limitations, and review notes. It clearly discloses that visual proof…
Linked Issues check Passed Issue #22707 requires positive foreground-shell evidence from the current controller, preservation of the exit candidate when evidence is unavailable or stale, and later exit detection after a valid s…
Out of Scope Changes check Passed The six changed files stay within issue #22707. The source changes implement runtime exit evidence and native Chat startup routing. The added tests directly verify those behaviors. No unrelated featur…
Full details: Description check

Explanation

The description is complete and covers the required sections, linked issue, user impact, implementation, rationale, testing scope, limitations, and review notes. It clearly discloses that visual proof and full-suite validation are not available.

Full details: Linked Issues check

Explanation

Issue #22707 requires positive foreground-shell evidence from the current controller, preservation of the exit candidate when evidence is unavailable or stale, and later exit detection after a valid shell observation. confirmLegacyPtyAgentExit checks controller identity, availability, and a trimmed non-empty process string. It restores the exit candidate on unverifiable reads and rejects stale controller results. The added runtime tests cover unavailable, empty, missing-capability, later-shell, and reconnect cases. The renderer keeps an unbound Chat request during hydration, does not bind an ineligible shell, and exits on confirmed agent exit. The startup-routing tests cover these cases.

Full details: Out of Scope Changes check

Explanation

The six changed files stay within issue #22707. The source changes implement runtime exit evidence and native Chat startup routing. The added tests directly verify those behaviors. No unrelated feature, status store, lifecycle producer, wire-format change, mobile implementation, or unsupported agent foundation appears in the reviewed changes.

  • Fix all pre-merge checks with AI
  • 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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Keep the exit candidate when foreground… · terminal-agent-status-and-submission.ts:168-172

src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts:168-172
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the exit candidate when foreground inspection is absent.

If no hook-presence checker is configured, confirmPtyAgentExit passes keepOnSilence=false. If the controller is absent, this branch then emits agent-exited without observing a shell. The new no-controller test uses an unverifiable checker, so it does not cover this path. Preserve the candidate when a title-derived exit has no foreground evidence.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6affcaad-f838-4363-a10a-90347a83d50d
📥 Commits

Reviewing files that changed from the base of the PR and between d5cd082 and af0b73e.

📒 Files selected for processing: 5
  • src/main/runtime/orca-runtime-tests/terminal-agent-exit-evidence.spec.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts
  • src/renderer/src/components/native-chat/native-chat-leaf-routing.ts
  • src/renderer/src/components/native-chat/native-chat-startup-routing.test.ts

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

Comment on lines +216 to +217
typeof result.process === 'string' &&
result.process.trim().length > 0

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -o pipefail
printf '%s\n' '--- changed-file diff ---'
git diff --no-ext-diff 922014afcb8e277c0dc4bd6e13244fb29f01171b af0b73ea3046b032773c924636667df32cef798d -- src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts

printf '%s\n' '--- relevant references ---'
rg -n -F --glob '*.ts' -e 'ptyForegroundAgent' -e 'confirmLegacyPtyAgentExit' -e 'confirmPtyAgentExit' src/main/runtime src/main | head -200

printf '%s\n' '--- changed-file excerpt ---'
nl -ba src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts | sed -n '150,260p'

printf '%s\n' '--- foreground-reader declarations and implementations ---'
rg -n -F --glob '*.ts' -e 'class PtyForeground' -e 'ForegroundAgent' -e 'readForeground' -e 'foregroundProcess' -e 'isAvailable' src/main | head -240

Repository: stablyai/orca

Length of output: 39086


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- runtime service foreground agent ---'
nl -ba src/main/runtime/construction/runtime-service-state.ts | sed -n '130,205p'
rg -n -F --glob '*.ts' -e 'class RuntimePtyForegroundAgent' -e 'RuntimePtyForegroundAgent' -e 'ForegroundRead' -e 'foreground read' src | head -200

printf '%s\n' '--- likely implementation files ---'
rg --files src | rg -i 'foreground|pty.*agent|process.*inspection' | head -200

printf '%s\n' '--- terminal-host inspection implementation ---'
nl -ba src/main/daemon/terminal-host-process-inspection.ts | sed -n '1,175p'
nl -ba src/main/daemon/terminal-host-process-inspection-cheap-tier.test.ts | sed -n '240,370p'

Repository: stablyai/orca

Length of output: 40359


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- RuntimePtyForegroundAgent ---'
nl -ba src/main/runtime/runtime-pty-foreground-agent.ts | sed -n '1,280p'

printf '%s\n' '--- remote foreground evidence ---'
nl -ba src/main/providers/agent-foreground-process.ts | sed -n '1,280p'
nl -ba src/shared/remote-foreground-evidence-admission.ts | sed -n '1,260p'
nl -ba src/shared/foreground-wrapper-agent.ts | sed -n '1,220p'
nl -ba src/shared/foreground-process-evidence.ts | sed -n '1,220p'

printf '%s\n' '--- controller read binding ---'
nl -ba src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts | sed -n '1,130p'

Repository: stablyai/orca

Length of output: 39878


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- controller contract and getForegroundProcess implementations ---'
rg -n -F --glob '*.ts' -e 'getForegroundProcess(ptyId' -e 'getForegroundProcess:' -e 'getForegroundProcess =' -e 'getForegroundProcess(' src/main/runtime src/main/providers src/main/daemon src/main | head -260
nl -ba src/main/runtime/runtime-pty-controller-contract.ts | sed -n '1,220p'

printf '%s\n' '--- controller construction and execution-host bindings ---'
rg -n -F --glob '*.ts' -e 'new RuntimePtyController' -e 'implements RuntimePtyController' -e 'getForegroundProcess' src/main | head -260
rg -n -F --glob '*.ts' -e 'ssh.exe' -e 'wsl.exe' -e 'ssh' -e 'wsl' src/main/runtime src/main/daemon src/main/providers | head -260

Repository: stablyai/orca

Length of output: 41422


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- controller contract ---'
rg -n -F --glob '*.ts' -e 'getForegroundProcess' src/main/runtime/runtime-pty-controller-contract.ts src/main/runtime | head -200
nl -ba src/main/runtime/runtime-pty-controller-contract.ts | sed -n '1,180p'

printf '%s\n' '--- controller bindings ---'
rg -n -F --glob '*.ts' -e 'getForegroundProcess:' -e 'getForegroundProcess =' -e 'getForegroundProcess(' src/main | head -260

printf '%s\n' '--- shell predicate ---'
rg -n -F --glob '*.ts' -e 'function isShellProcess' -e 'const isShellProcess' -e 'export { isShellProcess' -e 'isShellProcess' src/shared/agent-detection.ts src/shared/shell-process-detection.ts
nl -ba src/shared/shell-process-detection.ts | sed -n '1,180p'
nl -ba src/shared/agent-detection.ts | sed -n '1,100p'

Repository: stablyai/orca

Length of output: 41631


Require a confirmed shell before consuming the exit candidate.

RuntimePtyForegroundAgent.read marks any fulfilled process-name read as available. When keepOnSilence is enabled, answered must also require isShellProcess(result.process). A non-empty wrapper name such as ssh.exe or wsl.exe must remain unverifiable and preserve the exit candidate.

🐛 Suggested fix
--- "a/src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts"
+++ "b/src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts"
@@ -210,11 +210,13 @@
         this.restoreDisprovedAgentExit(ptyId, confirmedStatus)
         return
       }
+import { isShellProcess } from '../../../../shared/shell-process-detection'
+
       const answered =
         result.controller === this.ptyController &&
         result.available &&
         typeof result.process === 'string' &&
-        result.process.trim().length > 0
+        isShellProcess(result.process)
       if (!keepOnSilence || answered) {
         if (!recoverCompletedHook) {
           this.recordTerminalSideEffectFact(ptyId, { kind: 'agent-exited' })

Comment on lines +118 to +120
if (!args.chatLeafId && !confirmedAgentExit) {
// Host and agent evidence can hydrate after the pane; keep the request unbound until eligible.
return { chatLeafId: null, exitChat: false }

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -n -C 6 'chatLeafHasConfirmedAgentExit|applyNativeChatLeafRoute|agent-exited|agentExited' src/renderer/src/components

Repository: stablyai/orca

Length of output: 29818


🏁 Script executed:

set -eu
printf '%s\n' '--- native-chat-leaf-routing.ts ---'
nl -ba src/renderer/src/components/native-chat/native-chat-leaf-routing.ts | sed -n '80,145p'
printf '%s\n' '--- use-terminal-pane-chat-state.ts ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts | sed -n '125,215p'
printf '%s\n' '--- use-terminal-pane-projection.ts ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-projection.ts | sed -n '100,145p'
printf '%s\n' '--- route references and exit callback references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'handleConfirmedAgentExit' -e 'onAgentExitedRef' -e 'resolveNativeChatLeafRoute' -e 'setNativeChatViewMode' src/renderer/src/components

Repository: stablyai/orca

Length of output: 14762


🏁 Script executed:

set -eu
printf '%s\n' '--- changed diff for routing and chat state ---'
git diff --no-ext-diff --unified=35 922014afcb8e277c0dc4bd6e13244fb29f01171b  af0b73ea3046b032773c924636667df32cef798d -- \
  src/renderer/src/components/native-chat/native-chat-leaf-routing.ts \
  src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts \
  src/renderer/src/components/terminal-pane/use-terminal-pane-projection.ts
printf '%s\n' '--- exit callback contract and dispatch ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-process-exit-actions.ts | sed -n '80,155p'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts | sed -n '1,55p'
printf '%s\n' '--- routing tests around exit and startup ---'
nl -ba src/renderer/src/components/native-chat/native-chat-leaf-routing.test.ts | sed -n '100,255p'
nl -ba src/renderer/src/components/native-chat/native-chat-startup-routing.test.ts | sed -n '1,75p'

Repository: stablyai/orca

Length of output: 17548


Handle a confirmed exit while Chat is unbound.

When chatLeafId is null, handleConfirmedAgentExit returns before resolveNativeChatLeafRoute receives the confirmed-exit flag. A confirmed exit can therefore leave the pending Chat request open. Keep the mismatch guard for a bound Chat leaf, but allow an unbound request through.

Suggested fix
-      if (leafId !== chatLeafId) {
+      if (chatLeafId && leafId !== chatLeafId) {
         return
       }

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep desktop Chat during startup and unverifiable foreground process reads

1 participant