Skip to content

Make local Git metadata observation event-driven - #16352

Closed
nwparker wants to merge 16 commits into
mainfrom
perf/event-driven-git-metadata
Closed

nwparker wants to merge 16 commits into
mainfrom
perf/event-driven-git-metadata

Conversation

@nwparker

@nwparker nwparker commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​887 $\color{#cf222e}{\Huge{\mathbf{−}}}$​303 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​584
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1147 $\color{#cf222e}{\Huge{\mathbf{−}}}$​507 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​640

Problem

Local Git-common metadata observation repeatedly scanned every linked worktree even while idle. With E linked worktrees, the recurring path was approximately:

6 * E linked-worktree stats + 6 primary metadata stats + one worktrees listing every poll interval

That background work competes with renderer updates, Git subprocesses, and worktree interaction. The live responsiveness incident showed the need to remove the linked-worktree scan from the healthy path without changing remote behavior.

Design

The full design is in docs/reference/git-metadata-event-driven-refresh.md.

Healthy local observation now follows:

native event
  -> path classification
  -> existing targeted notification pipeline
  -> bounded downstream refresh

Fallback remains:

watcher failure / interruption / unsupported platform
  -> bounded reconciliation poll
  -> targeted or conservative refresh

The change deliberately does not introduce a new remote protocol, local watcher for SSH/WSL paths, or renderer subscription model.

Implementation

Linked worktree metadata

  • Extends the existing crash-isolated native watcher from macOS to Linux and Windows.
  • Watches only <common>/.git/worktrees.
  • Pins the Windows backend explicitly.
  • Preserves root deletion/recreation handling.
  • Preserves watcher-child interruption handling.
  • Preserves crash-fuse and bounded polling fallback behavior.
  • Keeps unsupported local platforms on the existing full poller.

Primary checkout metadata

Adds a shallow watcher mode to the existing watcher-child protocol:

{
  mode: 'shallow',
  include: ['HEAD', 'packed-refs', 'index', 'config', 'config.worktree', 'logs/HEAD']
}

The shallow implementation:

  • watches only allowlisted files;
  • watches the nested logs directory separately when present;
  • maps rename/change notifications to conservative update events;
  • remains isolated from the Electron main process;
  • stops forwarding after unsubscribe;
  • reports watcher errors through the existing host protocol.

The healthy local primary path no longer stats the six primary files every poll. Selected upstream ref paths remain on a bounded targeted stat poll. If the shallow watcher fails, the six-file poll is restored.

Safety and compatibility

  • No RPC or remote wire changes.
  • SSH and WSL observation remains provider-owned.
  • Folder-workspace behavior is unchanged.
  • Existing event delivery limits and overflow signaling remain in use.
  • Existing hidden-window parking remains in use for fallback and selected-ref polling.
  • Existing recursive watcher subscriptions continue to use the same child lifecycle and recovery machinery.

Verification

Passed:

pnpm exec vitest run --config config/vitest.config.ts \
  src/main/ipc/parcel-watcher-shallow-subscription.test.ts \
  src/main/ipc/worktree-git-common-watch.test.ts \
  src/main/ipc/parcel-watcher-process-entry.test.ts \
  src/main/ipc/parcel-watcher-process.test.ts \
  src/main/ipc/parcel-watcher-event-delivery.test.ts

5 test files passed
84 tests passed

pnpm run typecheck:node

Also passed:

git diff --check -- src/main/ipc

The focused tests cover:

  • Linux and Windows platform dispatch;
  • explicit Windows backend selection;
  • shallow top-level and nested metadata filtering;
  • no forwarding after unsubscribe;
  • child-process shallow mode without recursive native subscription;
  • primary metadata stat elimination on the healthy path;
  • watcher error and root recreation behavior;
  • crash-fuse fallback;
  • hidden-window lifecycle behavior.

Validation gap

A real native filesystem-event smoke test still needs to run on physical macOS, Linux, and Windows hosts. This environment did not deliver reliable Darwin node:fs.watch events, so the new shallow behavior is covered deterministically through mocked native callbacks and watcher-child protocol tests.

Required follow-up validation before merge:

  1. Linux inotify watch-count test with many linked worktrees.
  2. Windows active git worktree prune test.
  3. Packaged Electron watcher-child startup test.
  4. Native event delivery smoke test on all three local platforms.

Prior-art references

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 3 minutes.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7067c469-9613-4689-90b0-211e9d1a79d7

📥 Commits

Reviewing files that changed from the base of the PR and between dd8ec43 and 3a31b9e.

📒 Files selected for processing (13)
  • src/main/ipc/folder-repo-git-upgrade.ts
  • src/main/ipc/git-metadata-poll-scheduler.test.ts
  • src/main/ipc/git-metadata-poll-scheduler.ts
  • src/main/ipc/worktree-base-directory-poller.test.ts
  • src/main/ipc/worktree-base-directory-poller.ts
  • src/main/ipc/worktree-git-common-entry-snapshot.ts
  • src/main/ipc/worktree-git-common-narrow-watch.ts
  • src/main/ipc/worktree-git-common-polling-gate.test.ts
  • src/main/ipc/worktree-git-common-polling.ts
  • src/main/ipc/worktree-git-common-primary-polling.ts
  • src/main/ipc/worktree-git-common-watch-reconciliation.ts
  • src/main/ipc/worktree-git-common-watch.test.ts
  • src/main/ipc/worktree-git-common-watch.ts
📝 Walkthrough

Walkthrough

The change adds shallow native filesystem subscriptions with included path patterns and asynchronous disposal. The watcher process selects shallow or recursive subscriptions and forwards events and errors over IPC. Primary Git metadata now uses a shallow watcher with status-reference polling and fallback polling. Local macOS, Linux, and Windows worktree watching uses separate narrow and primary subscriptions, while unsupported platforms retain full polling. Tests cover watcher events, platform options, recovery, visibility, interruption, and disposal.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, design, implementation, safety considerations, testing, and validation gap. However, it does not follow the repository template and omits the required linked issu… Add the required template sections. Include a valid issue reference after "Fixes #". Add N/A with a reason under Visual Proof if there is no visual change. Complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes,…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 9 files. 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 summarizes the main change: local Git metadata observation now uses an event-driven approach.
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.
Full details: Description check

Explanation

The description explains the problem, design, implementation, safety considerations, testing, and validation gap. However, it does not follow the repository template and omits the required linked issue, Visual Proof entry, checklist, and several required section headings.

Resolution

Add the required template sections. Include a valid issue reference after "Fixes #". Add N/A with a reason under Visual Proof if there is no visual change. Complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.

✨ 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 force-pushed the perf/event-driven-git-metadata branch from d2d44c2 to dd8ec43 Compare August 25, 2026 02:49

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/main/ipc/worktree-git-common-watch.test.ts (1)

181-196: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add and run native watcher integration tests before release.

The unit tests mock subscribeViaWatcherProcess and @parcel/watcher. Exercise real filesystem mutations through the watcher child on macOS, Linux, and Windows.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0aee0fea-25f3-442f-8f9c-80b9fe909dd9

📥 Commits

Reviewing files that changed from the base of the PR and between 5c116b6 and dd8ec43.

📒 Files selected for processing (9)
  • src/main/ipc/parcel-watcher-process-entry.test.ts
  • src/main/ipc/parcel-watcher-process-entry.ts
  • src/main/ipc/parcel-watcher-process-protocol.ts
  • src/main/ipc/parcel-watcher-shallow-subscription.test.ts
  • src/main/ipc/parcel-watcher-shallow-subscription.ts
  • src/main/ipc/worktree-git-common-primary-polling.ts
  • src/main/ipc/worktree-git-common-primary-watch.ts
  • src/main/ipc/worktree-git-common-watch.test.ts
  • src/main/ipc/worktree-git-common-watch.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

@nwparker

Copy link
Copy Markdown
Contributor Author

Closing as superseded after checking current main.

Superseded by merged #16404, which delivered event-driven local Git metadata observation without a scheduler. Main already uses the native watcher, fallback, and reconciliation approach; this branch's separate polling scheduler is an alternative implementation of work already delivered.

Closing this PR only; its branch is being retained.

@nwparker nwparker closed this Oct 14, 2026
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