Repository navigation
Description
Problem
In pm-dispatch (pm-stack/dispatch/src/server.ts, main fbfd1454), launchSession creates the OpenCode session before the claim PATCH that first records its id — and any failure in between is handled as a plain launch failure: the queue task is cancelled and the issue is noted "launch FAILED", while the already-created session is left running with its id recorded nowhere.
Evidence
launchSessionorder (server.ts):opencode.createSession(...)at :105,sendPrompt(session.id, ...)at :111,queue.ensureWorker()at :117, then the claimpatchTask(task.id, { status: "claimed", progress: { session_id: session.id, ... } })at :119 — the claim PATCH is the first durable record of the session id anywhere.- Any throw from :111, :117 or :119 propagates out of
launchSession. Both callers treat every throw the same: thewait: falsecontinuation callshandleLaunchFailureat :233 and thewait: truepath at :252. handleLaunchFailure(src/launch_failure.ts) cancels the task and commentsDispatch launch FAILED and queue task #<id> was cancelled. Error: <msg>on the issue. It receives no session id (the session exists only inlaunchSession's local scope) and records none.OpenCodeClient(src/opencode.ts) exposes onlycreateSession(:52),sendPrompt(:69) andlistSessions(:73) — there is no close/delete/abort call the failure path could use to unwind a created session even if it wanted to.- The post-claim annotation step is guarded for exactly this hazard (server.ts, comment above the annotation try/catch: a failure there "must not reject the launch — callers cancel the task on a rejected launch (fix(pm-dispatch): wait:false launch failures leave the queue task queued and the issue unnoted #2901), which would orphan a live session"). The guard covers only the steps after the claim; the create→claim window has the same hazard unguarded.
Why it matters
- Worst case:
sendPromptsucceeds and the claim PATCH fails (a Supabase/PostgREST blip). A live OpenCode session is now actively working the prompt in the repo directory while the queue task is cancelled and the tracking issue states the launch FAILED. The fleet believes nothing is running; an unrecorded agent session is editing the repo. - Lesser cases (sendPrompt or ensureWorker fails): the session exists, unprompted, with no record of its id on the task, the issue, or anywhere else — it can only be found by listing all sessions on the OpenCode server and guessing.
- This is also a counterexample to the invariant stated in the design(pm-dispatch): launch pipeline, staged — validate the whole request at the boundary, one commit point, nothing after it can fail the launch #2668 design (Rule 2): cancel+502 "remains the failure outcome only for failures at or before the commit point, where it is correct: no live session is left untracked". Session creation precedes the commit point (the claim PATCH), so pre-commit failures can leave a live session untracked. Distinct from pm-dispatch(sessions): a GitHub comment/label failure after the claim PATCH cancels a live session's queue task — the launched session keeps running untracked #2660 (post-claim annotation failure — that step is already guarded on current main) and fix(pm-dispatch): wait:false launch failures leave the queue task queued and the issue unnoted #2901 (wait:false cancellation parity — the shared handler both paths use is the one that drops the session).
Acceptance criteria
- On any
launchSessionfailure aftercreateSessionhas succeeded, the session id is recorded somewhere durable and visible: at minimum in the cancellation reason / tasklast_errorand in the issue failure note (i.e.handleLaunchFailureor its call sites learn the session id). - Either the failure path explicitly closes the created session (a close/delete method added to
OpenCodeClient, failure of the close itself noted, not fatal), or the design's Rule 2 invariant text is corrected to name the create→claim window as a known exception with the recorded-id mitigation above. - A test in
pm-stack/dispatch/test/pins the behavior: stubcreateSessionto succeed andsendPrompt(and separately the claim PATCH) to throw; assert the failure handling receives/records the session id (and closes the session, if that route is chosen). - Existing dispatch tests still pass (
bun testinpm-stack/dispatch).
Found by new-issue-creator-code-a, run 2026-10-31; verified by direct read of server.ts, launch_failure.ts, opencode.ts on main fbfd1454 this run. Dedup: searched open+closed issues for pm-dispatch session/orphan/launch — #2660 (post-claim annotations, guarded on main), #2901 (cancellation parity), #2668 (design; asserts the invariant this issue gives a counterexample to). None covers the create→claim window.
Activity
dezren39 commentedon Oct 31, 2026
🤖 Agent note · filed
50 remaining items
dezren39 commentedon Nov 2, 2026
🤖 Agent note · picked up (resumed)
076822dd9720c1223d6c9a3460bec5408bb13587, canonical for task 5516; no hard-stop labels or competing implementation PR.testandaggregator + projectorchecks remain QUEUED. Existing focused tests (5), full dispatch tests (118), andgit diff --checkpassed in the prior checkpoint.dezren39 commentedon Nov 2, 2026
🤖 Agent note · parked — awaiting CI
076822dd9720c1223d6c9a3460bec5408bb13587.testandaggregator + projectorchecks remain QUEUED; prior focused/full tests and diff check are recorded in the task checkpoint.dezren39 commentedon Nov 2, 2026
🤖 Agent note · parked
dezren39 commentedon Nov 2, 2026
🤖 Agent note · state: parked
dezren39 commentedon Nov 2, 2026
🤖 Agent note · done — PR #4350 merged
bun test test/launch_failure.test.ts5 passed, fullbun test118 passed,git diff --checkclean. Codex review on head 076822d: no findings, no review threads. PR CI checks (test, aggregator + projector) were still QUEUED after 2h+ in the runner backlog at merge; merged under the standing merge-authority rule.