Skip to content

Commit 3e6ca84

Browse files
t3dotggclaude
andcommitted
fix(server): backdate cached folders so later changes are always detected
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 861dff8 commit 3e6ca84

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎apps/server/src/vcs/worktreeCheckoutCache.test.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,8 @@ describe.skipIf(!symlinksSupported)("worktree checkout cache", () => {
277277
},
278278
{
279279
name: "a file was added to the cache",
280-
change: (fixture: { cacheDir: string; repo: string; root: string }) => {
281-
const folder = NodePath.join(cacheEntry(fixture), "src");
282-
NodeFS.writeFileSync(NodePath.join(folder, "extra.txt"), "extra\n");
283-
// Linux stamps times from a coarse clock, so a write right after the build can keep the
284-
// folder's mtime; APFS has no such gap. Move it on so the test does not depend on that.
285-
const moved = NodeFS.statSync(folder).mtimeMs / 1000 + 1;
286-
NodeFS.utimesSync(folder, moved, moved);
287-
},
280+
change: (fixture: { cacheDir: string; repo: string; root: string }) =>
281+
NodeFS.writeFileSync(NodePath.join(cacheEntry(fixture), "src", "extra.txt"), "extra\n"),
288282
},
289283
{
290284
name: "the repository's checkout settings changed",

‎apps/server/src/vcs/worktreeCheckoutCache.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,19 @@ export const makeWorktreeCheckoutCache = Effect.fn("WorktreeCheckoutCache.make")
363363
return yield* new WorktreeCheckoutCacheError({ detail: "folder names differ only in case" });
364364
}
365365
const list = [...directories];
366-
const times = yield* directoryTimes(path.join(entryDirectory, "files"), list);
366+
// Backdated, so any later change moves the time even on a filesystem with a coarse clock.
367+
const root = path.join(entryDirectory, "files");
368+
yield* Effect.tryPromise({
369+
try: () =>
370+
Promise.all(
371+
list.map((directory) =>
372+
NodeFSP.utimes(directory === "" ? root : `${root}/${directory}`, 1_000_000, 1_000_000),
373+
),
374+
),
375+
catch: (cause) =>
376+
new WorktreeCheckoutCacheError({ detail: `could not backdate cached folders: ${cause}` }),
377+
});
378+
const times = yield* directoryTimes(root, list);
367379
yield* fileSystem.writeFileString(
368380
path.join(entryDirectory, "directories"),
369381
list.map((directory, index) => `${times[index]}\0${directory}\0`).join(""),

‎docs/user/project-settings.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ On a Mac, T3 Code keeps a few recent checkouts of each repository in the `caches
207207
home directory. A new worktree is cloned from one of them with APFS copy-on-write, which is about
208208
twice as fast as writing every file and makes the first `git status` in it fast as well. The first
209209
worktree of a repository uses Git's normal checkout and fills the cache. It needs Git 2.42 or newer.
210-
Git's normal checkout is also used for worktrees on another drive than the T3 home directory, sparse checkouts, repositories
211-
whose attributes use filters such as Git LFS, and repositories whose checkout settings changed.
210+
Git's normal checkout is also used for worktrees on a different drive from the T3 home directory,
211+
sparse checkouts, repositories whose attributes use filters such as Git LFS, and repositories
212+
whose checkout settings changed.
212213
Turn it off in **Settings → Worktrees → Fast checkout** under Advanced, which also deletes the
213214
cache.
214215

0 commit comments

Comments
 (0)