Skip to content

Commit 2e99561

Browse files
committed
fix(server): checkpoints skip a project folder its parent repo ignores
Capture probes git check-ignore and reports the folder as unsupported instead of running git add, which exits 1. A tracked folder ignored later falls back to git add -u, so tracked edits are still captured. V2 records these checkpoints as missing, like a non-git folder, instead of error.
1 parent cc1e634 commit 2e99561

4 files changed

Lines changed: 184 additions & 15 deletions

File tree

‎apps/server/src/orchestration-v2/CheckpointService.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ThreadId,
88
type OrchestrationV2CheckpointScope,
99
VcsProcessTimeoutError,
10+
VcsUnsupportedOperationError,
1011
} from "@t3tools/contracts";
1112
import * as DateTime from "effect/DateTime";
1213
import * as Effect from "effect/Effect";
@@ -101,3 +102,53 @@ it.effect.each([false, true, "interrupt"] as const)(
101102
}).pipe(Effect.provide(testLayer));
102103
},
103104
);
105+
106+
it.effect("marks a checkpoint missing when the workspace cannot be checkpointed", () => {
107+
const scope: OrchestrationV2CheckpointScope = {
108+
id: CheckpointScopeId.make("checkpoint-scope:unsupported"),
109+
threadId: ThreadId.make("thread:unsupported"),
110+
runId: RunId.make("run:unsupported:1"),
111+
nodeId: NodeId.make("node:unsupported:1"),
112+
parentScopeId: null,
113+
providerThreadId: ProviderThreadId.make("provider-thread:unsupported"),
114+
kind: "root_run",
115+
ordinalWithinParent: 0,
116+
advancesAppRunCount: true,
117+
cwd: "/repo/ignored",
118+
createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
119+
};
120+
const testLayer = CheckpointService.layer.pipe(
121+
Layer.provide(
122+
Layer.mergeAll(
123+
IdAllocator.layer,
124+
Layer.mock(CheckpointStore.CheckpointStore)({
125+
isGitRepository: () => Effect.succeed(true),
126+
hasCheckpointRef: () => Effect.succeed(false),
127+
captureCheckpoint: () =>
128+
Effect.fail(
129+
new VcsUnsupportedOperationError({
130+
operation: "test.capture",
131+
kind: "git",
132+
detail: "The workspace directory is ignored by its Git repository.",
133+
}),
134+
),
135+
}),
136+
),
137+
),
138+
);
139+
140+
return Effect.gen(function* () {
141+
const checkpoints = yield* CheckpointService.CheckpointServiceV2;
142+
yield* checkpoints.captureBaseline({ scope, ordinalWithinScope: 0 });
143+
const checkpoint = yield* checkpoints.capture({
144+
scope,
145+
ordinalWithinScope: 1,
146+
runId: scope.runId!,
147+
nodeId: scope.nodeId!,
148+
appRunOrdinal: 1,
149+
capturedAt: scope.createdAt,
150+
});
151+
152+
assert.equal(checkpoint.status, "missing");
153+
}).pipe(Effect.provide(testLayer));
154+
});

‎apps/server/src/orchestration-v2/CheckpointService.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,12 @@ export const layer: Layer.Layer<
298298
return;
299299
}
300300

301-
yield* checkpointStore.captureCheckpoint({
302-
cwd: input.scope.cwd,
303-
checkpointRef,
304-
});
301+
yield* checkpointStore
302+
.captureCheckpoint({
303+
cwd: input.scope.cwd,
304+
checkpointRef,
305+
})
306+
.pipe(Effect.catchTag("VcsUnsupportedOperationError", () => Effect.void));
305307
}),
306308
).pipe(
307309
Effect.mapError(
@@ -408,23 +410,26 @@ export const layer: Layer.Layer<
408410
});
409411
}
410412

411-
const captured = yield* checkpointStore
413+
const captureStatus = yield* checkpointStore
412414
.captureCheckpoint({
413415
cwd: input.scope.cwd,
414416
checkpointRef,
415417
})
416418
.pipe(
417-
Effect.as(true),
419+
Effect.as("ready" as const),
420+
Effect.catchTag("VcsUnsupportedOperationError", () =>
421+
Effect.succeed("missing" as const),
422+
),
418423
Effect.catch((cause) =>
419424
Effect.logWarning("orchestration V2 checkpoint capture failed", {
420425
scopeId: input.scope.id,
421426
checkpointRef,
422427
cause: String(cause),
423-
}).pipe(Effect.as(false)),
428+
}).pipe(Effect.as("error" as const)),
424429
),
425430
);
426431

