Skip to content

fix(terminal): retire tab icon after confirmed shell return (STA-3867) - #15711

Closed
brennanb2025 wants to merge 2 commits into
mainfrom
brennanb2025/sta-3867-agent-icon-stale
Closed

brennanb2025 wants to merge 2 commits into
mainfrom
brennanb2025/sta-3867-agent-icon-stale

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​331 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​330
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

ELI5

After Codex (or another agent) finishes and you /exit back to a live shell, the tab could still show the agent's icon even though the prompt is back. Orca now treats that leftover sleeping-session identity as stale, and only keeps the agent icon when there is still a real occupant.

What Changed

  • Tab-icon identity no longer treats a leftover sleeping-session record as occupancy when the pane has already returned to a local shell.
  • The confirmed-shell lifecycle now clears that pane-scoped sleeping identity the same way it already cleared titles and launch routing.
  • ksh/dash/fish-style interactive shells stay recognized as shells, so a confirmed return to those prompts retires the same way as zsh/bash.

Why

STA-3867 / #13749: after a launched Codex pane completed and /exited, the process tracker correctly saw a shell, but identity resolution still fell back to the sleeping-session record that owned the same pane. That is the same class of "last occupant wins" bug as launch-routing reuse, not a missing title-change.

Related in-flight work this does not replace:

Linked Issue

Fixes #13749
STA-3867

Visual Proof

N/A — no new chrome. The user-visible effect is the existing terminal tab icon retiring to the shell after /exit. Automated tests pin the live identity ladder, including leftover sleeping occupancy, confirmed-shell clearing, and ksh/dash/fish shell names.

Testing

  • Automated tests added/updated
  • I manually tested these changes locally (live Codex /exit not driven from this worktree)

TDD:

Stage Result
Pre-fix (012e9f410c) FAIL. use-tab-agent-sleeping-session expected a retired icon after /exit with leftover sleeping occupancy (expected 'codex' to be null). Confirmed-shell did not clear the sleeping record. ksh/dash were not treated as shells.
Post-fix PASS. use-tab-agent-sleeping-session.test.ts, tui-agent-startup.test.ts shell names, pty-connection-command-finished-cleanup.test.ts confirmed-shell sleeping clear.
Neutered (sleeping occupancy treated as live again; confirmed-shell clear removed) FAIL, same assertions.

Also: pnpm typecheck passed. oxlint on changed files — clean.

Covered: leftover sleeping occupancy after /exit; confirmed-shell clearing of pane-scoped sleeping identity; ksh/dash/fish recognized as shells; conversation-title keep path from #15665 left intact.

Platforms: identity is process-table + sleeping-record state (macOS / Linux / Windows / SSH identical once the host reports a shell). Folder workspaces use the same tab/leaf model.

Review

  • Security: no new network, credentials, or command execution. Sleeping-record clear is pane-scoped.
  • Cross-platform: shell-name matching is basename-based; Windows .exe stripping already happens in isShellProcess.
  • SSH/remote: confirmed-shell retirement stays local-only (processProvesShell); remote panes still require the existing title/hook evidence and are not inferred from an unconfirmed shell.
  • Agent compatibility: conversation-title keep from fix(sidebar): keep launched agent rows after conversation titles #15665 is unchanged. Explicit title identity still outranks sleeping occupancy.
  • Performance: one extra sleeping-record delete on confirmed shell; no extra process scans.
  • UI: no new controls.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Out of scope (file separately):

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Focused unit tests and pnpm typecheck passed locally.

Author

  • X / Twitter: @BrennanKB5

@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Expanded shell detection for additional shell types and executable paths. Added shared title-based no-agent detection. Updated tab-agent resolution to suppress sleeping-session identity when launched-agent exit evidence and a no-agent title are present. Updated confirmed-shell PTY handling to track foreground-agent evidence and clear sleeping-agent sessions under confirmed conditions. Added tests for shell detection, session cleanup, restore-shell retention, leaked markers, and tab/sidebar indicators.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes directly address issue #13749 by clearing stale sleeping-session identity after confirmed shell return and adding relevant shell coverage.
Out of Scope Changes check ✅ Passed The production changes and tests remain focused on stale tab identity cleanup, shell recognition, and preservation of existing title behavior.
Title check ✅ Passed The title clearly identifies the terminal behavior change: retiring the tab icon after a confirmed shell return.
Description check ✅ Passed The description covers the required sections, linked issue, rationale, testing, visual proof, scope, compatibility, and checklist status.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

