Skip to content

Commit 23dccb3

Browse files
committed
fix(web): check deletion support before stopping resources
Signed-off-by: 0x00-sys <[email protected]>
1 parent 3b13860 commit 23dccb3

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

‎apps/web/src/hooks/useThreadActions.deletion.test.tsx‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,29 @@ it("retains a thread that changes worktrees while its reference check is pending
449449
expect(mocks.run.mock.calls.some(([label]) => label.endsWith(":thread:delete"))).toBe(false);
450450
});
451451

452-
it("does not use destructive client cleanup against an older server", async () => {
452+
it("keeps the session and terminal running when an older server cannot delete the worktree", async () => {
453453
mocks.recoverableDeletion = false;
454+
mocks.readThreadShell.mockImplementation(({ threadId }) => {
455+
const thread = threads.find((entry) => entry.id === threadId);
456+
return thread ? { ...thread, session: { status: "ready" } } : null;
457+
});
454458
const result = await actions.deleteThread(entries[0]!.threadRef);
455459
expect(result._tag).toBe("Failure");
456-
expect(
457-
mocks.run.mock.calls.some(
458-
([label]) => label.endsWith(":thread:delete") || label.endsWith(":remove-worktree"),
459-
),
460-
).toBe(false);
460+
expect(mocks.run).not.toHaveBeenCalled();
461+
});
462+
463+
it("still deletes on an older server when refreshed references require keeping the worktree", async () => {
464+
mocks.recoverableDeletion = false;
465+
mocks.archived.mockResolvedValue(
466+
AsyncResult.success({
467+
threads: [{ id: ThreadId.make("archived"), worktreePath: "/repo/one" }],
468+
}),
469+
);
470+
expect((await actions.deleteThread(entries[0]!.threadRef))._tag).toBe("Success");
471+
expect(mocks.run.mock.calls.find(([label]) => label.endsWith(":thread:delete"))?.[1]).toEqual({
472+
environmentId,
473+
input: { threadId: threads[0]!.id },
474+
});
461475
});
462476

463477
it("reports committed deletion separately from pending cleanup and retries only cleanup", async () => {

‎apps/web/src/hooks/useThreadActions.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,20 +410,6 @@ export function useThreadActions() {
410410

411411
const completeDeletion = async (): Promise<AtomCommandResult<unknown, unknown>> => {
412412
let deleteWorktreePath: string | undefined;
413-
if (thread.session && thread.session.status !== "stopped") {
414-
const stopResult = await stopThreadSession({
415-
environmentId: threadRef.environmentId,
416-
input: { threadId: threadRef.threadId },
417-
});
418-
if (stopResult._tag === "Failure") return stopResult;
419-
}
420-
421-
const closeResult = await closeTerminal({
422-
environmentId: threadRef.environmentId,
423-
input: { threadId: threadRef.threadId, deleteHistory: false },
424-
});
425-
if (closeResult._tag === "Failure") return closeResult;
426-
427413
if (shouldDeleteWorktree && orphanedWorktreePath && threadProject) {
428414
// Archived threads are absent from the sidebar; refresh them before removing files.
429415
const archived = await executeAtomQuery(
@@ -474,6 +460,20 @@ export function useThreadActions() {
474460
}
475461
}
476462

463+
if (thread.session && thread.session.status !== "stopped") {
464+
const stopResult = await stopThreadSession({
465+
environmentId: threadRef.environmentId,
466+
input: { threadId: threadRef.threadId },
467+
});
468+
if (stopResult._tag === "Failure") return stopResult;
469+
}
470+
471+
const closeResult = await closeTerminal({
472+
environmentId: threadRef.environmentId,
473+
input: { threadId: threadRef.threadId, deleteHistory: false },
474+
});
475+
if (closeResult._tag === "Failure") return closeResult;
476+
477477
const deletedThreadIds = deletedIds ?? new Set<ThreadId>();
478478
const currentRouteThreadRef = getCurrentRouteThreadRef();
479479
const shouldNavigateToFallback =

0 commit comments

Comments
 (0)