fix(server): status polling no longer locks the git index #14718
main fromrefs/pull/14718/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub🤖 Generated with Claude Code
Problem#
The server polls git status --porcelain=2 and git diff HEAD --numstat in each open project. Both save their refreshed index under .git/index.lock. So a user's own git checkout or git commit fails with Unable to create '.git/index.lock': File exists when it runs during a poll. #9845 stops polling while someone else holds the lock, but polling can still take the lock itself.
Seen in practice: a build script's git checkout --detach <sha> failed. The server trace shows GitVcsDriver.statusDetails.status running in that repo during the same ~170 ms.
Change#
git subprocess env
+ GIT_OPTIONAL_LOCKS=0 # git status skips saving its refreshed index
statusDetails numstat
- git diff HEAD --numstat --
+ git diff-index -M --numstat HEAD --
unborn HEAD
- git diff --numstat
+ git diff-files --numstat
Porcelain git diff rewrites the index whenever it finds stat-dirty entries, and it ignores GIT_OPTIONAL_LOCKS (verified on git 2.56). The plumbing equivalents never write the index. -M keeps porcelain's default rename detection, so the numstat output doesn't change.
Scope and approval#
This is a small fix for an obvious bug in existing behavior: background polling shouldn't make the user's own git commands fail. Git's documentation recommends GIT_OPTIONAL_LOCKS=0 for exactly this case (background status polling).
Verification#
- Repo with a stat-dirty tracked file (
touch -t 202001010000 f): the index checksum stays the same afterGIT_OPTIONAL_LOCKS=0 git statusand aftergit diff-index -M --numstat HEAD --. It changes afterGIT_OPTIONAL_LOCKS=0 git diff HEAD --numstat --. - A throwaway integration test did the same: make a tracked file stat-dirty, call
statusDetails, and assert.git/indexis byte-identical. It failed before this change and passed after. I left it out of this PR. diff-index -M --numstat HEADmatchesgit diff HEAD --numstaton renamed, edited, and staged files. On an unborn HEAD it fails with the samebad revision 'HEAD'stderr, so the existing fallback still triggers.vp test run src/vcs/GitVcsDriverCore.test.ts src/vcs/GitVcsDriver.test.ts: 154 pass. The one failure, "still creates the worktree when submodule checkout fails", fails without this change too, on this machine.
Claude Opus 5.5 in Claude Code.
- 1
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:S
- @@ -1771,7 +1774,9 @@17711774 const statusCacheKey = repositoryPaths?.gitCommonDir;17721775 const [numstatStdout, defaultBranch, hasPrimaryRemote] = yield* Effect.all(17731776 [1777+ // Plumbing, because porcelain `git diff` rewrites the index even with1778+ // GIT_OPTIONAL_LOCKS=0. -M keeps porcelain's rename detection.17741779 executeGitWithStableDiagnostics(17751780 "GitVcsDriver.statusDetails.numstat",17761781 cwd,1777- ["diff", "HEAD", "--numstat", "--"],1782+ ["diff-index", "-M", "--numstat", "HEAD", "--"],
🟡 Medium
vcs/GitVcsDriverCore.ts:1782Status reports zero insertions/deletions for files handled by configured textconv drivers, even when the converted content has changes.
git diff-indexdoes not enable textconv by default, unlike the replacedgit diff; pass--textconvto preserve the previous statistics.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/vcs/GitVcsDriverCore.ts around line 1782: Status reports zero insertions/deletions for files handled by configured textconv drivers, even when the converted content has changes. `git diff-index` does not enable textconv by default, unlike the replaced `git diff`; pass `--textconv` to preserve the previous statistics.🤖 Generated with Claude Code
False positive: porcelain
git diff --numstatdoesn't apply textconv either; textconv only affects patch output. Checked on git 2.56. With an uppercasing textconv driver,a→Agives1 1from bothgit diff HEAD --numstatandgit diff-index -M --numstat HEAD. With astringsdriver on a binary file, both report- -(--statshowsBin 12 -> 12 bytes). Sodiff-indexproduces the same counts as before, and adding--textconvdoesn't change them.Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Approvability#
Verdict: Approved at
3711421Macroscope's review found this PR approvable — This is a focused one-file server bug fix that prevents background Git status polling from taking optional index locks while preserving existing status and rename-detection behavior. An unresolved Medium finding raises a separate textconv statistics concern, but the implementation itself is small and self-contained.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
🧰 Additional context used
📚 Code guidelines (1)
docs/internals/effect-services.md — configuredNo actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
cda610d5-a1c4-403e-be3d-08b6df598f35📥 Commits
Reviewing files that changed from the base of the PR and between 2731929610ecb64617ff5e066980302da328f658 and 3711421bf1e61425d0ba9414b8b8449af04cecc1.
📒 Files selected for processing (1)
apps/server/src/vcs/GitVcsDriverCore.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
Git child processes now disable optional locks by default unless
input.envoverrides the setting. Local status numstat collection uses updated Git diff commands, and its failure diagnostic names the command and arguments.Changes#
Git VCS updates
Layer / File(s) Summary Git child process environment
apps/server/src/vcs/GitVcsDriverCore.tsGit child processes receive GIT_OPTIONAL_LOCKS=0by default. Values frominput.envcan override this setting.Local status numstat commands
apps/server/src/vcs/GitVcsDriverCore.tsLocal status statistics use git diff-index -M --numstat HEAD --. For an unbornHEAD, unstaged statistics usegit diff-files --numstat, while staged statistics still use cached diff. The failure diagnostic identifies thegit diff-indexcommand and arguments.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested reviewers:
t3dotgg,juliusmarmingeMerge Risk: ⚪ Minimal · up to
37114The alleged textconv undercount is unchanged from the prior behavior, so no supported merge-blocking risk remains.
Architecture Summary#
Architecture risk: 🔵 Low · up to
37114The change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
- observed — apps/server (service) was modified; 1 changed file maps to changed impact.
Before / after behavior
- observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: Git child processes now receive
GIT_OPTIONAL_LOCKS=0by default;input.envis spread afterward and can override it. - observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: Local status statistics switch from
git diff HEAD --numstat --togit diff-index -M --numstat HEAD --. On the unborn-HEAD fallback, unstaged statistics switch fromgit diff --numstattogit diff-files --numstat; staged statistics remain obtained from cached diff. - observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: The unborn-HEAD unstaged-statistics command changes from
git difftogit diff-files. - observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: The numstat failure reports
git diff-index -M --numstat HEAD --as the failing command and updates its detail from agit difffailure to agit diff-indexfailure.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Description check ✅ Passed The description covers the problem, implementation, scope rationale, verification steps, observed results, and the known test failure. It also identifies the agent and harness used. Title check ✅ Passed The title clearly and concisely describes the primary change: preventing server status polling from locking the Git index. Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1… 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
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Autopilot is currently an internal CodeRabbit preview.
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed