Skip to content

perf: coalesce cancellable git status reads - #11691

Merged
OrcaWin merged 1 commit into
stablyai:mainfrom
nwparker:perf-coalesce-git-status
Jul 31, 2026
Merged

OrcaWin merged 1 commit into
stablyai:mainfrom
nwparker:perf-coalesce-git-status

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

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 getStatus calls collapsing to 1 physical git status read.

Screenshots

No visual change.

Testing

  • pnpm lint (targeted oxlint --deny-warnings passed)
  • pnpm typecheck (pnpm run typecheck:node)
  • pnpm test (12 related status suites, 157 tests passed)
  • pnpm build (pnpm run build:electron-vite)
  • Added or updated high-quality tests that would catch regressions

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.

@OrcaWin
OrcaWin marked this pull request as ready for review July 31, 2026 05:55
@OrcaWin
OrcaWin merged commit d5c4d95 into stablyai:main Jul 31, 2026
42 checks passed
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 19977086-2500-4671-afe1-c858a745554b

📥 Commits

Reviewing files that changed from the base of the PR and between a2d0e77 and fb102a8.

📒 Files selected for processing (4)
  • src/main/git/git-status-read-lease-owner.test.ts
  • src/main/git/git-status-read-lease-owner.ts
  • src/main/git/status.test.ts
  • src/main/git/status.ts

📝 Walkthrough

Walkthrough

The 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces the simple Map<string, Promise<GitStatusResult>> in-flight deduplication with a new GitStatusReadLeaseOwner class that issues per-caller cancellable leases over a shared underlying read. Previously, any caller providing a signal bypassed deduplication entirely; now all callers — signalled or not — coalesce onto one physical git status run, and the shared process is only aborted when every live lease has cancelled.

  • git-status-read-lease-owner.ts: New generic lease-management class. Each lease() call joins or starts a shared operation keyed by a string. The release() closure tracks per-caller liveness via an active flag, decrements liveLeases, and aborts the shared AbortController only when all leases have cancelled and the operation hasn't settled. invalidate() clears the map; identity checks (this.entries.get(key) === entry) prevent post-invalidation interference.
  • status.ts: getStatus is simplified to a single statusReadLeaseOwner.lease(...) call; the old signal-bypass branch is removed. getStatusReadKey migrates from a manual join('\\0') to stableInFlightKey (JSON serialisation with SHA-256 fallback for large keys), which fixes array comparison correctness for sharedLinkPaths.
  • Tests: Six new integration tests in status.test.ts cover signal sharing, last-lease abort, pre-aborted fast-rejection, cache-key isolation, and mutation fencing across three timing phases (before/during/after mutation).

Confidence Score: 5/5

The 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.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "perf: coalesce cancellable git status re..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants