perf(server): skip local git status on unchanged idle remote polls #40021
Closedonly21mil(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/40021/headopened View on GitHubonly21mil(GitHub profile, opens in a new tab) linked this to fix #39986
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -679,5 +685,11 @@679685 ? null680686 : yield* maybeAutoPull(cwd, remoteRead, options?.policyCwds ?? [cwd]);681687 if (pulled !== null) return pulled.remote;682- // Base refs and merge bases can move without changing divergence counts.683- yield* refreshLocalStatusCore(cwd);688+ const refs = yield* workflow.readRefSnapshot(cwd);689+ const local = (yield* getCachedStatus(cwd))?.local ?? null;690+ const localIsFresh =691+ !options?.alwaysRefreshLocal &&692+ refs !== null &&693+ local !== null &&694+ local.refSnapshot === refs &&695+ (local.includesBranchChanges || !wantsBranchChanges(cwd));
Pushed1816c6d
Pushed5244934
- @@ -1947,3 +1947,9 @@19471947 Effect.orElseSucceed(() => null),19481948 );194919491950+ const readWorkingTreeSnapshot: GitVcsDriver.GitVcsDriver["Service"]["readWorkingTreeSnapshot"] =1951+ Effect.fn("GitVcsDriver.readWorkingTreeSnapshot")(1952+ function* (cwd) {1953+ const worktreeRoot = (yield* resolveRepositoryPaths(cwd))?.worktreeRoot;1954+ if (!worktreeRoot) return null;1955+ const result = yield* executeGit(@@ -679,5 +686,13 @@679686 ? null680687 : yield* maybeAutoPull(cwd, remoteRead, options?.policyCwds ?? [cwd]);681688 if (pulled !== null) return pulled.remote;682- // Base refs and merge bases can move without changing divergence counts.683- yield* refreshLocalStatusCore(cwd);689+ // Working-tree edits move no ref, so both must match the snapshot taken before the cached read.690+ const refs = yield* workflow.readRefSnapshot(cwd);691+ const workingTree = refs === null ? null : yield* workflow.readWorkingTreeSnapshot(cwd);692+ const snapshot = workingTree === null ? null : `${refs}\0${workingTree}`;693+ const local = (yield* getCachedStatus(cwd))?.local ?? null;694+ const localIsFresh =695+ !options?.alwaysRefreshLocal &&696+ snapshot !== null &&697+ local !== null &&698+ local.snapshot === snapshot &&@@ -679,5 +686,18 @@679686 ? null680687 : yield* maybeAutoPull(cwd, remoteRead, options?.policyCwds ?? [cwd]);681688 if (pulled !== null) return pulled.remote;682- // Base refs and merge bases can move without changing divergence counts.683- yield* refreshLocalStatusCore(cwd);689+ // Working-tree edits move no ref, so both must match the snapshot taken before the cached read.690+ const refs = yield* workflow.readRefSnapshot(cwd);691+ const workingTree = refs === null ? null : yield* workflow.readWorkingTreeSnapshot(cwd);692+ const snapshot = workingTree === null ? null : `${refs}\0${workingTree}`;693+ const local = (yield* getCachedStatus(cwd))?.local ?? null;694+ const localIsFresh =695+ !options?.alwaysRefreshLocal &&696+ snapshot !== null &&697+ local !== null &&698+ local.snapshot === snapshot &&699+ ((local.includesBranchChanges && local.value.branchChanges !== undefined) ||700+ !wantsBranchChanges(cwd));701+ if (!localIsFresh) {702+ // Base refs and merge bases can move without changing divergence counts.703+ yield* refreshLocalStatusCore(cwd, { snapshot });
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
Pushed5afee22
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:ready
only21mil(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.




Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
Walkthrough
The Git driver now reads nullable working-tree snapshots. The broadcaster compares them with ref snapshots to decide whether remote polling refreshes local status. Tests cover unchanged and changed snapshots, missing totals, unavailable snapshots, and checkout reconciliation.
Changes: Snapshot-aware local status refresh
apps/server/src/vcs/GitVcsDriver.ts,apps/server/src/vcs/GitVcsDriverCore.ts,apps/server/src/git/GitWorkflowService.ts,apps/server/src/vcs/GitVcsDriverCore.test.tsnullwhen it cannot read the snapshot. The workflow service exposes the reader. Tests check snapshot stability and changes after tracked-file edits, staging, and untracked-file changes.apps/server/src/vcs/VcsStatusBroadcaster.ts,apps/server/src/vcs/VcsStatusBroadcaster.test.tsEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor · Severity of issue fixed: Medium
Possibly related issues
Suggested reviewers:
t3dotgg,juliusmarminge,yash-singh1Merge Risk:
Low · up to
5afeeThis change cuts idle Git polling work noticeably. In a few edge cases the displayed Changes totals or cached status can stay stale until the next window return or turn end. Examples are an external edit that preserves file size and mtime, a change to the comparison-base configuration, or a tree that changes mid-read. Merging is low risk, but the owner should be aware of these limitations or address them in a follow-up.
Pre-merge checks:
4
#39986, is closed and marked as historical context only. No active directly linked target remains, so no linked-issue coding requirements apply to this pull request. Th…Full details: Title check
Explanation
The title "perf(server): skip local git status on unchanged idle remote polls" matches the main change. The PR caches the ref snapshot with local status and skips refreshLocalStatusCore during remote polls when refs and cached branchChanges are unchanged. The title is a conventional commit, short, and specific.
Full details: Description check
Explanation
The description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem section states the cause and the 16-git-process cost per poll. The Change section explains the snapshot cache and the re-read conditions, and it states the trade-off. The Scope section links
#39986. The Verification section gives specific measurements, environment details, and tests, and it lists what was not shown (Windows Server 2025 x64). The template's agent-model line is present at the end ("Generated with Gemini 4 Neon in T3 Code Nightly"). Reviewers could still ask for a clearer statement of why the issue link satisfies the bug-fix scope rule, but the description is mostly complete.Full details: Linked Issues check
Explanation
The only directly linked issue,
#39986, is closed and marked as historical context only. No active directly linked target remains, so no linked-issue coding requirements apply to this pull request. The acceptance criteria in#39986(ref-unchanged polls skip local status re-reads, fetches that move refs still refresh, and head-watcher delivery is preserved) are not assessed as PR objectives. For context only, the head adds a working-tree snapshot next to the ref snapshot in the remote-refresh skip guard in VcsStatusBroadcaster.ts, and the tests cover moved refs, unavailable snapshots, and missing totals.Full details: Out of Scope Changes check
Explanation
The changes stay in the server VCS and git layers: VcsStatusBroadcaster.ts and its test, GitWorkflowService.ts, GitVcsDriver.ts, and GitVcsDriverCore.ts and its test. They address the idle remote-poll local-status re-read described in
#39986. The new readWorkingTreeSnapshot method is needed so the skip guard does not miss working-tree edits that move no ref. Its tests in GitVcsDriverCore.test.ts cover that behavior. The PR description is stale on one point: it says edits that move no ref surface only on window return or turn end, but the current code refreshes on the next poll when the working-tree snapshot changes. This is a documentation mismatch, not an unrelated change. Note that the idle measurements in the description were taken at ce36b9214a, not at the current head, so the added git status call per poll is not measured at head.Finishing Touches
Generate unit tests (beta)