Repository navigation
Clear stale agent identity when a pane is reused (codex vs claude) - #6543
Conversation
When a terminal pane is reused for a different agent, its launchAgent goes stale. resolveTabAgentFromSignals ignored the terminal title while launchAgent was set and ranked the stale launch ahead of the live title, so the tab icon and notifications kept showing the previous agent (e.g. codex when claude is now running). Extract the title->agent mapping into terminal-title-agent-type.ts and let a live, explicit title override a stale launchAgent once the pane has shown activity. Apply the same guard to notification dispatch so a stored snapshot from a different agent is not reused for the rich notification. Also add the missing MiMo Code title mapping. Fixes #6355
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughA new module, 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
⚔️ Resolve 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. Comment |
The working->idle completion test paired a stored codex snapshot with a live '* Claude done' title. After the stale-identity guard, an explicit Claude title correctly drops a mismatched codex snapshot, so the rich notification no longer carried codex's prompt/tool fields. Make the fixture self-consistent (snapshot agentType: 'claude') so the test still verifies the rich completion snapshot flows through on working->idle, matching the corrected dispatch behavior. The discard path is covered separately in use-notification-dispatch.test.ts. Refs #6355
|
CI fix: the Root cause: that test's fixture paired a stored Fix: made the fixture self-consistent (snapshot Verified: failing test now green; full |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/lib/use-tab-agent.ts (1)
182-191: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftRemote reused panes still stick to the stale launch agent.
titleOverridesLaunchonly activates afterhasObservedAgentSignalflips, but this effect ignores explicit title signals whenevertab.launchAgentis set. Because the foreground probe exits for remote-like panes (Lines 194-196), a reused remote pane launched ascodexand later titled✳ Claude Codenever reaches the override path until some hook/completion arrives, so the stale identity survives in the title-only case this PR is trying to fix.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: efee9c96-b04c-40c0-b1e7-c8823941a9ec
📒 Files selected for processing (7)
src/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/use-notification-dispatch.test.tssrc/renderer/src/components/terminal-pane/use-notification-dispatch.tssrc/renderer/src/lib/terminal-title-agent-type.test.tssrc/renderer/src/lib/terminal-title-agent-type.tssrc/renderer/src/lib/use-tab-agent.test.tssrc/renderer/src/lib/use-tab-agent.ts
🧒 ELI5 — for your merge decisionAfter reusing a terminal pane for a different agent, Orca sometimes kept showing the old agent's identity — e.g. labeling a Claude session as "codex" on the tab icon and in notifications. This PR lets the live terminal title correctly override a stale launch identity so the right agent is shown. What you'll notice: The tab icon and notifications show the agent that's actually running, even after a pane is reused for a different agent. Behavior change Behavior change is the fix: a live title signal now wins over a stale launch identity. Provider/OS-agnostic (just title-string parsing). No setting, no user action. (Minor pre-existing note: a parallel label map elsewhere still lacks one agent's entry — out of scope.) Merge risk: low Auto-generated summary to aid review. Reproduction + lint/typecheck/test evidence is in the PR body / checks. This PR was produced and independently reviewed by an automated bug-bash; please verify before merging. |
|
Reviewed and added one maintainer hardening commit so explicit completion snapshots are filtered by the same live-title identity guard as stored snapshots. Local validation: focused tab-agent/notification/pty tests passed and pnpm typecheck passed. |
# Conflicts: # src/renderer/src/lib/use-tab-agent.ts
…tablyai#6543) * Clear stale agent identity when a pane is reused (codex vs claude) When a terminal pane is reused for a different agent, its launchAgent goes stale. resolveTabAgentFromSignals ignored the terminal title while launchAgent was set and ranked the stale launch ahead of the live title, so the tab icon and notifications kept showing the previous agent (e.g. codex when claude is now running). Extract the title->agent mapping into terminal-title-agent-type.ts and let a live, explicit title override a stale launchAgent once the pane has shown activity. Apply the same guard to notification dispatch so a stored snapshot from a different agent is not reused for the rich notification. Also add the missing MiMo Code title mapping. Fixes stablyai#6355 * test(terminal-pane): align completion fixture with live agent identity The working->idle completion test paired a stored codex snapshot with a live '* Claude done' title. After the stale-identity guard, an explicit Claude title correctly drops a mismatched codex snapshot, so the rich notification no longer carried codex's prompt/tool fields. Make the fixture self-consistent (snapshot agentType: 'claude') so the test still verifies the rich completion snapshot flows through on working->idle, matching the corrected dispatch behavior. The discard path is covered separately in use-notification-dispatch.test.ts. Refs stablyai#6355 * Harden agent notification snapshot identity guard --------- Co-authored-by: brennanb2025 <[email protected]> Co-authored-by: Neil <[email protected]>
Fixes #6355
Root cause
When a terminal pane is reused for a different agent (e.g. a pane Orca launched as
codexlater runsclaude), the tab'slaunchAgentbecomes stale.resolveTabAgentFromSignals(src/renderer/src/lib/use-tab-agent.ts) had two problems that let that stale identity win:launchAgentis set —titleAgentwas computed aslaunchAgent ? null : agentFromTabTitle(title), so a live terminal title that explicitly names a different agent never contributed.focusedHookAgent ?? activeLaunchAgent ?? fallbackHookAgent ?? titleAgent, putting the stale launch ahead of the title.The same stale-snapshot reuse affected notifications:
dispatchTerminalNotification(use-notification-dispatch.ts) reused any fresh stored agent snapshot for the rich notification, even when the completion title named a different agent — so the notification showed the previous agent's type and last message.Change summary
src/renderer/src/lib/terminal-title-agent-type.tsextracts the title→TuiAgentmapping andresolveExplicitTerminalTitleAgentType(Claude's bare spinner/✳/./*prefixes stay activity-only, never identity). Also adds the missing MiMo Code mapping.resolveTabAgentFromSignals: once the pane has shown activity (hasObservedAgentSignal), a live title that explicitly names an agent different fromlaunchAgentoverrides the stale launch identity, andtitleAgentnow ranks ahead ofactiveLaunchAgent/fallback hooks. Before any activity,titleAgentstaysnullwhilelaunchAgentexists, so launch bootstrap still wins the startup window.dispatchTerminalNotification: a fresh stored snapshot is only reused when itsagentTypematches the title's explicit agent, so notifications no longer leak the previous agent's identity/prompt after pane reuse.Touches:
use-tab-agent.ts, newterminal-title-agent-type.ts,use-notification-dispatch.ts(+ tests). Provider-agnostic and platform-agnostic (no GitHub/OS-specific assumptions).Evidence
New regression tests fail before the fix:
All tests pass after the fix (includes the new
terminal-title-agent-type.test.ts):Lint clean on changed files:
Typecheck clean:
UI before/after