Confirmed-shell already cleared titles and launch routing, but identity
resolution still fell back to the pane sleeping-session record, so a
Codex /exit left the previous icon on a live shell tab. Suppress that
sleeping occupancy on the same local exit evidence as launch identity,
clear the pane-scoped sleeping record at the confirmed-shell boundary,
and treat ksh/dash and similar interactive shells as shell foreground.

Fixes #13749
STA-3867
Confirmed-shell /exit still retires leftover occupancy after this PTY
generation hosted the agent. A replacement shell before resume must not
blank the icon or delete the sleeping record.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-3867-agent-icon-stale branch from 353e463 to cd4368b Compare August 21, 2026 03:02

@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: Pro Plus

Run ID: 98373f9c-3c5c-44ba-9a34-845c85a141e1

📥 Commits

Reviewing files that changed from the base of the PR and between 353e463 and cd4368b.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/pty-connection-command-finished-cleanup.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/lib/use-tab-agent-sleeping-session.test.ts
  • src/renderer/src/lib/use-tab-agent.ts

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

// pane sleeping record would keep painting the exited agent on the tab.
// Restore shells must not wipe occupancy or the persisted agent title
// before resume consumes the sleeping record.
state.clearSleepingAgentSession(cacheKey)

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Clear the resolved sleeping record.

getSleepingRecordForPane can return a legacy pane key. Clearing only cacheKey leaves that record available for a later cold restore. Clear the resolved record and its provider-session aliases with clearSleepingRecordProviderDuplicates.

