Skip to content

fix(mcpx): supervised transport (PR #1495) — pumpStdout writes to the attached daemon while holding the supervisor mutex, so a stalled daemon wedges exit and detach #2390

Closed

Description

@dezren39

Finding

PR #1495 (commit 18ba1ee35b, "mcpx: supervised stdio transport behind a flag (#1385, Phase 1 of #1384)") added pkgs/mcpx/internal/mcpclient/supervised.go. In pumpStdout the supervisor performs a blocking socket write to the attached daemon while holding the supervisor's global state mutex — verified unchanged on current main (origin/main at 5a34fa7070, 2026-10-29):

  • supervised.go:290 pumpStdout() — at :297 it takes s.mu.Lock(), and at :299 it calls s.attached.Write(data) inside that lock before unlocking.
  • The child-exit goroutine at :210-211 does s.child.Wait() and then needs the same s.mu.Lock() to record exited/exitErr and close waitDone.
  • detach() (:344-area lock), handleAttach() (attach/drain path), and finishWhenDone() also need the same mutex.

Failure chain: if the attached daemon stops reading (paused, wedged, or slow enough that the unix-socket send buffer fills — the pump writes 32 KiB chunks), the Write blocks indefinitely with the mutex held. From that moment:

  1. a child exit can never be recorded (the Wait goroutine blocks on the mutex), so waitDone never closes and finishWhenDone never runs — the supervisor wedges instead of surfacing the exit;
  2. no detach or replacement attach can proceed (both need the mutex), so the stalled attach cannot be cleared;
  3. child output stops being consumed, so the child can in turn block on a full stdout pipe — a full supervisor/child stall, behind the (default-off, Phase 1) supervised flag.

The existing tests from #1495 (TestSupervisedPumpDetachReattach, TestSupervisedSingleAttachRefused, TestSupervisedBufferOverflow, TestSupervisedChildExitSurfaced) cover a reading daemon and unattached buffering, but nothing covers an attached daemon that stops reading.

Why it matters

The supervised transport exists precisely so a daemon going away never harms the child, and so a child exit always surfaces. A stalled-but-connected daemon is the one case the current locking defeats both guarantees for, and it fails silently (no error, no exit report, supervisor process lingers).

Acceptance criteria

  • pumpStdout never performs a blocking write to the attached connection while holding the supervisor state mutex (e.g. a dedicated per-connection write mutex/queue owns attach writes and preserves the reply → buffered → live byte ordering that handleAttach's under-lock flush was protecting).
  • With an attached daemon that never reads: the child can still exit and the exit is recorded/reported (or the attach is dropped after a bounded write timeout), and a later attach/detach proceeds.
  • A regression test pins the stalled-reader case (daemon attaches, stops reading, child emits more than a socket buffer of output and/or exits; the supervisor does not wedge).
  • Existing supervised tests keep passing; unattached tail-buffer behaviour and droppedBytes accounting are unchanged.

Found by the pr-diff-review job reviewing PR #1495's diff against current main; deduped against open/closed issues (searched "supervised", "pumpStdout", "supervisor blocked/deadlock" — only the closed implementation issue #1385 covers this code, and it does not name this flaw).

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
    on Oct 29, 2026
  2. developing-today commented on Oct 29, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    on Oct 29, 2026
  4. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Oct 30, 2026
  6. 33 remaining items

  7. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  8. chatgpt-codex-connector commented on Oct 31, 2026

    @chatgpt-codex-connector
  9. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 31, 2026
  10. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up (resume)

  11. added a commit that references this issue on Oct 31, 2026
  12. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/pr-diff-reviewFiled by the pr-diff-review jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions