Skip to content

Commit 7fd630b

Browse files
committed
fix: preserve worktrees when thread deletion fails
Stage worktrees on the server before committing thread deletion, restore them on failure, and recheck references at commit time. Report post-commit cleanup separately and avoid destructive retries when cleanup cannot be verified. Drain rejected bulk deletions and always close their loading notifications. Add focused recovery and concurrency tests. Implemented with GPT-6 Astra (Codex) in T3 Code. Signed-off-by: 0x00-sys <[email protected]>
1 parent 99a4a25 commit 7fd630b

14 files changed

Lines changed: 935 additions & 104 deletions

File tree

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export const make = Effect.gen(function* () {
223223
pullRequests: true,
224224
inlineMessageContext: true,
225225
threadSettlement: true,
226+
recoverableThreadDeletion: true,
226227
threadAutoSettlement: true,
227228
threadRestartContinuation: true,
228229
projectSettingsOverrides: true,

‎apps/server/src/orchestration/decider.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
threadPullRequestKeysEqual,
2222
} from "@t3tools/shared/threadPullRequests";
2323
import { compareDateTimeStrings } from "@t3tools/shared/dateTime";
24+
import { normalizeProjectPathForComparison } from "@t3tools/shared/path";
2425
import * as DateTime from "effect/DateTime";
2526
import * as Crypto from "effect/Crypto";
2627
import * as Effect from "effect/Effect";
@@ -411,11 +412,30 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
411412
}
412413

413414
case "thread.delete": {
414-
yield* requireThread({
415+
const thread = yield* requireThread({
415416
readModel,
416417
command,
417418
threadId: command.threadId,
418419
});
420+
if (command.deleteWorktreePath) {
421+
const worktreePath = normalizeProjectPathForComparison(command.deleteWorktreePath);
422+
if (
423+
thread.worktreePath === null ||
424+
normalizeProjectPathForComparison(thread.worktreePath) !== worktreePath ||
425+
readModel.threads.some(
426+
(entry) =>
427+
entry.id !== thread.id &&
428+
entry.deletedAt === null &&
429+
entry.worktreePath !== null &&
430+
normalizeProjectPathForComparison(entry.worktreePath) === worktreePath,
431+
)
432+
) {
433+
return yield* new OrchestrationCommandInvariantError({
434+
commandType: command.type,
435+
detail: "Worktree references changed during deletion. Try deleting the thread again.",
436+
});
437+
}
438+
}
419439
const occurredAt = yield* nowIso;
420440
return {
421441
...(yield* withEventBase({

0 commit comments

Comments
 (0)