Repository navigation
perf: coalesce cancellable git status reads - #11691
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe change adds keyed sharing for concurrent Git status reads. Each caller receives an independent lease and can cancel without affecting other active callers. The shared Git operation aborts when its final lease cancels. Pre-aborted callers do not start work. Invalidation separates reads across mutations. Status tests cover cancellation, option-based isolation, mutation fencing, cleanup, and streamed abort signals. 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 |
Greptile SummaryThis PR replaces the simple
Confidence Score: 5/5The change is safe to merge. The lease-owner correctly manages shared in-flight state, the signal abort only fires when all live leases have cancelled, and the entry identity check prevents post-invalidation interference. The core release() closure is airtight: the active guard prevents double-release, liveLeases tracks exactly the number of non-released callers, and the this.entries.get(key) === entry identity check correctly isolates post-invalidation entries. The ordering guarantee — settle is registered before any createLease callback on the same promise — means entry.settled is always true by the time per-lease success handlers run, making the abort guard in release() reliable. The one unreachable branch (getAbortReason fallback at line 14) is harmless dead code. No correctness issues were found. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/git/git-status-read-lease-owner.ts | New generic lease-owner class; logic for liveLeases counting, identity-checked abort/eviction, and settled-flag ordering is correct. The getAbortReason fallback (line 14) is unreachable in any conformant AbortSignal implementation but is harmless. |
| src/main/git/status.ts | getStatus simplified to a single lease() call; signal-bypass branch removed; getStatusReadKey migrated to stableInFlightKey for correct array serialisation. The sharedSignal is correctly threaded into runGetStatus and then into gitStreamStdout. |
| src/main/git/git-status-read-lease-owner.test.ts | Unit tests cover all six advertised scenarios (partial cancel, full cancel, pre-aborted, cleanup, invalidation, no-cache-after-settle) with explicit timing control via deferred promises. |
| src/main/git/status.test.ts | Six new integration tests added; benchmark extended to cover both signalled and unsignalled bursts; gitStreamOptionsMock correctly captures the shared AbortSignal for inspection. Existing tests updated to expect objectContaining for gitExecFileAsync call options. |
Sequence Diagram
sequenceDiagram
participant C1 as Caller 1 (signal1)
participant C2 as Caller 2 (signal2)
participant LO as GitStatusReadLeaseOwner
participant GS as gitStreamStdout (shared signal)
C1->>LO: lease(key, signal1, load)
LO->>GS: load(sharedSignal) starts git status
LO-->>C1: "lease promise 1 liveLeases=1"
C2->>LO: lease(key, signal2, load)
Note over LO: entry exists, joins, liveLeases=2
LO-->>C2: lease promise 2
C1->>LO: signal1.abort(reason1)
LO->>LO: release reason1 liveLeases to 1 no abort
LO-->>C1: reject(reason1)
Note over GS: sharedSignal still live
GS-->>LO: git status resolves entry.promise settles
Note over LO: settle entry.settled=true remove from map
LO-->>C2: resolve(result)
Note over LO: mutation calls invalidate
LO->>LO: entries.clear
C1->>LO: lease(key, signal3, load)
LO->>GS: load newSharedSignal fresh git status
LO-->>C1: new lease promise
Reviews (1): Last reviewed commit: "perf: coalesce cancellable git status re..." | Re-trigger Greptile
Summary
Coalesce concurrent native and WSL Git status reads even when callers provide distinct cancellation signals.
Each caller receives an independent cancellable lease. The underlying Git operation is aborted only after its last live caller cancels, and mutations invalidate joinability without disrupting already-issued callers.
The focused concurrency test measures 10 concurrent, separately signalled
getStatuscalls collapsing to 1 physicalgit statusread.Screenshots
No visual change.
Testing
pnpm lint(targetedoxlint --deny-warningspassed)pnpm typecheck(pnpm run typecheck:node)pnpm test(12 related status suites, 157 tests passed)pnpm build(pnpm run build:electron-vite)Also passed targeted formatting, max-lines ratchet, and
git diff --check.AI Review Report
Reviewed cancellation races, last-lease abort, pre-aborted callers, failure cleanup, settled-read eviction, mutation invalidation, cache-key isolation, and stale-entry fencing. No unresolved findings.
Cross-platform review confirmed there are no changed Git commands, shortcuts, labels, paths, shell syntax, or Electron platform branches. Worktree paths remain opaque key values, WSL distro is part of the key, and folder workspaces remain supported.
Security Audit
No new IPC, command, path, authentication, secret, dependency, or persistence surface is introduced. The bounded stable key prevents retaining arbitrarily large raw option keys, caller-provided abort reasons are propagated only to the shared in-process operation, and entries are removed after success, failure, cancellation, or invalidation.
Notes
This is the second focused extraction from draft PR #11539. It is independent of PR #11687 and based directly on
main.