Repository navigation
Prevent index churn from refreshing worktrees - #8431
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change separates worktree filesystem events into structural and Git-status metadata categories. New Git-common polling detects linked-worktree and primary-checkout metadata changes, while collectors and watchers debounce and broadcast category-specific notifications. Main-process readers and refresh state now propagate changed worktree head identities through IPC to renderer state. Preload, web compatibility, status-refresh hooks, and tests support the new events. A reliability gate documents the event semantics and validation coverage. Unrelated settings and test formatting changes are also included. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 (3)
src/main/ipc/worktree-git-common-watch.ts (1)
41-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicate diff-signature logic between Darwin and non-Darwin paths.
diffMtimeMap(mtime-only) duplicates the purpose ofclassifySignatureDiff/diffSignatureMapsinworktree-git-common-polling.ts, but with a weaker signature (no ctime/ino/size) used only for Darwin's primary-checkout metadata poll. Consider extendingstartGitCommonPollingwith a "primary-only" mode (skipworktrees/scanning) so Darwin can reuse the stronger, single diffing implementation instead of maintaining two parallel mechanisms.src/main/ipc/worktree-base-directory-poller.test.ts (1)
211-235: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider adding the analogous regression test for
index.This test proves HEAD rewrites are detected regardless of entry-dir mtime restoration (since structural files bypass the shortcut). There's no equivalent test proving
indexrewrites are detected under the same restored-mtime condition — which is exactly the shortcut-dependent path flagged inworktree-git-common-polling.ts(snapshotGitCommonEntry'sshouldReadIndex). Adding a sibling test here (rewriteindex, restore entry-dir mtime, assertupdate) would directly validate or falsify that shortcut.src/main/ipc/worktree-git-common-polling.ts (1)
48-67: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd coverage for the linked-worktree index shortcut in
src/main/ipc/worktree-git-common-polling.ts:48-67.snapshotGitCommonEntryreusesprevious.indexSignaturewhen the entry dir signature is unchanged; current tests only cover first-time index creation and linked HEAD rewrites. Add a regression test for rewriting an existingworktrees/*/index(with the dir mtime restored) or drop the optimization if you don’t want to rely on that assumption.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bb2b137d-3134-4124-a9f1-6543caa73c8d
📒 Files selected for processing (16)
config/reliability-gates.jsoncsrc/main/ipc/worktree-base-directory-change-collector.tssrc/main/ipc/worktree-base-directory-event-filter.test.tssrc/main/ipc/worktree-base-directory-event-filter.tssrc/main/ipc/worktree-base-directory-poller.test.tssrc/main/ipc/worktree-base-directory-watcher.test.tssrc/main/ipc/worktree-base-directory-watcher.tssrc/main/ipc/worktree-git-common-polling.tssrc/main/ipc/worktree-git-common-watch.tssrc/main/ipc/worktree-remote.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/right-sidebar/git-status-push-signal-refresh.test.tssrc/renderer/src/components/right-sidebar/git-status-push-signal-refresh.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/web/web-preload-api.ts
External commits, amends, and soft resets in non-active worktrees now reach store rows through spawn-free Git metadata reads diffed in the watcher's existing debounce, emitted only on real head moves. HEAD reflog appends become status-only triggers, config.worktree becomes structural for sparse-flag freshness, and the non-darwin poller gains a periodic ungated index re-stat so in-place rewrites on coarse-mtime filesystems cannot be missed forever.
Freshness follow-up: background worktree heads (1eb8163)Review of this PR found that narrowing the classifier removed an accidental-but-relied-on freshness path: external/agent commits in non-active worktrees previously refreshed every row's This commit closes all three without touching the invariant:
Live evidence (macOS, dev build, fresh profile): with no active worktree, an external commit and a subsequent Tests: gate grows 109 → 128 (reader layouts incl. packed-refs/detached/unborn/relative-gitdir; watcher emit-on-change, silent re-baseline, SSH skip; poller reflog leaves + in-place-index backstop; renderer apply-by-path incl. Windows separators). Gate manifest checker passes; full typecheck and lint clean. Known gap (documented in the gate): the head diff is local-only — SSH background-worktree heads still wait on a structural event or activation, since diffing over SSH would add per-signal network reads. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9ec392f2-9aa7-4698-b027-77365de2429d
📒 Files selected for processing (20)
config/reliability-gates.jsoncsrc/main/ipc/worktree-base-directory-event-filter.test.tssrc/main/ipc/worktree-base-directory-event-filter.tssrc/main/ipc/worktree-base-directory-poller.test.tssrc/main/ipc/worktree-base-directory-watcher.test.tssrc/main/ipc/worktree-base-directory-watcher.tssrc/main/ipc/worktree-git-common-polling.tssrc/main/ipc/worktree-git-common-watch.tssrc/main/ipc/worktree-head-identity-reader.test.tssrc/main/ipc/worktree-head-identity-reader.tssrc/main/ipc/worktree-head-identity-refresh.tssrc/main/ipc/worktree-remote.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/hooks/worktree-head-identity-apply.test.tssrc/renderer/src/hooks/worktree-head-identity-apply.tssrc/renderer/src/web/web-preload-api.tssrc/shared/types.ts
🚧 Files skipped from review as they are similar to previous changes (9)
- config/reliability-gates.jsonc
- src/renderer/src/hooks/useIpcEvents.test.ts
- src/main/ipc/worktree-base-directory-event-filter.ts
- src/main/ipc/worktree-git-common-polling.ts
- src/preload/api-types.ts
- src/main/ipc/worktree-base-directory-event-filter.test.ts
- src/preload/index.ts
- src/main/ipc/worktree-base-directory-watcher.ts
- src/main/ipc/worktree-git-common-watch.ts
…2025/terminal-input-lag-investigation # Conflicts: # config/reliability-gates.jsonc
…2025/terminal-input-lag-investigation
Ref content comes from repo files an attacker can craft. Backslash segments traverse on Windows where join treats them as separators, and colons are forbidden in Git ref names; both now fail isSafeRefName before any path is built. Resolved values are additionally emitted only when they match a hex SHA-1/SHA-256 object id, so no file content can leak through the identity event even in principle.
* Prevent index churn from refreshing worktrees * Cover IPC contract in worktree reliability gate * Refresh background worktree heads without re-entering structural fanout External commits, amends, and soft resets in non-active worktrees now reach store rows through spawn-free Git metadata reads diffed in the watcher's existing debounce, emitted only on real head moves. HEAD reflog appends become status-only triggers, config.worktree becomes structural for sparse-flag freshness, and the non-darwin poller gains a periodic ungated index re-stat so in-place rewrites on coarse-mtime filesystems cannot be missed forever. * Reject unsafe symref paths and validate object ids in the head reader Ref content comes from repo files an attacker can craft. Backslash segments traverse on Windows where join treats them as separators, and colons are forbidden in Git ref names; both now fail isSafeRefName before any path is built. Resolved values are additionally emitted only when they match a hex SHA-1/SHA-256 object id, so no file content can leak through the identity event even in principle. --------- Co-authored-by: Brennan Benson <[email protected]> Co-authored-by: Brennan Benson <>

Summary
worktrees:changedstructural-only and add a desktop status-metadata signal for Source Control.worktrees:headIdentitiesChangedevent emitted only on real head moves.config.worktreeas structural (the only file whose write flips the sparse flag; never touched by status/commit).At the reported 1:57 PM stall, one Orca-owned
git worktreespan lasted 5.502 seconds amid 142 worktree commands in one minute. Ordinary externalgit statuscalls rewrite a linked worktree index. The watcher labeled every event below.git/worktrees/as structural, invalidating worktree caches and triggeringfetchWorktrees/git worktree list. Main-process spawn pressure then queuedpty:write.This keeps index churn as a Source Control freshness hint without treating it as a worktree graph mutation. Real add/remove/HEAD/gitdir/locked changes retain the structural path.
Screenshots
The terminal has no visual design change. Live validation evidence shows all 50 sequential input chunks delivered during the linked-index storm.
Testing
pnpm test(CIverifypassed instead)Live run: 2,000 external linked-worktree
git statuscalls while sending 50 sequential terminal input chunks. All 50 arrived in order. Six consecutive five-second diagnostic windows recorded zero Orca-ownedgit worktreespawns; the worst gap was 75 ms from unrelatedglab auth. A linkedlockedcreate/delete positive control subsequently produced the expected structural refreshes.Second live run (freshness fix): with no active worktree, an external commit and then an external
commit --amendin a background linked worktree each updated the store row's head to the exact new sha within one debounce, with zeroworktrees:changed.git sparse-checkout initfired exactly one structural refresh. A sustained index storm (readout taken mid-storm) produced 0 structural events, 27 coalesced status signals, and 0 head-identity events — the emit-on-change gate holds; typed terminal input executed during the storm.AI Review Report
The review traced the complete renderer → main
pty:writepath, cache invalidation andfetchWorktreesfanout, local native/poll watcher paths, SSH event shapes, and earlier refresh-storm fixes (#5608, #6020, #6153, #6324, #6390, #7595, and the Source Control signal introduced by #7086).It explicitly checked macOS, Linux, and Windows behavior, Node path handling (including Windows separators), SSH rename/overflow semantics, bounded/non-overlapping polling, preload cleanup, and structural Source Control nudges. It found and fixed a macOS performance regression where a repo starting without linked worktrees would remain on leaf polling instead of upgrading to the native narrow watcher. CodeRabbit then found that the reliability command omitted the touched IPC API-shape fixture; that test is now included in the gate.
The review also challenged the linked-index signature shortcut. The shortcut is intentionally gated by entry-directory changes because Git replaces indexes through lock/create/rename; a missed nonstandard in-place status-only write remains eventually consistent through normal Source Control polling. Structural HEAD/gitdir/locked signatures are always compared and have a regression test with restored parent mtime.
Security Audit
No user command execution, Git command/options, authentication, secrets, dependencies, or permission boundaries changed. Filesystem events are reduced to an explicit shallow metadata allowlist and paths are normalized with Node path utilities. The new IPC event carries only the existing internal
repoId, has explicit unsubscribe cleanup, is desktop-only, and does not cross the runtime/mobile structural event boundary. Overflow/error behavior remains conservatively structural. No security follow-up is required.Notes