427-
if (!captured) {
432+
if (captureStatus !== "ready") {
428433
return makeCheckpoint({
429434
id: checkpointId,
430435
scope: input.scope,
@@ -434,7 +439,7 @@ export const layer: Layer.Layer<
434439
ordinalWithinScope: input.ordinalWithinScope,
435440
appRunOrdinal: input.appRunOrdinal,
436441
ref: checkpointRef,
437-
status: "error",
442+
status: captureStatus,
438443
files: [],
439444
capturedAt: input.capturedAt,
440445
});

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,98 @@ it.effect("checkpoint capture refuses a truncated nested repository listing", ()
245245
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
246246
);
247247

248+
it.effect("checkpoint capture skips a workspace its parent repository ignores", () =>
249+
Effect.gen(function* () {
250+
const fileSystem = yield* FileSystem.FileSystem;
251+
const path = yield* Path.Path;
252+
const liveProcess = yield* VcsProcess.VcsProcess;
253+
const parent = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-checkpoint-ignored-" });
254+
let stageAttempts = 0;
255+
const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
256+
Effect.provideService(VcsProcess.VcsProcess, {
257+
run: (input) => {
258+
if (input.args.includes("add")) stageAttempts++;
259+
return liveProcess.run(input);
260+
},
261+
}),
262+
);
263+
const git = (args: ReadonlyArray<string>) =>
264+
driver.execute({ operation: "checkpoint-test", cwd: parent, args });
265+
yield* git(["init"]);
266+
yield* git(["config", "user.name", "Test"]);
267+
yield* git(["config", "user.email", "[email protected]"]);
268+
yield* fileSystem.writeFileString(
269+
path.join(parent, ".gitignore"),
270+
"*\n!.gitignore\n!keep/\n!keep/**\n",
271+
);
272+
yield* fileSystem.makeDirectory(path.join(parent, "keep"));
273+
yield* fileSystem.writeFileString(path.join(parent, "keep", "file.txt"), "v1\n");
274+
yield* fileSystem.makeDirectory(path.join(parent, "ignored"));
275+
yield* fileSystem.writeFileString(path.join(parent, "ignored", "file.txt"), "secret\n");
276+
yield* git(["add", "."]);
277+
yield* git(["commit", "-m", "initial"]);
278+
stageAttempts = 0;
279+
const ignoredRef = CheckpointRef.make("refs/t3/checkpoints/ignored");
280+
281+
const ignored = yield* Effect.result(
282+
driver.checkpoints.captureCheckpoint({
283+
cwd: path.join(parent, "ignored"),
284+
checkpointRef: ignoredRef,
285+
}),
286+
);
287+
288+
assert.strictEqual(ignored._tag, "Failure");
289+
if (ignored._tag === "Failure") {
290+
assert.strictEqual(ignored.failure._tag, "VcsUnsupportedOperationError");
291+
}
292+
assert.strictEqual(stageAttempts, 0);
293+
assert.isFalse(
294+
yield* driver.checkpoints.hasCheckpointRef({ cwd: parent, checkpointRef: ignoredRef }),
295+
);
296+
297+
const keepRef = CheckpointRef.make("refs/t3/checkpoints/keep");
298+
yield* fileSystem.writeFileString(path.join(parent, "keep", "file.txt"), "v2\n");
299+
yield* driver.checkpoints.captureCheckpoint({
300+
cwd: path.join(parent, "keep"),
301+
checkpointRef: keepRef,
302+
});
303+
assert.strictEqual((yield* git(["show", `${keepRef}:keep/file.txt`])).stdout, "v2\n");
304+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
305+
);
306+
307+
it.effect("checkpoint capture stages tracked edits in a directory ignored later", () =>
308+
Effect.gen(function* () {
309+
const fileSystem = yield* FileSystem.FileSystem;
310+
const path = yield* Path.Path;
311+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
312+
const parent = yield* fileSystem.makeTempDirectoryScoped({
313+
prefix: "t3-checkpoint-ignored-later-",
314+
});
315+
const git = (args: ReadonlyArray<string>) =>
316+
driver.execute({ operation: "checkpoint-test", cwd: parent, args });
317+
yield* git(["init"]);
318+
yield* git(["config", "user.name", "Test"]);
319+
yield* git(["config", "user.email", "[email protected]"]);
320+
const cwd = path.join(parent, "sub");
321+
yield* fileSystem.makeDirectory(cwd);
322+
yield* fileSystem.writeFileString(path.join(cwd, "tracked.txt"), "v1\n");
323+
yield* git(["add", "."]);
324+
yield* git(["commit", "-m", "initial"]);
325+
yield* fileSystem.writeFileString(path.join(parent, ".gitignore"), "sub/\n");
326+
yield* fileSystem.writeFileString(path.join(cwd, "tracked.txt"), "v2\n");
327+
yield* fileSystem.writeFileString(path.join(cwd, "new.txt"), "ignored\n");
328+
const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/ignored-later");
329+
330+
yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
331+
332+
assert.strictEqual(
333+
(yield* git(["ls-tree", "-r", "--name-only", checkpointRef, "--", "sub"])).stdout,
334+
"sub/tracked.txt\n",
335+
);
336+
assert.strictEqual((yield* git(["show", `${checkpointRef}:sub/tracked.txt`])).stdout, "v2\n");
337+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
338+
);
339+
248340
it.effect("checkpoint recovery refuses excessive candidates before probing", () =>
249341
Effect.gen(function* () {
250342
const fs = yield* FileSystem.FileSystem;
@@ -1214,7 +1306,8 @@ it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publi
12141306
? ".git\n"
12151307
: "";
12161308
return {
1217-
exitCode: ChildProcessSpawner.ExitCode(0),
1309+
// Like real Git, check-ignore exits 1 when the workspace is not ignored.
1310+
exitCode: ChildProcessSpawner.ExitCode(input.args.includes("check-ignore") ? 1 : 0),
12181311
stdout,
12191312
stderr: "",
12201313
stdoutTruncated: false,

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ChildProcessSpawner } from "effect/unstable/process";
1313
import {
1414
GitCommandError,
1515
VcsProcessExitError,
16+
VcsUnsupportedOperationError,
1617
type VcsSwitchRefInput,
1718
type VcsSwitchRefResult,
1819
type VcsCreateRefInput,
@@ -803,6 +804,21 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
803804
"-c",
804805
"sparse.expectFilesOutsideOfPatterns=false",
805806
];
807+
// Git refuses to stage a directory its parent repository ignores, and forcing the add
808+
// would capture the caches and secrets those rules exclude.
809+
const ignored = yield* execute({
810+
operation,
811+
cwd: input.cwd,
812+
args: ["check-ignore", "-q", "--", "."],
813+
allowNonZeroExit: true,
814+
});
815+
if (ignored.exitCode === 0) {
816+
return yield* new VcsUnsupportedOperationError({
817+
operation,
818+
kind: "git",
819+
detail: "The workspace directory is ignored by its Git repository.",
820+
});
821+
}
806822
const gitCommonDir = yield* resolveGitCommonDir(input.cwd);
807823
const tempIndexPath = path.join(
808824
gitCommonDir,
@@ -950,7 +966,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
950966
}
951967
}
952968

953-
const stageFiles = (exclusions: ReadonlyArray<string>) =>
969+
const stageFiles = (exclusions: ReadonlyArray<string>, mode: "-A" | "-u" = "-A") =>
954970
execute({
955971
operation,
956972
cwd: input.cwd,
@@ -960,7 +976,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
960976
...durableWrite,
961977
"add",
962978
...(sparseCheckout ? ["--sparse"] : []),
963-
"-A",
979+
mode,
964980
"--",
965981
".",
966982
...exclusions,
@@ -981,9 +997,13 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
981997
maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,
982998
});
983999
if (untracked.stdoutTruncated) return yield* error;
984-
const candidates = splitNullSeparatedGitStdoutPaths(untracked).filter((entry) =>
985-
entry.endsWith("/"),
986-
);
1000+
const untrackedPaths = splitNullSeparatedGitStdoutPaths(untracked);
1001+
// A tracked directory ignored later fails `add -A` by name. With nothing
1002+
// untracked to capture, `add -u` stages exactly what `add -A` would.
1003+
if (untrackedPaths.length === 0 && error.retryable !== true) {
1004+
return yield* stageFiles([], "-u").pipe(Effect.mapError(() => error));
1005+
}
1006+
const candidates = untrackedPaths.filter((entry) => entry.endsWith("/"));
9871007
// Refuse excessive recovery work before probing any nested repositories.
9881008
if (candidates.length > CHECKPOINT_RECOVERY_MAX_CANDIDATES) return yield* error;
9891009
// Discover each child's repository instead of inheriting the server's Git bindings.

0 commit comments

Comments
 (0)