Skip to content

Unify tab agent identity with the agent-status pipeline - #7059

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/codex-icon-running-agent
Jul 4, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/codex-icon-running-agent

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tab-bar agent icons now resolve identity through the same already-computed state as the sidebar agent rows — hook status entries, explicit titles, and launch bootstrap — instead of running their own foreground-process probe. One pipeline drives both surfaces, so the tab icon and the WorktreeCard rows can no longer disagree about which agent a pane is running.

This replaces the earlier foreground-probe approach on this branch per review direction: the agent-status state is already kept correct (live hook rows are dropped by the OSC 133 command-finished machinery on crash/kill/Ctrl+C exits), so identity should reuse it rather than maintain a parallel probing pipeline.

What changed

  • useTabAgent no longer calls getForegroundProcess (no reads, no retry timers). Identity resolution is now: focused-pane hook agent → explicit title (with the existing stale-launch override) → launch bootstrap → sibling/completed hook fallback — the same evidence the sidebar rows derive from.
  • The probe's one unique local job — clearing stale launchAgent identity after the launched agent exits — is replaced with probe-free evidence, expressed as a single shared predicate (resolveLaunchedAgentExitEvidence) used by both the resolver and the clear effect: the title shows no agent (a shell name, or the tab's neutral default title — the inferred-interrupt reset target), no live hook row remains anywhere in the tab, and either the hook completed or previously observed activity vanished (the crash/kill path, where OSC 133;D removes the entry without a completed hook).
  • Local panes now clear launch identity on completed-hook + no-agent-title evidence, matching the rule remote panes already used. Remote-specific behavior is preserved by construction: the vanished-activity disjunct is explicitly local-only (remote hook rows also drop on transport blips — reconnects, snapshot gaps — that say nothing about the process), and remote title-trust (keeping completed hook identity at a shell title) is unchanged.
  • Stale doc comments describing the probe as the primary signal were updated (tab-agent.ts, SortableTab.tsx), and the never-consumed composed wrappers (resolveTabAgent, hasCompletedTabAgent, resolveCompletedTabAgent) were removed — useTabAgent composes the focused/sibling resolvers directly.

Hardening (review round)

A review pass on the first cut of this rework found races and scope bugs in the clear rule; all fixed in 1f8219c:

  • Remote gate: the vanished-activity clear no longer applies to remote/SSH/runtime panes — without it, a relay reconnect plus a lagging shell title permanently cleared launch identity for a live remote agent (and paired-web mirrors churned against host snapshots re-applying launchAgent).
  • Split tabs: pane-scoped evidence can no longer clear the tab-scoped launchAgent while an agent is still running — clears require no live hook row anywhere in the tab, and a layout-less multi-pane tab no longer treats a sibling's done row as focused-pane exit evidence.
  • Generation race: the observed-activity signal resets and re-seeds in one effect keyed on the pane generation, and the clear effect reads the generation-safe ref — a focus switch or respawn that lands the new PTY, the dropped row, and a shell title in one commit no longer clears on the previous generation's stale signal (and a still-live row re-seeds the signal instead of leaving it stuck false).
  • Neutral titles: the tab's defaultTitle ("Terminal N") counts as exit evidence alongside shell names — Orca's inferred-interrupt flow parks titles there, and previously the stale agent icon survived indefinitely on that path.
  • Hookless launched agents: a title naming the launched agent now counts as its observed activity, so title-emitting agents without hook integration (Gemini-class) clear their launch icon when the title returns to a shell instead of staying stale forever.

Live verification (dev instance, this branch @ 3b925bd)

Exercised end-to-end in a real Electron dev build with the store instrumented and the tab bar inspected (data-agent-icon):

  • Hookless manual launch: a compiled binary named aider (no hooks, no titles) run by hand → tab icon flipped to aider via the process tracker; Ctrl+C → OSC 133;D published shell-foreground with no RPC → icon reverted.
  • Launch bootstrap + hookless launched exit: tab created with launchAgent: 'aider' showed the icon instantly pre-start; after the process ran and was interrupted, clearTabLaunchAgent fired via process-grade evidence and the clear persisted across an app reload.
  • Real Claude Code turn: working → done hook states observed live with correct pane attribution; tab icon, sidebar WorktreeCard indicator (orange Claude dot), and Agent Session History all agreed; clean /exit published shell-foreground and cleared the icon.
  • Two gaps found live and fixed in 3b925bd: (1) a TUI dying with a stuck agent title kept its icon through the title-fallback layer even though the pane was provably at the shell — shell-foreground proof now suppresses title-derived identity and the local completed-hook fallback (remote panes unaffected); (2) the daemon's wrapper→agent ancestry resolution took >1.5s for the real node-wrapped claude, so the tracker's bounded ladder gets a second re-read at 3.5s.

