Skip to content

fix(terminal): clear stale agent identity after shell exit - #21714

Merged
nwparker merged 2 commits into
mainfrom
fix/13749-stale-agent-icon
Sep 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
fix/13749-stale-agent-icon

Conversation

@nwparker

@nwparker nwparker commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​138 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​128
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

Fixes #13749.

ELI5

After /exit, the terminal had returned to a shell, but Orca could still remember the old Pi/OMP session for that pane and redraw its agent icon. Orca now clears that stale sleeping identity only after local shell evidence confirms the agent is gone.

What changed

  • Clear the pane's sleeping agent record when the foreground process is confirmed as a local shell.
  • Suppress stale sleeping identity during local shell/exit resolution.
  • Recognize additional POSIX shells (ksh, dash, ash, tcsh, and others).
  • Preserve sleeping identity for remote panes and inconclusive process scans.

Proof

  • Focused renderer/identity suite: 52 tests passed.
  • Web typecheck passed.
  • Changed-code quality passed with 0 new findings.
  • Oxlint, React Doctor, formatting, and pre-commit checks passed.
  • Regression coverage includes confirmed shell cleanup, leaked-agent retention, local-vs-remote resolver behavior, and pane sibling safety.

No visual proof applies: the fix changes pane identity state after a terminal lifecycle event; the regression covers the rendered identity source directly.

Readiness checklist

  • Functional correctness: stale local /exit identity is retired; active or inconclusive sessions are retained.
  • Crash/retry/resource safety: cleanup uses the existing scoped sleeping-record/provider-duplicate helper and does not add timers or polling.
  • Cross-platform: shell detection covers POSIX and Windows shell names; remote panes keep their existing semantics.
  • Compatibility: no persisted schema, IPC, RPC, or mobile-facing surface changes.
  • User-facing trade-offs: a completed agent icon no longer reappears after the pane is back at a shell; active agents are not hidden by an unconfirmed scan.
  • Merge risk: low.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3c6acfa5-5192-4f45-8f58-3f9fbed93886

📥 Commits

Reviewing files that changed from the base of the PR and between f90e103 and 859675e.

📒 Files selected for processing (1)
  • src/renderer/src/lib/tab-agent-identity-decision-table.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The change expands shell-process detection and shares titleShowsNoAgent across modules. Tab agent resolution now suppresses stale sleeping-session identity when exit or shell evidence confirms a local shell. The confirmed-shell path clears pane sleeping occupancy before resetting agent state. Tests cover additional shell names, local and remote resolution, decision-table counts, and command-finished cleanup or retention.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: clearing stale agent identity after a shell exit.
Description check ✅ Passed The description is mostly complete. It explains the user impact, implementation, rationale, linked issue, testing, compatibility, and visual-proof rationale. Some template headings and checklist items…
Linked Issues check ✅ Passed Issue #13749 requires the terminal icon after the pane returns to a confirmed local shell. The PR clears the pane sleeping identity at onConfirmedShellForeground and suppresses stale sleeping identi…
Out of Scope Changes check ✅ Passed The changes stay within Issue #13749. Sleeping-session cleanup, stale-identity suppression, shell detection, title handling, decision-table updates, and regression tests support reliable detection of …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

Important

The pinned decision-table test now fails on this branch, and the resolver-level suppression lands in the palette resolver rather than the tab-bar one. Details below.

Reviewed changes

Reviewed the complete diff at f90e103 (7 files, 1 commit) against main.

  • Confirmed shell retires the pane's sleeping record — onConfirmedShellForeground clears the pane's sleeping session and provider-session duplicates before the existing title/routing cleanup.
  • Ladder suppresses the sleeping rung on exit evidence — resolveTabAgentFromSignals in tab-agent-from-signals.ts gates sleeping on launchedAgentExited || processProvesShell.
  • titleShowsNoAgent moved to shared — extracted into shared/shell-process-detection.ts and re-exported from shared/agent-detection.ts.
  • Wider shell recognition — ksh, mksh, dash, ash, tcsh, csh, elvish, xonsh added to SHELL_NAMES.
  • Tests — confirmed-shell cleanup tests in pty-connection-command-finished-cleanup.test.ts; ladder tests in use-tab-agent-sleeping-session.test.ts.

