Skip to content

Commit fceaa6f

Browse files
PR Batch Testerclaude
andcommitted
fix(server): show the Git index lock message when a rollback is blocked
Rollback failures reached clients as a fixed generic message, so the index-lock explanation only appeared in server logs. Clients now get the lock message when a restore fails on a held index lock; every other failure keeps the generic message, since those carry internal ids or raw Git output. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8e7e9c3 commit fceaa6f

4 files changed

Lines changed: 147 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/CheckpointRollbackService.test.ts‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ProviderSessionId,
99
ProviderThreadId,
1010
ThreadId,
11+
VcsProcessExitError,
1112
} from "@t3tools/contracts";
1213
import * as Effect from "effect/Effect";
1314
import * as FileSystem from "effect/FileSystem";
@@ -29,6 +30,7 @@ import * as ProjectStore from "./ProjectStore.ts";
2930
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
3031
import * as ProviderSessionManager from "./ProviderSessionManager.ts";
3132
import * as RuntimePolicy from "./RuntimePolicy.ts";
33+
import { GIT_INDEX_LOCKED_DETAIL } from "../vcs/VcsProcess.ts";
3234

3335
// A root that does not exist never overlaps, so other owners decide isolation.
3436
const unrelatedProject = Option.some({
@@ -342,6 +344,123 @@ it.effect("reports a missing provider turn as a structured rollback failure", ()
342344
}).pipe(Effect.provide(layerTest));
343345
});
344346

347+
it.effect.each([
348+
{
349+
name: "a held Git index lock",
350+
restoreCause: new VcsProcessExitError({
351+
operation: "GitVcsDriverCore.restoreCheckpoint",
352+
command: "git",
353+
cwd: process.cwd(),
354+
exitCode: 128,
355+
detail: GIT_INDEX_LOCKED_DETAIL,
356+
failureKind: "command-failed",
357+
retryable: true,
358+
}),
359+
expectedMessage: GIT_INDEX_LOCKED_DETAIL,
360+
},
361+
{
362+
name: "raw Git output",
363+
restoreCause: new VcsProcessExitError({
364+
operation: "GitVcsDriver.restoreCheckpoint",
365+
command: "git",
366+
cwd: process.cwd(),
367+
exitCode: 1,
368+
detail: "error: could not clean /home/user/project/secret.txt",
369+
failureKind: "command-failed",
370+
}),
371+
expectedMessage: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
372+
},
373+
{
374+
name: "an unclassified Git failure",
375+
restoreCause: new VcsProcessExitError({
376+
operation: "GitVcsDriverCore.restoreCheckpoint",
377+
command: "git",
378+
cwd: process.cwd(),
379+
exitCode: 128,
380+
detail: "Process exited with a non-zero status.",
381+
failureKind: "command-failed",
382+
}),
383+
expectedMessage: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
384+
},
385+
])(
386+
"tells clients about $name only when it is a held index lock",
387+
({ restoreCause, expectedMessage }) => {
388+
const threadId = ThreadId.make("thread:rollback-restore-failed");
389+
const providerThreadId = ProviderThreadId.make("provider-thread:rollback-restore-failed");
390+
const providerSessionId = ProviderSessionId.make("provider-session:rollback-restore-failed");
391+
const checkpointId = CheckpointId.make("checkpoint:rollback-restore-failed");
392+
const scopeId = CheckpointScopeId.make("checkpoint-scope:rollback-restore-failed");
393+
const providerInstanceId = ProviderInstanceId.make("provider_rollback_restore_failed");
394+
// Checkpoint has no appRunOrdinal, so rollback targets thread_start and
395+
// never needs a provider turn; it still goes through checkpoints.restore.
396+
const restore = vi.fn(() =>
397+
Effect.fail(
398+
new CheckpointService.CheckpointRestoreError({
399+
scopeId,
400+
checkpointId,
401+
cause: restoreCause,
402+
}),
403+
),
404+
);
405+
const projection = {
406+
thread: {
407+
worktreePath: process.cwd(),
408+
activeProviderThreadId: providerThreadId,
409+
modelSelection: { instanceId: providerInstanceId, model: "test-model" },
410+
},
411+
providerThreads: [{ id: providerThreadId, providerSessionId, providerInstanceId }],
412+
providerSessions: [],
413+
checkpoints: [{ id: checkpointId, scopeId, status: "ready", appRunOrdinal: null }],
414+
checkpointScopes: [{ id: scopeId, cwd: process.cwd() }],
415+
runs: [],
416+
attempts: [],
417+
providerTurns: [],
418+
} as unknown as OrchestrationV2ThreadProjection;
419+
const layerTest = layerCheckpointRollbackService.pipe(
420+
Layer.provide(
421+
Layer.mergeAll(
422+
ThreadCommandExecutor.layer,
423+
Layer.mock(CheckpointService.CheckpointServiceV2)({ restore }),
424+
Layer.mock(EventSink.EventSinkV2)({}),
425+
IdAllocator.layer,
426+
Layer.mock(ProjectionStore.ProjectionStoreV2)({
427+
getThreadRecords: () => Effect.succeed(projection),
428+
getShellSnapshot: () =>
429+
Effect.succeed({
430+
schemaVersion: 1,
431+
snapshotSequence: 0,
432+
threads: [],
433+
archivedThreads: [],
434+
}),
435+
}),
436+
Layer.mock(ProviderSessionManager.ProviderSessionManagerV2)({
437+
open: () => Effect.succeed({} as never),
438+
}),
439+
Layer.mock(RuntimePolicy.RuntimePolicyV2)({
440+
resolve: () => Effect.succeed({} as never),
441+
}),
442+
),
443+
),
444+
);
445+
446+
return Effect.gen(function* () {
447+
const service = yield* CheckpointRollbackService.CheckpointRollbackServiceV2;
448+
const error = yield* service
449+
.execute({
450+
threadId,
451+
providerThreadId,
452+
checkpointId,
453+
scopeId,
454+
})
455+
.pipe(Effect.flip);
456+
457+
assert.equal(error.reason, "unexpected-failure");
458+
assert.equal(CheckpointRollbackService.rollbackFailureClientMessage(error), expectedMessage);
459+
assert.equal(restore.mock.calls.length, 1);
460+
}).pipe(Effect.provide(layerTest));
461+
},
462+
);
463+
345464
it.effect.each([
346465
{ restoreFiles: true, shared: "none" },
347466
{ restoreFiles: false, shared: "root" },

‎apps/server/src/orchestration-v2/CheckpointRollbackService.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type OrchestrationV2DomainEvent,
66
ProviderThreadId,
77
ThreadId,
8+
VcsProcessExitError,
89
} from "@t3tools/contracts";
910
import * as Context from "effect/Context";
1011
import * as DateTime from "effect/DateTime";
@@ -18,10 +19,11 @@ import {
1819
isCheckpointRestoreIsolated,
1920
SHARED_WORKSPACE_RESTORE_MESSAGE,
2021
} from "./CheckpointRestoreSafety.ts";
21-
import { CheckpointServiceV2 } from "./CheckpointService.ts";
22+
import { CheckpointRestoreError, CheckpointServiceV2 } from "./CheckpointService.ts";
2223
import { EventSinkV2 } from "./EventSink.ts";
2324
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
2425
import { ProjectionStoreV2 } from "./ProjectionStore.ts";
26+
import { GIT_INDEX_LOCKED_DETAIL } from "../vcs/VcsProcess.ts";
2527
import * as ProjectStore from "./ProjectStore.ts";
2628
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
2729
import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts";
@@ -64,6 +66,20 @@ export class CheckpointRollbackExecutionError extends Schema.TaggedError<Checkpo
6466
}
6567

