Repository navigation
Reduce repeated git probes during worktree refresh - #6153
Conversation
Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughTwo independent caching and invalidation improvements are added. First, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 3
🧹 Nitpick comments (3)
src/main/github/client.ts (1)
2306-2344: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a short comment explaining why this null-only TTL cache exists.
The caching and in-flight dedup here are driven by a non-obvious constraint (the renderer OOM crash from repeated
git.execupstream probes during PR polling), and why onlynullresults are cached. A one-line note prevents a future reader from "simplifying" this away.📝 Suggested comment
+ // Cache only missing-upstream (null) results: PR polling repeatedly probes branches + // without an upstream, and that subprocess churn drove a renderer OOM. Coalesce + // concurrent probes and suppress repeats for the TTL window. const cacheKey = getTrackedUpstreamBranchCacheKey( repoPath, branchName, connectionId, localGitOptions )As per coding guidelines: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."
Source: Coding guidelines
src/main/ipc/worktree-change-invalidators.ts (1)
12-15: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winIsolate invalidator failures before sending notifications.
This runner is called before
worktrees:changedis sent; one throwing subscriber would skip later invalidators and suppress the renderer notification. Snapshot the set and catch per callback.🛡️ Proposed resilience fix
export function runWorktreeChangeInvalidators(repoId: string): void { - for (const invalidator of worktreeChangeInvalidators) { - invalidator(repoId) + for (const invalidator of [...worktreeChangeInvalidators]) { + try { + invalidator(repoId) + } catch (error) { + console.warn('[worktrees] worktree change invalidator failed:', error) + } } }src/main/ipc/worktrees.ts (1)
391-391: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the 5-second cache tradeoff.
The TTL is a non-obvious balance between subprocess churn and external-worktree-change lag; add a short
Why:comment so future edits preserve the intent.As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”
💬 Proposed comment
+// Why: absorb renderer polling bursts while keeping external worktree-change +// lag bounded to one short refresh window. const DETECTED_WORKTREE_SCAN_CACHE_TTL_MS = 5_000Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 57b0ff82-3715-43b9-bd2a-89388550f14a
📒 Files selected for processing (8)
src/main/github/client.test.tssrc/main/github/client.tssrc/main/ipc/worktree-change-invalidators.tssrc/main/ipc/worktree-remote.tssrc/main/ipc/worktrees.test.tssrc/main/ipc/worktrees.tssrc/main/window/attach-main-window-services.test.tssrc/main/window/attach-main-window-services.ts
Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
Summary
Reduces repeated git subprocess churn seen in crash report
a219317b-4f81-42cb-89dd-872657f4ae21by:worktrees:listDetectedrawGitWorktreeInfo[]scans for 5 seconds with in-flight coalescingThe cache intentionally skips SSH/folder worktree listing for safety; SSH-relevant tracked-upstream behavior remains on the existing provider path and is covered by focused tests.
Crash Evidence / Classification
Crash classification: likely renderer OOM pressure from git polling/subprocess churn with retained trace/error payloads.
Evidence from the downloaded diagnostics:
2222MB / 2995MBto the3586MBV8 limit before renderer exit code 510,369git.execspans9,934git worktreeprobes112failedgit remote get-url upstreamprobes141no-upstream branch failuresThis change removes the dominant measured repeated worktree-list probe pattern and the smaller stable-negative tracked-upstream fallback probes.
Design Review
tmp/git-upstream-probe-memory-crash-design.md(not committed)git worktreechurn.Implementation / Deviations
Completeness Verification
worktrees:createflow invalidation test and a direct host/WSL cache identity regression.Code Review
Two independent reviewers in the same round returned clean.
Reviewer A:
origin/mainReviewer B:
Brennan Test Changes
Verdict:
landValidation matrix covered:
worktrees:listDetectedlocal cache: repeated calls, concurrent calls, TTL expiry, metadata rebuild during cache hit, mutation invalidation, stale in-flight scan side effectsworktrees:changedAccepted gap:
pnpm run lintwas reported by the validation subagent as failing in repo-global localization verification for unrelatedTerminalInteractionSection.tsxkeys outside this diff. Changed-file lint passed.Tests
pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/worktrees.test.ts -t "detected"pnpm exec vitest run --config config/vitest.config.ts src/main/github/client.test.ts -t "tracked[- ]upstream"pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/worktrees.test.ts src/main/window/attach-main-window-services.test.ts src/main/github/client.test.ts src/main/git/status-upstream-probe-churn.test.ts(248 passedafter CodeRabbit fixes)pnpm run typecheck:nodepnpm exec oxlint src/main/ipc/worktree-change-invalidators.ts src/main/ipc/worktrees.ts src/main/ipc/worktree-remote.ts src/main/ipc/worktrees.test.ts src/main/window/attach-main-window-services.ts src/main/window/attach-main-window-services.test.ts src/main/github/client.ts src/main/github/client.test.tsgit diff --checkverifypassedPost-PR Stabilization
Complete.
verifycheck passed.Non-actionable note: CodeRabbit's pre-merge summary still shows a generic docstring-coverage warning; it did not produce actionable review comments after the final commit.
Residual Risk