@devries-cameron20 / t3code-1 / commits / 07a1e799d6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): checkpoints no longer rehash every file when one entry is skip-worktree or assume-unchanged (#23624)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 2, 2026 at 18:01 UTC 07a1e799d6dd819e825321842e54c644b9844a7c
2 files changed +112 -38
apps/server/src/vcs/GitVcsDriver.test.ts
+38 -8
@@ -597,7 +597,17 @@ it.effect.each(
597 Effect.gen(function* () {
598 const fs = yield* FileSystem.FileSystem;
599 const path = yield* Path.Path;
600 - const driver = yield* GitVcsDriver.makeVcsDriverShape();
600 + const liveProcess = yield* VcsProcess.VcsProcess;
601 + let freshReadTrees = 0;
602 + const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
603 + Effect.provideService(VcsProcess.VcsProcess, {
604 + run: (input) => {
605 + if (input.args.includes("read-tree") && input.args.includes("index.sparse=true"))
606 + freshReadTrees++;
607 + return liveProcess.run(input);
608 + },
609 + }),
610 + );
611 const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-sparse-" });
612 const { git } = yield* makeCheckpointFixture(driver, cwd);
613 const write = Effect.fn(function* (name: string, contents: string) {
@@ -680,11 +690,12 @@ it.effect.each(
690 "working outside\n",
691 );
692 }
693 + assert.strictEqual(freshReadTrees, indexState === "missing" ? 2 : 0);
694 }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
695 );
696
697 it.effect.each(
687 - (["normal", "flags", "sparse"] as const).flatMap((indexMode) =>
698 + (["normal", "skip-worktree", "assume-unchanged", "sparse"] as const).flatMap((indexMode) =>
699 [1, 3, 4096].map((chunkSize) => ({ indexMode, chunkSize })),
700 ),
701 )(
@@ -700,6 +711,7 @@ it.effect.each(
711 yield* fs.writeFileString(path.join(cwd, ".gitattributes"), "stable filter=probe\n");
712 yield* fs.writeFileString(path.join(cwd, "stable"), "unchanged\n");
713 yield* fs.writeFileString(path.join(cwd, "z-skipped"), "original\n");
714 + yield* fs.writeFileString(path.join(cwd, "z-deleted"), "original\n");
715 yield* fs.makeDirectory(path.join(cwd, "excluded"));
716 yield* fs.writeFileString(path.join(cwd, "excluded/file"), "absent\n");
717 yield* fs.writeFileString(
@@ -707,19 +719,31 @@ it.effect.each(
719 'require("node:fs").appendFileSync(".git/reads", "read\\n"); process.stdin.pipe(process.stdout);',
720 );
721 yield* git(["config", "filter.probe.clean", "node .git/filter.cjs"]);
722 + yield* git(["config", "core.trustctime", "false"]);
723 yield* fs.utimes(path.join(cwd, "stable"), 1_700_000_000, 1_700_000_000);
724 + yield* fs.utimes(path.join(cwd, "z-skipped"), 1_700_000_000, 1_700_000_000);
725 yield* git(["add", "."]);
726 yield* git(["commit", "-m", "inspection fixture"]);
713 - if (indexMode === "flags") yield* git(["update-index", "--skip-worktree", "z-skipped"]);
727 + const flagged = indexMode === "skip-worktree" || indexMode === "assume-unchanged";
728 + if (flagged) {
729 + yield* git(["update-index", `--${indexMode}`, "z-skipped", "z-deleted"]);
730 + yield* git(["config", "core.ignorestat", "true"]);
731 + yield* fs.remove(path.join(cwd, "z-deleted"));
732 + }
733 if (indexMode === "sparse")
734 yield* git(["sparse-checkout", "set", "--cone", "--sparse-index", "included"]);
735 yield* fs.writeFileString(path.join(cwd, "z-skipped"), "modified\n");
736 + // A flagged edit with the indexed size and mtime is invisible to Git's stat check.
737 + if (flagged) yield* fs.utimes(path.join(cwd, "z-skipped"), 1_700_000_000, 1_700_000_000);
738 yield* fs.writeFileString(path.join(cwd, ".git/reads"), "");
739 const originalIndex = yield* fs.readFile(path.join(cwd, ".git/index"));
740 + let freshReadTrees = 0;
741 const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
742 Effect.provideService(VcsProcess.VcsProcess, {
721 - run: (input) =>
722 - liveProcess.run(
743 + run: (input) => {
744 + if (input.args.includes("read-tree") && !input.args.includes("--reset"))
745 + freshReadTrees++;
746 + return liveProcess.run(
747 input.args.includes("ls-files")
748 ? {
749 ...input,
@@ -730,13 +754,19 @@ it.effect.each(
754 },
755 }
756 : input,
733 - ),
757 + );
758 + },
759 }),
760 );
761 yield* captureDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
762 assert.strictEqual((yield* git(["show", `${checkpointRef}:z-skipped`])).stdout, "modified\n");
738 - if (indexMode !== "flags")
739 - assert.strictEqual(yield* fs.readFileString(path.join(cwd, ".git/reads")), "");
763 + const files = (yield* git(["ls-tree", "-z", "--name-only", checkpointRef])).stdout.split(
764 + "\0",
765 + );
766 + if (flagged) assert.notInclude(files, "z-deleted");
767 + else assert.include(files, "z-deleted");
768 + assert.strictEqual(freshReadTrees, 0);
769 + assert.strictEqual(yield* fs.readFileString(path.join(cwd, ".git/reads")), "");
770 assert.deepEqual(yield* fs.readFile(path.join(cwd, ".git/index")), originalIndex);
771 }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
772 );
apps/server/src/vcs/GitVcsDriver.ts
+74 -30
@@ -444,6 +444,7 @@ export class GitVcsDriver extends Context.Service<
444 >()("t3/vcs/GitVcsDriver") {}
445
446 const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
447 +const FLAGGED_INDEX_ENTRIES_MAX_BYTES = 1024 * 1024;
448 const CHECKPOINT_RECOVERY_MAX_CANDIDATES = 64;
449 const CHECKPOINT_RECOVERY_TIMEOUT = "5 seconds";
450 const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
@@ -967,43 +968,60 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
968 });
969 // read-tree can rewrite the index, so restore its racy timestamp afterward.
970 yield* fileSystem.utimes(tempIndexPath, indexTime, indexTime);
970 - let specialFlags = false;
971 + // Manually flagged entries hide edits from add -A, so they are re-added below
972 + // with no stat cache. Every other entry keeps its stat data and is not rehashed.
973 + let fallback = false;
974 + let flaggedBytes = 0;
975 let recordStart = true;
972 - let skipped = false;
973 - let skippedRecord: Uint8Array[] = [];
974 - const skippedPaths: string[] = [];
976 + let collect: "flagged" | "skipped" | undefined;
977 + let record: Uint8Array[] = [];
978 + const flagged: string[] = [];
979 + const skipped: string[] = [];
980 yield* vcsProcess.run({
981 operation,
982 command: "git",
983 cwd: input.cwd,
979 - args: [...indexConfig, "ls-files", "--full-name", "--sparse", "-v", "-z"],
984 + args: [...indexConfig, "ls-files", "--full-name", "--sparse", "--stage", "-v", "-z"],
985 env: commitEnv,
986 maxOutputBytes: 4_096,
987 outputMode: "truncate",
983 - // Only tags and sparse skip-worktree paths matter; scan NUL-delimited records.
988 + // Only tags and flagged or skip-worktree records matter; scan NUL-delimited records.
989 onStdoutChunk: (chunk) => {
990 let start = 0;
986 - while (start < chunk.length) {
991 + while (start < chunk.length && !fallback) {
992 const end = chunk.indexOf(0, start);
993 if (recordStart) {
994 const tag = chunk[start]!;
990 - skipped = tag === 83;
991 - if ((tag >= 97 && tag <= 122) || (!sparseCheckout && tag === 83)) {
992 - specialFlags = true;
993 - }
995 + record = [];
996 + // Sparse skip-worktree bits are expected; only in-cone ones are manual.
997 + collect =
998 + tag === 83 && sparseCheckout
999 + ? "skipped"
1000 + : (tag >= 97 && tag <= 122) || tag === 83
1001 + ? "flagged"
1002 + : undefined;
1003 + // index-info cannot keep skip-worktree while dropping assume-unchanged.
1004 + if (tag === 115 && sparseCheckout) fallback = true;
1005 }
995 - if (skipped && sparseCheckout) {
996 - skippedRecord.push(
997 - Buffer.from(chunk.subarray(start, end === -1 ? undefined : end)),
998 - );
999 - if (end !== -1) {
1000 - const record = Buffer.concat(skippedRecord);
1001 - if (record.at(-1) !== 47) {
1002 - const name = record.subarray(2);
1003 - if (!NodeBuffer.isUtf8(name)) specialFlags = true;
1004 - else skippedPaths.push(name.toString("utf8"));
1006 + if (collect !== undefined && !fallback) {
1007 + const piece = chunk.subarray(start, end === -1 ? undefined : end);
1008 + record.push(Buffer.from(piece));
1009 + if (
1010 + collect === "flagged" &&
1011 + (flaggedBytes += piece.length) > FLAGGED_INDEX_ENTRIES_MAX_BYTES
1012 + )
1013 + fallback = true;
1014 + if (end !== -1 && !fallback) {
1015 + const full = Buffer.concat(record);
1016 + record = [];
1017 + // Sparse directory entries stay collapsed.
1018 + if (collect === "flagged" || full.at(-1) !== 47) {
1019 + // Drop the "<tag> " prefix, leaving index-info's "<mode> <oid> <stage>\t<path>".
1020 + const entry = full.subarray(2);
1021 + if (!NodeBuffer.isUtf8(entry)) fallback = true;
1022 + else
1023 + (collect === "flagged" ? flagged : skipped).push(entry.toString("utf8"));
1024 }
1006 - skippedRecord = [];
1025 }
1026 }
1027 recordStart = end !== -1;
@@ -1012,20 +1030,46 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1030 }
1031 },
1032 });
1015 - if (skippedPaths.length > 0 && !specialFlags) {
1016 - const selected = yield* execute({
1033 + if (fallback) return false;
1034 + if (skipped.length > 0) {
1035 + const paths = skipped.map((entry) => entry.slice(entry.indexOf("\t") + 1));
1036 + const stdin = paths.join("\0") + "\0";
1037 + // check-rules echoes a subset of its input, so the input size bounds its output.
1038 + const rules = yield* execute({
1039 operation,
1040 cwd: input.cwd,
1041 args: [...indexConfig, "sparse-checkout", "check-rules", "-z"],
1020 - stdin: skippedPaths.join("\0") + "\0",
1042 + stdin,
1043 + env: commitEnv,
1044 + maxOutputBytes: Buffer.byteLength(stdin),
1045 + outputMode: "error",
1046 + });
1047 + const selected = new Set(rules.stdout.split("\0"));
1048 + skipped.forEach((entry, index) => {
1049 + if (selected.has(paths[index]!)) flagged.push(entry);
1050 + });
1051 + }
1052 + if (flagged.length > 0) {
1053 + // Flagged gitlinks keep the fresh-index behaviour rather than a guessed one.
1054 + if (flagged.some((entry) => entry.startsWith("160000 "))) return false;
1055 + yield* execute({
1056 + operation,
1057 + cwd: input.cwd,
1058 + // core.ignorestat would mark these assume-unchanged, hiding edits from add -A.
1059 + args: [
1060 + ...indexConfig,
1061 + "-c",
1062 + "core.ignorestat=false",
1063 + "update-index",
1064 + "-z",
1065 + "--index-info",
1066 + ],
1067 + stdin: flagged.join("\0") + "\0",
1068 env: commitEnv,
1022 - maxOutputBytes: 1,
1023 - outputMode: "truncate",
1069 });
1025 - specialFlags = selected.stdout.length > 0 || selected.stdoutTruncated;
1070 + yield* fileSystem.utimes(tempIndexPath, indexTime, indexTime);
1071 }
1027 - // Sparse Git clears skip-worktree for present files. Manual flags still need a reset.
1028 - return !specialFlags;
1072 + return true;
1073 }).pipe(Effect.orElseSucceed(() => false));
1074 if (!reusedIndex) {
1075 if (sparseCheckout) {