6668
const isCheckpointRollbackExecutionError = Schema.is(CheckpointRollbackExecutionError);
69+
const isVcsProcessExitError = Schema.is(VcsProcessExitError);
70+
const isCheckpointRestoreError = Schema.is(CheckpointRestoreError);
71+
72+
/**
73+
* The message clients see when a rollback fails. Only a held Git index lock
74+
* gets its own explanation; other reasons carry internal ids or raw Git
75+
* output, so they fall back to the generic message.
76+
*/
77+
export function rollbackFailureClientMessage(error: CheckpointRollbackExecutionError): string {
78+
const restoreCause = isCheckpointRestoreError(error.cause) ? error.cause.cause : undefined;
79+
return isVcsProcessExitError(restoreCause) && restoreCause.detail === GIT_INDEX_LOCKED_DETAIL
80+
? GIT_INDEX_LOCKED_DETAIL
81+
: ROLLBACK_FAILED_MESSAGE;
82+
}
6783

6884
export interface CheckpointRollbackServiceV2Shape {
6985
readonly execute: (input: {

‎apps/server/src/orchestration-v2/EffectWorker.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ export const layerExecutor: Layer.Layer<
428428
.pipe(
429429
// The last failed attempt tells waiting clients it failed,
430430
// instead of leaving them to time out. Clients get a fixed
431-
// message; the worker logs the full cause for each attempt.
431+
// message unless the failure has a user-facing reason; the
432+
// worker logs the full cause for each attempt.
432433
Effect.tapCause((cause) =>
433434
willRetry || Cause.hasInterruptsOnly(cause)
434435
? Effect.void
@@ -438,7 +439,10 @@ export const layerExecutor: Layer.Layer<
438439
commandId: CommandId.make(`${effect.commandId}:rollback-failed`),
439440
threadId: effect.threadId,
440441
requestId: effect.commandId,
441-
message: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
442+
message: Option.match(Cause.findErrorOption(cause), {
443+
onNone: () => CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
444+
onSome: CheckpointRollbackService.rollbackFailureClientMessage,
445+
}),
442446
})
443447
.pipe(
444448
Effect.catchCause((recordCause) =>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
6060
const VCS_PROCESS_CONCURRENCY = 8;
6161
const GITHUB_PROCESS_CONCURRENCY = 4;
6262

63+
/** Shown to users when a Git command fails because another process holds the index lock. */
64+
export const GIT_INDEX_LOCKED_DETAIL =
65+
"Git's index is locked. Wait for other Git operations to finish, then try again.";
66+
6367
export const CHECKPOINT_CAPTURE_OPERATION = "GitVcsDriver.checkpoints.captureCheckpoint";
6468

6569
const classifyNonZeroExit = (command: string, stderr: string): VcsProcessExitFailureKind => {
@@ -197,7 +201,7 @@ export const make = Effect.gen(function* () {
197201
) {
198202
return yield* new VcsProcessExitError({
199203
...error,
200-
detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
204+
detail: GIT_INDEX_LOCKED_DETAIL,
201205
});
202206
}
203207
return yield* error;

0 commit comments

Comments
 (0)