From cb787da976438f5adfac438454f1f2200850a0f2 Mon Sep 17 00:00:00 2001 From: Dr Kennedy Umege <205099287+Kenmege@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:24:06 +0000 Subject: [PATCH] fix(vcs): stage checkpoints again with per-object fsync when Git's batch mode loses a pack On macOS and Windows checkpoints stage with core.fsyncMethod=batch. Git 2.54 and 2.56 lose a large file's bulk-checkin pack when a smaller file was written loose earlier in the same add: the pack is written inside Git's tmp_objdir-bulk-fsync folder, which is migrated away before the pack is renamed, and add exits 128 with "unable to rename temporary file". A checkpoint of a workspace with a file over core.bigFileThreshold then fails. A failed batch add is now staged once more with per-object fsync, which Git finalizes correctly; batch stays the first try because it is about 7x faster on macOS. Reproduce: git -c core.fsync=objects -c core.fsyncMethod=batch -c core.bigFileThreshold=1m add -A, with a.txt (small) and m.bin (2 MB) in a fresh repository. Test-Assertion-Change: apps/server/src/vcs/GitVcsDriver.test.ts restated: the operation's tmp_pack is looked up anywhere in its private object folder, since batch fsync writes it in Git's nested bulk-fsync folder; the count, size and cleanup assertions are unchanged. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 11 +++++++---- apps/server/src/vcs/GitVcsDriver.ts | 25 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 1acbf036fb52c..904b3eed11aeb 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -261,12 +261,15 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( ), ), ); - const packs = (yield* fs.readDirectory(path.join(objectDirectory, "pack"))).filter( - (name) => name.startsWith("tmp_pack_") && name !== "tmp_pack_other_operation", + // Batch fsync (macOS, Windows) writes the pack in Git's own bulk-fsync folder inside it. + const packs = (yield* fs.readDirectory(objectDirectory, { recursive: true })).filter( + (name) => + path.basename(name).startsWith("tmp_pack_") && + path.basename(name) !== "tmp_pack_other_operation", ); assert.strictEqual(packs.length, 1); assert.isAbove( - Number((yield* fs.stat(path.join(objectDirectory, "pack", packs[0]!))).size), + Number((yield* fs.stat(path.join(objectDirectory, packs[0]!))).size), 1024 * 1024, ); // An overlapping capture publishes the same large blob while the first @@ -310,7 +313,7 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( sharedPackBytes, ); assert.strictEqual((yield* git(["rev-parse", concurrentRef])).stdout, concurrentOid); - assert.isFalse(yield* fs.exists(path.join(objectDirectory, "pack", packs[0]!))); + assert.isFalse(yield* fs.exists(path.join(objectDirectory, packs[0]!))); assert.isFalse(yield* fs.exists(objectDirectory)); assert.strictEqual(yield* fs.readFileString(sharedPack), "owned by another Git operation"); if (stop !== "success") diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index d1e9dae66f1fa..f41db732cb1d5 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -1003,6 +1003,16 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ? ["-c", "core.fsyncMethod=batch"] : []), ] as const; + // Git 2.54-2.56 batch mode loses a large file's bulk-checkin pack when a smaller file was + // written loose earlier in the same add ("unable to rename temporary file"), so a failed + // batch add is staged once more with per-object fsync, which Git finalizes correctly. + const perObjectDurableWrite = [ + "-c", + "core.fsync=objects,reference", + "-c", + "core.fsyncMethod=fsync", + ] as const; + const durableWriteBatches = durableWrite.length > perObjectDurableWrite.length; // Checkpoints must handle existing paths beyond Windows MAX_PATH, even when // core.longpaths is disabled in the user's Git configuration. @@ -1379,13 +1389,16 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( } } - const stageFiles = (exclusions: ReadonlyArray) => + const stageFilesWith = ( + durability: ReadonlyArray, + exclusions: ReadonlyArray, + ) => execute({ operation, cwd: input.cwd, args: [ ...indexConfig, - ...durableWrite, + ...durability, ...longPaths, // safecrlf=true refuses LF files under CRLF conversion; capture them as Git's default does. "-c", @@ -1400,6 +1413,14 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ], env: commitEnv, }); + const stageFiles = (exclusions: ReadonlyArray) => + durableWriteBatches + ? stageFilesWith(durableWrite, exclusions).pipe( + Effect.catchTags({ + VcsProcessExitError: () => stageFilesWith(perObjectDurableWrite, exclusions), + }), + ) + : stageFilesWith(durableWrite, exclusions); yield* stageFiles([]).pipe( Effect.catchTags({ VcsProcessExitError: (error) =>