Behavior trades (accepted with this direction)

  • Agents that never emit hooks and never set a title resolve no identity signals at all; their launch icon persists until the pane produces evidence. The probe previously recovered their identity from the process table. Addressed by the stacked follow-up Restore process-table agent identity via OSC 133-triggered foreground reads #7189, which restores process-table identity as a store-level producer (OSC 133-triggered reads) instead of a parallel probe pipeline.
  • A done-but-still-open agent whose title reads as a shell (or the neutral default) shows no tab icon and has its launch identity cleared — the sidebar's retained "done" row still shows it. done is turn-scoped, so title-less hook agents idle at a shell-reading title blank between turns; this matches the existing remote-pane behavior and is inherent to probe-free evidence.

Checks

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/use-tab-agent.test.ts src/renderer/src/lib/tab-agent.test.ts src/renderer/src/components/sidebar/useWorktreeAgentRows.test.ts src/renderer/src/components/sidebar/WorktreeCardAgents.test.tsx — 107 tests passed
  • Regression pins: useTabAgent never calls getForegroundProcess; row-drop clears at a shell title (local only — remote pinned to not clear); live focused or sibling rows block clearing; neutral-default-title exit; hookless same-agent-title exit; layout-less multi-pane completed rows don't clear; the one-commit generation switch doesn't clear.
  • pnpm run typecheck — passed
  • pnpm run lint — passed
  • git diff --check — passed

Notes

The previous foreground-probe implementation (including its review fixes) is preserved on the local branch backup/7059-foreground-probe-approach. One orthogonal piece of it may be worth its own PR later: the terminal protocol auto-reply filter that stops xterm.js query replies (DA/DSR/CPR/OSC color/DCS) from counting as user input for hibernation idle tracking.

Known follow-ups (pre-existing, out of scope here): the tab and sidebar title→agent maps have drifted (MiMo Code exists only in shared/terminal-title-agent-type.ts) and tab-agent.ts maps entry.agentType without the sidebar's compatible-owner normalization, so the two surfaces can still disagree for Pi-compatible harnesses; SHELL_NAMES in shared/shell-process-detection.ts accidentally contains the empty string (leading-| split) — neutralized here by the blank-title guard, but worth fixing at the source.

@ghost

ghost commented Jul 2, 2026 •

Copy link
Copy Markdown

@brennanb2025
brennanb2025 force-pushed the brennanb2025/codex-icon-running-agent branch from 16987e9 to 31c5e6a Compare July 2, 2026 02:23
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review 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
📝 Walkthrough

Walkthrough

Changes

This change adds pane-scoped foreground agent state to the terminal store and updates cleanup paths to remove it. It introduces foreground signal extraction and resolution helpers, a worktree foreground sync hook, and tab-agent foreground caching. Sidebar row building now consumes foreground identity through new selector and row-builder helpers, and the review notes menu now disables foreground syncing when reading worktree rows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it omits the required Screenshots, AI Review Report, and Security Audit sections from the repository template. Add the missing template sections, including No visual change if applicable, a concise AI review report, and a basic security audit summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly reflects the main change: aligning tab agent identity with the shared agent-status pipeline.

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.

@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: 2

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/store/slices/terminals.ts (1)

1847-2051: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

shutdownCompletedAgentPaneForHibernation never clears foregroundAgentByPaneKey[opts.paneKey].

This function hibernates a single completed-agent pane and explicitly clears the pane's other per-pane ephemeral state — unreadTerminalPanes, unreadAgentCompletionPanes, and lastTerminalInputAtByPaneKey (Lines 2013–2018, 2035–2037) — but omits foregroundAgentByPaneKey, even though the underlying PTY for this pane is being killed/stopped here just like in closeTab and shutdownWorktreeTerminals, both of which do sweep this map. This leaves a stale foreground-agent entry for a dead pane in the "ephemeral, non-persistent" cache the PR describes, contradicting the stated design goal of clearing foreground entries through all lifecycle/cleanup paths.

