Skip to content

🐛 Supervisor crash mid-leaf leaves session unrecoverable #558

Closed

Description

@evaline-ju

Describe the bug

Crashing a moca harness/supervisor pod led to a an unrecoverable session and some status reporting differences:

  1. Session unrecoverable after supervisor restart. No failure result ever finalizes server-side. mocactl get <sid> returns http_404 indefinitely (>3 min observed). Contrast: kubectl -n moca-sandbox delete pod ... eventually produces a responded session with an failure body. The sandbox-kill path reconciles, but the supervisor-kill path doesn't.
  2. mocactl get and mocactl sessions disagree. get → http_404. sessions → the same listed as state=active. Operator can't tell from the client surface whether the session is dead, running, or lost.
  3. Ledger reports a client-side error as if server-side. mocactl subagents --tag <tag> shows state=failed, detail="fetch failed (UND_ERR_SOCKET)". That's the detached spawn worker reporting its own severed POST /v1/runs connection, not a server status — but it reads to the operator as if the server declared the session failed.
  4. Orphan cleanup is manual. The dead session row needs mocactl sessions delete <sid> to free. Compounds with the related missing mocactl workloads list in feature: mocactl workloads list to enumerate caller's live workloads #552.

Steps To Reproduce

  1. mocactl spawn --kind prompt --config DIGEST --workload WLID --tag … a leaf whose first tool call sleeps briefly.
  2. After ~20s (leaf pinned to a sandbox pod), kubectl -n moca delete pod -l app=moca-supervisor.
  3. Supervisor pod respawns in ~10s. Sandbox pods never touched.

Expected Behavior

Supervisor crash mid-leaf should either:

  • (a) reconcile the session on supervisor restart and finalize a failure result — same shape as the sandbox-pod-kill path (client observes responded with a server-written body), or
  • (b) mark the session terminally failed server-side so mocactl get returns a legible terminal status (not 404) and mocactl sessions reflects the same state.

Moca Version

Tested on moca version edge-12536a6 (upstream/main as of 2026-10-20)

Additional Context

Potential fix: On supervisor startup, scan Redis for sessions in state=active with no live /v1/runs holder and finalize them. Mirrors the sandbox-pod-kill resilience that already exists. Fixes the get/sessions disagreement as a side effect.

Workaround today:

mocactl subagents --tag "$TAG" --json \
  | jq -r '.subagents[] | select(.detail | test("UND_ERR_SOCKET"; "n")?) | .sessionId' \
  | xargs -I{} mocactl sessions delete {}
# then re-dispatch under a fresh label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions