Skip to content

pm-dispatch(sessions): a failure between createSession and the claim PATCH orphans a live OpenCode session — task cancelled, 'launch FAILED' noted, session id recorded nowhere #3009

Closed

Description

@dezren39

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

  • launchSession order (server.ts): opencode.createSession(...) at :105, sendPrompt(session.id, ...) at :111, queue.ensureWorker() at :117, then the claim patchTask(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: the wait: false continuation calls handleLaunchFailure at :233 and the wait: true path at :252.
  • handleLaunchFailure (src/launch_failure.ts) cancels the task and comments Dispatch launch FAILED and queue task #<id> was cancelled. Error: <msg> on the issue. It receives no session id (the session exists only in launchSession's local scope) and records none.
  • OpenCodeClient (src/opencode.ts) exposes only createSession (:52), sendPrompt (:69) and listSessions (: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

Acceptance criteria

  • On any launchSession failure after createSession has succeeded, the session id is recorded somewhere durable and visible: at minimum in the cancellation reason / task last_error and in the issue failure note (i.e. handleLaunchFailure or 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: stub createSession to succeed and sendPrompt (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 test in pm-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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    effort/xsTrivial: expected under 30 minutes of work
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    on Oct 31, 2026
  2. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  4. 50 remaining items

  5. removed
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  6. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up (resumed)

  7. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 2, 2026
  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked — awaiting CI

  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  10. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: parked

  11. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — PR #4350 merged

  12. removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/pm-stackpm-stack (Pad/Grist) in developing-today/codeeffort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator job

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions