Skip to content

Clear stale agent identity when a pane is reused (codex vs claude) - #6543

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/issue-6355-agent-identity-stale
Jun 29, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/issue-6355-agent-identity-stale

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Fixes #6355

Root cause

When a terminal pane is reused for a different agent (e.g. a pane Orca launched as codex later runs claude), the tab's launchAgent becomes stale. resolveTabAgentFromSignals (src/renderer/src/lib/use-tab-agent.ts) had two problems that let that stale identity win:

  1. Title ignored while launchAgent is set — titleAgent was computed as launchAgent ? null : agentFromTabTitle(title), so a live terminal title that explicitly names a different agent never contributed.
  2. Stale launch ranked over the live title — the fallback chain returned 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

  • New module src/renderer/src/lib/terminal-title-agent-type.ts extracts the title→TuiAgent mapping and resolveExplicitTerminalTitleAgentType (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 from launchAgent overrides the stale launch identity, and titleAgent now ranks ahead of activeLaunchAgent/fallback hooks. Before any activity, titleAgent stays null while launchAgent exists, so launch bootstrap still wins the startup window.
  • dispatchTerminalNotification: a fresh stored snapshot is only reused when its agentType matches the title's explicit agent, so notifications no longer leak the previous agent's identity/prompt after pane reuse.
  • Re-implements the approach of community PR fix: clear stale Codex branding when a pane is reused by another agent #6474 with an added control test and a dedicated unit test for the new module.

Touches: use-tab-agent.ts, new terminal-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:

$ pnpm vitest run --config config/vitest.config.ts \
    src/renderer/src/lib/use-tab-agent.test.ts \
    src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts
 × keeps title fallback for real Gemini, MiMo, and Pi titles
 × lets an explicit title override stale launch identity after the pane shows newer activity
 × does not reuse a fresh stale agent snapshot when the terminal title names another agent
 × does not reuse an untyped fresh agent snapshot when the terminal title names an agent
 Test Files  2 failed (2)
      Tests  4 failed | 54 passed (58)

All tests pass after the fix (includes the new terminal-title-agent-type.test.ts):

$ pnpm vitest run --config config/vitest.config.ts \
    src/renderer/src/lib/use-tab-agent.test.ts \
    src/renderer/src/lib/terminal-title-agent-type.test.ts \
    src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts
 Test Files  3 passed (3)
      Tests  62 passed (62)

Lint clean on changed files:

$ npx oxlint <changed files>
OXLINT_EXIT=0
$ npx oxlint --config config/oxlint-react-doctor.json <changed source files>
REACT_DOCTOR_EXIT=0

Typecheck clean:

$ pnpm typecheck
> tsgo --noEmit -p config/tsconfig.node.json && tsgo --noEmit -p config/tsconfig.tc.cli.json && tsgo --noEmit -p config/tsconfig.tc.web.json
TYPECHECK_EXIT=0

UI before/after

  • Before: a pane launched as Codex but now running Claude keeps the Codex tab icon, and a Claude completion fires an OS notification labeled Codex (with Codex's last message).
  • After: once the reused pane shows activity and its title explicitly names Claude, the tab icon switches to Claude and the notification carries the correct agent type/message.

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
@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bcb36d72-0cc0-4d23-876b-078a1a12b1ff

📥 Commits

Reviewing files that changed from the base of the PR and between f7bab23 and cfeb067.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts
  • src/renderer/src/components/terminal-pane/use-notification-dispatch.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts
  • src/renderer/src/components/terminal-pane/use-notification-dispatch.ts

📝 Walkthrough

Walkthrough

A new module, terminal-title-agent-type.ts, adds resolveExplicitTerminalTitleAgentType for mapping terminal titles to TuiAgent ids while ignoring generic Claude activity-style titles. use-tab-agent.ts now uses this resolver to rank explicit title identity above activeLaunchAgent in some paths and to override stale launch identity after agent activity is observed. use-notification-dispatch.ts now requires stored agent snapshots to match the explicit title agent type before reusing them for agent-task-complete notifications. Tests were added and updated for the resolver, tab-agent precedence, and notification dispatch behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and fix, but it does not follow the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite the description to match the repository template and include all required sections, even if some are marked as no visual change or no additional notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: stale agent identity in reused panes, with Codex versus Claude as the key example.
Linked Issues check ✅ Passed The changes address #6355 by making explicit terminal titles override stale launch metadata and by fixing notification reuse so the current agent is shown.
Out of Scope Changes check ✅ Passed The added title-parsing module, MiMo Code mapping, and regression tests support the stated stale-identity fix and do not appear unrelated.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch brennanb2025/issue-6355-agent-identity-stale

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.

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
@brennanb2025

Copy link
Copy Markdown
Contributor Author

CI fix: the verify job (full suite on Linux) was red on the sibling test dispatches agent-task-complete on working→idle and raises tab/worktree unread in pty-connection.test.ts — not in the per-file affected run.

Root cause: that test's fixture paired a stored codex snapshot with a live '* Claude done' (explicit-Claude) completion title. The new stale-identity guard in dispatchTerminalNotification correctly drops a snapshot whose agentType doesn't match the explicit title agent, so the rich notification no longer carried codex's prompt/tool fields — exactly the pane-reuse leak #6355 fixes. The completion still fires and still raises tab/worktree/pane unread (those assertions pass); only the stale agent-identity assertion was wrong.

Fix: made the fixture self-consistent (snapshot agentType: 'claude' to match the '* Claude done' title) so the test keeps verifying that the rich snapshot flows through on working→idle. The discard path is covered separately in use-notification-dispatch.test.ts. No production code changed; completion dispatch behavior is unchanged.

Verified: failing test now green; full terminal-pane directory (1176 tests) + the touched lib/shared agent suites all pass; lint + web typecheck clean. Platform-independent change (string-literal fixture only).

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

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 lift

Remote reused panes still stick to the stale launch agent.

titleOverridesLaunch only activates after hasObservedAgentSignal flips, but this effect ignores explicit title signals whenever tab.launchAgent is set. Because the foreground probe exits for remote-like panes (Lines 194-196), a reused remote pane launched as codex and later titled ✳ Claude Code never 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

📥 Commits

Reviewing files that changed from the base of the PR and between bed5060 and f7bab23.

📒 Files selected for processing (7)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/use-notification-dispatch.test.ts
  • src/renderer/src/components/terminal-pane/use-notification-dispatch.ts
  • src/renderer/src/lib/terminal-title-agent-type.test.ts
  • src/renderer/src/lib/terminal-title-agent-type.ts
  • src/renderer/src/lib/use-tab-agent.test.ts
  • src/renderer/src/lib/use-tab-agent.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

🧒 ELI5 — for your merge decision

After 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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

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
@brennanb2025
brennanb2025 merged commit de00bd9 into main Jun 29, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/issue-6355-agent-identity-stale branch June 29, 2026 08:40
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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]: Thinks my project is running codex but it is claude?

2 participants