️ Pinned decision table is stale and now red

src/renderer/src/lib/tab-agent-identity-decision-table.test.ts:138 fails on this branch. I confirmed it passes against 97763ed's resolver and fails with the new sleeping gate: disagreements 2,622 → 2,634, launch 1,884 → 1,890, completed-hook 478 → 480, sleeping-session 144 → 148. Both the proofFree and freshProof expectations (lines 138 and 150) plus the "Re-derived against…" comment need re-deriving.

Technical details
# Decision-table expectations are pinned to the pre-fix ladder

## Affected sites
- `src/renderer/src/lib/tab-agent-identity-decision-table.test.ts:138` — `proofFree` `toEqual` (2,622) no longer matches.
- `src/renderer/src/lib/tab-agent-identity-decision-table.test.ts:150` — `freshProof` `toEqual` also exercises the changed ladder and must be re-derived.
- `src/renderer/src/lib/tab-agent-from-signals.ts:155` — the gate that shifted the counts.

## Required outcome
- Update both pinned expectation objects (and the explanatory comment above them) to the values the current ladder produces, so the ratchet reflects the intended behavior change.

## Suggested approach (optional)
- Run `pnpm test src/renderer/src/lib/tab-agent-identity-decision-table.test.ts`; the assertion prints the received object, or read the JSON it writes to `orca-pane-agent-identity-decision-table-real.json` in the tmp dir.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +155 to +156
const activeSleepingSessionAgent =
launchedAgentExited || processProvesShell ? null : sleepingSessionAgent

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.

resolveTabAgentFromSignals here is only reached by open-tab-occupant-agent.ts (the command palette); the tab-bar icon renders through useTabAgent in use-tab-agent.ts, which keeps its own copy of this ladder with no sleeping gate. For this exact input (title: 'zsh', processShellForeground: true, sleepingSessionAgent: 'codex') that resolver still returns 'codex' where this one returns null, so the new tests and the shared titleShowsNoAgent extraction cover a resolver the icon does not use.

Technical details
# Sleeping suppression does not reach the tab-bar resolver

## Affected sites
- `src/renderer/src/lib/tab-agent-from-signals.ts:155` — new `activeSleepingSessionAgent` gate (this comment).
- `src/renderer/src/lib/use-tab-agent.ts:160-169` — `useTabAgent`'s private resolver keeps `sleepingSessionAgent ??` ahead of `activeLaunchAgent`, with no `launchedAgentExited || processProvesShell` gate.
- `src/renderer/src/lib/use-tab-agent.ts:25-29` — still defines a private `titleShowsNoAgent` rather than importing the newly shared one.
- `src/renderer/src/lib/use-tab-agent-sleeping-session.test.ts:115-153` — new assertions import `./tab-agent-from-signals`, not `useTabAgent`.

## Required outcome
- Decide whether the tab-bar icon is meant to get the ladder-level suppression. If yes, apply the gate in `use-tab-agent.ts` (or collapse the duplicate ladders) and point the new tests at `useTabAgent`; if the store clear in `pane-agent-identity.ts` is the only intended fix for the icon, say so and retitle the tests so they no longer imply tab-icon coverage.

## Suggested approach (optional)
- `useTabAgent` already gathers every input the shared resolver needs, so delegating its final call to the shared resolver would remove one of the two divergent ladders instead of adding the gate a third time. Note the two ladders differ today (`resolvePaneAgentOwner` vs `resolvePaneAgentOwnerRecord`, and owner-normalized vs launch-normalized signals), so this needs its own before/after check.

@nwparker

Copy link
Copy Markdown
Contributor Author

CI found the existing renderer decision-table contract also changes when stale sleeping identity is correctly suppressed. Updated expected proof-free totals to 2,634 disagreements (launch 1,890; completed-hook 480; sleeping-session 148) and fresh-proof totals to 670 (launch 594; completed-hook 48; sleeping-session 4). The decision-table test passes locally (2/2); this is a test-contract update for the intended resolver behavior, not a production workaround.

@nwparker
nwparker merged commit b6b974c into main Sep 19, 2026
35 checks passed
@nwparker
nwparker deleted the fix/13749-stale-agent-icon branch September 19, 2026 19:10
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.

[Bug]: Completed agent icon remains after the pane returns to shell

1 participant