Skip to content

Commit e196708

Browse files
fix(server): restrict checkpoint update fallback and record notice after dispatch
Address review feedback: only attempt git add -u when ls-files --others reports nothing untracked to drop, so unrelated staging failures keep failing loudly instead of publishing partial checkpoints. Mark threads notified only after the notice activity dispatches successfully.
1 parent 4825379 commit e196708

3 files changed

Lines changed: 63 additions & 11 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,16 +1002,23 @@ const make = Effect.gen(function* () {
10021002
yield* captureCheckpointFromTurnCompletion(event).pipe(
10031003
Effect.catch((error) =>
10041004
Effect.flatMap(nowIso, (createdAt) => {
1005-
if (error._tag === "VcsUnsupportedOperationError") {
1006-
if (checkpointUnsupportedNoticed.has(event.threadId)) return Effect.void;
1007-
checkpointUnsupportedNoticed.add(event.threadId);
1008-
}
1005+
const unsupported = error._tag === "VcsUnsupportedOperationError";
1006+
if (unsupported && checkpointUnsupportedNoticed.has(event.threadId)) return Effect.void;
10091007
return appendCaptureFailureActivity({
10101008
threadId: event.threadId,
10111009
turnId,
10121010
detail: error.message,
10131011
createdAt,
1014-
}).pipe(Effect.catch(() => Effect.void));
1012+
}).pipe(
1013+
Effect.andThen(
1014+
Effect.sync(() => {
1015+
// Only treat the thread as notified once the notice is recorded;
1016+
// a failed dispatch stays eligible for a notice on a later turn.
1017+
if (unsupported) checkpointUnsupportedNoticed.add(event.threadId);
1018+
}),
1019+
),
1020+
Effect.catch(() => Effect.void),
1021+
);
10151022
}),
10161023
),
10171024
);

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,49 @@ it.effect("checkpoint capture stages tracked edits when the directory was ignore
333333
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
334334
);
335335

336+
it.effect(
337+
"checkpoint keeps failing when untracked files would be dropped by the update fallback",
338+
() =>
339+
Effect.gen(function* () {
340+
const fileSystem = yield* FileSystem.FileSystem;
341+
const path = yield* Path.Path;
342+
const liveProcess = yield* VcsProcess.VcsProcess;
343+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
344+
const cwd = yield* fileSystem.makeTempDirectoryScoped({
345+
prefix: "t3-checkpoint-update-guard-",
346+
});
347+
const { checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
348+
yield* fileSystem.writeFileString(path.join(cwd, "untracked.txt"), "new\n");
349+
const stageError = new VcsProcessExitError({
350+
operation: "GitVcsDriver.checkpoints.captureCheckpoint",
351+
command: "git",
352+
cwd,
353+
exitCode: 1,
354+
detail: "mock add failure",
355+
});
356+
let updateAttempts = 0;
357+
const captureDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
358+
Effect.provideService(VcsProcess.VcsProcess, {
359+
run: (input) => {
360+
if (input.args.includes("add") && input.args.includes("-A"))
361+
return Effect.fail(stageError);
362+
if (input.args.includes("-u")) updateAttempts++;
363+
return liveProcess.run(input);
364+
},
365+
}),
366+
);
367+
368+
const result = yield* Effect.result(
369+
captureDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef }),
370+
);
371+
372+
assert.strictEqual(result._tag, "Failure");
373+
if (result._tag === "Failure") assert.strictEqual(result.failure, stageError);
374+
assert.strictEqual(updateAttempts, 0);
375+
assert.isFalse(yield* driver.checkpoints.hasCheckpointRef({ cwd, checkpointRef }));
376+
}).pipe(Effect.scoped, Effect.provide(GitContractLayer)),
377+
);
378+
336379
it.effect("checkpoint capture from a subdirectory snapshots only that subdirectory", () =>
337380
Effect.gen(function* () {
338381
const fileSystem = yield* FileSystem.FileSystem;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
983983
maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,
984984
});
985985
if (untracked.stdoutTruncated) return yield* error;
986-
const candidates = splitNullSeparatedGitStdoutPaths(untracked).filter((entry) =>
987-
entry.endsWith("/"),
988-
);
986+
const untrackedPaths = splitNullSeparatedGitStdoutPaths(untracked);
987+
const candidates = untrackedPaths.filter((entry) => entry.endsWith("/"));
989988
// Refuse excessive recovery work before probing any nested repositories.
990989
if (candidates.length > CHECKPOINT_RECOVERY_MAX_CANDIDATES) return yield* error;
991990
// Discover each child's repository instead of inheriting the server's Git bindings.
@@ -1014,9 +1013,12 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
10141013
// The directory itself is not ignored (see the probe above), but
10151014
// `git add -A` still refuses a project directory that was ignored
10161015
// 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) {
1016+
// edits while leaving ignored files alone — but it also drops
1017+
// every untracked file, so it may only run when there is nothing
1018+
// untracked left to drop. Any other `add -A` failure (unreadable
1019+
// or unfiltrable untracked files, ...) keeps failing loudly
1020+
// instead of publishing a partial checkpoint.
1021+
if (untrackedPaths.length === 0 && error.retryable !== true) {
10201022
const updated = yield* stageFiles([], true).pipe(
10211023
Effect.as(true),
10221024
Effect.orElseSucceed(() => false),

0 commit comments

Comments
 (0)