You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(git): invalidate settled diff cache when a file's ctime advances - #47639
Some tools rewrite a file in place and then put its old "last modified" time back. When the new content has the same length, Orca's diff cache thought nothing had changed and kept showing the old diff. Orca now also checks the file's "status changed" time (ctime), which the operating system always updates on a write, so the cache notices the change.
What Changed
Before: a working-tree file's diff-cache stamp was mtime:size:inode. An in-place rewrite that kept size, inode and mtime (touch -r, rsync --times, some editors and formatters) gave the same stamp, so the settled diff cache returned the old diff until something else invalidated it.
After: the stamp is mtime:ctime:size:inode. The racy-write guard (no caching within 2s of a write) now uses the later of mtime and ctime, so a freshly rewritten file stays out of the cache until its timestamps settle.
Mechanism:readWorkingTreeComponent in input-stamps/worktree-diff-stamp.ts reads ctimeMs from the stat result it already has. StampComponent.mtimeMs / WorktreeDiffStamp.newestMtimeMs are renamed to timestampMs / newestTimestampMs because they can now hold ctime. Ref and config stamps (readFileStampComponent, the commit-pair cache) still use mtime only; only the field names changed there.
Why
Two different file versions produced identical stamps, so the cache could serve stale diffs indefinitely. ctime cannot be set from user space with utimes, so it catches timestamp-preserving rewrites. The alternative, hashing file contents, would add reads on every diff.
N/A for screenshots. The bug is stale data from the main-process diff cache, not a rendering change. Before/after from the production diff reader on a real Git fixture (macOS): same-size rewrite with the mtime restored. Inode and size stay the same, and ctime advances.
main (before) this PR (after)
first read (diff content) "yyyy\n" "yyyy\n"
git numstat after rewrite 2 1 2 1
second read (diff content) "yyyy\n" stale "a\nbc\n" fresh
second read (line stats) +1 -1 stale +2 -1 fresh
Testing
Reproduced on macOS with real Git: a probe test rewrote a file in place, kept its size, inode and mtime, then read the diff twice. On main the second read returned the stale diff. With this change it matches Git.
Added worktree-diff-stamp.test.ts: two stats with the same mtime, size and inode and different ctimes must produce different stamps, and newestTimestampMs must equal the newer ctime. It fails on main (identical stamps) and passes here.
vitest run src/main/git (17 files, 92 tests) passes. oxfmt, oxlint, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on the touched files.
Platforms: macOS. Linux, Windows and remote SSH hosts use the same Node fs.stat field (ctimeMs), which Node fills on every platform (on Windows it is the NTFS change time).
Performance
There are no new syscalls or subprocesses. The same async stat call supplies ctimeMs, and the change only adds one more number to each file's stamp string. This runs once per file on diff reads, not on a polling path. I benchmarked readHostFilesStamp against main (ms, 1 file / 512 files). The differences are within run-to-run noise:
Trade-off: right after a timestamp-preserving rewrite, the file stays out of the cache for the existing 2s margin, where it was previously cached with stale content.
Risk
Level: Low. On filesystems that update ctime when only metadata changes (chmod, chown, link count), the cache misses more often. That costs a normal Git read and never returns wrong data. The stamp lives only in memory, so mixed-version and remote compatibility is not affected. To back it out, revert this commit.
Review
Original fix by @0718lol in #47639. Authorship is kept on the squashed commit.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
No actionable comments were generated in the recent review.
Walkthrough
Working-tree stamps now include ctime in their identity and use the later of ctime and mtime as their timestamp. Stamp freshness and clock-skew checks use the newest timestamp. Commit-pair scope checks also use timestamps. A test verifies that a ctime change produces a different stamp when size, inode, and mtime stay the same.
Severity of issue fixed: Medium
Merge Risk: Low · up to bc3ae
This fixes stale unstaged diffs after in-place rewrites that preserve size and modification time. Because change time now also invalidates the cache, diffs for recently modified files may be recomputed more often. Check that the extra recomputation is acceptable before merging.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
Issue #47631 requires that a second unstaged diff read after an in-place rewrite that preserves size, inode, and mtime returns the new contents. At head bc3ae09, readWorkingTreeComponent in `worktr…
Out of Scope Changes check
All changes support the #47631 fix. In worktree-diff-stamp.ts, the renames mtimeMs to timestampMs and newestMtimeMs to newestTimestampMs carry the ctime-aware value through `WorktreeDiffStam…
Title check
The title names the main change: the settled diff cache is invalidated when a file's ctime advances. The changeset adds ctime to working-tree file stamps and renames the timestamp fields to match, so …
Description check
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #47631), Visual Proof (N/A with reason and a before/after table), Testing, Performance, Ris…
Full details: Linked Issues check
Explanation
Issue #47631 requires that a second unstaged diff read after an in-place rewrite that preserves size, inode, and mtime returns the new contents. At head bc3ae09, readWorkingTreeComponent in worktree-diff-stamp.ts builds the stamp text as ${mtimeMs}:${ctimeMs}:${size}:${inode}, so a ctime change changes the stamp value and forces a cache miss. Its timestampMs is Math.max(mtimeMs, ctimeMs), so canProveUnchangedByStamp also refuses reuse within the two-second margin. The same stat call supplies both values, so no filesystem reads are added. The regression test in worktree-diff-stamp.test.ts mocks stat with equal mtime, size, and inode and different ctime, then asserts that the stamp value differs. I read the test source. I did not run it, so its pass or fail status relies on the PR summary. The non-coding reproduction steps add no requirements.
Full details: Out of Scope Changes check
Explanation
All changes support the #47631 fix. In worktree-diff-stamp.ts, the renames mtimeMs to timestampMs and newestMtimeMs to newestTimestampMs carry the ctime-aware value through WorktreeDiffStamp, canProveUnchangedByStamp, and isDiffStampClockSkewed. requireMtimeMs becomes requireTimestampMs for the same reason and also checks ctime. readFileStampComponent keeps mtime and size only, so its behavior does not change. In commit-pair-cache.ts, shallow and packed-refs components keep timestampMs equal to mtimeMs, so commit-pair behavior is unchanged. The test file and the settled-diff-cache.ts documentation changes are supporting changes. The diff adds no commands, UI, agent, or integration changes.
Full details: Title check
Explanation
The title names the main change: the settled diff cache is invalidated when a file's ctime advances. The changeset adds ctime to working-tree file stamps and renames the timestamp fields to match, so the title is related to the main change. It follows the conventional type(scope) form and is 68 characters long.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #47631), Visual Proof (N/A with reason and a before/after table), Testing, Performance, Risk with level, Review, Agent skill boundary, Notes and Checklist. The Performance section gives a concrete reason and benchmark data. The AI Disclosure section is empty, but the template marks it as optional for StablyAI team members, and the author's identity is not stated. The final pnpm checklist item is unchecked, and the description says the full lint, typecheck, test and build suites were not run locally.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Working-tree file stamps now include ctime alongside mtime, size and
inode, and the racy-write guard uses the later of the two timestamps.
A timestamp-preserving in-place rewrite (same size, inode and mtime)
previously produced an identical stamp, so the settled diff cache served
the old diff. The same stat call already reports ctime, so no extra I/O.
Fixesstablyai#47631
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(git): invalidate diff cache when file change time advances
fix(git): invalidate settled diff cache when a file's ctime advances
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Some tools rewrite a file in place and then put its old "last modified" time back. When the new content has the same length, Orca's diff cache thought nothing had changed and kept showing the old diff. Orca now also checks the file's "status changed" time (ctime), which the operating system always updates on a write, so the cache notices the change.
What Changed
mtime:size:inode. An in-place rewrite that kept size, inode and mtime (touch -r,rsync --times, some editors and formatters) gave the same stamp, so the settled diff cache returned the old diff until something else invalidated it.mtime:ctime:size:inode. The racy-write guard (no caching within 2s of a write) now uses the later of mtime and ctime, so a freshly rewritten file stays out of the cache until its timestamps settle.readWorkingTreeComponentininput-stamps/worktree-diff-stamp.tsreadsctimeMsfrom thestatresult it already has.StampComponent.mtimeMs/WorktreeDiffStamp.newestMtimeMsare renamed totimestampMs/newestTimestampMsbecause they can now hold ctime. Ref and config stamps (readFileStampComponent, the commit-pair cache) still use mtime only; only the field names changed there.Why
Two different file versions produced identical stamps, so the cache could serve stale diffs indefinitely. ctime cannot be set from user space with
utimes, so it catches timestamp-preserving rewrites. The alternative, hashing file contents, would add reads on every diff.Linked Issue
Fixes #47631
Visual Proof
N/A for screenshots. The bug is stale data from the main-process diff cache, not a rendering change. Before/after from the production diff reader on a real Git fixture (macOS): same-size rewrite with the mtime restored. Inode and size stay the same, and ctime advances.
Testing
mainthe second read returned the stale diff. With this change it matches Git.worktree-diff-stamp.test.ts: two stats with the same mtime, size and inode and different ctimes must produce different stamps, andnewestTimestampMsmust equal the newer ctime. It fails onmain(identical stamps) and passes here.vitest run src/main/git(17 files, 92 tests) passes. oxfmt, oxlint, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on the touched files.fs.statfield (ctimeMs), which Node fills on every platform (on Windows it is the NTFS change time).Performance
There are no new syscalls or subprocesses. The same async
statcall suppliesctimeMs, and the change only adds one more number to each file's stamp string. This runs once per file on diff reads, not on a polling path. I benchmarkedreadHostFilesStampagainstmain(ms, 1 file / 512 files). The differences are within run-to-run noise:Trade-off: right after a timestamp-preserving rewrite, the file stays out of the cache for the existing 2s margin, where it was previously cached with stale content.
Risk
Level: Low. On filesystems that update ctime when only metadata changes (chmod, chown, link count), the cache misses more often. That costs a normal Git read and never returns wrong data. The stamp lives only in memory, so mixed-version and remote compatibility is not affected. To back it out, revert this commit.
Review
Original fix by @0718lol in #47639. Authorship is kept on the squashed commit.
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)