The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a rollback blocked by Git's index lock says so instead of a generic error (#11340)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
shivam committed
Oct 19, 2026 at 23:04 UTC
9448aa572a75082a6434889ba0981c553d9eef3c
5 files changed
+175
-8
apps/server/src/orchestration-v2/CheckpointRollbackService.ts
+17
-1
@@ -5,6 +5,7 @@ import {
5
type OrchestrationV2DomainEvent,
6
ProviderThreadId,
7
ThreadId,
8
+ VcsProcessExitError,
9
} from "@t3tools/contracts";
10
import * as Context from "effect/Context";
11
import * as DateTime from "effect/DateTime";
@@ -24,10 +25,11 @@ import {
25
isCheckpointRestoreIsolated,
26
SHARED_WORKSPACE_RESTORE_MESSAGE,
27
} from "./CheckpointRestoreSafety.ts";
27
-import { CheckpointServiceV2 } from "./CheckpointService.ts";
28
+import { CheckpointRestoreError, CheckpointServiceV2 } from "./CheckpointService.ts";
29
import { EventSinkV2 } from "./EventSink.ts";
30
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
31
import { ProjectionStoreV2 } from "./ProjectionStore.ts";
32
+import { GIT_INDEX_LOCKED_DETAIL } from "../vcs/VcsProcess.ts";
33
import * as ProjectStore from "./ProjectStore.ts";
34
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
35
import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts";
@@ -70,6 +72,20 @@ export class CheckpointRollbackExecutionError extends Schema.TaggedError<Checkpo
72
}
73
74
const isCheckpointRollbackExecutionError = Schema.is(CheckpointRollbackExecutionError);
75
+const isVcsProcessExitError = Schema.is(VcsProcessExitError);
76
+const isCheckpointRestoreError = Schema.is(CheckpointRestoreError);
77
+
78
+/**
79
+ * The message clients see when a rollback fails. Only a held Git index lock
80
+ * gets its own explanation; other reasons carry internal ids or raw Git
81
+ * output, so they fall back to the generic message.
82
+ */
83
+export function rollbackFailureClientMessage(error: CheckpointRollbackExecutionError): string {
84
+ const restoreCause = isCheckpointRestoreError(error.cause) ? error.cause.cause : undefined;
85
+ return isVcsProcessExitError(restoreCause) && restoreCause.detail === GIT_INDEX_LOCKED_DETAIL
86
+ ? GIT_INDEX_LOCKED_DETAIL
87
+ : ROLLBACK_FAILED_MESSAGE;
88
+}
89
90
export interface CheckpointRollbackServiceV2Shape {
91
readonly execute: (input: {
apps/server/src/orchestration-v2/EffectWorker.test.ts
+77
-1
@@ -1,5 +1,7 @@
1
import { assert, it } from "@effect/vitest";
2
import {
3
+ CheckpointId,
4
+ CheckpointScopeId,
5
CommandId,
6
NodeId,
7
ProviderSessionId,
@@ -8,6 +10,7 @@ import {
10
RunAttemptId,
11
RunId,
12
ThreadId,
13
+ VcsProcessExitError,
14
} from "@t3tools/contracts";
15
import * as Cause from "effect/Cause";
16
import * as DateTime from "effect/DateTime";
@@ -21,6 +24,7 @@ import * as Ref from "effect/Ref";
24
import * as TestClock from "effect/testing/TestClock";
25
26
import * as CheckpointRollbackService from "./CheckpointRollbackService.ts";
27
+import * as CheckpointService from "./CheckpointService.ts";
28
import * as EffectOutbox from "./EffectOutbox.ts";
29
import * as EffectWorker from "./EffectWorker.ts";
30
import * as RunFinalizationService from "./RunFinalizationService.ts";
@@ -83,6 +87,7 @@ function layerExecutorFor(input: {
87
readonly threads?: Partial<ThreadManagementService.ThreadManagementService["Service"]>;
88
readonly continueAfterRestart?: boolean;
89
readonly interrupt?: ProviderTurnControlService.ProviderTurnControlServiceV2Shape["interrupt"];
90
+ readonly rollback?: CheckpointRollbackService.CheckpointRollbackServiceV2Shape["execute"];
91
}) {
92
const record = (event: string) => Ref.update(input.events, (events) => [...events, event]);
93
const layerDependencies = Layer.mergeAll(
@@ -136,7 +141,9 @@ function layerExecutorFor(input: {
141
),
142
Layer.succeed(
143
CheckpointRollbackService.CheckpointRollbackServiceV2,
139
- CheckpointRollbackService.CheckpointRollbackServiceV2.of({ execute: () => Effect.void }),
144
+ CheckpointRollbackService.CheckpointRollbackServiceV2.of({
145
+ execute: input.rollback ?? (() => Effect.void),
146
+ }),
147
),
148
Layer.succeed(
149
RuntimeRequestService.RuntimeRequestServiceV2,
@@ -231,6 +238,75 @@ it.effect("settles a stopped run when its adapter has already lost the native tu
238
}),
239
);
240
241
+const lockedIndexMessage =
242
+ "Git's index is locked. Wait for other Git operations to finish, then try again.";
243
+const rollbackCheckpointId = CheckpointId.make("checkpoint:effect-worker-rollback");
244
+const rollbackScopeId = CheckpointScopeId.make("checkpoint-scope:effect-worker-rollback");
245
+const restoreFailure = (detail: string) =>
246
+ new CheckpointRollbackService.CheckpointRollbackExecutionError({
247
+ reason: "unexpected-failure",
248
+ threadId,
249
+ providerThreadId,
250
+ checkpointId: rollbackCheckpointId,
251
+ cause: new CheckpointService.CheckpointRestoreError({
252
+ scopeId: rollbackScopeId,
253
+ checkpointId: rollbackCheckpointId,
254
+ cause: new VcsProcessExitError({
255
+ operation: "GitVcsDriverCore.restoreCheckpoint",
256
+ command: "git",
257
+ cwd: "/private/repo",
258
+ exitCode: 128,
259
+ detail,
260
+ failureKind: "command-failed",
261
+ }),
262
+ }),
263
+ });
264
+
265
+it.effect.each([
266
+ {
267
+ name: "a held Git index lock",
268
+ failure: restoreFailure(lockedIndexMessage),
269
+ message: lockedIndexMessage,
270
+ },
271
+ {
272
+ name: "raw Git output",
273
+ failure: restoreFailure("error: could not clean /private/repo/secret.txt"),
274
+ message: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
275
+ },
276
+])("reports a rollback blocked by $name only after the last attempt", ({ failure, message }) =>
277
+ Effect.gen(function* () {
278
+ const now = yield* DateTime.now;
279
+ const failures = yield* Ref.make<ReadonlyArray<string>>([]);
280
+ const layer = layerExecutorFor({
281
+ events: yield* Ref.make<ReadonlyArray<string>>([]),
282
+ rollback: () => Effect.fail(failure),
283
+ threads: {
284
+ dispatch: (command) =>
285
+ Ref.update(failures, (current) =>
286
+ command.type === "checkpoint.rollback.fail" ? [...current, command.message] : current,
287
+ ).pipe(Effect.as({ sequence: 1, storedEvents: [] })),
288
+ },
289
+ });
290
+ yield* Effect.gen(function* () {
291
+ const executor = yield* EffectWorker.OrchestrationEffectExecutorV2;
292
+ const rollback: EffectOutbox.OrchestrationEffectV2 = {
293
+ ...restartEffect(now, { type: "detach" }),
294
+ request: {
295
+ type: "provider-thread.rollback",
296
+ providerThreadId,
297
+ checkpointId: rollbackCheckpointId,
298
+ scopeId: rollbackScopeId,
299
+ restoreFiles: true,
300
+ },
301
+ };
302
+ yield* Effect.flip(executor.execute(rollback, { willRetry: true }));
303
+ assert.deepEqual(yield* Ref.get(failures), []);
304
+ yield* Effect.flip(executor.execute(rollback, { willRetry: false }));
305
+ }).pipe(Effect.provide(layer));
306
+ assert.deepEqual(yield* Ref.get(failures), [message]);
307
+ }),
308
+);
309
+
310
it.effect("requeues a claim when a pre-execution worker check fails", () =>
311
Effect.gen(function* () {
312
const now = DateTime.formatIso(yield* DateTime.now);
apps/server/src/orchestration-v2/EffectWorker.ts
+4
-1
@@ -422,7 +422,10 @@ export const layerExecutor: Layer.Layer<
422
commandId: CommandId.make(`${effect.commandId}:rollback-failed`),
423
threadId: effect.threadId,
424
requestId: effect.commandId,
425
- message: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
425
+ message: Option.match(Cause.findErrorOption(cause), {
426
+ onNone: () => CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
427
+ onSome: CheckpointRollbackService.rollbackFailureClientMessage,
428
+ }),
429
})
430
.pipe(
431
Effect.catchCause((recordCause) =>
apps/server/src/vcs/VcsProcess.test.ts
+60
-4
@@ -57,8 +57,63 @@ const captureProcessResult = (
57
);
58
59
describe("VcsProcess.run", () => {
60
+ it.effect("explains a locked Git index and allows restore after the lock is released", () =>
61
+ Effect.gen(function* () {
62
+ const fs = yield* FileSystem.FileSystem;
63
+ const path = yield* Path.Path;
64
+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-index-lock-" });
65
+ const git = (args: readonly string[]) =>
66
+ run({ operation: "test.checkpoint.restore", command: "git", cwd, args });
67
+ yield* git(["init"]);
68
+ const file = path.join(cwd, "README.md");
69
+ yield* fs.writeFileString(file, "before\n");
70
+ yield* git(["add", "README.md"]);
71
+ yield* git([
72
+ "-c",
73
+ "user.name=Test",
74
+ "-c",
75
+ "user.email=test@example.com",
76
+ "commit",
77
+ "-m",
78
+ "initial",
79
+ ]);
80
+ yield* fs.writeFileString(file, "after\n");
81
+ const lock = path.join(cwd, ".git", "index.lock");
82
+ yield* fs.writeFileString(lock, "held by another process\n");
83
+ const restore = ["restore", "--source=HEAD", "--worktree", "--staged", "--", "README.md"];
84
+
85
+ const error = yield* Effect.flip(git(restore));
86
+ expect(error).toBeInstanceOf(VcsProcessExitError);
87
+ expect(error).toMatchObject({
88
+ exitCode: 128,
89
+ failureKind: "command-failed",
90
+ detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
91
+ });
92
+ expect(error.message).not.toContain("index.lock");
93
+ expect(yield* fs.readFileString(file)).toBe("after\n");
94
+ expect(yield* fs.readFileString(lock)).toBe("held by another process\n");
95
+
96
+ yield* fs.remove(lock);
97
+ yield* git(restore);
98
+ expect(yield* fs.readFileString(file)).toBe("before\n");
99
+ }).pipe(provideLive, Effect.provide(NodeServices.layer), Effect.scoped),
100
+ );
101
+
102
it.effect.each([
61
- { stderr: "fatal: Unable to create '/private/repo/index.lock': File exists", retryable: true },
103
+ {
104
+ stderr: "fatal: Unable to create '/private/repo/index.lock': File exists",
105
+ retryable: true,
106
+ detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
107
+ },
108
+ {
109
+ stderr: "fatal: Unable to create 'C:\\private\\repo\\.git\\index.lock': File exists.",
110
+ retryable: true,
111
+ detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
112
+ },
113
+ {
114
+ stderr: "fatal: Unable to create '/private/repo/.git/config.lock': File exists.",
115
+ retryable: true,
116
+ },
117
{
118
stderr: "fatal: Unable to create '/private/repo/index.lock': Permission denied",
119
retryable: false,
@@ -75,8 +130,8 @@ describe("VcsProcess.run", () => {
130
},
131
{ stderr: "fatal: index file corrupt", retryable: false },
132
])(
78
- "classifies Git exit retryability without retaining stderr: $stderr",
79
- ({ stderr, retryable }) =>
133
+ "classifies Git exit retryability and safe detail without retaining stderr: $stderr",
134
+ ({ stderr, retryable, detail = "Process exited with a non-zero status." }) =>
135
Effect.gen(function* () {
136
const error = yield* captureProcessResult(
137
Effect.succeed({
@@ -92,8 +147,9 @@ describe("VcsProcess.run", () => {
147
);
148
assert.instanceOf(error, VcsProcessExitError);
149
expect(error.retryable === true).toBe(retryable);
150
+ expect(error.detail).toBe(detail);
151
const encoded = yield* encodeExitError(error);
96
- expect(encoded).not.toContain("/private/repo");
152
+ expect(encoded).not.toContain("private");
153
}),
154
);
155
apps/server/src/vcs/VcsProcess.ts
+17
-1
@@ -62,6 +62,10 @@ const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
62
const VCS_PROCESS_CONCURRENCY = 8;
63
const GITHUB_PROCESS_CONCURRENCY = 4;
64
65
+/** Shown to users when a Git command fails because another process holds the index lock. */
66
+export const GIT_INDEX_LOCKED_DETAIL =
67
+ "Git's index is locked. Wait for other Git operations to finish, then try again.";
68
+
69
export const CHECKPOINT_CAPTURE_OPERATION = "GitVcsDriver.checkpoints.captureCheckpoint";
70
71
/**
@@ -263,7 +267,7 @@ export const make = Effect.gen(function* () {
267
268
if (!input.allowNonZeroExit && result.code !== 0) {
269
const failureKind = classifyNonZeroExit(input.command, result.stderr);
266
- return yield* VcsProcessExitError.fromProcessExit(
270
+ const error = VcsProcessExitError.fromProcessExit(
271
baseError,
272
{
273
exitCode: result.code,
@@ -275,6 +279,18 @@ export const make = Effect.gen(function* () {
279
failureKind === "command-failed" &&
280
isTransientGitExit(result.stderr),
281
);
282
+ if (
283
+ input.command === "git" &&
284
+ /^fatal: unable to create ['"][^\r\n]*[/\\]index\.lock['"]: file exists\.?$/im.test(
285
+ result.stderr,
286
+ )
287
+ ) {
288
+ return yield* new VcsProcessExitError({
289
+ ...error,
290
+ detail: GIT_INDEX_LOCKED_DETAIL,
291
+ });
292
+ }
293
+ return yield* error;
294
}
295
296
return {