🐛 Proposed fix
       const nextUnreadTerminalPanes = { ...s.unreadTerminalPanes }
       const nextUnreadAgentCompletionPanes = { ...s.unreadAgentCompletionPanes }
       const nextLastTerminalInputAtByPaneKey = { ...s.lastTerminalInputAtByPaneKey }
+      const nextForegroundAgentByPaneKey = { ...s.foregroundAgentByPaneKey }
       delete nextUnreadTerminalPanes[opts.paneKey]
       delete nextUnreadAgentCompletionPanes[opts.paneKey]
       delete nextLastTerminalInputAtByPaneKey[opts.paneKey]
+      delete nextForegroundAgentByPaneKey[opts.paneKey]

       return {
         tabsByWorktree: nextTabsByWorktree,
         ptyIdsByTabId: {
           ...s.ptyIdsByTabId,
           [opts.tabId]: remainingPtyIds
         },
         lastKnownRelayPtyIdByTabId: nextLastKnownRelay,
         suppressedPtyExitIds: {
           ...s.suppressedPtyExitIds,
           ...Object.fromEntries(shutdownPtyIds.map((ptyId) => [ptyId, true] as const))
         },
         codexRestartNoticeByPtyId: nextCodexRestartNoticeByPtyId,
         ...(nextRuntimePaneTitlesByTabId !== s.runtimePaneTitlesByTabId
           ? { runtimePaneTitlesByTabId: nextRuntimePaneTitlesByTabId }
           : {}),
         unreadTerminalPanes: nextUnreadTerminalPanes,
         unreadAgentCompletionPanes: nextUnreadAgentCompletionPanes,
-        lastTerminalInputAtByPaneKey: nextLastTerminalInputAtByPaneKey
+        lastTerminalInputAtByPaneKey: nextLastTerminalInputAtByPaneKey,
+        foregroundAgentByPaneKey: nextForegroundAgentByPaneKey
       }
     })
🧹 Nitpick comments (8)
src/renderer/src/components/sidebar/worktree-foreground-agent-row-selectors.ts (1)

22-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a short "why" comment for the caching design.

