Repository navigation
Worktree list safety sweep skips unchanged worktrees instead of re-reading all of them every 30s - #31253
Merged
Conversation
… entry's dir signature The native-watch reconciliation forced an ungated stat of every leaf of every worktree admin entry each tick (~7 stats/entry). It now uses the entry-dir signature gate plus the two leaves git writes in place (gitdir, logs/HEAD), runs the ungated sweep every 10 ticks (~5 min), and falls back to sweeping every tick if a sweep ever finds a change the dir signature missed. Co-Authored-By: Claude <noreply@anthropic.com>
…med, repeated miss Detect a missed change on any entry rescan, including ones the in-place leaf probes trigger, not just full sweeps. Re-stat the admin dir after the leaf rescan so a rename racing the scan isn't counted, ignore transient missing leaves, and require misses on two separate ticks before sweeping every tick. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Orca keeps a list of every git worktree of each repo so the sidebar notices worktrees being added or removed. As a safety net it re-reads every worktree's metadata every 30 seconds, and that re-read skipped its own cache, so it read seven small files per worktree every time even when nothing had changed. On a repo with ~1,740 worktrees (many of them agent worktrees) that was about 12,000 file reads every 30 seconds. This PR lets the safety net use the cache.
What Changed
.git/worktrees/<name>folder's change time.gitdirandlogs/HEADchange without updating the folder's change time, so they are checked directly; if either changed, that worktree is fully re-read. (HEAD,config.worktreeandindexare written by rename andlockedis only created or deleted, so the folder check covers them; verified against git 2.25 and 2.55 source.)Per sweep at 1,740 worktrees: about 12,180 file checks before; about 5,220 on a normal sweep after (3 per worktree), with the full ~12,180 every 10th sweep — about 5,900 on average.
Why
The full re-read every 30 seconds was a backstop for missed watch events, not something the sidebar needs at that rate. The cache it bypassed already existed; the gaps it has (in-place writes, file systems with unreliable folder change times) are covered explicitly instead of by re-reading everything. The 2-second fallback poller, the native watch, notifications and anything remote are unchanged. This code runs only in the local main process; SSH hosts don't use it.
Linked Issue
N/A (found while investigating high
fseventsdand Orca activity on a machine with many agent worktrees).Visual Proof
N/A: no visible change.
Testing
pnpm test src/main/ipc/worktree: 74 files / 868 tests pass. New tests: an unchanged worktree costs 3 checks per sweep; in-placegitdir/logs/HEADchanges are caught on the next sweep; the full sweep still runs periodically; the fallback triggers from a re-read set off by the in-place checks; a HEAD rename racing the scan (three times) does not trigger it; add/remove of worktrees is detected in both modes. Disabling each fix makes its test fail.pnpm tc,pnpm run check:code-quality:changed,oxfmt --checkpass.Reviewed by GPT, including two rounds on the fallback detector.
Not manually tested in the app; macOS only.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Windows, Linux and network file systems with unreliable folder change times fall back to the previous full-sweep behaviour automatically.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)