From b3d79de856667be117454c6c30cff91c1fb8f58e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 21:59:49 +0000 Subject: [PATCH 1/2] test(server): checkpoint with batch fsync loses a big file staged after small new files Reproduces #39913: with core.fsyncMethod=batch (darwin, win32), git add fails with exit 128 when a loose object is written before a file over core.bigFileThreshold is streamed into a pack. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 8140e7522bd7..747fe13be593 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -341,6 +341,41 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( }).pipe(Effect.scoped, Effect.provide(layerGitContract)), ); +it.effect.each(["darwin", "win32"] as const)( + "checkpoint on $0 captures a big file staged after small new files", + (platform) => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const driver = yield* GitVcsDriver.makeVcsDriverShape(); + const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-big-file-" }); + const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd); + yield* git(["config", "core.bigFileThreshold", "1m"]); + yield* fs.writeFileString(path.join(cwd, "a-note.txt"), "small\n"); + const crypto = yield* SecureRandom.SecureRandom; + yield* fs.writeFile( + path.join(cwd, "b-media.bin"), + yield* crypto.randomBytes(2 * 1024 * 1024), + ); + // More embedded repositories than staging's recovery scans, so a failed add is final. + const nested = path.join(cwd, "nested-0"); + yield* fs.makeDirectory(nested); + yield* makeCheckpointFixture(driver, nested); + for (let index = 1; index <= 64; index++) + yield* fs.copy(nested, path.join(cwd, `nested-${index}`)); + const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe( + Effect.provideService(HostProcess.Platform, platform), + ); + + yield* captureDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); + + assert.strictEqual( + (yield* git(["rev-parse", `${checkpointRef}:b-media.bin`])).stdout.trim(), + (yield* git(["hash-object", "b-media.bin"])).stdout.trim(), + ); + }).pipe(Effect.scoped, Effect.provide(layerGitContract)), +); + it.effect.each(["failure", "interrupt"] as const)( "checkpoint publication $0 preserves existing refs and permits retry", (stop) => From 2b07bda19f32cb33309f09e6123bf3adef01b89c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 22:07:31 +0000 Subject: [PATCH 2/2] fix(server): checkpoints keep big files staged under batch fsync On macOS and Windows checkpoint staging uses core.fsyncMethod=batch, and Git 2.43 through 2.56.1 loses a file over core.bigFileThreshold when a smaller loose object was written earlier in the same add (exit 128). Retry a failed batch add once with per-object fsync, and stage the embedded-repository recovery with per-object fsync too. Fixes pingdotgg/t3code#39913 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index ddaa958fc979..d4c181cdd5f3 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -1035,14 +1035,16 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( // Set fsync first: Git 2.36 ignores unknown batch without resetting the method. // Batch fully flushes refs and equals fsync on macOS HFS+/APFS and Windows NTFS/ReFS. // Keep per-object fsync elsewhere; VcsProcess retries unsupported macOS full flushes with plain fsync. - const durableWrite = [ + const perObjectFsync = [ "-c", "core.fsync=objects,reference", "-c", "core.fsyncMethod=fsync", - ...(hostPlatform === "darwin" || hostPlatform === "win32" - ? ["-c", "core.fsyncMethod=batch"] - : []), + ] as const; + const batchFsync = hostPlatform === "darwin" || hostPlatform === "win32"; + const durableWrite = [ + ...perObjectFsync, + ...(batchFsync ? ["-c", "core.fsyncMethod=batch"] : []), ] as const; // Checkpoints must handle existing paths beyond Windows MAX_PATH, even when @@ -1433,13 +1435,17 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ? CheckpointUntrackedBlobs.NOTHING : yield* untrackedBlobs.reuse({ ...untracked, indexConfig }); - const stageFiles = (exclusions: ReadonlyArray, ignoreErrors = false) => + const stageFiles = ( + exclusions: ReadonlyArray, + ignoreErrors = false, + fsync: ReadonlyArray = durableWrite, + ) => execute({ operation, cwd: input.cwd, args: [ ...indexConfig, - ...durableWrite, + ...fsync, ...longPaths, // safecrlf=true refuses LF files under CRLF conversion; capture them as Git's default does. "-c", @@ -1465,6 +1471,11 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ); const stagingAt = yield* Clock.currentTimeMillis; yield* stageFiles([]).pipe( + // Git 2.43-2.56.1 under batch fsync loses a big file's pack when a loose object precedes it. + Effect.catchTags({ + VcsProcessExitError: (error) => + batchFsync ? stageFiles([], false, perObjectFsync) : Effect.fail(error), + }), Effect.catchTags({ VcsProcessExitError: (error) => Effect.gen(function* () { @@ -1511,7 +1522,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( exclusions.push(`:(exclude,literal)${entry}`); } } - return yield* stageFiles(exclusions, true); + return yield* stageFiles(exclusions, true, perObjectFsync); }).pipe( Effect.timeoutOrElse({ duration: CHECKPOINT_RECOVERY_TIMEOUT,