Skip to content

Commit 4825379

Browse files
fix(server): skip checkpoints when the project folder is gitignored
Checkpoint capture runs git add -A -- . from the project directory, which exits 1 when a parent repository ignores that folder. Probe git check-ignore first and report VcsUnsupportedOperationError so callers skip instead of failing every turn; fall back to git add -u for directories ignored after their files were tracked. The reactor records one notice per thread and skips later turns quietly.
1 parent 295d7cb commit 4825379

4 files changed

Lines changed: 253 additions & 16 deletions

File tree

‎apps/server/src/orchestration/Layers/CheckpointReactor.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as NodeChildProcess from "node:child_process";
77
import {
88
VcsProcessTimeoutError,
99
VcsProcessSpawnError,
10+
VcsUnsupportedOperationError,
1011
ProviderDriverKind,
1112
ProviderRuntimeEvent,
1213
ProviderSession,
@@ -295,6 +296,7 @@ describe("CheckpointReactor", () => {
295296
readonly checkpointLookupFailure?: (
296297
cwd: string,
297298
) => VcsProcessTimeoutError | VcsProcessSpawnError | undefined;
299+
readonly checkpointCaptureFailure?: (cwd: string) => VcsUnsupportedOperationError | undefined;
298300
readonly workspaceRefresh?: (cwd: string) => Effect.Effect<void>;
299301
readonly hasSession?: boolean;
300302
readonly seedFilesystemCheckpoints?: boolean;
@@ -386,6 +388,10 @@ describe("CheckpointReactor", () => {
386388
const failure = options?.checkpointLookupFailure?.(input.cwd);
387389
return failure ? Effect.fail(failure) : store.hasCheckpointRef(input);
388390
},
391+
captureCheckpoint: (input) => {
392+
const failure = options?.checkpointCaptureFailure?.(input.cwd);
393+
return failure ? Effect.fail(failure) : store.captureCheckpoint(input);
394+
},
389395
})),
390396
),
391397
).pipe(Layer.provide(VcsDriverRegistry.layer)),
@@ -1532,6 +1538,55 @@ describe("CheckpointReactor", () => {
15321538
}),
15331539
);
15341540

