From e22f29927d060240ce9dd772e669fd5f9e6a342b Mon Sep 17 00:00:00 2001 From: Abhirup Ghosh <18056243+abhirupghosh@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:42:54 +0000 Subject: [PATCH 1/6] fix(server): an interrupted checkpoint capture no longer strands Git LFS temp files git-lfs's clean filter copies each file it hashes into lfs/tmp and leaves that copy behind when its process is killed. A checkpoint capture whose `git add` timed out or was interrupted therefore stranded one temp file per LFS file it was hashing, and the next turn's capture did the same again. When staging fails, the capture records the lfs/tmp entries that appeared since staging began, with their size and mtime. The next capture of the same repository removes those still unchanged, so a file another git-lfs process is still writing or renaming is left alone. Fixes #41680 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 105 +++++++++++++++++++++++ apps/server/src/vcs/GitVcsDriver.ts | 51 +++++++++++ 2 files changed, 156 insertions(+) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index c3b5d4143086b..d78af37299343 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -1,3 +1,5 @@ +// @effect-diagnostics-next-line nodeBuiltinImport:off -- skipIf needs to know synchronously whether git-lfs is installed. +import * as NodeChildProcess from "node:child_process"; import * as NodeNet from "node:net"; import * as SecureRandom from "effect/crypto/SecureRandom"; import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; @@ -369,6 +371,109 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( }).pipe(Effect.scoped, Effect.provide(layerGitContract)), ); +const gitLfsAvailable = NodeChildProcess.spawnSync("git", ["lfs", "version"]).status === 0; + +// git-lfs runs extension commands without a shell, so it needs git-lfs and a POSIX `cat`. +for (const stop of ["interrupt", "timeout"] as const) + it.effect.skipIf(!gitLfsAvailable || HostProcess.Platform.defaultValue() === "win32")( + `checkpoint staging stopped by ${stop} does not strand Git LFS temp files`, + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const driver = yield* GitVcsDriver.makeVcsDriverShape(); + const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-lfs-" }); + const cwd = path.join(sandbox, "repo"); + yield* fs.makeDirectory(cwd); + const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd); + yield* git(["lfs", "install", "--local"]); + + // git-lfs creates its temp file before it starts an extension, so an extension that waits + // on this socket holds the clean filter mid-file until the capture is stopped. + const connected = Promise.withResolvers(); + const server = yield* Effect.acquireRelease( + Effect.sync(() => + NodeNet.createServer((socket) => { + socket.resume(); + connected.resolve(); + }), + ), + (server) => Effect.sync(() => server.close()), + ); + yield* Effect.promise( + () => + new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }), + ); + const address = server.address(); + if (address === null || typeof address === "string") return yield* Effect.die("no port"); + const extension = path.join(sandbox, "barrier.cjs"); + yield* fs.writeFileString( + extension, + `require('node:net').connect(${address.port}, '127.0.0.1').resume(); process.stdin.resume();`, + ); + yield* git([ + "config", + "lfs.extension.barrier.clean", + `${process.execPath} ${extension} %f`, + ]); + yield* git(["config", "lfs.extension.barrier.smudge", "cat"]); + yield* git(["config", "lfs.extension.barrier.priority", "0"]); + yield* fs.writeFileString( + path.join(cwd, ".gitattributes"), + "*.bin filter=lfs diff=lfs merge=lfs -text\n", + ); + yield* fs.writeFileString(path.join(cwd, "asset.bin"), "untracked asset\n"); + const lfsTemp = path.join(cwd, ".git/lfs/tmp"); + yield* fs.makeDirectory(lfsTemp, { recursive: true }); + yield* fs.writeFileString(path.join(lfsTemp, "earlier-writer"), "not this capture's\n"); + + const fiber = yield* driver.checkpoints + .captureCheckpoint({ cwd, checkpointRef }) + .pipe(Effect.exit, Effect.forkScoped); + yield* Effect.promise(() => connected.promise).pipe( + Effect.raceFirst( + Fiber.join(fiber).pipe( + Effect.andThen(Effect.die("capture ended before the LFS extension started")), + ), + ), + ); + const stranded = (yield* fs.readDirectory(lfsTemp)).filter( + (name) => name !== "earlier-writer", + ); + assert.strictEqual(stranded.length, 1); + // Another git-lfs process can create and keep writing a temp file while staging runs. + const concurrent = path.join(lfsTemp, "concurrent-writer"); + yield* fs.writeFileString(concurrent, "in progress\n"); + if (stop === "interrupt") yield* Fiber.interrupt(fiber); + else yield* TestClock.adjust("30 seconds"); + const result = yield* Fiber.await(fiber); + if (stop === "interrupt") + assert.isTrue(Exit.isFailure(result) && Cause.hasInterruptsOnly(result.cause)); + else { + const error = + Exit.isSuccess(result) && Exit.isFailure(result.value) + ? Cause.findErrorOption(result.value.cause) + : Option.none(); + assert.isTrue(Option.isSome(error) && error.value._tag === "VcsProcessTimeoutError"); + } + yield* fs.writeFileString(concurrent, "in progress, now longer\n"); + + yield* git(["config", "lfs.extension.barrier.clean", "cat"]); + yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); + assert.deepEqual((yield* fs.readDirectory(lfsTemp)).sort(), [ + "concurrent-writer", + "earlier-writer", + ]); + assert.include( + (yield* git(["show", `${checkpointRef}:asset.bin`])).stdout, + "https://git-lfs.github.com/spec/v1", + ); + }).pipe(Effect.scoped, Effect.provide(layerGitContract)), + ); + it.effect.each(["failure", "interrupt"] as const)( "checkpoint publication $0 preserves existing refs and permits retry", (stop) => diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index 3ba545caf97a8..611ea35fd3cf3 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -1197,6 +1197,52 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( }); const untrackedBlobs = CheckpointUntrackedBlobs.make(execute, fileSystem); + // git-lfs's clean filter copies each file into lfs/tmp and leaves the copy when it is killed. + // Entries that appear while staging fails are recorded, and the next capture removes those still + // unchanged: this capture's Git processes have exited by then, while a concurrent git-lfs process + // still using one would have renamed it away or written to it in the meantime. + const strandedLfsTemp = new Map>(); + const lfsTempEntries = (directory: string) => + fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray => [])); + const lfsTempSignature = (file: string) => + fileSystem.stat(file).pipe( + Effect.map((info) => + info.type === "File" && Option.isSome(info.mtime) + ? `${info.size}:${info.mtime.value.getTime()}` + : undefined, + ), + Effect.orElseSucceed(() => undefined), + ); + const removeStrandedLfsTemp = Effect.fn("GitVcsDriver.removeStrandedLfsTemp")(function* ( + directory: string, + ) { + const stranded = strandedLfsTemp.get(directory); + if (stranded === undefined) return; + strandedLfsTemp.delete(directory); + yield* Effect.forEach( + stranded, + ([name, signature]) => + Effect.gen(function* () { + const file = path.join(directory, name); + if ((yield* lfsTempSignature(file)) === signature) + yield* fileSystem.remove(file).pipe(Effect.ignore); + }), + { discard: true }, + ); + }); + const recordStrandedLfsTemp = Effect.fn("GitVcsDriver.recordStrandedLfsTemp")(function* ( + directory: string, + before: ReadonlySet, + ) { + const stranded = strandedLfsTemp.get(directory) ?? new Map(); + for (const name of yield* lfsTempEntries(directory)) { + if (before.has(name)) continue; + const signature = yield* lfsTempSignature(path.join(directory, name)); + if (signature !== undefined) stranded.set(name, signature); + } + if (stranded.size > 0) strandedLfsTemp.set(directory, stranded); + }); + const checkpoints: VcsDriver.VcsCheckpointOps = { captureCheckpoint: Effect.fn("GitVcsDriver.checkpoints.captureCheckpoint")(function* (input) { const operation = VcsProcess.CHECKPOINT_CAPTURE_OPERATION; @@ -1558,6 +1604,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( () => Effect.void, ), ); + const lfsTemp = path.join(gitCommonDir, "lfs", "tmp"); + yield* removeStrandedLfsTemp(lfsTemp); + const lfsTempBefore = new Set(yield* lfsTempEntries(lfsTemp)); const stagingAt = yield* Clock.currentTimeMillis; yield* stageFiles([]).pipe( Effect.catchTags({ @@ -1614,6 +1663,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( }), ), }), + // Runs after a failed or interrupted add's process group has been killed and awaited. + Effect.onError(() => recordStrandedLfsTemp(lfsTemp, lfsTempBefore)), ); const stagingMs = (yield* Clock.currentTimeMillis) - stagingAt; From 8b26dcf964cb8857f615cadc62915df17c1c6c43 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 22:10:19 +0000 Subject: [PATCH 2/6] fix(server): keep a concurrent capture's live Git LFS temp file A capture in a sibling worktree of the same repository shares lfs/tmp and can hold its own temp file unchanged while its clean filter waits, so the unchanged-signature rule alone could delete a live file. Removal of recorded entries now waits until no other capture of that repository is staging, and the test covers a second, blocked capture instead of a simulated writer. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 62 +++++++++++++----------- apps/server/src/vcs/GitVcsDriver.ts | 23 +++++++-- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 1e91592e871f5..7acdd34c111c6 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -16,6 +16,7 @@ import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; +import * as Queue from "effect/Queue"; import * as PlatformError from "effect/PlatformError"; import { ChildProcessSpawner } from "effect/process"; import * as Metric from "effect/Metric"; @@ -376,7 +377,7 @@ const gitLfsAvailable = NodeChildProcess.spawnSync("git", ["lfs", "version"]).st // git-lfs runs extension commands without a shell, so it needs git-lfs and a POSIX `cat`. for (const stop of ["interrupt", "timeout"] as const) it.effect.skipIf(!gitLfsAvailable || HostProcess.Platform.defaultValue() === "win32")( - `checkpoint staging stopped by ${stop} does not strand Git LFS temp files`, + `checkpoint staging stopped by ${stop} removes its Git LFS temp files but not a concurrent capture's`, () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; @@ -389,13 +390,13 @@ for (const stop of ["interrupt", "timeout"] as const) yield* git(["lfs", "install", "--local"]); // git-lfs creates its temp file before it starts an extension, so an extension that waits - // on this socket holds the clean filter mid-file until the capture is stopped. - const connected = Promise.withResolvers(); + // on this socket holds the clean filter mid-file until its capture is stopped. + const connections = yield* Queue.unbounded(); const server = yield* Effect.acquireRelease( Effect.sync(() => NodeNet.createServer((socket) => { socket.resume(); - connected.resolve(); + Queue.offerUnsafe(connections, undefined); }), ), (server) => Effect.sync(() => server.close()), @@ -429,27 +430,30 @@ for (const stop of ["interrupt", "timeout"] as const) const lfsTemp = path.join(cwd, ".git/lfs/tmp"); yield* fs.makeDirectory(lfsTemp, { recursive: true }); yield* fs.writeFileString(path.join(lfsTemp, "earlier-writer"), "not this capture's\n"); - - const fiber = yield* driver.checkpoints - .captureCheckpoint({ cwd, checkpointRef }) - .pipe(Effect.exit, Effect.forkScoped); - yield* Effect.promise(() => connected.promise).pipe( - Effect.raceFirst( - Fiber.join(fiber).pipe( - Effect.andThen(Effect.die("capture ended before the LFS extension started")), + const lfsTempEntries = Effect.map(fs.readDirectory(lfsTemp), (names) => names.toSorted()); + + const startBlockedCapture = Effect.gen(function* () { + const fiber = yield* driver.checkpoints + .captureCheckpoint({ cwd, checkpointRef }) + .pipe(Effect.exit, Effect.forkScoped); + yield* Queue.take(connections).pipe( + Effect.raceFirst( + Fiber.join(fiber).pipe( + Effect.andThen(Effect.die("capture ended before the LFS extension started")), + ), ), - ), - ); - const stranded = (yield* fs.readDirectory(lfsTemp)).filter( - (name) => name !== "earlier-writer", - ); - assert.strictEqual(stranded.length, 1); - // Another git-lfs process can create and keep writing a temp file while staging runs. - const concurrent = path.join(lfsTemp, "concurrent-writer"); - yield* fs.writeFileString(concurrent, "in progress\n"); - if (stop === "interrupt") yield* Fiber.interrupt(fiber); - else yield* TestClock.adjust("30 seconds"); - const result = yield* Fiber.await(fiber); + ); + return fiber; + }); + const stopped = yield* startBlockedCapture; + yield* TestClock.adjust("15 seconds"); + // A capture of the same repository holds its own unchanged temp file while it waits. + const concurrent = yield* startBlockedCapture; + const held = yield* lfsTempEntries; + assert.strictEqual(held.length, 3); + if (stop === "interrupt") yield* Fiber.interrupt(stopped); + else yield* TestClock.adjust("15 seconds"); + const result = yield* Fiber.await(stopped); if (stop === "interrupt") assert.isTrue(Exit.isFailure(result) && Cause.hasInterruptsOnly(result.cause)); else { @@ -459,14 +463,14 @@ for (const stop of ["interrupt", "timeout"] as const) : Option.none(); assert.isTrue(Option.isSome(error) && error.value._tag === "VcsProcessTimeoutError"); } - yield* fs.writeFileString(concurrent, "in progress, now longer\n"); yield* git(["config", "lfs.extension.barrier.clean", "cat"]); yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); - assert.deepEqual((yield* fs.readDirectory(lfsTemp)).sort(), [ - "concurrent-writer", - "earlier-writer", - ]); + assert.deepEqual(yield* lfsTempEntries, held); + + yield* Fiber.interrupt(concurrent); + yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); + assert.deepEqual(yield* lfsTempEntries, ["earlier-writer"]); assert.include( (yield* git(["show", `${checkpointRef}:asset.bin`])).stdout, "https://git-lfs.github.com/spec/v1", diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index e5436b35d3e81..a4cfa75376859 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -1198,10 +1198,22 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( const untrackedBlobs = CheckpointUntrackedBlobs.make(execute, fileSystem); // git-lfs's clean filter copies each file into lfs/tmp and leaves the copy when it is killed. - // Entries that appear while staging fails are recorded, and the next capture removes those still - // unchanged: this capture's Git processes have exited by then, while a concurrent git-lfs process - // still using one would have renamed it away or written to it in the meantime. + // Entries that appear while staging fails are recorded, and a later capture removes those still + // unchanged once no other capture of the repository is staging: a sibling worktree's git-lfs can + // hold its own entry unchanged while it waits, and other git-lfs processes rename or write theirs. const strandedLfsTemp = new Map>(); + const lfsTempStaging = new Map(); + const withLfsTempStaging = (directory: string, effect: Effect.Effect) => + Effect.acquireUseRelease( + Effect.sync(() => lfsTempStaging.set(directory, (lfsTempStaging.get(directory) ?? 0) + 1)), + () => effect, + () => + Effect.sync(() => { + const remaining = (lfsTempStaging.get(directory) ?? 1) - 1; + if (remaining > 0) lfsTempStaging.set(directory, remaining); + else lfsTempStaging.delete(directory); + }), + ); const lfsTempEntries = (directory: string) => fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray => [])); const lfsTempSignature = (file: string) => @@ -1217,7 +1229,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( directory: string, ) { const stranded = strandedLfsTemp.get(directory); - if (stranded === undefined) return; + if (stranded === undefined || lfsTempStaging.has(directory)) return; strandedLfsTemp.delete(directory); yield* Effect.forEach( stranded, @@ -1608,7 +1620,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( yield* removeStrandedLfsTemp(lfsTemp); const lfsTempBefore = new Set(yield* lfsTempEntries(lfsTemp)); const stagingAt = yield* Clock.currentTimeMillis; - yield* stageFiles([]).pipe( + const staging = stageFiles([]).pipe( Effect.catchTags({ VcsProcessExitError: (error) => Effect.gen(function* () { @@ -1666,6 +1678,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( // Runs after a failed or interrupted add's process group has been killed and awaited. Effect.onError(() => recordStrandedLfsTemp(lfsTemp, lfsTempBefore)), ); + yield* withLfsTempStaging(lfsTemp, staging); const stagingMs = (yield* Clock.currentTimeMillis) - stagingAt; From 2a40aecd1dc282c70e6d7ca273a35cbbf365e60d Mon Sep 17 00:00:00 2001 From: Abhirup Ghosh <18056243+abhirupghosh@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:17:58 +0000 Subject: [PATCH 3/6] fix(server): only remove Git LFS temp files that are known new and long idle An unreadable lfs/tmp listing before staging no longer counts as empty, so files that predate the capture are never recorded. A recorded entry is dropped only once it is removed, renamed or rewritten, so a failed removal is retried. An entry is removed only after it has sat unchanged for 60 seconds by the Clock, so a git-lfs process outside T3 that is stalled mid-file keeps its temp file. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 50 ++++++++++++++-- apps/server/src/vcs/GitVcsDriver.ts | 74 ++++++++++++++++-------- 2 files changed, 95 insertions(+), 29 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 7acdd34c111c6..5899fdccbb366 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -375,14 +375,39 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( const gitLfsAvailable = NodeChildProcess.spawnSync("git", ["lfs", "version"]).status === 0; // git-lfs runs extension commands without a shell, so it needs git-lfs and a POSIX `cat`. -for (const stop of ["interrupt", "timeout"] as const) +for (const { stop, baseline } of [ + { stop: "interrupt", baseline: "listed" }, + { stop: "timeout", baseline: "listed" }, + { stop: "interrupt", baseline: "unreadable" }, +] as const) it.effect.skipIf(!gitLfsAvailable || HostProcess.Platform.defaultValue() === "win32")( - `checkpoint staging stopped by ${stop} removes its Git LFS temp files but not a concurrent capture's`, + `checkpoint staging stopped by ${stop} with a ${baseline} lfs/tmp baseline removes its Git LFS temp files but not a concurrent capture's`, () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; - const driver = yield* GitVcsDriver.makeVcsDriverShape(); + const lfsTempSuffix = path.join(".git", "lfs", "tmp"); + let failBaselineRead = baseline === "unreadable"; + let failRemovals = false; + const failure = (method: string) => + Effect.fail( + PlatformError.systemError({ _tag: "PermissionDenied", module: "FileSystem", method }), + ); + const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe( + Effect.provideService(FileSystem.FileSystem, { + ...fs, + readDirectory: (directory, options) => { + if (!failBaselineRead || !directory.endsWith(lfsTempSuffix)) + return fs.readDirectory(directory, options); + failBaselineRead = false; + return failure("readDirectory"); + }, + remove: (file, options) => + failRemovals && path.dirname(file).endsWith(lfsTempSuffix) + ? failure("remove") + : fs.remove(file, options), + }), + ); const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-lfs-" }); const cwd = path.join(sandbox, "repo"); yield* fs.makeDirectory(cwd); @@ -446,6 +471,7 @@ for (const stop of ["interrupt", "timeout"] as const) return fiber; }); const stopped = yield* startBlockedCapture; + const stoppedTemp = (yield* lfsTempEntries).filter((name) => name !== "earlier-writer"); yield* TestClock.adjust("15 seconds"); // A capture of the same repository holds its own unchanged temp file while it waits. const concurrent = yield* startBlockedCapture; @@ -469,8 +495,24 @@ for (const stop of ["interrupt", "timeout"] as const) assert.deepEqual(yield* lfsTempEntries, held); yield* Fiber.interrupt(concurrent); + // Both temp files are still too recently written to count as abandoned. + yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); + assert.deepEqual(yield* lfsTempEntries, held); + // File mtimes are real time; move the test clock well past them. + yield* TestClock.adjust("36500 days"); + // Removals that fail stay recorded, so the next capture retries them. + failRemovals = true; + yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); + failRemovals = false; + assert.deepEqual(yield* lfsTempEntries, held); yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); - assert.deepEqual(yield* lfsTempEntries, ["earlier-writer"]); + // Without a listing from before its staging, the stopped capture recorded nothing. + assert.deepEqual( + yield* lfsTempEntries, + baseline === "listed" + ? ["earlier-writer"] + : ["earlier-writer", ...stoppedTemp].toSorted(), + ); assert.include( (yield* git(["show", `${checkpointRef}:asset.bin`])).stdout, "https://git-lfs.github.com/spec/v1", diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index a4cfa75376859..98f78fd8fa390 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -515,6 +515,9 @@ const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; const FLAGGED_INDEX_ENTRIES_MAX_BYTES = 1024 * 1024; const CHECKPOINT_RECOVERY_MAX_CANDIDATES = 64; const CHECKPOINT_RECOVERY_TIMEOUT = "5 seconds"; +// Twice VcsProcess's default command timeout: a clean filter that wrote nothing for this long is +// stalled far past the point where a capture would have killed its own. +const LFS_TEMP_SETTLED_MS = 60_000; const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024; // Reflog subjects that only point a ref at an existing commit. Anything else counts as creating // one, so an unknown subject keeps its commit attributed. @@ -1198,10 +1201,13 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( const untrackedBlobs = CheckpointUntrackedBlobs.make(execute, fileSystem); // git-lfs's clean filter copies each file into lfs/tmp and leaves the copy when it is killed. - // Entries that appear while staging fails are recorded, and a later capture removes those still - // unchanged once no other capture of the repository is staging: a sibling worktree's git-lfs can - // hold its own entry unchanged while it waits, and other git-lfs processes rename or write theirs. - const strandedLfsTemp = new Map>(); + // Entries that appear while staging fails are recorded. A later capture removes one once no other + // capture of the repository is staging and the entry has sat unchanged for LFS_TEMP_SETTLED_MS, + // since any git-lfs process can hold its entry unchanged while it waits for input. + const strandedLfsTemp = new Map< + string, + Map + >(); const lfsTempStaging = new Map(); const withLfsTempStaging = (directory: string, effect: Effect.Effect) => Effect.acquireUseRelease( @@ -1214,13 +1220,23 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( else lfsTempStaging.delete(directory); }), ); + // A missing directory has no entries; any other failure leaves the listing unknown. const lfsTempEntries = (directory: string) => - fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray => [])); - const lfsTempSignature = (file: string) => + fileSystem.readDirectory(directory).pipe( + Effect.catchIf( + (cause) => cause.reason._tag === "NotFound", + (): Effect.Effect> => Effect.succeed([]), + ), + Effect.orElseSucceed(() => undefined), + ); + const lfsTempStat = (file: string) => fileSystem.stat(file).pipe( Effect.map((info) => info.type === "File" && Option.isSome(info.mtime) - ? `${info.size}:${info.mtime.value.getTime()}` + ? { + signature: `${info.size}:${info.mtime.value.getTime()}`, + mtimeMs: info.mtime.value.getTime(), + } : undefined, ), Effect.orElseSucceed(() => undefined), @@ -1230,27 +1246,34 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ) { const stranded = strandedLfsTemp.get(directory); if (stranded === undefined || lfsTempStaging.has(directory)) return; - strandedLfsTemp.delete(directory); - yield* Effect.forEach( - stranded, - ([name, signature]) => - Effect.gen(function* () { - const file = path.join(directory, name); - if ((yield* lfsTempSignature(file)) === signature) - yield* fileSystem.remove(file).pipe(Effect.ignore); - }), - { discard: true }, - ); + const settledBefore = (yield* Clock.currentTimeMillis) - LFS_TEMP_SETTLED_MS; + for (const [name, recorded] of stranded) { + const file = path.join(directory, name); + const current = yield* lfsTempStat(file); + // Another process renamed or wrote it, so it was never this capture's to remove. + if (current?.signature !== recorded.signature) stranded.delete(name); + else if (recorded.mtimeMs < settledBefore) { + // A failed removal stays recorded for the next capture to retry. + const removed = yield* fileSystem.remove(file).pipe( + Effect.as(true), + Effect.orElseSucceed(() => false), + ); + if (removed) stranded.delete(name); + } + } + if (stranded.size === 0) strandedLfsTemp.delete(directory); }); const recordStrandedLfsTemp = Effect.fn("GitVcsDriver.recordStrandedLfsTemp")(function* ( directory: string, - before: ReadonlySet, + before: ReadonlySet | undefined, ) { - const stranded = strandedLfsTemp.get(directory) ?? new Map(); - for (const name of yield* lfsTempEntries(directory)) { - if (before.has(name)) continue; - const signature = yield* lfsTempSignature(path.join(directory, name)); - if (signature !== undefined) stranded.set(name, signature); + // Without a listing from before staging, a new entry cannot be told from an older one. + if (before === undefined) return; + const stranded = strandedLfsTemp.get(directory) ?? new Map(); + for (const name of (yield* lfsTempEntries(directory)) ?? []) { + if (before.has(name) || stranded.has(name)) continue; + const current = yield* lfsTempStat(path.join(directory, name)); + if (current !== undefined) stranded.set(name, current); } if (stranded.size > 0) strandedLfsTemp.set(directory, stranded); }); @@ -1618,7 +1641,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ); const lfsTemp = path.join(gitCommonDir, "lfs", "tmp"); yield* removeStrandedLfsTemp(lfsTemp); - const lfsTempBefore = new Set(yield* lfsTempEntries(lfsTemp)); + const lfsTempListing = yield* lfsTempEntries(lfsTemp); + const lfsTempBefore = lfsTempListing === undefined ? undefined : new Set(lfsTempListing); const stagingAt = yield* Clock.currentTimeMillis; const staging = stageFiles([]).pipe( Effect.catchTags({ From 771107ec196ea3b97d313270b82eb96fbc3be037 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 22:20:10 +0000 Subject: [PATCH 4/6] fix(server): merge concurrent LFS temp records instead of replacing them Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index 98f78fd8fa390..c75193f00a4bc 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -1269,13 +1269,17 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ) { // Without a listing from before staging, a new entry cannot be told from an older one. if (before === undefined) return; - const stranded = strandedLfsTemp.get(directory) ?? new Map(); + const observed = new Map(); for (const name of (yield* lfsTempEntries(directory)) ?? []) { - if (before.has(name) || stranded.has(name)) continue; + if (before.has(name) || strandedLfsTemp.get(directory)?.has(name)) continue; const current = yield* lfsTempStat(path.join(directory, name)); - if (current !== undefined) stranded.set(name, current); + if (current !== undefined) observed.set(name, current); } - if (stranded.size > 0) strandedLfsTemp.set(directory, stranded); + if (observed.size === 0) return; + // Merge into the current map: a concurrent capture may have recorded entries meanwhile. + const stranded = strandedLfsTemp.get(directory) ?? new Map(); + for (const [name, current] of observed) if (!stranded.has(name)) stranded.set(name, current); + strandedLfsTemp.set(directory, stranded); }); const checkpoints: VcsDriver.VcsCheckpointOps = { From 28778eadf3d5f14ede8a5cc1fc30411be909342d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 22:32:55 +0000 Subject: [PATCH 5/6] fix(server): give each checkpoint capture its own Git LFS storage A file appearing in the shared lfs/tmp while a capture stages does not prove the capture created it: a git-lfs process outside T3 can create one at the same time and stay stalled past any idle threshold, so removing "unchanged new entries" could delete a live writer's temp file. The capture now passes git-lfs a private lfs.storage directory whose objects entry is a symlink to the shared object store, and removes that directory when the capture ends. git-lfs's temp files for this capture therefore land only in a directory the capture owns, and the shared lfs/tmp is never read or cleaned. Repositories without lfs/objects, with a configured lfs.storage, or where the symlink cannot be made keep today's behaviour. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 132 +++++++++-------------- apps/server/src/vcs/GitVcsDriver.ts | 127 ++++++---------------- 2 files changed, 83 insertions(+), 176 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index 5899fdccbb366..daa634c88a734 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -374,54 +374,31 @@ it.effect.each(["interrupt", "timeout", "success"] as const)( const gitLfsAvailable = NodeChildProcess.spawnSync("git", ["lfs", "version"]).status === 0; -// git-lfs runs extension commands without a shell, so it needs git-lfs and a POSIX `cat`. -for (const { stop, baseline } of [ - { stop: "interrupt", baseline: "listed" }, - { stop: "timeout", baseline: "listed" }, - { stop: "interrupt", baseline: "unreadable" }, -] as const) +// git-lfs runs extension commands without a shell, so it needs git-lfs and POSIX paths. +for (const stop of ["interrupt", "timeout"] as const) it.effect.skipIf(!gitLfsAvailable || HostProcess.Platform.defaultValue() === "win32")( - `checkpoint staging stopped by ${stop} with a ${baseline} lfs/tmp baseline removes its Git LFS temp files but not a concurrent capture's`, + `checkpoint staging stopped by ${stop} strands no Git LFS temp file and spares another writer's`, () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; - const lfsTempSuffix = path.join(".git", "lfs", "tmp"); - let failBaselineRead = baseline === "unreadable"; - let failRemovals = false; - const failure = (method: string) => - Effect.fail( - PlatformError.systemError({ _tag: "PermissionDenied", module: "FileSystem", method }), - ); - const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe( - Effect.provideService(FileSystem.FileSystem, { - ...fs, - readDirectory: (directory, options) => { - if (!failBaselineRead || !directory.endsWith(lfsTempSuffix)) - return fs.readDirectory(directory, options); - failBaselineRead = false; - return failure("readDirectory"); - }, - remove: (file, options) => - failRemovals && path.dirname(file).endsWith(lfsTempSuffix) - ? failure("remove") - : fs.remove(file, options), - }), - ); + const driver = yield* GitVcsDriver.makeVcsDriverShape(); const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-lfs-" }); const cwd = path.join(sandbox, "repo"); yield* fs.makeDirectory(cwd); const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd); yield* git(["lfs", "install", "--local"]); + const lfsDir = path.join(cwd, ".git/lfs"); + yield* fs.makeDirectory(path.join(lfsDir, "objects"), { recursive: true }); // git-lfs creates its temp file before it starts an extension, so an extension that waits - // on this socket holds the clean filter mid-file until its capture is stopped. - const connections = yield* Queue.unbounded(); + // on this socket holds the clean filter mid-file until the socket ends or it is killed. + const barriers = yield* Queue.unbounded(); const server = yield* Effect.acquireRelease( Effect.sync(() => NodeNet.createServer((socket) => { socket.resume(); - Queue.offerUnsafe(connections, undefined); + Queue.offerUnsafe(barriers, socket); }), ), (server) => Effect.sync(() => server.close()), @@ -438,7 +415,9 @@ for (const { stop, baseline } of [ const extension = path.join(sandbox, "barrier.cjs"); yield* fs.writeFileString( extension, - `require('node:net').connect(${address.port}, '127.0.0.1').resume(); process.stdin.resume();`, + `const s = require('node:net').connect(${address.port}, '127.0.0.1'); +s.resume(); +s.on('end', () => process.stdin.pipe(process.stdout));`, ); yield* git([ "config", @@ -452,34 +431,30 @@ for (const { stop, baseline } of [ "*.bin filter=lfs diff=lfs merge=lfs -text\n", ); yield* fs.writeFileString(path.join(cwd, "asset.bin"), "untracked asset\n"); - const lfsTemp = path.join(cwd, ".git/lfs/tmp"); - yield* fs.makeDirectory(lfsTemp, { recursive: true }); - yield* fs.writeFileString(path.join(lfsTemp, "earlier-writer"), "not this capture's\n"); - const lfsTempEntries = Effect.map(fs.readDirectory(lfsTemp), (names) => names.toSorted()); - - const startBlockedCapture = Effect.gen(function* () { - const fiber = yield* driver.checkpoints - .captureCheckpoint({ cwd, checkpointRef }) - .pipe(Effect.exit, Effect.forkScoped); - yield* Queue.take(connections).pipe( - Effect.raceFirst( - Fiber.join(fiber).pipe( - Effect.andThen(Effect.die("capture ended before the LFS extension started")), - ), + yield* fs.writeFileString(path.join(cwd, "external.bin"), "another writer's asset\n"); + + const fiber = yield* driver.checkpoints + .captureCheckpoint({ cwd, checkpointRef }) + .pipe(Effect.exit, Effect.forkScoped); + yield* Queue.take(barriers).pipe( + Effect.raceFirst( + Fiber.join(fiber).pipe( + Effect.andThen(Effect.die("capture ended before the LFS extension started")), ), - ); - return fiber; + ), + ); + // A git-lfs writer outside T3 holds its own temp file in the shared lfs/tmp meanwhile. + const external = NodeChildProcess.spawn("git", ["add", "external.bin"], { + cwd, + stdio: "ignore", }); - const stopped = yield* startBlockedCapture; - const stoppedTemp = (yield* lfsTempEntries).filter((name) => name !== "earlier-writer"); - yield* TestClock.adjust("15 seconds"); - // A capture of the same repository holds its own unchanged temp file while it waits. - const concurrent = yield* startBlockedCapture; - const held = yield* lfsTempEntries; - assert.strictEqual(held.length, 3); - if (stop === "interrupt") yield* Fiber.interrupt(stopped); - else yield* TestClock.adjust("15 seconds"); - const result = yield* Fiber.await(stopped); + const externalExit = new Promise((resolve) => + external.once("exit", resolve), + ); + const externalBarrier = yield* Queue.take(barriers); + if (stop === "interrupt") yield* Fiber.interrupt(fiber); + else yield* TestClock.adjust("30 seconds"); + const result = yield* Fiber.await(fiber); if (stop === "interrupt") assert.isTrue(Exit.isFailure(result) && Cause.hasInterruptsOnly(result.cause)); else { @@ -489,33 +464,24 @@ for (const { stop, baseline } of [ : Option.none(); assert.isTrue(Option.isSome(error) && error.value._tag === "VcsProcessTimeoutError"); } + const lfsEntries = Effect.all([ + Effect.map(fs.readDirectory(lfsDir), (names) => names.toSorted()), + Effect.map(fs.readDirectory(path.join(lfsDir, "tmp")), (names) => names.length), + ]); + assert.deepEqual(yield* lfsEntries, [["objects", "tmp"], 1]); + // The other writer stays stalled through a later capture, however long it waits. yield* git(["config", "lfs.extension.barrier.clean", "cat"]); + yield* TestClock.adjust("1 hour"); yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); - assert.deepEqual(yield* lfsTempEntries, held); - - yield* Fiber.interrupt(concurrent); - // Both temp files are still too recently written to count as abandoned. - yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); - assert.deepEqual(yield* lfsTempEntries, held); - // File mtimes are real time; move the test clock well past them. - yield* TestClock.adjust("36500 days"); - // Removals that fail stay recorded, so the next capture retries them. - failRemovals = true; - yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); - failRemovals = false; - assert.deepEqual(yield* lfsTempEntries, held); - yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }); - // Without a listing from before its staging, the stopped capture recorded nothing. - assert.deepEqual( - yield* lfsTempEntries, - baseline === "listed" - ? ["earlier-writer"] - : ["earlier-writer", ...stoppedTemp].toSorted(), - ); - assert.include( - (yield* git(["show", `${checkpointRef}:asset.bin`])).stdout, - "https://git-lfs.github.com/spec/v1", + assert.deepEqual(yield* lfsEntries, [["objects", "tmp"], 1]); + externalBarrier.end(); + assert.strictEqual(yield* Effect.promise(() => externalExit), 0); + assert.deepEqual(yield* lfsEntries, [["objects", "tmp"], 0]); + const pointer = (yield* git(["show", `${checkpointRef}:asset.bin`])).stdout; + const oid = /oid sha256:([0-9a-f]{64})/.exec(pointer)?.[1] ?? ""; + assert.isTrue( + yield* fs.exists(path.join(lfsDir, "objects", oid.slice(0, 2), oid.slice(2, 4), oid)), ); }).pipe(Effect.scoped, Effect.provide(layerGitContract)), ); diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index c75193f00a4bc..f843190c6de86 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -515,9 +515,6 @@ const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; const FLAGGED_INDEX_ENTRIES_MAX_BYTES = 1024 * 1024; const CHECKPOINT_RECOVERY_MAX_CANDIDATES = 64; const CHECKPOINT_RECOVERY_TIMEOUT = "5 seconds"; -// Twice VcsProcess's default command timeout: a clean filter that wrote nothing for this long is -// stalled far past the point where a capture would have killed its own. -const LFS_TEMP_SETTLED_MS = 60_000; const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024; // Reflog subjects that only point a ref at an existing commit. Anything else counts as creating // one, so an unknown subject keeps its commit attributed. @@ -1200,88 +1197,6 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( }); const untrackedBlobs = CheckpointUntrackedBlobs.make(execute, fileSystem); - // git-lfs's clean filter copies each file into lfs/tmp and leaves the copy when it is killed. - // Entries that appear while staging fails are recorded. A later capture removes one once no other - // capture of the repository is staging and the entry has sat unchanged for LFS_TEMP_SETTLED_MS, - // since any git-lfs process can hold its entry unchanged while it waits for input. - const strandedLfsTemp = new Map< - string, - Map - >(); - const lfsTempStaging = new Map(); - const withLfsTempStaging = (directory: string, effect: Effect.Effect) => - Effect.acquireUseRelease( - Effect.sync(() => lfsTempStaging.set(directory, (lfsTempStaging.get(directory) ?? 0) + 1)), - () => effect, - () => - Effect.sync(() => { - const remaining = (lfsTempStaging.get(directory) ?? 1) - 1; - if (remaining > 0) lfsTempStaging.set(directory, remaining); - else lfsTempStaging.delete(directory); - }), - ); - // A missing directory has no entries; any other failure leaves the listing unknown. - const lfsTempEntries = (directory: string) => - fileSystem.readDirectory(directory).pipe( - Effect.catchIf( - (cause) => cause.reason._tag === "NotFound", - (): Effect.Effect> => Effect.succeed([]), - ), - Effect.orElseSucceed(() => undefined), - ); - const lfsTempStat = (file: string) => - fileSystem.stat(file).pipe( - Effect.map((info) => - info.type === "File" && Option.isSome(info.mtime) - ? { - signature: `${info.size}:${info.mtime.value.getTime()}`, - mtimeMs: info.mtime.value.getTime(), - } - : undefined, - ), - Effect.orElseSucceed(() => undefined), - ); - const removeStrandedLfsTemp = Effect.fn("GitVcsDriver.removeStrandedLfsTemp")(function* ( - directory: string, - ) { - const stranded = strandedLfsTemp.get(directory); - if (stranded === undefined || lfsTempStaging.has(directory)) return; - const settledBefore = (yield* Clock.currentTimeMillis) - LFS_TEMP_SETTLED_MS; - for (const [name, recorded] of stranded) { - const file = path.join(directory, name); - const current = yield* lfsTempStat(file); - // Another process renamed or wrote it, so it was never this capture's to remove. - if (current?.signature !== recorded.signature) stranded.delete(name); - else if (recorded.mtimeMs < settledBefore) { - // A failed removal stays recorded for the next capture to retry. - const removed = yield* fileSystem.remove(file).pipe( - Effect.as(true), - Effect.orElseSucceed(() => false), - ); - if (removed) stranded.delete(name); - } - } - if (stranded.size === 0) strandedLfsTemp.delete(directory); - }); - const recordStrandedLfsTemp = Effect.fn("GitVcsDriver.recordStrandedLfsTemp")(function* ( - directory: string, - before: ReadonlySet | undefined, - ) { - // Without a listing from before staging, a new entry cannot be told from an older one. - if (before === undefined) return; - const observed = new Map(); - for (const name of (yield* lfsTempEntries(directory)) ?? []) { - if (before.has(name) || strandedLfsTemp.get(directory)?.has(name)) continue; - const current = yield* lfsTempStat(path.join(directory, name)); - if (current !== undefined) observed.set(name, current); - } - if (observed.size === 0) return; - // Merge into the current map: a concurrent capture may have recorded entries meanwhile. - const stranded = strandedLfsTemp.get(directory) ?? new Map(); - for (const [name, current] of observed) if (!stranded.has(name)) stranded.set(name, current); - strandedLfsTemp.set(directory, stranded); - }); - const checkpoints: VcsDriver.VcsCheckpointOps = { captureCheckpoint: Effect.fn("GitVcsDriver.checkpoints.captureCheckpoint")(function* (input) { const operation = VcsProcess.CHECKPOINT_CAPTURE_OPERATION; @@ -1344,6 +1259,36 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ), ), ); + // A stopped add strands git-lfs's copy in lfs/tmp, which other git-lfs writers share, so this + // capture gives git-lfs its own storage that reaches the shared objects through a symlink. + const lfsObjects = path.join(gitCommonDir, "lfs", "objects"); + const privateLfsStorage = yield* Effect.gen(function* () { + if (!(yield* fileSystem.exists(lfsObjects))) return undefined; + const configuredStorage = yield* execute({ + operation, + cwd: input.cwd, + args: ["config", "--get", "lfs.storage"], + allowNonZeroExit: true, + }); + if (configuredStorage.stdout.trim() !== "") return undefined; + const directory = yield* Effect.acquireRelease( + fileSystem.makeTempDirectory({ + directory: path.dirname(lfsObjects), + prefix: "t3-checkpoint-", + }), + (directory) => + fileSystem.remove(directory, { recursive: true, force: true }).pipe( + Effect.catch((cause) => + Effect.logWarning("Could not remove private checkpoint LFS storage", { + reason: cause.reason._tag, + }), + ), + ), + ); + // Windows can refuse the symlink; git-lfs then uses its shared storage as before. + yield* fileSystem.symlink(lfsObjects, path.join(directory, "objects")); + return directory; + }).pipe(Effect.orElseSucceed(() => undefined)); const commitEnv: NodeJS.ProcessEnv = { GIT_INDEX_FILE: tempIndexPath, GIT_OBJECT_DIRECTORY: privateObjects, @@ -1623,6 +1568,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( // safecrlf=true refuses LF files under CRLF conversion; capture them as Git's default does. "-c", "core.safecrlf=false", + ...(privateLfsStorage === undefined + ? [] + : ["-c", `lfs.storage=${privateLfsStorage}`]), "add", // Unreadable files keep their indexed version and unreadable new files are left out. ...(ignoreErrors ? ["--ignore-errors"] : []), @@ -1643,12 +1591,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( () => Effect.void, ), ); - const lfsTemp = path.join(gitCommonDir, "lfs", "tmp"); - yield* removeStrandedLfsTemp(lfsTemp); - const lfsTempListing = yield* lfsTempEntries(lfsTemp); - const lfsTempBefore = lfsTempListing === undefined ? undefined : new Set(lfsTempListing); const stagingAt = yield* Clock.currentTimeMillis; - const staging = stageFiles([]).pipe( + yield* stageFiles([]).pipe( Effect.catchTags({ VcsProcessExitError: (error) => Effect.gen(function* () { @@ -1703,10 +1647,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( }), ), }), - // Runs after a failed or interrupted add's process group has been killed and awaited. - Effect.onError(() => recordStrandedLfsTemp(lfsTemp, lfsTempBefore)), ); - yield* withLfsTempStaging(lfsTemp, staging); const stagingMs = (yield* Clock.currentTimeMillis) - stagingAt; From fda03fd8210fd36509e9909f0b98152e8846351e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 23:40:16 +0000 Subject: [PATCH 6/6] fix(server): isolate checkpoint Git LFS storage without a symlink The private lfs.storage reached the shared objects through a symlink, which Windows refuses without symlink rights, so those hosts fell back to the shared lfs/tmp and kept stranding temp files. The private storage now has its own objects directory, and after staging succeeds the capture renames the objects git-lfs wrote into the shared store. A stopped capture's storage is removed with its temp files as before. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/GitVcsDriver.test.ts | 18 ++++++++++++-- apps/server/src/vcs/GitVcsDriver.ts | 31 +++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.ts index daa634c88a734..78383768a73e0 100644 --- a/apps/server/src/vcs/GitVcsDriver.test.ts +++ b/apps/server/src/vcs/GitVcsDriver.test.ts @@ -382,7 +382,20 @@ for (const stop of ["interrupt", "timeout"] as const) Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; - const driver = yield* GitVcsDriver.makeVcsDriverShape(); + // Windows hosts without symlink rights must get the same isolation. + const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe( + Effect.provideService(FileSystem.FileSystem, { + ...fs, + symlink: () => + Effect.fail( + PlatformError.systemError({ + _tag: "PermissionDenied", + module: "FileSystem", + method: "symlink", + }), + ), + }), + ); const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-lfs-" }); const cwd = path.join(sandbox, "repo"); yield* fs.makeDirectory(cwd); @@ -479,7 +492,8 @@ s.on('end', () => process.stdin.pipe(process.stdout));`, assert.strictEqual(yield* Effect.promise(() => externalExit), 0); assert.deepEqual(yield* lfsEntries, [["objects", "tmp"], 0]); const pointer = (yield* git(["show", `${checkpointRef}:asset.bin`])).stdout; - const oid = /oid sha256:([0-9a-f]{64})/.exec(pointer)?.[1] ?? ""; + const oid = /oid sha256:([0-9a-f]{64})/.exec(pointer)?.[1]; + if (oid === undefined) return assert.fail(`not an LFS pointer: ${pointer}`); assert.isTrue( yield* fs.exists(path.join(lfsDir, "objects", oid.slice(0, 2), oid.slice(2, 4), oid)), ); diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts index f843190c6de86..382eee566061f 100644 --- a/apps/server/src/vcs/GitVcsDriver.ts +++ b/apps/server/src/vcs/GitVcsDriver.ts @@ -666,6 +666,9 @@ const gitSupportsRemergeDiff = (versionOutput: string): boolean => { return major > 2 || (major === 2 && Number(match[2]) >= 36); }; +// git-lfs stores each object at objects///. +const LFS_OBJECT_PATH = /^[0-9a-f]{2}[\\/][0-9a-f]{2}[\\/][0-9a-f]{64}$/; + export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* () { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -1260,7 +1263,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ), ); // A stopped add strands git-lfs's copy in lfs/tmp, which other git-lfs writers share, so this - // capture gives git-lfs its own storage that reaches the shared objects through a symlink. + // capture gives git-lfs its own storage and moves the objects it wrote out once staging succeeds. const lfsObjects = path.join(gitCommonDir, "lfs", "objects"); const privateLfsStorage = yield* Effect.gen(function* () { if (!(yield* fileSystem.exists(lfsObjects))) return undefined; @@ -1285,10 +1288,30 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( ), ), ); - // Windows can refuse the symlink; git-lfs then uses its shared storage as before. - yield* fileSystem.symlink(lfsObjects, path.join(directory, "objects")); return directory; }).pipe(Effect.orElseSucceed(() => undefined)); + const publishLfsObjects = Effect.fn("GitVcsDriver.publishLfsObjects")( + function* (storage: string) { + const objects = path.join(storage, "objects"); + const entries = yield* fileSystem.readDirectory(objects, { recursive: true }).pipe( + Effect.catchIf( + (cause) => cause.reason._tag === "NotFound", + (): Effect.Effect> => Effect.succeed([]), + ), + ); + for (const entry of entries) { + if (!LFS_OBJECT_PATH.test(entry)) continue; + const target = path.join(lfsObjects, entry); + if (yield* fileSystem.exists(target)) continue; + yield* fileSystem.makeDirectory(path.dirname(target), { recursive: true }); + yield* fileSystem.rename(path.join(objects, entry), target); + } + }, + Effect.mapError( + (cause) => + new VcsCheckpointStorageError({ operation, cwd: input.cwd, stage: "publish", cause }), + ), + ); const commitEnv: NodeJS.ProcessEnv = { GIT_INDEX_FILE: tempIndexPath, GIT_OBJECT_DIRECTORY: privateObjects, @@ -1649,6 +1672,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ( }), ); + if (privateLfsStorage !== undefined) yield* publishLfsObjects(privateLfsStorage); + const stagingMs = (yield* Clock.currentTimeMillis) - stagingAt; const writeTreeResult = yield* execute({