The best way to control Claude Code, Codex and more from any computer or phone
fix(server): interrupted checkpoints no longer leak temporary packs (#23715)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Kolja committed
Nov 14, 2026 at 09:50 UTC
4652544f33ccfa2fda12745438067a3b4e55c269
4 files changed
+486
-1
apps/server/src/vcs/GitVcsDriver.test.ts
+345
@@ -1,3 +1,5 @@
1
+import * as NodeNet from "node:net";
2
+import * as SecureRandom from "effect/crypto/SecureRandom";
3
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
4
import * as NodeServices from "@effect/platform-node/NodeServices";
5
import * as Cause from "effect/Cause";
@@ -173,6 +175,349 @@ const makeCheckpointFixture = Effect.fn("makeCheckpointFixture")(function* (
175
return { git, checkpointRef };
176
});
177
178
+it.effect.each(["interrupt", "timeout", "success"] as const)(
179
+ "checkpoint bulk staging cleans operation-owned packs after $0 and can retry",
180
+ (stop) =>
181
+ Effect.gen(function* () {
182
+ const fs = yield* FileSystem.FileSystem;
183
+ const path = yield* Path.Path;
184
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
185
+ const liveProcess = yield* VcsProcess.VcsProcess;
186
+ const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-bulk-checkpoint-" });
187
+ const cwd = path.join(sandbox, "repo");
188
+ yield* fs.makeDirectory(cwd);
189
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
190
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
191
+ const originalCheckpoint = (yield* git(["rev-parse", checkpointRef])).stdout;
192
+ const originalIndex = yield* fs.readFile(path.join(cwd, ".git/index"));
193
+ const originalHead = (yield* git(["rev-parse", "HEAD"])).stdout;
194
+ yield* git(["config", "core.bigFileThreshold", "1m"]);
195
+ const crypto = yield* SecureRandom.SecureRandom;
196
+ const payload = yield* crypto.randomBytes(2 * 1024 * 1024);
197
+ yield* fs.writeFile(path.join(cwd, "a-media.bin"), payload);
198
+
199
+ // Git keeps bulk-checkin's pack open while the next path's clean filter runs.
200
+ // The socket is a barrier, not a race against the speed of compression.
201
+ const connected = Promise.withResolvers<NodeNet.Socket>();
202
+ const sockets = new Set<NodeNet.Socket>();
203
+ let released = false;
204
+ const server = yield* Effect.acquireRelease(
205
+ Effect.sync(() =>
206
+ NodeNet.createServer((socket) => {
207
+ sockets.add(socket);
208
+ connected.resolve(socket);
209
+ // Git can run the filter again while refreshing the staged entry.
210
+ if (released) socket.end();
211
+ }),
212
+ ),
213
+ (server) =>
214
+ Effect.sync(() => {
215
+ for (const socket of sockets) socket.destroy();
216
+ server.close();
217
+ }),
218
+ );
219
+ yield* Effect.promise(
220
+ () =>
221
+ new Promise<void>((resolve, reject) => {
222
+ server.once("error", reject);
223
+ server.listen(0, "127.0.0.1", resolve);
224
+ }),
225
+ );
226
+ const address = server.address();
227
+ assert.isTrue(address !== null && typeof address !== "string");
228
+ if (address === null || typeof address === "string") return;
229
+ const filter = path.join(sandbox, "filter.cjs");
230
+ yield* fs.writeFileString(
231
+ filter,
232
+ `const s = require('node:net').connect(${address.port}, '127.0.0.1'); s.resume(); process.stdin.resume(); s.on('end', () => process.exit(0));`,
233
+ );
234
+ yield* git(["config", "filter.barrier.clean", `"${process.execPath}" "${filter}"`]);
235
+ yield* git(["config", "filter.barrier.required", "true"]);
236
+ yield* fs.writeFileString(path.join(cwd, ".gitattributes"), "z-gate filter=barrier\n");
237
+ yield* fs.writeFileString(path.join(cwd, "z-gate"), "gate\n");
238
+ const sharedPack = path.join(cwd, ".git/objects/pack/tmp_pack_other_operation");
239
+ yield* fs.writeFileString(sharedPack, "owned by another Git operation");
240
+ let objectDirectory = path.join(cwd, ".git/objects");
241
+ const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
242
+ Effect.provideService(VcsProcess.VcsProcess, {
243
+ run: (input) => {
244
+ if (input.args.includes("add") && input.env?.GIT_OBJECT_DIRECTORY)
245
+ objectDirectory = input.env.GIT_OBJECT_DIRECTORY;
246
+ return liveProcess.run(input);
247
+ },
248
+ }),
249
+ );
250
+ const fiber = yield* captureDriver.checkpoints
251
+ .captureCheckpoint({ cwd, checkpointRef })
252
+ .pipe(Effect.exit, Effect.forkScoped);
253
+ const socket = yield* Effect.promise(() => connected.promise).pipe(
254
+ Effect.raceFirst(
255
+ Fiber.join(fiber).pipe(
256
+ Effect.flatMap((result) =>
257
+ Exit.isFailure(result)
258
+ ? Effect.failCause(result.cause)
259
+ : Effect.die("capture ended before the filter connected"),
260
+ ),
261
+ ),
262
+ ),
263
+ );
264
+ const packs = (yield* fs.readDirectory(path.join(objectDirectory, "pack"))).filter(
265
+ (name) => name.startsWith("tmp_pack_") && name !== "tmp_pack_other_operation",
266
+ );
267
+ assert.strictEqual(packs.length, 1);
268
+ assert.isAbove(
269
+ Number((yield* fs.stat(path.join(objectDirectory, "pack", packs[0]!))).size),
270
+ 1024 * 1024,
271
+ );
272
+ // An overlapping capture publishes the same large blob while the first
273
+ // still owns an unfinished pack. Its objects/ref must survive either exit.
274
+ const concurrentRef = CheckpointRef.make("refs/t3/checkpoints/concurrent");
275
+ const concurrentDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
276
+ Effect.provideService(VcsProcess.VcsProcess, {
277
+ run: (input) =>
278
+ liveProcess.run({ ...input, args: ["-c", "filter.barrier.clean=cat", ...input.args] }),
279
+ }),
280
+ );
281
+ yield* concurrentDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef: concurrentRef });
282
+ const concurrentOid = (yield* git(["rev-parse", concurrentRef])).stdout;
283
+ const sharedPackNames = (yield* fs.readDirectory(path.join(cwd, ".git/objects/pack"))).sort();
284
+ const packName = sharedPackNames.find((name) => name.endsWith(".pack"));
285
+ assert.isDefined(packName);
286
+ const sharedPackBytes = yield* fs.readFile(path.join(cwd, ".git/objects/pack", packName!));
287
+ if (stop === "interrupt") yield* Fiber.interrupt(fiber);
288
+ else if (stop === "timeout") yield* TestClock.adjust("30 seconds");
289
+ released = true;
290
+ socket.end();
291
+ const result = yield* Fiber.await(fiber);
292
+ if (stop === "interrupt")
293
+ assert.isTrue(Exit.isFailure(result) && Cause.hasInterruptsOnly(result.cause));
294
+ else if (stop === "timeout") {
295
+ assert.isTrue(Exit.isSuccess(result));
296
+ if (Exit.isSuccess(result)) {
297
+ assert.isTrue(Exit.isFailure(result.value));
298
+ if (Exit.isFailure(result.value)) {
299
+ const error = Cause.findErrorOption(result.value.cause);
300
+ assert.isTrue(Option.isSome(error) && error.value._tag === "VcsProcessTimeoutError");
301
+ }
302
+ }
303
+ } else assert.isTrue(Exit.isSuccess(result) && Exit.isSuccess(result.value));
304
+ assert.deepEqual(
305
+ (yield* fs.readDirectory(path.join(cwd, ".git/objects/pack"))).sort(),
306
+ sharedPackNames,
307
+ );
308
+ assert.deepEqual(
309
+ yield* fs.readFile(path.join(cwd, ".git/objects/pack", packName!)),
310
+ sharedPackBytes,
311
+ );
312
+ assert.strictEqual((yield* git(["rev-parse", concurrentRef])).stdout, concurrentOid);
313
+ assert.isFalse(yield* fs.exists(path.join(objectDirectory, "pack", packs[0]!)));
314
+ assert.isFalse(yield* fs.exists(objectDirectory));
315
+ assert.strictEqual(yield* fs.readFileString(sharedPack), "owned by another Git operation");
316
+ if (stop !== "success")
317
+ assert.strictEqual((yield* git(["rev-parse", checkpointRef])).stdout, originalCheckpoint);
318
+ assert.deepEqual(yield* fs.readFile(path.join(cwd, ".git/index")), originalIndex);
319
+ assert.strictEqual((yield* git(["rev-parse", "HEAD"])).stdout, originalHead);
320
+ assert.deepEqual(yield* fs.readFile(path.join(cwd, "a-media.bin")), payload);
321
+
322
+ yield* git(["config", "filter.barrier.clean", "cat"]);
323
+ yield* captureDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
324
+ assert.isFalse(yield* fs.exists(objectDirectory));
325
+ const blob = (yield* git(["hash-object", "a-media.bin"])).stdout.trim();
326
+ assert.strictEqual(
327
+ (yield* git(["rev-parse", `${checkpointRef}:a-media.bin`])).stdout.trim(),
328
+ blob,
329
+ );
330
+ yield* fs.remove(sharedPack);
331
+ yield* git(["fsck", "--full"]);
332
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
333
+);
334
+
335
+it.effect.each(["failure", "interrupt"] as const)(
336
+ "checkpoint publication $0 preserves existing refs and permits retry",
337
+ (stop) =>
338
+ Effect.gen(function* () {
339
+ const fs = yield* FileSystem.FileSystem;
340
+ const path = yield* Path.Path;
341
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
342
+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-publish-" });
343
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
344
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
345
+ const previous = (yield* git(["show-ref"])).stdout;
346
+ yield* fs.writeFileString(path.join(cwd, "new.txt"), "new checkpoint content\n");
347
+ const published = yield* Deferred.make<void>();
348
+ const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
349
+ Effect.provideService(FileSystem.FileSystem, {
350
+ ...fs,
351
+ link: (source, destination) =>
352
+ fs.link(source, destination).pipe(
353
+ Effect.andThen(Deferred.succeed(published, undefined)),
354
+ Effect.andThen(
355
+ stop === "interrupt"
356
+ ? Effect.never
357
+ : Effect.fail(
358
+ PlatformError.systemError({
359
+ _tag: "BadResource",
360
+ module: "FileSystem",
361
+ method: "link",
362
+ }),
363
+ ),
364
+ ),
365
+ ),
366
+ }),
367
+ );
368
+ const fiber = yield* captureDriver.checkpoints
369
+ .captureCheckpoint({ cwd, checkpointRef })
370
+ .pipe(Effect.exit, Effect.forkScoped);
371
+ yield* Deferred.await(published);
372
+ if (stop === "interrupt") yield* Fiber.interrupt(fiber);
373
+ const result = yield* Fiber.await(fiber);
374
+ if (stop === "interrupt")
375
+ assert.isTrue(Exit.isFailure(result) && Cause.hasInterruptsOnly(result.cause));
376
+ else {
377
+ assert.isTrue(Exit.isSuccess(result) && Exit.isFailure(result.value));
378
+ if (Exit.isSuccess(result) && Exit.isFailure(result.value)) {
379
+ const error = Cause.findErrorOption(result.value.cause);
380
+ assert.isTrue(
381
+ Option.isSome(error) &&
382
+ error.value._tag === "VcsCheckpointStorageError" &&
383
+ error.value.stage === "publish",
384
+ );
385
+ }
386
+ }
387
+ assert.strictEqual((yield* git(["show-ref"])).stdout, previous);
388
+ assert.deepEqual(
389
+ (yield* fs.readDirectory(path.join(cwd, ".git/objects"))).filter((name) =>
390
+ name.startsWith("tmp_objdir-t3-checkpoint-"),
391
+ ),
392
+ [],
393
+ );
394
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
395
+ assert.strictEqual(
396
+ (yield* git(["show", `${checkpointRef}:new.txt`])).stdout,
397
+ "new checkpoint content\n",
398
+ );
399
+ yield* git(["fsck", "--full"]);
400
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
401
+);
402
+
403
+it.effect("checkpoint publication falls back to rename where hardlinks are unavailable", () =>
404
+ Effect.gen(function* () {
405
+ const fs = yield* FileSystem.FileSystem;
406
+ const path = yield* Path.Path;
407
+ const crypto = yield* SecureRandom.SecureRandom;
408
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
409
+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-publish-no-links-" });
410
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
411
+ yield* git(["config", "core.bigFileThreshold", "1m"]);
412
+ yield* fs.writeFile(path.join(cwd, "media.bin"), yield* crypto.randomBytes(2 * 1024 * 1024));
413
+ const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
414
+ Effect.provideService(FileSystem.FileSystem, {
415
+ ...fs,
416
+ link: () =>
417
+ Effect.fail(
418
+ PlatformError.systemError({
419
+ _tag: "PermissionDenied",
420
+ module: "FileSystem",
421
+ method: "link",
422
+ }),
423
+ ),
424
+ }),
425
+ );
426
+ yield* captureDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
427
+ const files = yield* fs.readDirectory(path.join(cwd, ".git/objects/pack"));
428
+ assert.isTrue(files.some((name) => name.endsWith(".pack")));
429
+ assert.isTrue(yield* driver.checkpoints.hasCheckpointRef({ cwd, checkpointRef }));
430
+ assert.match((yield* git(["count-objects", "-v"])).stdout, /^garbage: 0$/m);
431
+ yield* git(["fsck", "--full"]);
432
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
433
+);
434
+
435
+it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
436
+ "checkpoint publication preserves Git's shared object directory permissions",
437
+ () =>
438
+ Effect.gen(function* () {
439
+ const fs = yield* FileSystem.FileSystem;
440
+ const path = yield* Path.Path;
441
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
442
+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-publish-shared-" });
443
+ const git = (args: ReadonlyArray<string>) =>
444
+ driver.execute({ operation: "test.shared", cwd, args });
445
+ yield* git(["init", "--shared=0660"]);
446
+ const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/shared");
447
+ yield* fs.writeFileString(path.join(cwd, "shared.txt"), "new shared object\n");
448
+ const blob = (yield* git(["hash-object", "-w", "shared.txt"])).stdout.trim();
449
+ const directory = path.join(cwd, ".git/objects", blob.slice(0, 2));
450
+ const expectedMode = (yield* fs.stat(directory)).mode & 0o7777;
451
+ yield* fs.remove(directory, { recursive: true });
452
+ assert.isFalse(yield* fs.exists(directory));
453
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
454
+ assert.strictEqual((yield* fs.stat(directory)).mode & 0o7777, expectedMode);
455
+ yield* git(["fsck", "--full"]);
456
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
457
+);
458
+
459
+it.effect("checkpoint capture ignores an inherited object directory", () =>
460
+ Effect.gen(function* () {
461
+ const fs = yield* FileSystem.FileSystem;
462
+ const path = yield* Path.Path;
463
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
464
+ const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-inherited-objects-" });
465
+ const cwd = path.join(sandbox, "repo");
466
+ yield* fs.makeDirectory(cwd);
467
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
468
+ const unrelated = path.join(sandbox, "unrelated");
469
+ yield* git(["init", "--bare", unrelated]);
470
+ const unrelatedObjects = path.join(unrelated, "objects");
471
+ // VcsProcess clears inherited selectors from git children; only the driver sees this one.
472
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }).pipe(
473
+ Effect.provideService(HostProcess.Environment, {
474
+ ...(yield* HostProcess.Environment),
475
+ GIT_OBJECT_DIRECTORY: unrelatedObjects,
476
+ }),
477
+ );
478
+ assert.strictEqual((yield* git(["show", `${checkpointRef}:file.txt`])).stdout, "unstaged\n");
479
+ assert.deepEqual(
480
+ (yield* fs.readDirectory(unrelatedObjects)).filter(
481
+ (name) => name !== "info" && name !== "pack",
482
+ ),
483
+ [],
484
+ );
485
+ yield* git(["fsck", "--full"]);
486
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
487
+);
488
+
489
+it.effect.each(["sha1", "sha256"] as const)(
490
+ "checkpoint object isolation supports linked worktrees with $0 objects",
491
+ (format) =>
492
+ Effect.gen(function* () {
493
+ const fs = yield* FileSystem.FileSystem;
494
+ const path = yield* Path.Path;
495
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
496
+ const sandbox = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-worktree-" });
497
+ // A separator must remain part of the alternate's path, not split the list.
498
+ const platform = yield* HostProcess.Platform;
499
+ const cwd = path.join(sandbox, platform === "win32" ? "repo;space" : 'repo:space"\u0001');
500
+ yield* fs.makeDirectory(cwd);
501
+ yield* driver.execute({
502
+ operation: "test.init",
503
+ cwd,
504
+ args: ["init", `--object-format=${format}`],
505
+ });
506
+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
507
+ const worktree = path.join(sandbox, "linked");
508
+ yield* git(["worktree", "add", "-b", "linked", worktree]);
509
+ yield* fs.writeFileString(path.join(worktree, "untracked.txt"), "linked worktree\n");
510
+ const originalIndex = yield* fs.readFile(path.join(cwd, ".git/index"));
511
+ yield* driver.checkpoints.captureCheckpoint({ cwd: worktree, checkpointRef });
512
+ assert.strictEqual(
513
+ (yield* git(["show", `${checkpointRef}:untracked.txt`])).stdout,
514
+ "linked worktree\n",
515
+ );
516
+ assert.deepEqual(yield* fs.readFile(path.join(cwd, ".git/index")), originalIndex);
517
+ yield* git(["fsck", "--full"]);
518
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
519
+);
520
+
521
it.effect("checkpoint capture skips untracked nested repositories without a commit", () =>
522
Effect.gen(function* () {
523
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/vcs/GitVcsDriver.ts
+125
-1
@@ -12,6 +12,7 @@ import { ChildProcessSpawner } from "effect/process";
12
13
import {
14
GitCommandError,
15
+ VcsCheckpointStorageError,
16
VcsProcessExitError,
17
VcsUnsupportedOperationError,
18
type VcsSwitchRefInput,
@@ -37,6 +38,7 @@ import {
38
} from "@t3tools/contracts";
39
import { isMissingExecutable } from "@t3tools/source-control-core/server/discovery";
40
import * as HostProcess from "@t3tools/shared/HostProcess";
41
+import { quoteGitPatchPath } from "@t3tools/shared/gitPatchPath";
42
import {
43
makeGitVcsDriverCore,
44
PATCH_RENDER_PREFIX_ARGS,
@@ -1064,8 +1066,42 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1066
const indexId = yield* random.uuidV4();
1067
const tempIndexPath = path.join(gitCommonDir, `t3-checkpoint-index-${indexId}`);
1068
const hostEnv = yield* HostProcess.Environment;
1069
+ // VcsProcess clears inherited object selectors, so every other command uses this store.
1070
+ const sharedObjects = path.join(gitCommonDir, "objects");
1071
+ const quotedObjects = quoteGitPatchPath(sharedObjects);
1072
+ // Isolate bulk-checkin packs so cleanup cannot remove another Git writer's objects.
1073
+ const privateObjects = yield* Effect.acquireRelease(
1074
+ fileSystem
1075
+ .makeTempDirectory({ directory: sharedObjects, prefix: "tmp_objdir-t3-checkpoint-" })
1076
+ .pipe(
1077
+ Effect.mapError(
1078
+ (cause) =>
1079
+ new VcsCheckpointStorageError({
1080
+ operation,
1081
+ cwd: input.cwd,
1082
+ stage: "isolate",
1083
+ cause,
1084
+ }),
1085
+ ),
1086
+ ),
1087
+ (directory) =>
1088
+ fileSystem.remove(directory, { recursive: true, force: true }).pipe(
1089
+ Effect.catch((cause) =>
1090
+ Effect.logWarning("Could not remove private checkpoint objects", {
1091
+ reason: cause.reason._tag,
1092
+ }),
1093
+ ),
1094
+ ),
1095
+ );
1096
const commitEnv: NodeJS.ProcessEnv = {
1097
GIT_INDEX_FILE: tempIndexPath,
1098
+ GIT_OBJECT_DIRECTORY: privateObjects,
1099
+ // A filter must not publish refs that depend on our disposable store.
1100
+ GIT_QUARANTINE_PATH: privateObjects,
1101
+ // Git accepts C-quoted alternate paths, including path-list separators.
1102
+ GIT_ALTERNATE_OBJECT_DIRECTORIES: quotedObjects.startsWith('"')
1103
+ ? quotedObjects
1104
+ : `"${quotedObjects}"`,
1105
GIT_AUTHOR_NAME: "T3 Code",
1106
GIT_AUTHOR_EMAIL: "t3code@users.noreply.github.com",
1107
GIT_COMMITTER_NAME: "T3 Code",
@@ -1369,6 +1405,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1405
GIT_INDEX_FILE: undefined,
1406
GIT_OBJECT_DIRECTORY: undefined,
1407
GIT_ALTERNATE_OBJECT_DIRECTORIES: undefined,
1408
+ GIT_QUARANTINE_PATH: undefined,
1409
};
1410
const exclusions: Array<string> = [];
1411
for (const entry of candidates) {
@@ -1566,13 +1603,100 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1603
});
1604
}
1605
1606
+ // Git writers have exited; bound publication by fanout directory.
1607
+ yield* fileSystem.readDirectory(privateObjects).pipe(
1608
+ Effect.flatMap((directories) =>
1609
+ Effect.forEach(
1610
+ directories.filter(
1611
+ (directory) => directory === "pack" || /^[0-9a-f]{2}$/.test(directory),
1612
+ ),
1613
+ (directory) =>
1614
+ Effect.gen(function* () {
1615
+ const source = path.join(privateObjects, directory);
1616
+ const destination = path.join(sharedObjects, directory);
1617
+ // Most fanouts already exist; avoid constructing an EEXIST error
1618
+ // for each of them on every capture. mkdir still handles the race.
1619
+ if (!(yield* fileSystem.exists(destination)))
1620
+ yield* fileSystem.makeDirectory(destination).pipe(
1621
+ Effect.andThen(
1622
+ Effect.gen(function* () {
1623
+ // Git has already applied core.sharedRepository to the source.
1624
+ // chmod bypasses umask, but never changes a pre-existing bucket.
1625
+ const { mode } = yield* fileSystem.stat(source);
1626
+ yield* fileSystem.chmod(destination, mode & 0o7777);
1627
+ }),
1628
+ ),
1629
+ Effect.catchIf(
1630
+ (cause) => cause.reason._tag === "AlreadyExists",
1631
+ () => Effect.void,
1632
+ ),
1633
+ Effect.uninterruptible,
1634
+ );
1635
+ const names = yield* fileSystem.readDirectory(source);
1636
+ // Per-object spans would swamp the capture span for large workspaces.
1637
+ const linkObject = Effect.fnUntraced(function* (name: string) {
1638
+ const from = path.join(source, name);
1639
+ const to = path.join(destination, name);
1640
+ yield* fileSystem.link(from, to).pipe(
1641
+ Effect.catchIf(
1642
+ (cause) =>
1643
+ cause.reason._tag === "PermissionDenied" ||
1644
+ cause.reason._tag === "Unknown",
1645
+ () =>
1646
+ Effect.gen(function* () {
1647
+ if (yield* fileSystem.exists(to)) return;
1648
+ // Git also falls back to rename without hardlinks; identical object names are interchangeable.
1649
+ yield* fileSystem.rename(from, to);
1650
+ }),
1651
+ ),
1652
+ Effect.catchIf(
1653
+ (cause) => cause.reason._tag === "AlreadyExists",
1654
+ () => Effect.void,
1655
+ ),
1656
+ );
1657
+ });
1658
+ if (directory !== "pack") {
1659
+ yield* Effect.forEach(
1660
+ names.filter((name) => /^(?:[0-9a-f]{38}|[0-9a-f]{62})$/.test(name)),
1661
+ linkObject,
1662
+ { discard: true },
1663
+ );
1664
+ return;
1665
+ }
1666
+ const files = new Set(names);
1667
+ for (const name of names) {
1668
+ if (!/^pack-(?:[0-9a-f]{40}|[0-9a-f]{64})\.pack$/.test(name)) continue;
1669
+ const base = name.slice(0, -5);
1670
+ if (!files.has(`${base}.idx`)) continue;
1671
+ // Link metadata before the pack so an I/O error cannot strand a
1672
+ // large unindexed pack. Defer cancellation across this short group
1673
+ // of links. Never roll back shared links: a concurrent writer may
1674
+ // already depend on them. Ref publication still happens last.
1675
+ yield* Effect.forEach(
1676
+ [".keep", ".promisor", ".rev", ".idx", ".pack"]
1677
+ .map((extension) => `${base}${extension}`)
1678
+ .filter((file) => files.has(file)),
1679
+ linkObject,
1680
+ { discard: true },
1681
+ ).pipe(Effect.uninterruptible);
1682
+ }
1683
+ }),
1684
+ { concurrency: 16, discard: true },
1685
+ ),
1686
+ ),
1687
+ Effect.mapError(
1688
+ (cause) =>
1689
+ new VcsCheckpointStorageError({ operation, cwd: input.cwd, stage: "publish", cause }),
1690
+ ),
1691
+ );
1692
+
1693
yield* execute({
1694
operation,
1695
cwd: input.cwd,
1696
args: [...durableWrite, "update-ref", input.checkpointRef, commitOid],
1697
});
1698
}).pipe(Effect.ensuring(cleanupTempIndex));
1575
- }),
1699
+ }, Effect.scoped),
1700
1701
hasCheckpointRef: (input) =>
1702
resolveCheckpointCommit(input.cwd, input.checkpointRef).pipe(
packages/contracts/src/vcs.ts
+15
@@ -260,7 +260,22 @@ export class VcsUnsupportedOperationError extends Schema.TaggedError<VcsUnsuppor
260
}
261
}
262
263
+export class VcsCheckpointStorageError extends Schema.TaggedError<VcsCheckpointStorageError>()(
264
+ "VcsCheckpointStorageError",
265
+ {
266
+ operation: Schema.String,
267
+ cwd: Schema.String,
268
+ stage: Schema.Literals(["isolate", "publish"]),
269
+ cause: Schema.Defect(),
270
+ },
271
+) {
272
+ override get message(): string {
273
+ return `Could not ${this.stage} checkpoint objects.`;
274
+ }
275
+}
276
+
277
export const VcsError = Schema.Union([
278
+ VcsCheckpointStorageError,
279
VcsProcessSpawnError,
280
VcsProcessExitError,
281
VcsProcessTimeoutError,
packages/source-control-gitlab/src/server/GitLabCli.ts
+1
@@ -154,6 +154,7 @@ export class GitLabCliCommandError extends Schema.TaggedError<GitLabCliCommandEr
154
VcsProcessOutputLimitError: (cause) => new GitLabCliCommandError({ ...context, cause }),
155
VcsProcessMissingExitCodeError: (cause) => new GitLabCliCommandError({ ...context, cause }),
156
VcsRepositoryDetectionError: (cause) => new GitLabCliCommandError({ ...context, cause }),
157
+ VcsCheckpointStorageError: (cause) => new GitLabCliCommandError({ ...context, cause }),
158
VcsUnsupportedOperationError: (cause) => new GitLabCliCommandError({ ...context, cause }),
159
});
160
}