Repository navigation
fix(sidebar): stop the agent row's tool step from flickering on every hook (#11075) - #14682
brennanb2025 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe change adds Merge Risk: 🔵 Low · up to The PR stabilizes rapidly changing agent tool-step text, but a row may briefly show stale tool activity after work stops; this is a bounded display issue that should be corrected or explicitly accepted before merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/hooks/use-settled-agent-tool-step.ts (1)
8-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the new comments. Keep only brief rationale that is not already clear from the identifiers and code, following the repository guideline to prefer concise, non-obvious comments.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ececb065-cf26-4a5c-8843-9f4a11e31873
📒 Files selected for processing (5)
src/renderer/src/components/dashboard/DashboardAgentRow.tsxsrc/renderer/src/components/sidebar/worktree-card-compact-agent-row.tool-step-flicker.test.tsxsrc/renderer/src/components/sidebar/worktree-card-compact-agent-row.tsxsrc/renderer/src/hooks/use-settled-agent-tool-step.test.tssrc/renderer/src/hooks/use-settled-agent-tool-step.ts
| const toolStep = useSettledAgentToolStep( | ||
| isWorking ? (agent.entry.toolName?.trim() ?? '') : '', | ||
| isWorking ? (agent.entry.toolInput?.trim() ?? '') : '' | ||
| ) | ||
| const secondary = getCompactAgentSecondary(agent, toolStep) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Hide settled tool data when work stops.
When agent.state changes from 'working' to a terminal state, the hook retains the previous pair until the dwell ends. getCompactAgentSecondary then renders the stale tool step for up to 800 ms.
Pass an empty pair to getCompactAgentSecondary when isWorking is false. Keep the hook call unconditional. Add a test that rerenders a working row as non-working and asserts that no tool step remains before the dwell expires.
Proposed fix
+const EMPTY_TOOL_STEP: AgentToolStep = { toolName: '', toolInput: '' }
+
const toolStep = useSettledAgentToolStep(
isWorking ? (agent.entry.toolName?.trim() ?? '') : '',
isWorking ? (agent.entry.toolInput?.trim() ?? '') : ''
)
- const secondary = getCompactAgentSecondary(agent, toolStep)
+ const secondary = getCompactAgentSecondary(
+ agent,
+ isWorking ? toolStep : EMPTY_TOOL_STEP
+ )📝 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.
| const toolStep = useSettledAgentToolStep( | |
| isWorking ? (agent.entry.toolName?.trim() ?? '') : '', | |
| isWorking ? (agent.entry.toolInput?.trim() ?? '') : '' | |
| ) | |
| const secondary = getCompactAgentSecondary(agent, toolStep) | |
| const EMPTY_TOOL_STEP: AgentToolStep = { toolName: '', toolInput: '' } | |
| const toolStep = useSettledAgentToolStep( | |
| isWorking ? (agent.entry.toolName?.trim() ?? '') : '', | |
| isWorking ? (agent.entry.toolInput?.trim() ?? '') : '' | |
| ) | |
| const secondary = getCompactAgentSecondary( | |
| agent, | |
| isWorking ? toolStep : EMPTY_TOOL_STEP | |
| ) |
|
@nwparker @AmethystLiang Could you take a look at this one when you have a moment? I run a lot of Cursor CLI agents in Orca every day, and the sidebar flicker from #11075 has turned out to be more disruptive than I expected. With nine Cursor tabs in one worktree, every row keeps swapping names about twice a second, so it is hard to tell which session is which. I've added the repro details on Orca v1.4.220 in #11075 (comment). This PR and #11127 both address it. Getting either one merged would make Cursor much easier to use in Orca. Thanks! |
|
The remaining sidebar readability problem is still tracked in #11075. The row should be stabilized in the current design instead of carrying forward this older delay-based display fix. |
ELI5
While a Cursor agent works, it tells Orca what it's doing several times a second — "reading this file", "running that command". The sidebar row printed every single one of those onto the same line as the workspace's name. The name never actually changed, but the line it lived on was being rewritten ~8 times a second, so the whole row read as flickering. Now a step stays put long enough to read before the next one replaces it. Nothing is dropped — the row just stops repainting faster than a human can follow.
What Changed
useSettledAgentToolStep(toolName, toolInput)(src/renderer/src/hooks/use-settled-agent-tool-step.ts): holds an agent's tool-step pair for a minimum 800ms dwell, coalescing anything that arrives inside the window down to the newest value.worktree-card-compact-agent-row.tsx) and its siblingDashboardAgentRownow read theirtoolName/toolInputthrough it.use-settled-agent-tool-step.test.ts(9) andworktree-card-compact-agent-row.tool-step-flicker.test.tsx(3).Three properties matter and are each covered by a test:
toolNameandtoolInputsettle together, so the row can never show one step's name beside another step's input.The dwell is scheduled off an absolute deadline (
lastPaintedAt + 800ms), not a restarting timer. That's what lets the effect own its ownclearTimeoutcleanup — rescheduling on the next hook re-aims at the same instant instead of pushing the deadline out, so a continuously-churning row still repaints on schedule rather than being starved. (Sequential per-hooksetTimeoutbookkeeping was the first draft; React Doctor'seffect-needs-cleanupcorrectly rejected it, and the absolute-deadline form is both cleaner and leak-free.)Why
#11075 reports the Cursor tab and sidebar title flickering. Those are two different surfaces with different code paths, so I checked both:
The tab is already fixed on
main. The alternation the reporter saw was Orca's synthetic⠋ Cursor Agentspinner fightingcursor-agent's bareCursor Agentnative OSC title, which it re-emits on every redraw. Frame-to-frame spinner churn was already collapsed byisDecorativeAgentTitleFrameChange(#5294, June 12 — before this issue was filed), but that guard deliberately does not collapse the spinner ↔ bare-literal pair, because the bare literal detects asnullstatus and so has a different decorative signature. I verified that directly:That second pair was the tab flicker, and it was closed on Aug 9 by
shouldSuppressCursorNativeTitle(#12466), which now suppresses the native re-emission at bothpty-transport.ts:133and:458once a Cursor-owned title holds the pane. #11075 was filed July 28 against v1.4.158, so the tab half of this report is genuinely fixed — incidentally, by a PR for a different issue. No tab-path change is needed and none is in this PR.The sidebar is the live defect, and it is the one the reporter themselves isolated in the issue body ("the compact row is
primary - secondaryand secondary is livetool: input").getCompactAgentSecondaryrecomputedtoolName: toolInputon every status update and concatenated it onto the row's singletruncated line, immediately after the prompt. A Cursor turn emitspreToolUse/postToolUse/beforeShellExecution/beforeMCPExecutioncontinuously, so that line was rewritten several times a second.It's worse than a fast ticker, because the secondary is a priority ladder over three unrelated sources — tool step, then
lastAssistantMessage, then the agent-type label.extractCursorToolFieldsclears the tool pair outright onpostToolUseFailure(clearActiveToolFieldsUpdate(),agent-hook-listener.ts:1810) and setslastAssistantMessageto the error text on the same event. So a single failed tool made the line jump fromBash: pnpm testto a raw error string and back to a tool on the next hook — three unrelated content categories inside ~300ms. The dwell coalesces that transient away entirely, since it never outlives the window.Why stabilise the display rather than the events: the events are correct and other consumers need them, so the fix belongs at the paint. STYLEGUIDE.md's in-flight-feedback table puts the perceptual floor at ~100ms ("anything visible reads as a glitch"); 800ms gives a tool step time to actually be read.
Why
DashboardAgentRowtoo, given the report only names the sidebar: STYLEGUIDE.md UX rule 2 — it is the direct sibling (same data, same domain, adjacent surfaces), it renders the identical volatile pair, and it also feeds an expandable<pre>that a user opens specifically to read the tool input. Stabilising one and not the other would leave a seam. It's the same one-line change at both call sites.Superseded / related
Supersedes fix(tabs): stop Cursor working titles from flickering (#11075) #11127 (@Fazalkadivar21). Same issue, and it correctly identified the compact-row secondary — but its three changes are each a regression:
resolveTerminalTabTitle/resolveUnifiedTabLabelare rewritten so that whentabAutoGenerateTitleis on, thefallbackargument is dropped entirely and the function returns''if there's no generated title. Its own added test asserts.toBe(''). That is a blank tab, and the PR body acknowledges it. It also changes titles for every agent, not just Cursor.useAgentRowConversationNamefrom the compact row, so sidebar rows lose the conversation/generated tab name — an unrelated shipped feature.Its
terminals.tsguard is also now redundant withshouldSuppressCursorNativeTitle, which landed after that branch was cut.Complements fix(agent-hooks): reopen a retired pane on any provider's turn boundary (#12686) #14626 ([Bug]: Some Cursor panes remain Working despite completed stop hooks #12686, Cursor panes stuck
Working), which deliberately left this cluster out after testing the flicker hypothesis. This PR starts from its findings and reaches the sidebar-row conclusion it pointed at. No file overlap.Linked Issue
Fixes #11075
Visual Proof
Same component, same synthetic hook stream (a new tool step every 130ms, as Cursor emits), same 7-second window. Top is
main, bottom is this PR.11075-sidebar-flicker.mp4
Sampling the rendered row text every 60ms over that window gives a hard count of distinct painted strings:
mainThe capture harness mounted the real shipping
CompactAgentRowagainst the realmain.csstokens in Chromium and recorded both runs identically, reverting only the two source files in between. It was deleted before commit and is not part of the diff.Testing
src/renderer/src/hooks/use-settled-agent-tool-step.test.ts— 9 tests:(name, input)pair.postToolUseFailurecase) is coalesced away when a new step arrives inside the dwell, but a clear that outlives the dwell does land, so a finished row drops its tool step.src/renderer/src/components/sidebar/worktree-card-compact-agent-row.tool-step-flicker.test.tsx— 3 tests, rendering the real row into a real DOM and asserting itstextContentis byte-identical across a hook burst, that the prompt stays visible throughout, and that the newest step lands afterward.Proven non-vacuous. Keeping both test files and reverting only the two source files (
git stash push -- <sources>), the row suite goes 1 failed / 2 passed, failing exactly on the churn assertion:With the fix applied it is 3 passed. The 2 that pass pre-fix are the controls the fix must not change (the prompt stays visible; the newest step eventually lands — both already true on
main).Scoped checks run locally (full
pnpm typecheckskipped deliberately — OOM risk on this box; the node project is the one this diff touches):pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/hooks/use-settled-agent-tool-step.test.ts src/renderer/src/components/sidebar/worktree-card-compact-agent-row.tool-step-flicker.test.tsx— 12 passed… src/renderer/src/components/dashboard/ src/renderer/src/components/sidebar/WorktreeCardAgents*.test.tsx— 25 files, 188 passedtsc --noEmit -p config/tsconfig.node.json --composite false— cleanpnpm run check:code-quality:changed— oxlint,--type-aware, and React Doctor all 0 new findings across 5 changed files. The gate is demonstrably live: it failed this branch once onreact-doctor(effect-needs-cleanup)and drove the absolute-deadline restructure described above.oxfmt --writeon the changed filesSix
WorktreeCard.*suites (PR display, compact hover, lineage, pinned repo icon, hosted review refresh) time out when the full 250-file sidebar+dashboard run is executed in one parallel batch. All six pass when run on their own, none of them touch agent rows, and the set that times out varies between runs — load-dependent flake, not this change.Platforms actually exercised: macOS. The issue is labelled
os:linux; nothing here is platform-specific (see Review).Review
useState, oneuseRef, and two string compares, with no map or store scans. This matters because STA-3354 already flags tab-agent status resolution as scanning the global status map per tab per render; nothing here adds to that. It does not add renders either: the rows still re-render on every hook (their props change regardless), the dwell only governs what is painted. It removes work if anything, by cutting DOM text mutations ~5×. At most one live timer per churning row, cleared on unmount.interruptedis still checked ahead of the tool step so an interrupt surfaces immediately rather than waiting behind a dwell.deriveToolInputPreview.os:linux; the mechanism is the hook cadence, which is platform-independent, and I could not reproduce on Linux hardware from here.titleattribute is built from the same settled strings, so the tooltip and the visible text never disagree.Author