Skip to content

fix(sidebar): stop the agent row's tool step from flickering on every hook (#11075) - #14682

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/cursor-title-flicker-11075
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/cursor-title-flicker-11075

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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

  • New 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.
  • The compact sidebar agent row (worktree-card-compact-agent-row.tsx) and its sibling DashboardAgentRow now read their toolName/toolInput through it.
  • New suites: use-settled-agent-tool-step.test.ts (9) and worktree-card-compact-agent-row.tool-step-flicker.test.tsx (3).

Three properties matter and are each covered by a test:

  1. Nothing is dropped. This is display-only. Hook events, the status store, notifications, and every other consumer still see all of them.
  2. The pair is atomic. toolName and toolInput settle together, so the row can never show one step's name beside another step's input.
  3. The last value always lands. The dwell is a floor on how fast the row repaints, never a filter — when the burst stops, the newest step is painted.

The dwell is scheduled off an absolute deadline (lastPaintedAt + 800ms), not a restarting timer. That's what lets the effect own its own clearTimeout cleanup — 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-hook setTimeout bookkeeping was the first draft; React Doctor's effect-needs-cleanup correctly 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 Agent spinner fighting cursor-agent's bare Cursor Agent native OSC title, which it re-emits on every redraw. Frame-to-frame spinner churn was already collapsed by isDecorativeAgentTitleFrameChange (#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 as null status and so has a different decorative signature. I verified that directly:

isDecorativeAgentTitleFrameChange('⠋ Cursor Agent', '⠙ Cursor Agent') === true
isDecorativeAgentTitleFrameChange('⠋ Cursor Agent', 'Cursor Agent')  === false

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 both pty-transport.ts:133 and :458 once 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.

Correcting one detail from #14626, which reached the same conclusion by a slightly different route: it said the decorative-collapse machinery post-dates #11075. It predates it (#5294). The guard that actually fixed the tab is the native-title suppression from #12466, which does post-date the issue.

The sidebar is the live defect, and it is the one the reporter themselves isolated in the issue body ("the compact row is primary - secondary and secondary is live tool: input"). getCompactAgentSecondary recomputed toolName: toolInput on every status update and concatenated it onto the row's single truncated line, immediately after the prompt. A Cursor turn emits preToolUse / postToolUse / beforeShellExecution / beforeMCPExecution continuously, 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. extractCursorToolFields clears the tool pair outright on postToolUseFailure (clearActiveToolFieldsUpdate(), agent-hook-listener.ts:1810) and sets lastAssistantMessage to the error text on the same event. So a single failed tool made the line jump from Bash: pnpm test to 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 DashboardAgentRow too, 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:

    1. resolveTerminalTabTitle / resolveUnifiedTabLabel are rewritten so that when tabAutoGenerateTitle is on, the fallback argument 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.
    2. It deletes useAgentRowConversationName from the compact row, so sidebar rows lose the conversation/generated tab name — an unrelated shipped feature.
    3. It removes the tool secondary outright rather than stabilising it, losing the live activity signal instead of making it readable.

    Its terminals.ts guard is also now redundant with shouldSuppressCursorNativeTitle, 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:

distinct repaints in 7s
main 54
this PR 10

The capture harness mounted the real shipping CompactAgentRow against the real main.css tokens 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:

  • Mounted step paints with no dwell; the first rewrite after mount waits one dwell.
  • A burst of four rewrites inside one dwell paints nothing, then only the newest lands — the intermediates are never painted.
  • The final step always lands once the burst stops.
  • The pair never desyncs: every string the hook ever returns is a real (name, input) pair.
  • A transient clear (the postToolUseFailure case) 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.
  • A hook every 50ms for 2× the dwell still repaints on schedule — the absolute deadline is not restarted.
  • The pending dwell is cleared on unmount.

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 its textContent is 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:

AssertionError: expected 'Refactor the intake flow - Grep: TODO…'
                to be      'Refactor the intake flow - Read: src/…'

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 typecheck skipped 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 passed
  • tsc --noEmit -p config/tsconfig.node.json --composite false — clean
  • pnpm 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 on react-doctor(effect-needs-cleanup) and drove the absolute-deadline restructure described above.
  • oxfmt --write on the changed files

Six 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).

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

  • Performance: deliberately O(1) per render — the hook is one useState, one useRef, 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.
  • Correctness: the dwell is a floor on repaint rate, never a filter. Every value eventually lands; the pair is atomic; interrupted is still checked ahead of the tool step so an interrupt surfaces immediately rather than waiting behind a dwell.
  • Security: none. Display-only, no new inputs, IPC, paths, or process execution. Tool strings were already rendered by both rows and are still capped upstream by deriveToolInputPreview.
  • Cross-platform: no paths, shells, accelerators, shortcut labels, or platform branches — pure renderer state and string comparison. Identical on macOS, Linux, and Windows. The report is os:linux; the mechanism is the hook cadence, which is platform-independent, and I could not reproduce on Linux hardware from here.
  • Remote / SSH: no wire change, no new RPC params, stream frames, or published content. Status still arrives exactly as before; only the renderer's paint cadence changed. If anything this helps under SSH, where bursts arrive batchier.
  • Mobile: unaffected — neither row ships to mobile.
  • Backwards compatibility: no persisted state, no settings, no schema. Reverting the two call sites restores the previous behavior exactly.
  • Accessibility: the row's title attribute is built from the same settled strings, so the tooltip and the visible text never disagree.

Author

  • X / Twitter: @BrennanKB5

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds useSettledAgentToolStep, which maintains an atomic tool name and input pair for a configurable dwell period of 800 ms. The hook coalesces rapid updates, schedules absolute-deadline timers, and cleans up pending timers. Dashboard and compact agent rows now use settled tool-step values while working. Compact-row tests and hook tests cover delayed updates, flicker suppression, clearing, coalescing, and cleanup.

Merge Risk: 🔵 Low · up to b39a7

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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing agent-row tool-step flicker.
Description check ✅ Passed The description covers the required sections, linked issue, visual proof, testing, review considerations, and implementation rationale.
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.
✨ Finishing Touches
📝 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.

@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/hooks/use-settled-agent-tool-step.ts (1)

8-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten 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

📥 Commits

Reviewing files that changed from the base of the PR and between e570cad and b39a7ed.

📒 Files selected for processing (5)
  • src/renderer/src/components/dashboard/DashboardAgentRow.tsx
  • src/renderer/src/components/sidebar/worktree-card-compact-agent-row.tool-step-flicker.test.tsx
  • src/renderer/src/components/sidebar/worktree-card-compact-agent-row.tsx
  • src/renderer/src/hooks/use-settled-agent-tool-step.test.ts
  • src/renderer/src/hooks/use-settled-agent-tool-step.ts

Comment on lines +127 to +131
const toolStep = useSettledAgentToolStep(
isWorking ? (agent.entry.toolName?.trim() ?? '') : '',
isWorking ? (agent.entry.toolInput?.trim() ?? '') : ''
)
const secondary = getCompactAgentSecondary(agent, toolStep)

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.

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

Suggested change
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
)

@innocarpe

Copy link
Copy Markdown
Contributor

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

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.

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]: Cursor tab/sidebar title flickers while agent is working

2 participants