From 32d71293465cfb542f2870fd6bc24df5fc75f4a5 Mon Sep 17 00:00:00 2001 From: repo-worker-code Date: Mon, 16 Nov 2026 01:55:18 -0600 Subject: [PATCH] fix(pm-dispatch): note deleted session as deleted on cleanup success (#10632) The post-cleanup issue note hedged 'may still be live' even when deleteSession had just succeeded. The success branch now states the session was deleted; the hedge remains for cleanup failure and unavailable-callback branches, and for the pre-DELETE cancel reason. Adds a cleanup-success test pinning the new wording and the cancel-before-delete-before-note ordering. --- pm-stack/dispatch/src/launch_failure.ts | 2 +- pm-stack/dispatch/test/launch_failure.test.ts | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/pm-stack/dispatch/src/launch_failure.ts b/pm-stack/dispatch/src/launch_failure.ts index e2f29349e0..36801d29c8 100644 --- a/pm-stack/dispatch/src/launch_failure.ts +++ b/pm-stack/dispatch/src/launch_failure.ts @@ -124,7 +124,7 @@ export async function handleLaunchFailure( sessionId == null ? "" : cleanupError == null - ? `\n\nOpenCode session ${sessionId} may still be live; session cleanup succeeded.` + ? `\n\nOpenCode session ${sessionId} was deleted; session cleanup succeeded.` : `\n\nOpenCode session ${sessionId} may still be live; session cleanup failed: ${cleanupError}`; const note = cancelError == null diff --git a/pm-stack/dispatch/test/launch_failure.test.ts b/pm-stack/dispatch/test/launch_failure.test.ts index cca7e7c433..a1511c1406 100644 --- a/pm-stack/dispatch/test/launch_failure.test.ts +++ b/pm-stack/dispatch/test/launch_failure.test.ts @@ -83,6 +83,60 @@ describe("handleLaunchFailure", () => { expect(calls.closes).toEqual([["developing-today/code", 9, "not_planned"]]); }); + test("notes a deleted session without the may-still-be-live hedge when cleanup succeeds (#10632)", async () => { + const sessionId = "session/deleted-7"; + const launchError = new Error("prompt failed"); + const calls = { + deleted: [] as string[], + cancels: [] as [number, string][], + comments: [] as [string, number, string][], + closes: [] as [string, number, string | undefined][], + events: [] as string[], + }; + const queue = { + async cancelTask(id: number, reason: string): Promise { + calls.events.push("cancel"); + calls.cancels.push([id, reason]); + }, + }; + const github = { + async comment(repo: string, issueNumber: number, body: string): Promise { + calls.events.push("comment"); + calls.comments.push([repo, issueNumber, body]); + }, + async closeIssue(repo: string, issueNumber: number, stateReason?: "not_planned" | "completed"): Promise { + calls.events.push("close"); + calls.closes.push([repo, issueNumber, stateReason]); + }, + }; + const msg = await handleLaunchFailure( + queue, + github, + "developing-today/code", + 4135, + 2901, + launchError, + sessionId, + async (id: string) => { + calls.events.push("delete"); + calls.deleted.push(id); + }, + ); + expect(msg).toBe(launchError.message); + // The cancel reason is written before the DELETE runs, so its hedge + // is still accurate and stays out of scope for this fix. + expect(calls.cancels).toEqual([ + [4135, `dispatch launch failed: prompt failed; OpenCode session ${sessionId} may still be live`], + ]); + expect(calls.deleted).toEqual([sessionId]); + expect(calls.comments).toHaveLength(1); + expect(calls.comments[0][2]).toContain(`OpenCode session ${sessionId} was deleted`); + expect(calls.comments[0][2]).toContain("session cleanup succeeded"); + expect(calls.comments[0][2]).not.toContain("may still be live"); + expect(calls.events).toEqual(["cancel", "delete", "comment", "close"]); + expect(calls.closes).toEqual([["developing-today/code", 2901, "not_planned"]]); + }); + async function assertCreatedSessionFailure(stage: "sendPrompt" | "claim patch") { const sessionId = "session/created-42"; const launchError = new Error(`${stage} failed`);