Skip to content

perf: coalesce git upstream status reads - #11697

Merged
nwparker merged 3 commits into
mainfrom
nwparker/perf-coalesce-git-upstream
Aug 16, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/perf-coalesce-git-upstream

Conversation

@nwparker

@nwparker nwparker commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 +465 −1 +464
Prod 4 +81 −4 +77

Summary

Coalesce concurrent upstream-status reads across native, WSL, and SSH execution.

Identical in-flight reads share work by execution host, worktree, and complete push-target identity. Git mutations fence joins before and after execution, while completed or failed reads are never retained as a result cache.

Focused concurrency measurements:

  • Native/WSL: 10 callers, each requiring a four-command status chain, collapse from 40 physical Git calls to 4.
  • SSH: 10 callers collapse from 10 git.upstreamStatus RPCs to 1.

Depends on draft PR #11696 and, transitively, draft PR #11691. This PR is stacked so its GitHub diff contains only the upstream-status change.

Screenshots

No visual change.

Testing

  • pnpm lint (targeted oxlint --deny-warnings passed)
  • pnpm typecheck (pnpm run typecheck:node)
  • pnpm test (5 focused suites, 221 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 execution-host isolation, every GitPushTarget field, success/error eviction, bounded in-flight retention, native/WSL/SSH mutation fencing, provider-instance isolation, and existing error normalization. No unresolved findings.

Cross-platform and remote-workspace review confirmed that native paths remain opaque, WSL distros are distinct identities, SSH providers are per connection, and no Git commands or options changed. Git 2.25 compatibility is therefore unchanged.

Security Audit

No new IPC method, RPC method, command, path, authentication, secret, dependency, or persistence surface is introduced. Existing validated push-target fields form a bounded stable key, and entries are removed after settlement, timeout, or mutation invalidation.

Notes

This is the fourth and final focused extraction from draft PR #11539.


Readiness checklist review (2026-08-15)

Verdict: ship. No P0 or P1. One P1 was found and fixed in this branch; details below.

Fixed during review

P1 — the native/WSL path had no CI-enforced coalescing test. The only test exercising 10 concurrent native callers was gated behind ORCA_GIT_UPSTREAM_COALESCING_BENCH_JSON and returned early in CI. Verified by bypassing nativeAndWslGitUpstreamStatusReadOwner.read in getUpstreamStatus: all 22 tests in upstream.test.ts still passed. The remaining native tests are negative or count-neutral cases that hold with or without coalescing. Since the native path is the default for every local worktree, a later change to the key or the owner call would have gone undetected.

Added shares one physical read across ten identical native callers, which gates symbolic-ref behind a promise, fires ten concurrent reads, and asserts exactly one physical chain plus shared result identity — then asserts a second read after settle issues fresh Git work, so the lease cannot silently become a result cache. Re-running the same bypass now fails with expected [ …(10) ] to have a length of 1 but got 10.

P2 — invalidateGitUpstreamStatusReads was a test-only production export. status.ts reached into the singleton directly, leaving two ways to invalidate with only one used in production. invalidateGitReadCaches now calls the named function, matching the sibling invalidateGitBranchLineTotalInFlight pattern and keeping status.ts off the owner instance.

Verified clean

  • SSH / remote (01). A fresh SshGitProvider is constructed per connection establishment with a new mux and re-registered, so a reconnect cannot inherit a lease from a previous generation. Mutations fence reads before and after via runWithGitReadInvalidation.
  • Crash / retry / unbounded growth (02). InFlightPromiseDedupe caps at 128 entries, drops entries on settle, and clears its timer; overflow callers still run but cannot extend retention. A 30s max-in-flight timer prevents a hung read from pinning an entry. No unsafe casts introduced beyond the pre-existing as GitUpstreamStatus on the mux response.
  • Security (03). No new dependency, shell, eval, network sink, or persisted surface. Pure in-process memoization.
  • Functional correctness (05). GitPushTarget is exactly {remoteName, branchName, remoteUrl?, remoteCreated?}, matching the exhaustive destructure; the Record<string, never> spread makes a new field a compile error rather than a silently shared lease. All four getUpstreamStatus call sites (orca-runtime-git, hosted-review-creation, ipc/filesystem, provider contract) route through the coalesced entry point.
  • Backward compatibility (06). No persisted state, schema, migration, or wire change — git.upstreamStatus params are untouched. No mobile-facing surface touched.
  • Cross-platform (07). WSL distro is part of the execution identity, so a native and a WSL read of the same path never share a lease. Divergent path spellings on Windows produce distinct keys, which costs a missed coalescing opportunity and never a wrong result.

Residual risk

  • A signal passed in GitRuntimeOptions is dropped at the getUpstreamStatus boundary because the local GitExecOptions type does not declare it. This predates the PR — readUpstreamStatus never honoured a signal — so coalescing does not make cancellation any less effective than it is today.
  • Path-spelling differences (trailing slash, Windows drive-letter case) reduce coalescing effectiveness without affecting correctness.

Gates

tsc --noEmit clean · src/main/git + src/main/providers: 2,473 passed / 6 skipped · oxlint clean · oxfmt clean · audit:code-quality:type-aware exit 0 · check:max-lines-ratchet OK · check:reliability-gates OK (84 gates)

@nwparker
nwparker force-pushed the nwparker/perf-coalesce-ssh-status branch from 987a3d7 to b212c0b Compare August 15, 2026 09:08
@nwparker nwparker mentioned this pull request Aug 15, 2026
5 tasks done
@nwparker
nwparker force-pushed the nwparker/perf-coalesce-git-upstream branch from c8cf92d to f11110a Compare August 15, 2026 09:50
@nwparker
nwparker force-pushed the nwparker/perf-coalesce-ssh-status branch from b212c0b to 8474df1 Compare August 15, 2026 10:14
@nwparker
nwparker force-pushed the nwparker/perf-coalesce-git-upstream branch from f11110a to 2a6a2a9 Compare August 15, 2026 10:14
@nwparker
nwparker changed the base branch from nwparker/perf-coalesce-ssh-status to main August 15, 2026 11:28
The read owner imported the shared/types barrel deleted by #14447, and its
push-target key hand-enumerated fields, so a new GitPushTarget field would
silently share a lease between two different targets. The destructure now
fails to compile if a field is added. Lease tests moved into their own file
after #14728 split ssh-git-provider.test.ts.
@nwparker
nwparker force-pushed the nwparker/perf-coalesce-git-upstream branch from 2a6a2a9 to 073be35 Compare August 15, 2026 11:29
The 10-caller benchmark only runs under ORCA_GIT_UPSTREAM_COALESCING_BENCH_JSON,
so nothing in CI failed when the native/WSL lease was bypassed. Route status.ts
through invalidateGitUpstreamStatusReads so the export has a production caller.
@nwparker
nwparker marked this pull request as ready for review August 16, 2026 06:20
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a3b2738-0e5b-4b8b-99ed-1b8691b843e3

📥 Commits

Reviewing files that changed from the base of the PR and between c4e397b and 62e4aa4.

📒 Files selected for processing (7)
  • src/main/git/git-upstream-status-read-owner.test.ts
  • src/main/git/git-upstream-status-read-owner.ts
  • src/main/git/status.ts
  • src/main/git/upstream.test.ts
  • src/main/git/upstream.ts
  • src/main/providers/ssh-git-provider-upstream-lease.test.ts
  • src/main/providers/ssh-git-provider.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds shared keyed ownership for Git upstream-status reads. Native and WSL reads use execution identity, worktree path, and upstream-target fields as keys. SSH providers use provider-specific owners. Completed and rejected reads are removed, and invalidation fences reads across Git mutations. Tests cover deduplication, key isolation, recovery, invalidation, and command or RPC counts.

Merge Risk: ⚪ Minimal · up to 62e4a

This change coalesces identical in-flight Git upstream-status reads without changing Git commands, persisted state, or public interfaces. The current head is merge-ready after normal checks, with no actionable merge-blocking risk remaining.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed but omits the required Linked Issue and several template sections, and its visual proof does not use the required N/A format. Add a linked issue, restore the required template sections, and state exactly N/A with a brief reason for the lack of visual changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: coalescing Git upstream-status reads.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker merged commit eb3f683 into main Aug 16, 2026
91 checks passed
@nwparker
nwparker deleted the nwparker/perf-coalesce-git-upstream branch August 16, 2026 06:24
AmethystLiang pushed a commit that referenced this pull request Aug 17, 2026
* perf: coalesce git upstream status reads

* fix(git): repair upstream lease key imports and guard its field list

The read owner imported the shared/types barrel deleted by #14447, and its
push-target key hand-enumerated fields, so a new GitPushTarget field would
silently share a lease between two different targets. The destructure now
fails to compile if a field is added. Lease tests moved into their own file
after #14728 split ssh-git-provider.test.ts.

* test(git): enforce native upstream coalescing in CI

The 10-caller benchmark only runs under ORCA_GIT_UPSTREAM_COALESCING_BENCH_JSON,
so nothing in CI failed when the native/WSL lease was bypassed. Route status.ts
through invalidateGitUpstreamStatusReads so the export has a production caller.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* perf: coalesce git upstream status reads

* fix(git): repair upstream lease key imports and guard its field list

The read owner imported the shared/types barrel deleted by stablyai#14447, and its
push-target key hand-enumerated fields, so a new GitPushTarget field would
silently share a lease between two different targets. The destructure now
fails to compile if a field is added. Lease tests moved into their own file
after stablyai#14728 split ssh-git-provider.test.ts.

* test(git): enforce native upstream coalescing in CI

The 10-caller benchmark only runs under ORCA_GIT_UPSTREAM_COALESCING_BENCH_JSON,
so nothing in CI failed when the native/WSL lease was bypassed. Route status.ts
through invalidateGitUpstreamStatusReads so the export has a production caller.
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.

1 participant