Skip to content

fix(terminal): an app's own prompt markers no longer forget a live agent when its pane is hidden or shown - #31182

Open
brennanb2025 wants to merge 71 commits into
mainfrom
brennan/sta-11321-centralize-agent-status-detection-and-make-hooks-and
Open

brennanb2025 wants to merge 71 commits into
mainfrom
brennan/sta-11321-centralize-agent-status-detection-and-make-hooks-and

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 164 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11927 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3126 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8801
Prod 264 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10760 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4334 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6426

Agent tracking and pending completion notifications could reset when a pane attached, closed or reconnected, even though its terminal kept running. This keeps one tracker with the running terminal and makes pane attachment presentation-only, so accepted work and completion handling continue through those transitions.

Agent identity comes from hooks and process observations. An honestly observed agent name can remain visible during contact uncertainty, while input routing, process presence, status and other actions continue to require their own current evidence. This removes typed-command identity guesses, the special one-shot OpenCode status producer and the FIFO/lease machinery. A shell completion marker alone cannot prove that an agent has exited; cleanup requires evidence from the execution host.

Tracked in STA-11321 and STA-9149. This PR includes the current foreground display/action boundary and lands before the separate canonical identity correction tracked in #35950. It works on its own; #35950 is not a landing dependency.

Intended compatibility behavior: old hosts keep main's existing 15-second handoff window for a bell that arrives before the terminal's lookup answers; hosts reporting the new capability deliver it unconditionally. The existing 64-batch/32-PTY limits and older hosts' launch path remain supported, with no minimum server version. Contact loss keeps the execution uncertain until actual evidence establishes its state.

Intended behavior: double-Escape detection stays per pane; Escapes from different panes do not combine into an interrupt. Acknowledgment accounting uses the execution captured when input was dispatched. Input dispatch never waits for bookkeeping.

Intended behavior. Kill-switch fallback only: when status authority is off and a reopened terminal's ID is a stale mapping from another workspace, a Ctrl+C sent before Orca has confirmed the terminal's process is delivered immediately but isn't inferred as an interrupt; the status updates at the agent's next event. Status should not be inferred from terminal keys at all.

Temporary: applications subscribed to terminal color-scheme changes no longer receive automatic light/dark reports when Orca's theme changes. Explicit color-scheme queries still receive current answers. Automatic subscribed reports return with host-admitted mode writes, tracked in STA-11321, slice 4.

Follow-up: recording interrupts at server write acceptance is out of scope for this PR.

Verification is in progress. Source review and finite integration acceptance are complete through 597fee3b70cb42388f2ebb0e39c85d63b4ac04df; the final main merge passed 208 named tests, with 31 tests independently rerun. The retained native protocol/artifact evidence has independent acceptance. Current CI is failing; compiler, static-test, smoke-parser and fixture repairs are in progress. Final changed-flow QA with real Claude and Codex, targeted OpenCode v1/v2 runs, and the remaining Command Code/Pi recorded-input contracts are pending. These test results are not an app QA pass, and this PR is not ready to merge.

…keeps the live agent's launch identity (red)
…ent when its pane is hidden or shown

OMP closes each prompt bubble with OSC 133 B C D;0 while it keeps running.
Read as "the command finished", that D retired the pane's launch and hook
identity, so later hooks were refused and the phone lost the session. The
uninterrupted case was already recognized, but scan authority moves between
main and the daemon on every hide/show, and a fresh scanner that never saw
B C read the lone D as a real exit.

- A scanner that joins mid-stream holds an unseen D;0 and fires it only when
  the shell's next prompt (A) follows at once, as every Orca shell hook
  prints; OMP follows its zone close with output, which drops it.
- A finished command retires launch identity only once the agent's process
  is gone: the hook process exited, or the host sees nothing but the shell
  in the PTY's process tree (a backgrounded agent still counts as alive).
- Daemon protocol 51: older relays misread these zones, so they no longer
  get background scan authority and their queued command exits are dropped.

Tracked in STA-11321.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 20, 2026 18:06
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The OSC 133 scanner now tracks unseen marker adjacency and waits for a prompt marker before reporting qualifying command completion. Daemon protocol version 51 adds support for this behavior, and older daemons are gated from relaying affected completion facts or receiving background scan authority. PTY launch-authority retirement now checks that the agent process has exited, using process-table inspection when presence is unverifiable. Tests cover scanner state, protocol compatibility, and retirement paths.

Merge Risk: Minimal · up to 1fa64

The previously reported scanner risk does not affect the current path, and the callback fix is in place. No actionable merge-blocking risk remains from the supplied evidence.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description has substantive content on what the change does and why, but it does not follow the required template. Missing or incomplete sections: ELI5 is absent; 'What Changed' and 'Why' are not … Rewrite the description to follow the repository template. Add: an ELI5 section; labeled What Changed and Why sections (state the before and after behavior and why this approach beat alternatives); a Linked Issue section with a real 'Fixes …
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: preventing pane visibility changes from incorrectly retiring a live agent.
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.
Full details: Description check

Explanation

The description has substantive content on what the change does and why, but it does not follow the required template. Missing or incomplete sections: ELI5 is absent; 'What Changed' and 'Why' are not labeled as template sections (the content is present but unstructured); 'Linked Issue' has no 'Fixes #' issue link (it cites STA-11321 and STA-9149 and #35950 instead, and those are Linear or other references rather than a linked GitHub issue); 'Visual Proof' is missing, though the change includes a user-visible color-scheme behavior change; 'Testing' has no checklist ticked and no step-by-step reviewer instructions, and it does not state which platforms were manually tested (macOS unit and real-PTY tests only); 'Risk' has no Level and no rollback plan; 'AI Disclosure' is absent; 'Review' and 'Agent skill upstream boundary' are absent; 'Checklist' is not completed. The author states the PR is not ready to merge and that CI is failing, and the description says lint, typecheck, test, and build were not confirmed locally.

Resolution

Rewrite the description to follow the repository template. Add: an ELI5 section; labeled What Changed and Why sections (state the before and after behavior and why this approach beat alternatives); a Linked Issue section with a real 'Fixes #' issue, because outside contributors need one; a Visual Proof section with before and after media for the terminal color-scheme and agent-status display changes, or N/A with reason; a Testing section with reviewer steps, platforms actually tested (macOS, Linux, Windows, SSH), and the checklist items ticked accurately; a Risk section with Level (Low, Medium, or High), the riskiest part, affected users (older daemons, SSH hosts, kill-switch path), and the rollback method; an AI Disclosure section unless the author is a stablyai team member; the Agent skill upstream boundary checkbox; and the completed Checklist. Also state the current CI status and the remaining verification gates (lint, typecheck, test, build) in the Testing section.

Finishing Touches

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

ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: be284a2a-d0d7-4dc6-9756-8c8d6da106ac
📥 Commits

Reviewing files that changed from the base of the PR and between a7876a4 and 1fa6433.

📒 Files selected for processing: 1

  • src/main/daemon/terminal-shell-lifecycle-scanner.ts
🚧 Files skipped from review as they are similar to previous changes: 1

  • src/main/daemon/terminal-shell-lifecycle-scanner.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.

@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: 2c085f7f-161d-4f36-a040-b4ce6306a163
📥 Commits

Reviewing files that changed from the base of the PR and between 99e91c1 and 66e8c77.

📒 Files selected for processing: 27
  • src/main/daemon/daemon-background-transient-facts.test.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter-protocol-compatibility.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-runtime-state.ts
  • src/main/daemon/types.ts
  • src/main/runtime/omp-user-bubble-launch-authority.test.ts
  • src/main/runtime/opencode-finished-session-authority.test.ts
  • src/main/runtime/opencode-run-lifetime-runtime.test.ts
  • src/main/runtime/orca-runtime-agent-prompt-request-correlation.ts
  • src/main/runtime/orca-runtime-provider-reattach-launch-identity.test.ts
  • src/main/runtime/run-terminal-shell-alone.node-pty.test.ts
  • src/main/runtime/run-terminal-shell-alone.ts
  • src/main/runtime/terminal/lifecycle/pty-agent-launch-exit-retirement.ts
  • src/main/runtime/terminal/output/terminal-title-tracker.ts
  • src/main/runtime/terminal/output/terminal-transient-facts.ts
  • src/renderer/src/components/terminal-pane/parked-terminal-byte-watcher.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-command-finished-cleanup.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-command-finished-late-done.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hibernation-kill-shell-foreground.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-process-exit-row-retire.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-unanswered-command-finish.spec.ts
  • src/shared/local-build-compatibility-contract.json
  • src/shared/local-build-compatibility-contract.ts
  • src/shared/terminal-osc133-command-finished.ts
  • src/shared/terminal-osc133-self-closed-zone.test.ts

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

…or a mirror adopted mid-bubble, no longer reads as a finished command

- Raw-byte readers (the daemon's background relay and recovery barrier, main's
  ownership mirror) now treat complete OSC 9999 status frames the way main's
  stripped stream does: not as output, so a B C <status> D;0 bubble close still
  reads as the app's own zone.
- Main's ownership mirror joins the stream mid-flight (snapshot seed, data gap,
  reattach), so it holds an unseen D;0 until the shell's adjacent prompt, like
  the shared scanner. The daemon barrier reads from PTY birth and is unchanged.
