Skip to content

Defer assisted-commit Git metadata probes outside active runs - #23222

Merged
sergiou87 merged 11 commits into
developmentfrom
fix-assisted-commit-mutation-overhead
Nov 26, 2026
Merged

sergiou87 merged 11 commits into
developmentfrom
fix-assisted-commit-mutation-overhead

Conversation

@sergiou87

@sergiou87 sergiou87 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #23219

Description

  • Avoid spawning Copilot assisted-commit Git metadata probes (rev-parse --absolute-git-dir, rev-parse --git-common-dir, rev-parse --git-path objects, count-objects -v) and local-clone worktree probes outside of active Copilot-assisted commit runs:
    • Ordinary mutations (AppStore.withAssistedCommitMutationResources, repository-operation.ts, coordinator.ts): When no assisted-commit lease, protection, or admission check is active (hasActiveAssistedCommitProtection() === false), ordinary mutations only reserve their canonical working-directory path without invoking Git. If an assisted-commit run later starts while an ordinary mutation is still in flight, assisted admission (prepare, create, and acquireAssistedCommitGitLease) lazily resolves the active mutation's Git metadata paths to detect shared common directories and alternate object stores. Also short-circuit in-progress checks in withIsCommitting, withPushPullFetch, and withIsGeneratingCommitMessage before entering resource reservation.
    • Status loads (AssistedCommitReaders.loadStatusCore): Skip getAssistedCommitProtectedPaths unless an assisted-commit run or assisted-commit protection is active.
    • Local / file:// clones (git/clone.ts, repository-operation.ts): Skip getRepositoryType, getAssistedCommitProtectedPaths, and listWorktrees before cloning when no assisted-commit protection is active. The clone source remains tracked as an active read operation and is lazily discovered and drained if an assisted-commit lease is acquired on a shared peer worktree while the clone is in flight; when protection is already active, multi-path read admission uses withRepositoryGitReads to wait for leases atomically without deadlocking.
  • Updated docs/technical/assisted-commit-runs.md and added unit tests covering zero assisted-commit Git metadata commands during ordinary status/commit/branch/local-clone operations as well as lazy peer-worktree coordination.

Performance Benchmark (No Active Assisted Commit Run)

macOS

Measured on macOS (Darwin 25.6.0, Apple M3 Max, Node v24.22.1, bundled Git 2.56.1) comparing development (993bb4a319) vs. this branch (4cf2916963), using real AppStore + GitStore + dugite Git against a local repo with a bare remote (manual commit mode, pushAfterCommit: false, 1 warmup + 10 measured iterations per operation):

Operation Git Subprocesses (Before → After) assistedCommit* Calls Time to UI Busy (Median, Before → After) Total Duration Median (Before → After) Total Duration Mean (Before → After)
Commit (_commitIncludedChanges)¹ 14 → 6 (-57.1%) 8 → 0 21.13 ms → 0.16 ms (-99.2%) 146.75 ms → 100.82 ms (-31.3%) 144.27 ms → 105.46 ms (-26.9%)
Fetch (_fetch, user-initiated) 25 → 17 (-32.0%) 8 → 0 23.92 ms → 0.37 ms (-98.4%) 249.20 ms → 218.75 ms (-12.2%) 246.20 ms → 218.80 ms (-11.1%)
Pull (_pull, 1 remote commit) 28 → 20 (-28.6%) 8 → 0 28.16 ms → 0.55 ms (-98.1%) 646.04 ms → 581.73 ms (-10.0%) 615.48 ms → 589.94 ms (-4.1%)
Push (_push, 1 local commit) 29 → 17 (-41.4%) 12 → 0 54.45 ms → 0.53 ms (-99.0%) 516.61 ms → 422.33 ms (-18.2%) 480.01 ms → 423.90 ms (-11.7%)
Load status (_loadStatus) 6 → 2 (-66.7%) 4 → 0 N/A 41.55 ms → 12.99 ms (-68.7%) 39.86 ms → 12.88 ms (-67.7%)

¹ Unawaited background _refreshRepositoryAfterCommit also dropped from 19 → 15 Git calls (4 → 0 assistedCommit* calls), median 87.98 ms → 60.70 ms (-31.0%) (total commit + background refresh: 33 → 21 Git calls).

Windows

Measured on Windows (Windows 11 Pro Insider Preview 10.0.26340 Build 26340, Apple Silicon ARM64 VM, Node v24.15.0, bundled Git 2.56.1.windows.1) comparing development (993bb4a319) vs. this branch (0fc4691694), using the same methodology (manual commit mode, pushAfterCommit: false, 1 warmup + 10 measured iterations per operation):