1541+
effectIt.effect(
1542+
"records one notice when checkpoints are unsupported instead of failing every turn",
1543+
() =>
1544+
Effect.gen(function* () {
1545+
const harness = yield* Effect.promise(() =>
1546+
createHarness({
1547+
seedFilesystemCheckpoints: false,
1548+
checkpointCaptureFailure: () =>
1549+
new VcsUnsupportedOperationError({
1550+
operation: "test.capture",
1551+
kind: "git",
1552+
detail:
1553+
"Checkpoint workspace is ignored by one of the repository's gitignore rules.",
1554+
}),
1555+
}),
1556+
);
1557+
const threadId = ThreadId.make("thread-1");
1558+
const createdAt = "2026-01-01T00:00:00.000Z";
1559+
const emit = (type: "turn.started" | "turn.completed", turn: number) =>
1560+
harness.provider.emit({
1561+
type,
1562+
eventId: EventId.make(`${type}-unsupported-${turn}`),
1563+
provider: ProviderDriverKind.make("codex"),
1564+
createdAt,
1565+
threadId,
1566+
turnId: asTurnId(`turn-unsupported-${turn}`),
1567+
...(type === "turn.completed" ? { payload: { state: "completed" } } : {}),
1568+
});
1569+
emit("turn.started", 1);
1570+
emit("turn.completed", 1);
1571+
yield* Effect.promise(harness.drain);
1572+
emit("turn.started", 2);
1573+
emit("turn.completed", 2);
1574+
yield* Effect.promise(harness.drain);
1575+
const thread = (yield* Effect.promise(harness.readModel)).threads[0];
1576+
const failures =
1577+
thread?.activities.filter((activity) => activity.kind === "checkpoint.capture.failed") ??
1578+
[];
1579+
expect(failures).toHaveLength(1);
1580+
expect(failures[0]?.payload).toMatchObject({
1581+
detail: expect.stringContaining("ignored"),
1582+
});
1583+
expect(thread?.activities.some((activity) => activity.kind === "checkpoint.captured")).toBe(
1584+
false,
1585+
);
1586+
expect(thread?.checkpoints).toEqual([]);
1587+
}),
1588+
);
1589+
15351590
effectIt.effect.each([
15361591
{ timing: "between turns", commit: false },
15371592
{ timing: "between turns", commit: true },

‎apps/server/src/orchestration/Layers/CheckpointReactor.ts‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ const make = Effect.gen(function* () {
114114

115115
const startedTurns = new Map<ThreadId, TurnId>();
116116
const pending = new Set<ThreadId>();
117+
// Threads already told that checkpoints are unavailable for their workspace
118+
// (for example a project folder a parent repository gitignores). The
119+
// condition is permanent, so later turns skip quietly instead of recording
120+
// another notice.
121+
const checkpointUnsupportedNoticed = new Set<ThreadId>();
117122

118123
const appendRevertFailureActivity = (input: {
119124
readonly threadId: ThreadId;
@@ -494,10 +499,16 @@ const make = Effect.gen(function* () {
494499
return;
495500
}
496501

497-
yield* checkpointStore.captureCheckpoint({
498-
cwd: checkpointCwd,
499-
checkpointRef: baselineCheckpointRef,
500-
});
502+
const captured = yield* checkpointStore
503+
.captureCheckpoint({
504+
cwd: checkpointCwd,
505+
checkpointRef: baselineCheckpointRef,
506+
})
507+
.pipe(
508+
Effect.as(true),
509+
Effect.catchTag("VcsUnsupportedOperationError", () => Effect.succeed(false)),
510+
);
511+
if (!captured) return;
501512
yield* receiptBus.publish({
502513
type: "checkpoint.baseline.captured",
503514
threadId: thread.id,
@@ -705,10 +716,16 @@ const make = Effect.gen(function* () {
705716
return;
706717
}
707718

708-
yield* checkpointStore.captureCheckpoint({
709-
cwd: checkpointCwd,
710-
checkpointRef: baselineCheckpointRef,
711-
});
719+
const captured = yield* checkpointStore
720+
.captureCheckpoint({
721+
cwd: checkpointCwd,
722+
checkpointRef: baselineCheckpointRef,
723+
})
724+
.pipe(
725+
Effect.as(true),
726+
Effect.catchTag("VcsUnsupportedOperationError", () => Effect.succeed(false)),
727+
);
728+
if (!captured) return;
712729
yield* receiptBus.publish({
713730
type: "checkpoint.baseline.captured",
714731
threadId,
@@ -984,14 +1001,18 @@ const make = Effect.gen(function* () {
9841001
}
9851002
yield* captureCheckpointFromTurnCompletion(event).pipe(
9861003
Effect.catch((error) =>
987-
Effect.flatMap(nowIso, (createdAt) =>
988-
appendCaptureFailureActivity({
1004+
Effect.flatMap(nowIso, (createdAt) => {
1005+
if (error._tag === "VcsUnsupportedOperationError") {
1006+
if (checkpointUnsupportedNoticed.has(event.threadId)) return Effect.void;
1007+
checkpointUnsupportedNoticed.add(event.threadId);
1008+
}
1009+
return appendCaptureFailureActivity({
9891010
threadId: event.threadId,
9901011
turnId,
9911012
detail: error.message,
9921013
createdAt,
993-
}).pipe(Effect.catch(() => Effect.void)),
994-
),
1014+
}).pipe(Effect.catch(() => Effect.void));
1015+
}),
9951016
),
9961017
);
9971018
return;

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

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

248+
it.effect(
249+
"checkpoint capture reports unsupported when the project directory is ignored by git",
250+
() =>
251+
Effect.gen(function* () {
252+
const fileSystem = yield* FileSystem.FileSystem;
253+
const path = yield* Path.Path;
254+
const liveProcess = yield* VcsProcess.VcsProcess;
255+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
256+
const parent = yield* fileSystem.makeTempDirectoryScoped({
257+
prefix: "t3-checkpoint-ignored-",
258+
});
259+
const git = (args: ReadonlyArray<string>) =>
260+
driver.execute({ operation: "checkpoint-test", cwd: parent, args });
261+
yield* git(["init"]);
262+
yield* git(["config", "user.name", "Test"]);
263+
yield* git(["config", "user.email", "[email protected]"]);
264+
yield* fileSystem.writeFileString(
265+
path.join(parent, ".gitignore"),
266+
"*\n!keep/\n!keep/**\n!.gitignore\n",
267+
);
268+
yield* fileSystem.makeDirectory(path.join(parent, "keep"), { recursive: true });
269+
yield* fileSystem.writeFileString(path.join(parent, "keep", "ok.txt"), "keep\n");
270+
yield* git(["add", "keep", ".gitignore"]);
271+
yield* git(["commit", "-m", "initial"]);
272+
const cwd = path.join(parent, "sub");
273+
yield* fileSystem.makeDirectory(cwd, { recursive: true });
274+
yield* fileSystem.writeFileString(path.join(cwd, "file.txt"), "hello\n");
275+
const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/ignored");
276+
let stageAttempts = 0;
277+
const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
278+
Effect.provideService(VcsProcess.VcsProcess, {
279+
run: (input) => {
280+
if (input.args.includes("add")) stageAttempts++;
281+
return liveProcess.run(input);
282+
},
283+
}),
284+
);
285+
286+
const result = yield* Effect.result(
287+
captureDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef }),
288+
);
289+
290+
assert.strictEqual(result._tag, "Failure");
291+
if (result._tag === "Failure")
292+
assert.strictEqual(result.failure._tag, "VcsUnsupportedOperationError");
293+
assert.strictEqual(stageAttempts, 0);
294+
assert.isFalse(yield* driver.checkpoints.hasCheckpointRef({ cwd, checkpointRef }));
295+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
296+
);
297+
298+
it.effect("checkpoint capture stages tracked edits when the directory was ignored later", () =>
299+
Effect.gen(function* () {
300+
const fileSystem = yield* FileSystem.FileSystem;
301+
const path = yield* Path.Path;
302+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
303+
const parent = yield* fileSystem.makeTempDirectoryScoped({
304+
prefix: "t3-checkpoint-ignored-tracked-",
305+
});
306+
const git = (args: ReadonlyArray<string>) =>
307+
driver.execute({ operation: "checkpoint-test", cwd: parent, args });
308+
yield* git(["init"]);
309+
yield* git(["config", "user.name", "Test"]);
310+
yield* git(["config", "user.email", "[email protected]"]);
311+
yield* fileSystem.makeDirectory(path.join(parent, "sub"), { recursive: true });
312+
yield* fileSystem.writeFileString(path.join(parent, "sub", "tracked.txt"), "v1\n");
313+
yield* git(["add", "."]);
314+
yield* git(["commit", "-m", "initial"]);
315+
yield* fileSystem.writeFileString(path.join(parent, ".gitignore"), "sub/\n");
316+
yield* git(["add", ".gitignore"]);
317+
yield* git(["commit", "-m", "ignore sub"]);
318+
const cwd = path.join(parent, "sub");
319+
yield* fileSystem.writeFileString(path.join(cwd, "tracked.txt"), "v2\n");
320+
yield* fileSystem.writeFileString(path.join(cwd, "newfile.txt"), "new\n");
321+
const originalIndex = yield* fileSystem.readFile(path.join(parent, ".git", "index"));
322+
const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/ignored-tracked");
323+
324+
yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
325+
326+
assert.strictEqual((yield* git(["show", `${checkpointRef}:sub/tracked.txt`])).stdout, "v2\n");
327+
const names = (yield* git(["ls-tree", "-r", "--name-only", checkpointRef, "--", "sub"])).stdout
328+
.split("\n")
329+
.map((entry) => entry.trim())
330+
.filter((entry) => entry.length > 0);
331+
assert.deepEqual(names, ["sub/tracked.txt"]);
332+
assert.deepEqual(yield* fileSystem.readFile(path.join(parent, ".git", "index")), originalIndex);
333+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
334+
);
335+
336+
it.effect("checkpoint capture from a subdirectory snapshots only that subdirectory", () =>
337+
Effect.gen(function* () {
338+
const fileSystem = yield* FileSystem.FileSystem;
339+
const path = yield* Path.Path;
340+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
341+
const parent = yield* fileSystem.makeTempDirectoryScoped({
342+
prefix: "t3-checkpoint-subdirectory-",
343+
});
344+
const git = (args: ReadonlyArray<string>) =>
345+
driver.execute({ operation: "checkpoint-test", cwd: parent, args });
346+
yield* git(["init"]);
347+
yield* git(["config", "user.name", "Test"]);
348+
yield* git(["config", "user.email", "[email protected]"]);
349+
yield* fileSystem.makeDirectory(path.join(parent, "sub"), { recursive: true });
350+
yield* fileSystem.writeFileString(path.join(parent, "sub", "tracked.txt"), "v1\n");
351+
yield* fileSystem.writeFileString(path.join(parent, "keep.txt"), "keep\n");
352+
yield* git(["add", "."]);
353+
yield* git(["commit", "-m", "initial"]);
354+
const cwd = path.join(parent, "sub");
355+
yield* fileSystem.writeFileString(path.join(cwd, "tracked.txt"), "v2\n");
356+
yield* fileSystem.writeFileString(path.join(parent, "keep.txt"), "changed outside\n");
357+
const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/subdirectory");
358+
359+
yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef });
360+
361+
assert.strictEqual((yield* git(["show", `${checkpointRef}:sub/tracked.txt`])).stdout, "v2\n");
362+
assert.strictEqual((yield* git(["show", `${checkpointRef}:keep.txt`])).stdout, "keep\n");
363+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
364+
);
365+
248366
it.effect("checkpoint recovery refuses excessive candidates before probing", () =>
249367
Effect.gen(function* () {
250368
const fs = yield* FileSystem.FileSystem;
@@ -1104,7 +1222,9 @@ it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publi
11041222
? ".git\n"
11051223
: "";
11061224
return {
1107-
exitCode: ChildProcessSpawner.ExitCode(0),
1225+
// The fixture is a normal repository, so the checkpoint ignore
1226+
// probe reports "not ignored" (exit 1 like real git).
1227+
exitCode: ChildProcessSpawner.ExitCode(input.args.includes("check-ignore") ? 1 : 0),
11081228
stdout,
11091229
stderr: "",
11101230
stdoutTruncated: false,

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

Lines changed: 44 additions & 3 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,
@@ -806,6 +807,26 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
806807
);
807808

808809
yield* Effect.gen(function* () {
810+
// A project directory ignored by a parent repository cannot be staged by
811+
// name (`git add -A -- .` exits 1 with "paths are ignored"), and forcing
812+
// the add would stage caches and secrets the ignore rules exclude on
813+
// purpose. Report checkpoints as unsupported so callers skip them
814+
// instead of failing every turn.
815+
const ignoreProbe = yield* execute({
816+
operation,
817+
cwd: input.cwd,
818+
args: ["check-ignore", "-q", "--", "."],
819+
allowNonZeroExit: true,
820+
});
821+
if (ignoreProbe.exitCode === 0) {
822+
return yield* new VcsUnsupportedOperationError({
823+
operation,
824+
kind: "git",
825+
detail:
826+
"Checkpoint workspace is ignored by one of the repository's gitignore rules, so checkpoints are unavailable for this project.",
827+
});
828+
}
829+
809830
const headExists = yield* hasHeadCommit(input.cwd);
810831
const sparseConfig = yield* execute({
811832
operation,
@@ -931,7 +952,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
931952
}
932953
}
933954

934-
const stageFiles = (exclusions: ReadonlyArray<string>) =>
955+
const stageFiles = (exclusions: ReadonlyArray<string>, updateOnly = false) =>
935956
execute({
936957
operation,
937958
cwd: input.cwd,
@@ -941,7 +962,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
941962
...durableWrite,
942963
"add",
943964
...(sparseCheckout ? ["--sparse"] : []),
944-
"-A",
965+
updateOnly ? "-u" : "-A",
945966
"--",
946967
".",
947968
...exclusions,
@@ -989,7 +1010,27 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
9891010
exclusions.push(`:(exclude,literal)${entry}`);
9901011
}
9911012
}
992-
if (exclusions.length === 0) return yield* error;
1013+
if (exclusions.length === 0) {
1014+
// The directory itself is not ignored (see the probe above), but
1015+
// `git add -A` still refuses a project directory that was ignored
1016+
// after its files were tracked. `git add -u` stages those tracked
1017+
// edits while leaving ignored files alone. Anything it cannot
1018+
// stage fails the same way, so surface the original error then.
1019+
if (error.retryable !== true) {
1020+
const updated = yield* stageFiles([], true).pipe(
1021+
Effect.as(true),
1022+
Effect.orElseSucceed(() => false),
1023+
);
1024+
if (updated) {
1025+
yield* Effect.logDebug(
1026+
"checkpoint staging fell back to tracked files after add -A failed",
1027+
{ operation, cwd: input.cwd },
1028+
);
1029+
return yield* Effect.void;
1030+
}
1031+
}
1032+
return yield* error;
1033+
}
9931034
return yield* stageFiles(exclusions);
9941035
}).pipe(
9951036
// One budget covers discovery, queued Git admission, probes, and the staging retry.

0 commit comments

Comments
 (0)