From a61c2a5ee5dde8de3e7486e354aab67c994ae8fb Mon Sep 17 00:00:00 2001 From: Rishin Georgy Anil Date: Sun, 19 Jul 2026 18:43:47 +0100 Subject: [PATCH] fix: surface shadow checkpoint corruption --- .../src/checkpointing/CheckpointStore.test.ts | 31 +++++++++++++++++++ .../src/checkpointing/CheckpointStore.ts | 16 ++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/apps/server/src/checkpointing/CheckpointStore.test.ts b/apps/server/src/checkpointing/CheckpointStore.test.ts index b1c94454f5..800a544932 100644 --- a/apps/server/src/checkpointing/CheckpointStore.test.ts +++ b/apps/server/src/checkpointing/CheckpointStore.test.ts @@ -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(); diff --git a/apps/server/src/checkpointing/CheckpointStore.ts b/apps/server/src/checkpointing/CheckpointStore.ts index f5287596d4..f4c8423ad3 100644 --- a/apps/server/src/checkpointing/CheckpointStore.ts +++ b/apps/server/src/checkpointing/CheckpointStore.ts @@ -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 = {