Operation Git Subprocesses (Before → After) assistedCommit* Calls Time to UI Busy (Median, Before → After) Total Duration Median (Before → After) Total Duration Mean (Before → After)
Commit (_commitIncludedChanges)¹ 14 → 6 (-57.1%) 8 → 0 143.48 ms → 0.75 ms (-99.5%) 577.77 ms → 310.60 ms (-46.2%) 613.20 ms → 342.37 ms (-44.2%)
Fetch (_fetch, user-initiated) 25 → 17 (-32.0%) 8 → 0 151.04 ms → 1.04 ms (-99.3%) 1019.69 ms → 718.60 ms (-29.5%) 1018.09 ms → 711.78 ms (-30.1%)
Pull (_pull, 1 remote commit) 28 → 20 (-28.6%) 8 → 0 138.56 ms → 0.99 ms (-99.3%) 2353.53 ms → 2059.48 ms (-12.5%) 2388.82 ms → 2088.88 ms (-12.6%)
Push (_push, 1 local commit) 29 → 17 (-41.4%) 12 → 0 278.15 ms → 1.04 ms (-99.6%) 1304.03 ms → 876.30 ms (-32.8%) 1349.32 ms → 879.01 ms (-34.9%)
Load status (_loadStatus) 5 → 1 (-80.0%) 4 → 0 N/A 172.17 ms → 37.48 ms (-78.2%) 174.79 ms → 37.51 ms (-78.5%)

¹ Unawaited background _refreshRepositoryAfterCommit also dropped from 19 → 15 Git calls (4 → 0 assistedCommit* calls), median 576.27 ms → 443.80 ms (-23.0%) (total commit + background refresh: 33 → 21 Git calls, -36.4%).

On Windows (higher git.exe spawn + Defender overhead) and larger repositories (slower git count-objects -v), eliminating 4–12 Git subprocesses before UI busy state is emitted yields proportionally larger latency savings.