- The POSIX exit proof finds the shell under macOS's login wrapper and reads a
  fresh strict process table: a malformed capture proves nothing.

Tracked in STA-11321.
…e, so a bubble whose B C was dropped doesn't end the turn

The daemon keep-tail can drop a hidden pane's oldest output. Main already resets
every other cross-chunk carry on that gap; its OSC 133 scanner kept its old
context, so a D;0 whose B C was in the dropped span read as a finished command.

Tracked in STA-11321.
…ms until the host admits mode writes

Orca told programs that subscribed to mode 2031 about each theme flip from a
client-side check alone. A flip queued while the program withdraws reaches the
shell as typed ?997;Nn (#9993). Real color-scheme queries still get answers;
unsolicited flips return once the host admits mode writes (STA-11321 slice 4).

Tracked in STA-11321.

@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: 39e9073a-e71f-42e1-9b09-b44eba8319d6
📥 Commits

Reviewing files that changed from the base of the PR and between 66e8c77 and e2e39fd.

📒 Files selected for processing: 10
  • src/main/daemon/daemon-background-transient-facts.test.ts
  • src/main/daemon/terminal-shell-lifecycle-scanner-app-zone.test.ts
  • src/main/daemon/terminal-shell-lifecycle-scanner.ts
  • src/main/runtime/pty-shell-ownership-mirror.ts
  • src/main/runtime/run-terminal-shell-alone.test.ts
  • src/main/runtime/run-terminal-shell-alone.ts
  • src/shared/agent-status-osc.ts
  • src/shared/process-table-snapshot-reader.ts
  • src/shared/terminal-osc133-command-finished.ts
  • src/shared/terminal-osc133-self-closed-zone.test.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/main/runtime/run-terminal-shell-alone.ts

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

Comment thread src/shared/agent-status-osc.ts Resolved

@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: 052e7caf-56b2-40f2-8b41-17482c06daf6
📥 Commits

Reviewing files that changed from the base of the PR and between e2e39fd and f706c43.

📒 Files selected for processing: 7
  • src/main/daemon/macos-daemon-launchd.test.ts
  • src/main/runtime/omp-user-bubble-launch-authority.test.ts
  • src/main/runtime/terminal/output/terminal-transient-facts.ts
  • src/renderer/src/components/terminal-pane/pty-connection-foreground-agent-sampling.spec.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.test.ts
  • src/renderer/src/components/terminal-pane/terminal-mode-2031-replies.ts
  • src/shared/terminal-output-side-effects.ts

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

@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: eb6992c2-bb8f-4b54-833f-af675284e97b
📥 Commits

Reviewing files that changed from the base of the PR and between f706c43 and a7876a4.

📒 Files selected for processing: 8
  • src/main/daemon/terminal-shell-lifecycle-scanner.ts
  • src/main/runtime/run-terminal-shell-alone.test.ts
  • src/main/runtime/run-terminal-shell-alone.ts
  • src/main/runtime/terminal/output/pty-output-ingestion.ts
  • src/shared/terminal-osc133-command-finished.ts
  • src/shared/terminal-osc133-self-closed-zone.test.ts
  • src/shared/terminal-output-side-effects.ts
  • src/shared/terminal-status-frame-cursor.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.

brennanb2025 and others added 30 commits October 31, 2026 00:54
covered by a test fed a recorded real macOS login-wrapper tree; live run not possible under test-copy isolation
Resolve both beta.336 xterm patches, pnpm-lock.yaml, daemon transient facts and protocol version, typed agent identity, sleeping record access, and workspace cleanup preflight.

Conflicted files:
- config/patches/@[email protected]
- config/patches/xterm-src/@[email protected]
- pnpm-lock.yaml
- src/main/daemon/daemon-background-transient-facts.test.ts
- src/main/daemon/daemon-protocol-version.ts
- src/renderer/src/components/terminal-pane/pty-connection-typed-agent-identity.spec.ts
- src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
- src/renderer/src/store/slices/workspace-cleanup-agent-stop-preflight.test.ts

Retain protocol 55 foreground observation and previous versions 1-54 with the existing version-51 OSC 133 gate. Preserve host-owned remote agent status and pane-local notification arbitration.

generated beta.336 patch and lock hash pending regeneration with the listener removal
Keep appearance and reconnect reports with the pane reply owner. Restore the native color-scheme listener for standalone terminals and use the matching upstream patch hashes.
Allocate generation 56 and fix unseen-zone support at that introduction boundary. Keep generations 1-55 attached through the legacy raw-stream path, filter their queued completion facts, and align the packaged compatibility contract. Physical foreground observation remains available from generation 55.

The protocol number must be re-checked against main at final merge; if main has consumed it, allocate an unused generation for both the current daemon and the fixed introduction boundary.
Resolve src/main/agent-hooks/server/server-lifecycle.ts and src/shared/electron-remote-runtime-client-capabilities.ts, preserving accepted hook ownership and main plugin delivery.

Move launch-authority shutdown cleanup into src/main/agent-hooks/server/server-authority-state.ts without changing its statements or order.

Validated with node_modules/.bin/lint-staged --diff=MERGE_HEAD --concurrent false under the main-merge hook exception.
Move composed notification delivery cases to the e2e unit project, retaining all assertions and the shared terminal fixture. Supply complete resident identities and use current layout, connection and PTY identity owners in regression fixtures.

Tests only; no production behavior changes.
Carry the existing report payload through immediate pane notification dispatch without publishing a client status row. Keep quiet hydration and main-equivalent first-Done timing, with the source-cut stamp and replay checks intact.
Require live Working before testing delayed completion across a source cut. Keep remote hydration quiet and verify visible and hidden report delivery preserves the host row while retaining pause and reveal coverage.
Keep mirror retirement suppression through retention effects so a returning
row uses its own source observation for session ordering. A current ready
surface may retire an obsolete live row even when its terminal was replaced;
separately retained PTY-end history keeps its existing identity boundary.
Declare the retained and suppression batch records, keep ownership decisions
boolean, and expose the required status patch fields to retraction callers.
Initialize both current state maps in the existing test fixtures.
Use satisfies for the existing partial app state fixture, preserving its
values, test flow and assertions.
Complete the accepted session-tabs state shape in the retirement and title-fanout fixtures. Keep all existing test assertions and production types unchanged.
Keep automatic terminal replies out of command intent and both existing
D-settlement input fences while forwarding them to the PTY. Preserve
unclassified input and acknowledged interrupt handling.

Cover deferred process reads and interrupt inference, driving-input
successors, and carried pre-56 completion through replacement bytes.
Integrate c9845c5.

Resolve agent-pre-ready-typed-draft.test.ts and
pty-connection-spawn-deferred-sleep.test.ts by preserving main's test
pruning and the branch's callback and fixture typing in surviving cases.
No production conflict resolution or protocol behavior change.

Merge validation: node_modules/.bin/lint-staged --diff=MERGE_HEAD --concurrent false.
Replace reflective reads with checked typed member access. Keep all
provenance, retirement, interrupt and successor assertions unchanged.

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.

1 participant