fix: surface shadow checkpoint corruption

This commit is contained in:
Rishin Georgy Anil authored and Julius Marminge committed 2026-07-20 17:45:27 +02:00
1 parent 07c3500198
commit a61c2a5ee5
2 files changed
+44 -3

No files matched your search

@@ -1,4 +1,5 @@
// @effect-diagnostics nodeBuiltinImport:off
import * as NodeCrypto from "node:crypto";
import * as NodePath from "node:path";
import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -300,6 +301,36 @@ it.layer(TestLayer)("CheckpointStore.layer", (it) => {
}),
);
it.effect("surfaces corrupted shadow checkpoint refs instead of treating them as missing", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir("checkpoint-store-shadow-corrupt-ref-test-");
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const fileSystem = yield* FileSystem.FileSystem;
const config = yield* ServerConfig.ServerConfig;
const checkpointRef = checkpointRefForThreadTurn(
ThreadId.make("thread-shadow-corrupt-ref-checkpoint-store"),
0,
);
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef });
const shadowRepositoryPath = NodePath.join(
config.stateDir,
"checkpoints",
NodeCrypto.createHash("sha256").update(NodePath.resolve(tmp)).digest("hex"),
);
yield* fileSystem.writeFileString(
NodePath.join(shadowRepositoryPath, checkpointRef),
"not-a-commit\n",
);
const error = yield* Effect.flip(
checkpointStore.hasCheckpointRef({ cwd: tmp, checkpointRef }),
);
expect(error._tag).toBe("VcsProcessExitError");
expect(error.message).toContain("git rev-parse");
}),
);
it.effect("returns full oversized checkpoint diffs without truncation", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
@@ -152,11 +152,21 @@ export const make = Effect.gen(function* () {
args: ["rev-parse", "--verify", "--quiet", `${input.checkpointRef}^{commit}`],
allowNonZeroExit: true,
});
if (result.exitCode !== 0) {
const stdout = result.stdout.trim();
const stderr = result.stderr.trim();
if (result.exitCode === 1 && stdout.length === 0 && stderr.length === 0) {
return null;
}
const commit = result.stdout.trim();
return commit.length > 0 ? commit : null;
if (result.exitCode !== 0) {
return yield* new VcsProcessExitError({
operation: "CheckpointStore.shadow.resolveCheckpointCommit",
command: "git rev-parse",
cwd: input.cwd,
exitCode: result.exitCode,
detail: stderr || "Failed to resolve shadow checkpoint commit.",
});
}
return stdout.length > 0 ? stdout : null;
});
const shadowCheckpoints: VcsCheckpointOps = {