Validation (at 4cf29169632e20c9fe97c5ec4619650a12c465cb)

  • npm test -- app/test/unit/git/repository-operation-test.ts app/test/unit/git/clone-test.ts — passed (135/135).
  • npm test -- app/test/unit/*assisted* app/test/unit/git/*assisted* app/test/unit/stores/*assisted* app/test/unit/ui/*assisted* app/test/unit/stores/commit-auto-push-test.ts — 596/597 passed on initial run (1 transient ENOENT on .git/objects/maintenance.lock in app/test/unit/git/assisted-commit-execution-test.ts), followed by npm test -- app/test/unit/git/assisted-commit-execution-test.ts — passed (21/21).
  • npx tsc --noEmit — passed.
  • npm run lint:src — passed.
  • npm run markdownlint — passed.
  • Live unpackaged Electron build (npm run test:e2e:build:unpackaged) driven via Playwright CDP against a local mock OpenAI BYOK server verified all Copilot-assisted commit workflows (mode switching/persistence across repo switches & restart, single commit & unselected preservation, multi-file and intra-file hunk splitting, uncertain-boundaries fallback, repo & global custom instructions, commit options including sign-off/bypass hooks/empty commit, hook failure ignore/decline rollback, error stop, mid-run selected/unselected file edits, cancellation during analysis and mid-commit with rollback, push-after-commit + push failure retry) plus manual commit + push — all passed.
  • Manual testing.
  • Adversarial review with different models.

Manual Testing

  1. Open a repository in manual commit mode (no Copilot-assisted commit run active).
  2. Click Commit, Fetch, Pull, and Push — verify the button immediately enters its in-progress state with no pre-operation delay and no assistedCommitMetadataDirectory / assistedCommitAlternateObjectDirectories entries appear in Desktop's logs (Help > Show Logs).
  3. With two linked worktrees of the same repository, start a Copilot-assisted commit run in one worktree and verify competing mutations in the peer worktree are still rejected while the run is active.

Screenshots

N/A — no UI layout or visual changes.

Team-authored review

Evidence: See the Performance Benchmark and Validation sections above (covering 4cf29169632e20c9fe97c5ec4619650a12c465cb). Artifacts/screenshots are not applicable because this change does not alter UI layout.

Review path: lightweight review.

Release notes

Notes: [Fixed] Eliminate input delay before committing, fetching, pulling, and pushing

Avoid spawning four sequential Git metadata commands (rev-parse and
count-objects) before every ordinary repository mutation when no Copilot
assisted commit run or protection is active.

When no assisted commit protection is active, ordinary mutations reserve
their working-directory path without invoking Git. If an assisted commit
run begins while an ordinary mutation is still in flight, assisted
admission lazily resolves the active mutation's Git metadata paths to
detect shared common directories and alternate object stores before
admitting the run or acquiring a lease.

Also short-circuit busy checks in withIsCommitting, withPushPullFetch,
and withIsGeneratingCommitMessage before entering resource reservation.
Only run getAssistedCommitProtectedPaths in AssistedCommitReaders.loadStatusCore
when an assisted commit run or assisted-commit protection is active.

Previously every status refresh (app startup, focus, file changes, and
post-operation refreshes) spawned four sequential Git processes even
when no assisted commit run existed.
…tive

Skip getRepositoryType, getAssistedCommitProtectedPaths, and listWorktrees
before local and file:// clones when no assisted commit protection or lease
is active.

The clone source is still tracked as an active read operation so that any
assisted commit lease acquired while the clone is in flight lazily discovers
shared Git metadata and drains the clone before proceeding. When assisted
commit protection is already active, multi-path read admission waits for
leases atomically via withRepositoryGitReads to avoid deadlocks.
Skip missing candidate paths before probing Git metadata during lazy
active-repository resolution, document the lazy coordination policy,
and add unit tests covering:

- Zero assisted-commit Git metadata commands during ordinary status,
  commit, branch, and local clone operations when no run is active
- Lazy resolution of in-flight peer linked worktree mutations when an
  assisted commit run tries to start
- Rejection of starting a second assisted commit run on a peer linked
  worktree while another run is active
Copilot AI balanced review requested due to automatic review settings November 24, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical registry-lifetime races can hide active reads or leases from later operations, and suppressed metadata-discovery failures can let conflicting operations bypass overlap protection.

4 open issues
What changed in this PR

Reduces the input delay reported in #23219 by deferring GitHub Desktop’s assisted-commit Git metadata probes until coordination is needed.

Changes:

  • Adds fast paths for ordinary mutations, status loads, and local clones when no assisted-commit protection is active.
  • Introduces lazy shared-resource discovery and multi-path read coordination for assisted-commit admission.
  • Adds regression tests and documents the deferred-discovery behavior.
File Description
docs/​technical/​assisted-commit-runs.md Documents skipped probes and lazy resource discovery.
app/​test/​unit/​git/​repository-operation-test.ts Tests probe-free ordinary operations and peer-worktree admission.
app/​test/​unit/​git/​clone-test.ts Tests local cloning without assisted-commit source probes.
app/​src/​lib/​stores/​app-store.ts Adds lightweight mutation reservations and early busy checks.
app/​src/​lib/​git/​repository-operation.ts Implements lazy overlap discovery and multi-path read admission.
app/​src/​lib/​git/​clone.ts Defers source discovery and coordinates reads across shared resources.
app/​src/​lib/​assisted-commit/​readers.ts Skips metadata discovery during unprotected status loads.
app/​src/​lib/​assisted-commit/​coordinator.ts Adds asynchronous overlap checks and guards concurrent run starts.

Review effort: Balanced

Comment thread app/src/lib/git/repository-operation.ts Resolved
Comment thread app/src/lib/git/repository-operation.ts Resolved
Comment thread app/src/lib/git/repository-operation.ts Resolved
Review feedback: I1 (adversarial review F1; #23222 (comment)).

acquireAssistedCommitGitLease fetched its IRepositoryOperations registry
record before awaiting resolveUnresolvedMutationRepositories and
findOverlappingActiveRepositories, without pinning the record against
forget(). If an in-flight reader on the target repository finished during
those awaits, forget() deleted the record from the registry and the lease
was installed on a detached object invisible to later lookups, causing
lease.run mutations to fail hasAccess() and reject themselves as busy.
This PR exacerbated a narrow microtask race on development by introducing
multi-subprocess Git discovery awaits before lease installation.

Add a reference-counted pin (pins) on IRepositoryOperations checked by
forget(), and obtain the live registry entry via pinRepositoryOperations
in acquireAssistedCommitGitLease, unpinning in finally after the lease is
installed or acquisition fails. Add a regression test verifying that a
reader completing during unrelated discovery does not detach the lease.

Validation: npx eslint --rulesdir eslint-rules and npm test -- app/test/unit/git/repository-operation-test.ts passed (45/45).
…path read waits

Review feedback: I2 (adversarial review F1; #23222 (comment)).

withRepositoryGitReads collected IRepositoryOperations entries without
pinning them while resolving later paths or waiting for an active lease
to release. If an earlier path's last operation completed during that
wait, forget() removed the entry from the registry and the new read
operation was registered on a detached object invisible to subsequent
leases. This race was introduced by this PR's new withRepositoryGitReads
helper.

Pin every unique repository entry via pinRepositoryOperations for the
full duration of multi-path admission and execution, releasing all pins
in finally after operations settle. Add a regression test verifying that
a later lease on an earlier path still drains the multi-path read after
an unrelated prior reader finishes during a lease wait.

Validation: npx eslint --rulesdir eslint-rules and npm test -- app/test/unit/git/repository-operation-test.ts passed (46/46).
….git suffix fallback

Review feedback: I5 (adversarial review F4; #23222 (comment)).

resolveActiveRepositoryResourcePaths previously caught all errors from
realpath and getAssistedCommitProtectedPaths and returned an empty list,
after which resolveUnresolvedMutationRepositories deleted the unresolved
mutation entry. That allowed transient Git execution, alternate-parsing,
or filesystem failures to fail open instead of blocking overlapping
admission. It also tried a sibling <path>.git fallback for all callers
rather than only local clone sources. Both behaviors were introduced by
this PR.

Only suppress verified ENOENT (from realpath) and DugiteError.NotAGitRepository
(from getAssistedCommitProtectedPaths); propagate all other errors so
assisted admission fails closed and retains the unresolved mutation entry.
Restrict the .git-suffix candidate fallback to local clone source reads
tagged with allowGitSuffix. Add regression tests for both fail-closed
error propagation and sibling .git non-fallback.

Validation: npx eslint --rulesdir eslint-rules and npm test -- app/test/unit/git/repository-operation-test.ts app/test/unit/git/clone-test.ts passed (139/139).
…ree UI state

Review feedback: I3 (adversarial review F2).

Skipping idle status metadata probes left previously visited external
peer linked worktrees without repositoryResourcePaths entries when an
assisted commit run started in another worktree. That caused two gaps
exacerbated by this PR:

1. Unwrapped mutations invoking withRepositoryGitOperation(path, 'mutation')
   directly (such as GitStore.performFailableOperation for upstream remote
   setup or branch pruning, and worktree delete/move) only checked cached
   paths and could write into shared Git metadata while an assisted run
   protected it.
2. Synchronous UI guards (isRepositoryAffectedByAssistedCommit) left peer
   worktree controls enabled until an asynchronous post-switch status
   refresh and metadata probe completed.

Close both gaps with zero idle Git overhead:
- In withRepositoryGitOperation, pin the repository record and lazily call
  isRepositoryOverlappingAssistedCommit when kind === 'mutation' and an
  assisted commit resource lock is active.
- In getAssistedCommitProtectedResources (which only runs during active
  assisted commit runs/protection), record peer worktree common-dir paths
  from git worktree list --porcelain -z, and remember realpath aliases in
  canonicalPathAliases so synchronous UI checks recognize peer worktrees
  even through symlinked roots (such as /var -> /private/var on macOS).

Add a regression test covering synchronous peer UI detection, unwrapped
peer worktree mutations, and unwrapped alternate-sharing clone mutations.

Validation: npx eslint --rulesdir eslint-rules and npm test -- app/test/unit/git/repository-operation-test.ts passed (49/49).
… discovery

Review feedback: I4 (adversarial review F3; #23222 (comment)).

AssistedCommitCoordinator.prepare and un-prepared create previously
awaited hasOverlappingRepositoryGitMutation and
isRepositoryOverlappingAssistedCommit before reading initialState,
account, modelSelection, providerDefinition, providerRevision, and
freezing the request. If an unrelated repository triggered asynchronous
lazy discovery and the user changed model/provider or switched branches
during that wait, preparation silently captured the replacement values
instead of binding the first click. This regression was introduced by
this PR.

Capture initialState, account, modelSelection, providerDefinition,
providerRevision, and the frozen request synchronously before any
asynchronous lazy discovery awaits in both prepare and create, while
keeping synchronous fast busy checks ahead of capture and re-checking
availability after discovery completes. Add a regression test verifying
that changing the assisted model during prepare discovery preserves the
first-click model.

Validation: npx eslint --rulesdir eslint-rules and npm test -- app/test/unit/git/repository-operation-test.ts app/test/unit/assisted-commit-coordinator-test.ts passed (52/52).
@sergiou87
sergiou87 marked this pull request as ready for review November 24, 2026 13:03
@sergiou87
sergiou87 requested a review from a team as a code owner November 24, 2026 13:03
@sergiou87
sergiou87 requested a review from babakks November 24, 2026 13:03
@sergiou87
sergiou87 requested review from niik and tidy-dev November 24, 2026 13:19
tidy-dev
tidy-dev previously approved these changes Nov 24, 2026
@sergiou87
sergiou87 merged commit 189559a into development Nov 26, 2026
16 checks passed
@sergiou87
sergiou87 deleted the fix-assisted-commit-mutation-overhead branch November 26, 2026 08:48
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.

Input delay on GitHub desktop

5 participants