The module-level single-slot caches (tabWorktreeIndexCache, foregroundAgentsByWorktreeCache) and the reuseForegroundRecordIfEqual reference-reuse trick are non-obvious: a reader unfamiliar with the render-amplification concern (avoiding new object identities per worktree so useShallow/memo consumers don't re-render) could easily "simplify" this into a plain .map()/.filter() and reintroduce churn. A one- or two-line comment stating the rationale (why per-worktree reference stability matters here) would match the "Why:" comment convention used elsewhere in this codebase (e.g. useWorktreeAgentRows.ts, use-worktree-foreground-agent-sync.ts).

As per path instructions, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does. Keep comments short — one or two lines, capturing only the non-obvious reason."

Source: Path instructions

src/renderer/src/components/sidebar/worktree-foreground-agent-row-type.ts (2)

37-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short "why" comment for the single-PTY fallback heuristic.

When the layout hasn't recorded a ptyId for the leaf, this falls back to assuming the sole live PTY belongs to the pane whenever leafCount <= 1. That's a non-obvious assumption (it can be wrong the instant a tab gains a second pane before layout catches up) and currently has no explanation.

📝 Suggested comment
   const leafCount = countTerminalLayoutLeaves(layout?.root)
+  // Why: layout metadata can lag a freshly-spawned pane. If there's exactly
+  // one live PTY and at most one tracked leaf, assume it's this pane's PTY.
   if (livePtyIds.length === 1 && leafCount <= 1) {

As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Source: Coding guidelines


10-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract countTerminalLayoutLeaves into a shared helper

src/renderer/src/components/sidebar/worktree-foreground-agent-row-type.ts and src/renderer/src/components/sidebar/worktree-agent-rows.ts both define the same leaf-count recursion. Moving it to a shared layout utility keeps the pane/PTy fallback and retained-alias logic from drifting.

src/renderer/src/components/sidebar/worktree-title-derived-agent-rows.ts (1)

155-181: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared title→status/label/agentType derivation to avoid drift.

buildTitleDerivedAgentRow (status/label/agentType computation) and titleCanBuildTitleDerivedAgentRow duplicate the same isClaudeManagementTitle → detectAgentStatusFromTitle/getAgentLabel → resolveTitleDerivedAgentType chain. titleCanBuildTitleDerivedAgentRow is consumed by the foreground-sync-targets logic to decide which panes get probed; if this copy diverges from the row-building copy, the sync hook could skip probing a pane that would actually get a title-derived row (or the reverse).

Consider factoring the shared {status, label, agentType} derivation into one helper used by both.

Also applies to: 208-222

src/renderer/src/store/slices/terminals.ts (1)

1028-1036: 📐 Maintainability & Code Quality | 🔵 Trivial

Consider extracting the repeated paneKey-prefix deletion loop into a helper.

The for (const paneKey of Object.keys(...)) { if (paneKey.startsWith(${tabId}:)) ... } pattern is now duplicated across closeTab, shutdownWorktreeTerminals, and buildOrphanTerminalCleanupPatch for foregroundAgentByPaneKey (on top of the pre-existing duplication for unreadTerminalPanes/cacheTimerByKey). A small deletePaneKeysWithPrefix(record, prefix) helper would reduce this to one call site per map.

Also applies to: 2280-2287

src/renderer/src/store/slices/worktrees.ts (2)

1903-1914: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a "why" comment for the composite pane-key parsing.

Unlike the sibling omitByTabId/omitByWorktree helpers that check plain membership (id in out), omitPaneKeysByTabId parses a composite key (tabId:leafId) to recover the tab id. This is a non-obvious constraint (pane keys are the only tab-scoped map here keyed by a composite string) and deserves a short inline note, consistent with other maps in this function that already carry "Why:" comments explaining non-obvious cleanup requirements.

As per coding guidelines, **/*.{ts,tsx,js,jsx}: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does. Keep comments short — one or two lines, capturing only the non-obvious reason."

📝 Proposed comment
+  // Why: foregroundAgentByPaneKey is keyed by composite `tabId:leafId` pane
+  // keys (see makePaneKey), unlike the other tab-scoped maps above that are
+  // keyed directly by tabId.
   const omitPaneKeysByTabId = <T>(obj: Record<string, T>): Record<string, T> => {

Source: Coding guidelines


3068-3080: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate pane-key cleanup logic diverges from the bulk-purge helper.

This inline cleanup re-implements the same "drop foregroundAgentByPaneKey entries whose tabId prefix is doomed" logic already added as omitPaneKeysByTabId in buildWorktreePurgeState (Lines 1903-1914), but as a nested loop (for tabId → for Object.keys(nextForegroundAgentByPaneKey)) instead of a single set-lookup pass. Two independent implementations of the same rule increase the risk that a future edit to one is missed in the other, and this variant is less efficient (O(tabIds × paneKeys) vs. O(paneKeys)).

Consider factoring both into one shared helper (e.g. taking a Set<string> of doomed tab ids and returning the filtered pane-key map) and reusing it from both buildWorktreePurgeState and removeWorktree.

src/renderer/src/components/sidebar/worktree-foreground-sync-targets.ts (1)

133-145: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Identical branch bodies — simplify the condition.

The if (titleCanBuildTitleDerivedAgentRow(...)) and else if (targetByPaneKey.has(paneKey)) branches execute the exact same targetByPaneKey.set(...) call. This can be collapsed into a single condition, which also makes the intent (re-read on title-derived-row-eligible OR already-tracked pane) explicit at a glance.

♻️ Suggested simplification
-        if (titleCanBuildTitleDerivedAgentRow(title, args.tab.launchAgent)) {
-          targetByPaneKey.set(paneKey, {
-            lifecycleKey: targetByPaneKey.get(paneKey)?.lifecycleKey ?? 'title',
-            titleForegroundKey: getTitleForegroundKey(title, args.tab.launchAgent)
-          })
-        } else if (targetByPaneKey.has(paneKey)) {
-          // Why: a live row whose pane title changes back to shell/unknown
-          // needs one re-read so stale foreground identity can be cleared.
-          targetByPaneKey.set(paneKey, {
-            lifecycleKey: targetByPaneKey.get(paneKey)?.lifecycleKey ?? 'title',
-            titleForegroundKey: getTitleForegroundKey(title, args.tab.launchAgent)
-          })
-        }
+        // Why: track this pane if the title can build a title-derived row, or
+        // if it was already tracked (a live row whose title changed back to
+        // shell/unknown needs one re-read so stale identity can be cleared).
+        if (
+          titleCanBuildTitleDerivedAgentRow(title, args.tab.launchAgent) ||
+          targetByPaneKey.has(paneKey)
+        ) {
+          targetByPaneKey.set(paneKey, {
+            lifecycleKey: targetByPaneKey.get(paneKey)?.lifecycleKey ?? 'title',
+            titleForegroundKey: getTitleForegroundKey(title, args.tab.launchAgent)
+          })
+        }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cd40957f-cab7-450a-aa08-65e125a3d1c7

📥 Commits

Reviewing files that changed from the base of the PR and between d7322ec and 16987e946ebbca1bbe7449be6c57357fb80e166c.

📒 Files selected for processing (22)
  • src/renderer/src/components/editor/ReviewNotesSendMenuContent.tsx
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.test.tsx
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.ts
  • src/renderer/src/components/sidebar/useWorktreeAgentRows.test.ts
  • src/renderer/src/components/sidebar/useWorktreeAgentRows.ts
  • src/renderer/src/components/sidebar/worktree-agent-row-agent-type.ts
  • src/renderer/src/components/sidebar/worktree-agent-row-selectors.test.ts
  • src/renderer/src/components/sidebar/worktree-agent-rows.ts
  • src/renderer/src/components/sidebar/worktree-foreground-agent-row-selectors.ts
  • src/renderer/src/components/sidebar/worktree-foreground-agent-row-type.ts
  • src/renderer/src/components/sidebar/worktree-foreground-agent-rows.test.ts
  • src/renderer/src/components/sidebar/worktree-foreground-derived-agent-rows.ts
  • src/renderer/src/components/sidebar/worktree-foreground-sync-targets.ts
  • src/renderer/src/components/sidebar/worktree-title-derived-agent-rows.ts
  • src/renderer/src/lib/use-tab-agent-foreground-cache.test.ts
  • src/renderer/src/lib/use-tab-agent.test.ts
  • src/renderer/src/lib/use-tab-agent.ts
  • src/renderer/src/store/slices/store-cascades.test.ts
  • src/renderer/src/store/slices/terminal-orphan-helpers.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts

@brennanb2025
brennanb2025 force-pushed the brennanb2025/codex-icon-running-agent branch from 31c5e6a to f6c2cb8 Compare July 2, 2026 02:37

@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

🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/worktree-foreground-sync-targets.ts (1)

26-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a short comment on why epochs are part of the identity key.

Folding commandFinishedEpoch/interruptInputEpoch into targetKey() is a non-obvious race-hardening mechanism (per the PR's "harden agent tab foreground races" intent) — a one-line comment would help future readers understand why these counters bump the key.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9802555b-2d91-4ff7-bdac-8a7aa9b33f72

📥 Commits

Reviewing files that changed from the base of the PR and between 7234d44 and 56c76b6bab2ce6e825e020d5ebe0d97752d3f684.

📒 Files selected for processing (10)
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.test.tsx
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.ts
  • src/renderer/src/components/sidebar/worktree-foreground-sync-targets.ts
  • src/renderer/src/lib/tab-agent-hook-signals.ts
  • src/renderer/src/lib/use-tab-agent-launch-lifecycle.test.ts
  • src/renderer/src/lib/use-tab-agent.ts
  • src/renderer/src/store/slices/store-cascades.test.ts
  • src/renderer/src/store/slices/terminal-orphan-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/renderer/src/store/slices/store-cascades.test.ts
  • src/renderer/src/store/slices/terminal-orphan-helpers.ts
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.test.tsx
  • src/renderer/src/lib/use-tab-agent-launch-lifecycle.test.ts
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.ts
  • src/renderer/src/lib/use-tab-agent.ts

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

🧹 Nitpick comments (2)
src/renderer/src/components/sidebar/worktree-foreground-sync-targets.ts (1)

16-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a short "why" comment for inputEpoch.

The rationale for including inputEpoch in the identity key (busting a stale-suppression window so a legitimate relaunch isn't hidden) is documented downstream in use-worktree-foreground-agent-sync.ts, but not here where the field/key is defined. A future edit to targetKey() could drop this field without realizing it breaks that downstream invalidation contract.

As per coding guidelines: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

📝 Suggested comment
 export type ForegroundSyncTarget = {
   commandFinishedEpoch: number
+  // Included so a fresh terminal input can invalidate a stale post-finish
+  // suppression in the sync hook and trigger a foreground re-read.
   inputEpoch: number

Source: Coding guidelines

src/renderer/src/components/sidebar/worktree-foreground-epoch-selectors.ts (1)

40-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short comment on why manual identity-preserving memoization is used here.

The module-level caches plus reuseNumberRecordIfEqual/reuseEpochsIfEqual are a deliberate, non-obvious technique: preserving object identity per worktree so unrelated worktrees don't get spuriously re-synced (each foreground re-sync triggers an IPC call via getForegroundProcess). Worth a one-line note so a future refactor doesn't "simplify" this into a plain rebuild and silently cause excessive foreground re-reads.

As per coding guidelines: "add a comment explaining why the code behaves the way it does... capturing only the non-obvious reason."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 73decc8f-1238-49bc-9ff0-3e87eab3c3db

📥 Commits

Reviewing files that changed from the base of the PR and between 56c76b6bab2ce6e825e020d5ebe0d97752d3f684 and 137e7541895160155094dafc615f0dc1312a573a.

📒 Files selected for processing (5)
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.test.tsx
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.ts
  • src/renderer/src/components/sidebar/worktree-agent-row-selectors.test.ts
  • src/renderer/src/components/sidebar/worktree-foreground-epoch-selectors.ts
  • src/renderer/src/components/sidebar/worktree-foreground-sync-targets.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/sidebar/worktree-agent-row-selectors.test.ts
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.ts
  • src/renderer/src/components/sidebar/use-worktree-foreground-agent-sync.test.tsx

Per Brennan's direction on this PR: tab icons must not run their own
foreground-process probe. Identity now flows through the same
already-computed state as the sidebar agent rows — hook entries (kept
live by the OSC 133 command-finished drop machinery), explicit titles,
and launch bootstrap.

The probe's one unique local job, clearing stale launch identity after
the launched agent exits, is replaced with probe-free evidence: a
completed hook at a shell title, or a previously observed live hook row
that was dropped (crash/kill path) while the title reads as a shell.

Behavior trades, accepted with this direction: agents that never emit
hooks resolve from title evidence or show no icon, and a done-but-open
agent whose title reads as a shell shows no icon (matches the existing
remote-pane behavior).

Co-authored-by: Orca <help@stably.ai>
@brennanb2025
brennanb2025 force-pushed the brennanb2025/codex-icon-running-agent branch from a9b74f3 to d58772e Compare July 3, 2026 01:30
@brennanb2025 brennanb2025 changed the title Show foreground agent icons in Worktree cards Unify tab agent identity with the agent-status pipeline Jul 3, 2026
Review fixes: gate the vanished-activity clear to local panes (remote rows
drop on transport blips), require no live hook row anywhere in the tab,
make the observed-signal generation reset race-safe and self-re-seeding,
accept the neutral default title as exit evidence (inferred-interrupt reset
target), count a title naming the launched agent as its activity so
hookless launched agents can clear, scope layout-less completed rows to
single-pane tabs, share one exit-evidence predicate between the resolver
and the clear effect, and drop the dead tab-agent wrappers.

Co-authored-by: Orca <help@stably.ai>
brennanb2025 and others added 5 commits July 3, 2026 13:45
…per retry ladder

Live verification on PR #7059 found two gaps: a TUI that dies leaving a
stuck agent title kept painting the tab through the title-fallback layer
(shell-foreground proof now suppresses title-derived identity and the
local completed-hook fallback), and the daemon's wrapper→agent ancestry
resolution can take >1.5s for real node-wrapped CLIs (the read ladder
gets a second bounded re-read at 3.5s).

Co-authored-by: Orca <help@stably.ai>
…on-running-agent

# Conflicts:
#	src/renderer/src/components/terminal-pane/pty-connection.ts
Wholesale teardowns (tab close, worktree sleep/remove) retire pane keys
without per-pane close events, stranding unreachable foreground entries
for the renderer's lifetime. Mirror the agent-status prefix sweeps at
both chokepoints; no-op sweeps bail without a state change.

Co-authored-by: Orca <help@stably.ai>
A settle-read that still runs means 133;D has not fired (D cancels pending
reads), so a shell seen there is a nested sh/bash without integration.
Publishing shell-foreground from reads let a stale mark suppress live title
identity for agents started inside nested shells; 133;D is now the only
shell-foreground source. Also gate the shell-foreground exit-evidence branch
on !isRemote (defense in depth; unreachable via production wiring) and
document the worktree sweep's must-run-before-tab-prune ordering assumption.

Co-authored-by: Orca <help@stably.ai>
@brennanb2025
brennanb2025 merged commit 4951168 into main Jul 4, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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.

1 participant