Repository navigation
perf(worktrees): back off worktree scans for agent-scratch repos - #9985
Conversation
Production crash diagnostics measured ~128 `git worktree list` execs/min (9,400 in one 80-minute session, ~16% of wall-clock in git subprocesses): the resolved-worktree scan fans out over every registered repo on a 30s cache TTL, and most registered repos on the affected installs were agent-CLI scratch repos (~/.codex-tmp capsules, vendor imports, skill checkouts) that need no freshness. Classify agent-scratch repo roots with a curated shared matcher and stamp their scan-cache entries with a 5-minute TTL instead of 30s. Orca-driven mutations still bypass the TTL via the per-repo generation bump, so only passive pickup of external changes slows for scratch repos. Expected steady-state reduction on the measured install: ~82% fewer git spawns.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
…blyai#9985) Production crash diagnostics measured ~128 `git worktree list` execs/min (9,400 in one 80-minute session, ~16% of wall-clock in git subprocesses): the resolved-worktree scan fans out over every registered repo on a 30s cache TTL, and most registered repos on the affected installs were agent-CLI scratch repos (~/.codex-tmp capsules, vendor imports, skill checkouts) that need no freshness. Classify agent-scratch repo roots with a curated shared matcher and stamp their scan-cache entries with a 5-minute TTL instead of 30s. Orca-driven mutations still bypass the TTL via the per-repo generation bump, so only passive pickup of external changes slows for scratch repos. Expected steady-state reduction on the measured install: ~82% fewer git spawns.
What & why
Crash-channel diagnostics from the renderer-OOM cluster surfaced a main-process problem along the way: one production install executed 10,216 git commands in 80 minutes (~128/min, 757s of git busy time — ~16% of wall-clock), 92% of them
git worktree list --porcelain. The resolved-worktree scan (computeResolvedWorktrees) fans out over every registered repo on a 30-second per-repo cache TTL — and on the affected installs, most registered repos were agent-CLI scratch repos (~/.codex-tmp/foragent-capsule-*,~/.codex/vendor_imports,~/.claude/skills/*) that were registered once (nested-repo import) and never need 30-second freshness. #9535 hides agent-scratch rows from the sidebar, but the scan layer still shelled out to all of them every cycle, forever.Fix: classify agent-scratch repo roots with the same curated shared-matcher pattern #9535 introduced (
isAgentScratchRepoRootPath), and stamp their scan-cache entries with a 5-minute TTL instead of 30 seconds (resolveWorktreeScanCacheTtlMs, wired at the single cache-stamp site).Nothing is skipped or hidden: scratch repos still scan — just 10× less often.
CLEAR fix evidence
/tmp/.codex-tmp/capsule-a), advancing 31s re-scans the normal repo but not the scratch repo; advancing +5min re-scans the scratch repo. Reverting the one-line cache-stamp wiring makes this test fail (expected 2 to be 1) — verified both directions.ELI5
Orca keeps a list of every project folder it has ever been shown, and every 30 seconds it walks the whole list asking git "anything new here?". On some machines, most of that list is temporary scratch folders that coding agents made for themselves — nobody is working in them, but Orca still knocked on every door twice a minute, thousands of times an hour. Now Orca recognizes those agent scratch folders and only checks them every 5 minutes. Real project folders keep the fast checks, and anything you do inside Orca still updates instantly.
Trade-offs
~/.claude/skills/x) only gets slower passive pickup — never missing rows, never wrong data.Adversarial review & perf
mockClear()matching the file's convention.Follow-ups (ranked by the perf review, not this PR)