Proposed fix
-        state.clearSleepingAgentSession(cacheKey)
+        const sleepingRecord = getSleepingRecordForPane(state)
+        if (sleepingRecord) {
+          clearSleepingRecordProviderDuplicates(state, sleepingRecord)
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
state.clearSleepingAgentSession(cacheKey)
const sleepingRecord = getSleepingRecordForPane(state)
if (sleepingRecord) {
clearSleepingRecordProviderDuplicates(state, sleepingRecord)
}

@brennanb2025

Copy link
Copy Markdown
Contributor Author

⚠️ Blocking conflict with the sibling PR in this batch

#15711 and #15713 add tests with byte-for-byte identical inputs and opposite expected outputs. They cannot both merge as written.

resolveTabAgentFromSignals({
  hasObservedAgentSignal: true, isRemote: false,
  title: "✳ Codex", hookAgent: null, processAgent: null,
  processShellForeground: true, sleepingSessionAgent: "codex", launchAgent: "codex"
})

Both underlying bugs are real: #15711/STA-3867 fixes a stale agent icon after /exit; #15713/STA-4130 keeps pane identity during a hibernation restore where the shell spawns before the agent relaunches.

No discriminator exists at this layer. The inputs are identical, so the resolver cannot separate "agent exited to shell" from "restore in flight". Narrowing #15711's guard from launchedAgentExited || processProvesShell to just launchedAgentExited fixes 2 of #15713's 3 new tests but not this one, because resolveLaunchedAgentExitEvidence itself treats local shell-foreground + observed-signal as exit evidence.

Fixing both needs new provenance — an explicit "restore in flight" signal, or a generation/timestamp marking the sleeping record as freshly re-seeded rather than left over.

Additionally, #15713 moves resolveTabAgentFromSignals into a new tab-agent-from-signals.ts, and that module carries the pre-#15711 unguarded precedence chain. Merging the two conflicts on use-tab-agent.ts. I verified the safety net holds — naive-resolving to #15713's side fails 6 of #15711's tests rather than reverting silently — but the resolver must carry the activeSleepingSessionAgent guard across, after which the contradiction above surfaces.

This is a product decision, not a merge mechanic.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual proof — tab-icon retirement after confirmed shell return (STA-3867)

Captured with Playwright CDP against this worktree's Orca dev build (Orca: brennanb2025/review-15711-sta-3867, devRepoRoot=/Users/brennanbenson/orca/workspaces/orca/review-15711). Live Codex /exit was not driven; leftover vs hibernated occupancy was applied through window.__store on real terminal tabs in the tab strip.

1. Before — launched agent pane still shows the Codex tab icon

01-before-live-codex-icon.png

Leftmost tab is titled Codex with launchAgent/processAgent = Codex (shellForeground: false); the tab leading icon is the Codex glyph, not the generic terminal.

2. After /exit leftover — icon retires to the generic terminal

02-after-exit-icon-retired.png

The same pane is now titled zsh with a leftover sleeping-session record (agent: codex) and processShellForeground: true. The tab icon has retired to the generic terminal glyph, proving leftover sleeping occupancy does not keep the agent icon after confirmed shell return.

3. Hibernated pane — agent icon remains

03-hibernated-agent-icon-remains.png

The second tab is a genuine hibernated Codex pane: sleeping-session record present, no processShellForeground, frozen conversation title (Run the shell command sleep 30…). Its tab icon stays the Codex glyph, sitting next to the retired zsh tab so the two occupancy cases can be compared in one strip.

Local screenshot paths (not committed): /tmp/orca-pr15711-proof/01-before-live-codex-icon.png, /tmp/orca-pr15711-proof/02-after-exit-icon-retired.png, /tmp/orca-pr15711-proof/03-hibernated-agent-icon-remains.png.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status (STA-3867 / #13749)

Rebased onto current main (df7460af41) and pushed. CI green checks against the previous base are stale; the known-red e2e / ssh docker watcher isolation (and e2e 1/4/7-of-10) fail on main itself and are not this PR.

What landed

The original fix still retires leftover tab-agent occupancy after a confirmed local /exit:

  • Sleeping occupancy is no longer treated as a live occupant once exit evidence includes a shell-named title.
  • Confirmed-shell (OSC 133;D + foreground confirm) clears the pane sleeping record only if this PTY generation actually published a foreground agent and the PTY is not in a hibernation/suppressed-exit kill.
  • SHELL_NAMES now includes ksh|mksh|dash|ash|tcsh|csh|elvish|xonsh (basename + Windows extension strip unchanged).

Follow-up commit cd4368b164 (fix(terminal): keep sleeping occupancy through restore-from-sleep shell) was required: the first version also treated processProvesShell as occupancy loss and always deleted the sleeping record on confirmed-shell. That would blank the icon (and could drop the resume record) in the restore-from-sleep window where a replacement shell is foreground before the agent relaunches. Standing hibernation (dead PTY, no processShellForeground) was already safe; the restore window was the hole.

Hibernation / restore

State Icon
Genuinely hibernated (no live process, sleeping record, frozen title) Agent icon kept
Restore shell before resume, no agent published on this PTY generation Occupancy kept; record not deleted
Real /exit after this generation hosted the agent, then confirmed shell Record cleared; icon retires
Leaked 133;D while confirm still shows the agent Record kept

Sibling PR #15658

Both PRs widen SHELL_NAMES identically. git merge-tree auto-merges src/shared/shell-process-detection.ts (this PR additionally moves titleShowsNoAgent into that file; #15658 consumes isShellProcess for nested-shell launch-authority). No semantic conflict. Land either first; rebase the later one so the lists cannot drift. Nested-shell false-confirm stays #15658's domain.

Checks

  • Readiness (start + end): PASS WITH RISK, zero candidate P0/P1 (counsel skipped).
  • Focused vitest (tab-agent, confirmed-shell cleanup, tracker, tui-agent-startup, hibernation/cold-restore related): pass.
  • Not this PR: known-red e2e on main.
  • Residual (not blocking): a restore shell that OSC-titles the tab to a shell name can briefly blank the icon (record stays); /exit that never published a foreground agent on this generation still needs a shell-named title to retire in the resolver.

Visual proof

Store-driven Electron CDP shots of the real tab strip are on this comment: launched Codex icon, leftover /exit retirement with a sleeping record still present, and a genuine hibernated pane keeping the Codex icon. Live hosted Codex /exit was not driven.

Merge bar: no revert. Ready to merge once CI on the rebased head is green (ignore the known-red e2e jobs that already fail on main).

@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded by merged PR #21714, which addresses the same stale agent identity after shell exit and overlaps the identity/cleanup paths changed here. Linked issue #13749 is completed.

@nwparker nwparker closed this Sep 27, 2026
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

2 participants