Skip to content

[Bug]: A failed dispatch never propagates to the task — dead agents leave tasks 'ready' forever and work is silently dropped #8984

Open

Description

@AKarode

Environment

  • Orca macOS 1.4.137 (com.stablyai.orca), macOS 26.5.2 (25F84), Apple Silicon
  • Local runtime healthy throughout (orca status → runtimeState: ready, runtimeReachable: true)
  • Local dispatch, Claude Code workers
  • Evidence below is from ~/Library/Application Support/orca/orchestration.db (read-only queries)

Summary

When a dispatched agent dies (last_failure = "Agent exited with code -1"), Orca records the failure on the dispatch row but never propagates it to the task row. The task stays status='ready' forever — indistinguishable in orca orchestration task-list from a task that simply hasn't started yet.

There is no retry, no re-queue, no escalation message, and no circuit_broken transition. The work is silently dropped.

In my case a 6-PR implementation campaign produced only 5 PRs. Nothing surfaced that PR 4 of 6 had been dispatched, run for 12 minutes, died, and been abandoned. I only discovered it days later by reading the DB by hand.

Evidence

1. Orca was alive and actively processing the failure — it wrote status and last_failure onto the dispatch row, but wrote nothing to the task:

task               dispatch_wrote  dispatch_reason            task_left_at  task_result
-----------------  --------------  -------------------------  ------------  -------------------
task_b81cc199e541  failed          Agent exited with code -1  ready         (no result written)

So this is not "the app died before it could update" — it updated one table and not the other.

2. It is systematic, across 5 separate days / independent campaigns (not a single crash):

SELECT COUNT(*) FROM tasks t JOIN dispatch_contexts d ON d.task_id = t.id
WHERE t.status = 'ready' AND d.status = 'failed';
-- 25
day         orphaned tasks
2026-07-01   3
2026-07-03   8
2026-07-09   2
2026-07-10   2
2026-07-15  10

All 25 share last_failure = 'Agent exited with code -1'.

3. Overall state divergence:

task_status  dispatch_status     n
-----------  ------------------  ---
completed    completed           106     <- happy path is fine
ready        failed               25     <- the bug: silently abandoned
ready        (never dispatched)    5
dispatched   dispatched            3
failed       failed                2     <- only because a human ran task-update by hand

The only 2 tasks that ever reached failed have the same "Agent exited with code -1" reason but carry an explicit hand-written result: {"reason":"cancelled: worker context-saturated"}. i.e. failure reaches the task table only when a human types it in.

4. The workers were healthy right up to death — heartbeats and even decision_gate question/answer traffic, then the whole bus went silent at 12:41:51Z and never emitted another message.

Correlation: serial dispatch survived, parallel fan-out did not

Same campaign, same day, same machine:

  • 00:09Z → 12:15Z — 14 tasks dispatched one at a time (each after the previous completed) → 14/14 completed.
  • 12:16Z → 12:30:54Z — coordinator fanned out 9 dispatches in ~100 seconds → 9/9 died with "Agent exited with code -1" within ~12 minutes.

Given the two hand-labelled cases say worker context-saturated, I suspect the workers exhausted context (each was pointed at a ~3,300-line spec) and exited. That part may be expected agent behaviour — the bug I'm reporting is that the death is silently swallowed rather than surfaced.

Expected

When a dispatch fails, at minimum one of:

  1. Propagate — set tasks.status = 'failed' (or back to pending/ready with a recorded result/attempt count) so the ledger reflects reality; and/or
  2. Retry / circuit-break — failure_count stays stuck at 1 and the schema already has a circuit_broken state that never engages; and/or
  3. Escalate — emit an escalation message so a supervising coordinator learns its worker died; and/or
  4. Surface — orca orchestration task-list should visibly distinguish "ready (never dispatched)" from "ready (last dispatch died)". Today they render identically, which is what made the loss invisible.

A stale last_heartbeat_at is already recorded and would be a sufficient signal for a reaper.

Actual

tasks.status stays ready indefinitely. task-list shows [ready]. Nothing indicates the agent ran and died. Work is dropped with zero signal.

Reproduction

  1. Create and dispatch a task to a worker agent.
  2. Kill the agent (or let it exit non-zero / saturate context) so the dispatch records Agent exited with code -1.
  3. orca orchestration task-list → the task is still [ready].
  4. Query the DB:
SELECT t.status AS task_status, d.status AS dispatch_status, d.failure_count, d.last_failure
FROM tasks t JOIN dispatch_contexts d ON d.task_id = t.id
WHERE d.status = 'failed';

→ task_status='ready' while dispatch_status='failed'.

Impact

This is a silent correctness/data-loss failure for any multi-agent campaign. A fan-out of N tasks can return N−k results and the operator has no way to notice from the tooling — the missing tasks look identical to queued ones. It scales badly: the more parallel the fleet, the more likely a worker dies, and every death is invisible.

Related but distinct: #8698 (successful worker_done needs an explicit inbox poll to be seen). This one is the failure path, where the outcome is dropped entirely rather than merely delayed.

Activity

  1. AKarode commented on Jul 16, 2026

    @AKarode
    Author

    Correction — root cause of the agent deaths identified, and it strengthens this report.

    In the original post I speculated the workers died of context saturation. That was wrong, and the real trigger is more mundane and more likely to hit other users:

    macOS auto-installed an OS update and restarted the machine out from under the running fleet.

    agents all died:   2026-07-15 05:42–05:43 PDT   (9/9, within 52s of each other)
    kern.boottime:     2026-07-15 07:05:06 PDT
    InstallHistory:    macOS 26.5.2 installed 2026-07-15 07:08:05 PDT (process=softwareupdated)
    SoftwareUpdate:    AutomaticallyInstallMacOSUpdates = 1
    

    Evidence it was an external kill, not per-agent exhaustion:

    • The three workers I still have transcripts for died within 52 seconds of each other at completely different context sizes (188k / 217k / 237k tokens). Individual context limits would kill them at different times, not simultaneously.
    • Their transcripts contain zero structural API errors, zero rate-limit events, and zero compaction events. The last entry for one is a Write tool call + successful tool_result — it was working normally, then simply ceased.

    Why this matters for the bug: an OS-initiated restart is a completely ordinary event for a long-running agent fleet (it's the default setting on macOS). So the "dispatch dies → task silently stays ready" path is not an exotic edge case — any unattended overnight campaign on a default-configured Mac can hit it. That is exactly what happened here: the reboot was recoverable (I could have just re-run the 9 tasks), but because the failure never reached the task ledger, 1 of the 9 was silently dropped and stayed lost until I read the DB by hand days later.

    The core report is unchanged and still fully evidenced: Orca wrote status='failed' + last_failure='Agent exited with code -1' onto the dispatch rows (so the app was alive and processing the failure after the reboot) and never propagated it to tasks.status, which remains ready today across 25 tasks / 5 separate days.

  2. AKarode commented on Jul 16, 2026

    @AKarode
    Author

    Code-level root cause (from app.asar, 1.4.137) — this is more specific than my original framing, and I think it makes the fix clearer. It is not a missing propagation; it's a requeue-for-retry into a queue that only exists when a coordinator loop is running.

    failDispatch:

    failDispatch(ctxId, error) {
      const ctx = /* … */;
      const newFailureCount = ctx.failure_count + 1;
      const newStatus = newFailureCount >= 3 ? "circuit_broken" : "failed";
      this.db.prepare(
        "UPDATE dispatch_contexts SET status = ?, failure_count = ?, last_failure = ? WHERE id = ?"
      ).run(newStatus, newFailureCount, error, ctxId);
      const taskStatus = newStatus === "circuit_broken" ? "failed" : "ready";
      this.db.prepare("UPDATE tasks SET status = ? WHERE id = ?").run(taskStatus, ctx.task_id);
      // …
    }

    and the agent-exit handler:

    const errorContext = `Agent exited with code ${exitCode}`;
    this._orchestrationDb.failDispatch(dispatch.id, errorContext);
    const run = this._orchestrationDb.getActiveCoordinatorRun();
    if (run) {                     // <-- escalation ONLY when a coordinator run is active
      this._orchestrationDb.insertMessage({ /* type: "escalation", priority: "high" */ });
    }

    So on an agent death with no active coordinator run (i.e. the CLI / manually-dispatched workflow — my coordinator_runs table is empty, I have only ever dispatched via orca orchestration dispatch from a supervising agent):

    1. tasks.status is set back to ready — intentionally, to be retried.
    2. Nothing ever retries it, because only the coordinator loop drains ready.
    3. failure_count therefore stays at 1 forever — it only increments per dispatch attempt — so the >= 3 circuit_broken path (the one that would set tasks.status='failed' and make the loss visible) is unreachable by construction.
    4. The escalation is skipped entirely because of if (run).

    Net effect: the task lands back in ready, indistinguishable from "never dispatched", with no message, no retry, and no possible escalation to circuit_broken. That matches my data exactly — 25 orphans, every one failure_count = 1, across 5 separate days.

    Suggested fixes (any one would have saved me)

    • When failDispatch fires with no active coordinator run, don't silently requeue to ready — either mark the task failed/blocked, or record the death on the task itself so it isn't indistinguishable from untouched work.
    • Make task-list show it: a task requeued after a dead dispatch should not render identically to a never-dispatched one (e.g. surface failure_count / last_failure / last_heartbeat_at).
    • Warn on orca orchestration dispatch when no coordinator run is active, since in that mode retry, circuit-breaking and escalation are all silently inert. That contract isn't documented anywhere I could find, and it's the entire safety net.

    Happy to test a fix against my DB (25 real orphans, preserved and untouched) if that helps.

  3. AKarode commented on Jul 16, 2026

    @AKarode
    Author

    Empirical repro + confirmation that the coordinator loop DOES recover — which pins the bug precisely.

    I reproduced both paths on a clean scratch worktree (1.4.137). Summary: the recovery machinery works correctly when a coordinator run is active. Without one, the exact same death is silently swallowed. That asymmetry is the bug.

    With a coordinator run active — works as designed ✅

    orca orchestration run --spec … --max-concurrent 1 --worktree name:<scratch>, one canary task, then kill -9 the worker PTY:

    term_9f8a161f   failed       fails=1   "Agent exited with code 0"     -> task set to 'ready'
    term_a5f61f54   dispatched   fails=2                                  -> NEW worker auto-created + RE-DISPATCHED
    messages: 2026-07-16 08:24:56 | escalation | high | "Agent exited unexpectedly (code 0)"
    

    failActiveDispatchOnExit fired, the task was requeued, the loop spun up a replacement terminal and re-dispatched it, and a high-priority escalation was emitted. Exactly right.

    Without a coordinator run — identical death, silently dropped ❌

    That is my production case: coordinator_runs empty, if (run) false → no escalation, and nothing drains ready → no retry → failure_count frozen at 1 → circuit_broken (the only state that would set tasks.status='failed' and make it visible) is unreachable. 25 tasks, 5 days, all ready/failed.

    So the entire safety net — retry, escalation, circuit-breaker — is silently conditional on a coordinator run existing, and orca orchestration dispatch will happily dispatch without one and give no hint. That contract isn't documented anywhere I could find.

    Minimal ask: warn (or refuse) on orchestration dispatch when no coordinator run is active, since in that mode every failure is invisible by construction.


    Two further findings from the same repro

    1. A worker that dies without a PTY exit wedges its task forever, and --max-concurrent slots leak.
    Killing the agent process (claude, a child of the shell) left the PTY alive, so failActiveDispatchOnExit never fired: task=dispatched, dispatch=dispatched, failure_count=0, last_heartbeat_at=NULL — permanently. Since slotsAvailable = maxConcurrent - count(status='dispatched'), that task permanently consumes a slot, and a --max-concurrent 1 loop is wedged forever at 0 slots. tick() calls warnStaleDispatches(), which the source says intentionally only warns:

    // Why: emit a single warning per stale dispatch per tick. This intentionally
    // does NOT auto-fail the dispatch — the false-positive cost (a slow worker
    // producing correct output) is higher than the false-negative cost (a hung
    // worker keeps its terminal slot until a human notices).

    I understand the false-positive reasoning, but "keeps its terminal slot until a human notices" is doing a lot of work when nothing tells the human. My DB has 3 such tasks stuck dispatched since 2026-07-01 with last_heartbeat_at = NULL — 2 weeks, zero heartbeats, never surfaced. A stale-dispatch reaper (or at least surfacing last_heartbeat_at in task-list) would close this.

    2. The loop's auto-created worker is a bare login shell, so auto-dispatch produces garbage.
    When no idle terminal exists, the loop does createTerminal(worktree, {title: 'Worker: …'}) — which starts /bin/zsh -l, not an agent. It then dispatches the task spec into it, and zsh just tries to execute the prompt:

    term_33ffa0d5…  connected  /…/orca-retry-proof
    preview: (base) adit@… % >....
             zsh: parse error near `)'
    

    So the loop only works if you pre-create agent terminals in the target worktree; its own fallback silently produces a non-worker that will never complete the task (and holds a slot). Happy to split this into its own issue if you'd prefer.

  4. added
    bug
    on Jul 27, 2026
  5. yoyofreeman commented on Oct 16, 2026

    @yoyofreeman

    Independent reproduction on Linux + a new dimension: this also happens when the Run did have a coordinator (not only when none ever existed).

    Confirming #8984 on a different platform and a different workflow shape, with a variant that your analysis doesn't cover.

    Environment

    • Ubuntu 24.04.5 LTS (Linux, not macOS), x86_64
    • Orca 1.4.224 (orca-ide --version)
    • Local dispatch via supervised orchestration (run-create → task-create → worker-start --agent pi), always inside a bound Run
    • Evidence from ~/.config/orca/orchestration.db, read-only

    Same signature, larger scale

    SELECT COUNT(*) FROM tasks t JOIN dispatch_contexts d ON d.task_id = t.id
    WHERE t.status IN ('ready','blocked') AND d.status = 'failed';
    -- 32

    32 of 208 tasks (15%), across 26 distinct Runs, multiple workspaces (harness / writing / ziwu_lan / video_studio / …), oldest 205h stale — and still growing (3 such tasks created on the most recent day). Every one has its dispatch at a terminal state (failed); none has a live dispatch. So it's not a snapshot artifact — it keeps accumulating.

    New dimension: a coordinator was present — it just doesn't help after the Run settles

    Your root-cause comment pins it on getActiveCoordinatorRun() returning null when no coordinator run exists (if (run) { …escalation… }), and your fleet had an empty coordinator_runs table.

    In ours the picture is: run_coordinator_handles has 119 rows across 115 Runs — these Runs did have a live coordinator — and coordinator_runs is empty because those Runs have since settled. The re-queue-to-ready still happens, and still nothing drains it, because by the time the dispatch died the Run had no active coordinator.

    So the failure mode is broader than "dispatched without a coordinator run": any Run that has settled still leaves its dead dispatches stranded in ready/blocked forever. The if (run) guard means escalation is skipped precisely in the common case where the coordinator has already moved on. A reaper keyed on last_heartbeat_at (still recorded) would fix both cases.

    failure_count is not always 1

    Your data showed every orphan at failure_count = 1 (hence circuit_broken unreachable). Ours splits two ways:

    task_status  dispatch_status  failure_count  n
    blocked      failed           0              4
    blocked      failed           1             17
    ready        failed           1             11
    

    28/32 are failure_count = 1 (consistent with your finding), but 4 are failure_count = 0 with dispatch.status='failed' — a dispatch that recorded a failure without ever incrementing the count. last_failure for these is stopped / Terminal closed by operator request. Whatever the cause, it's a second path into the same dead-end state, and it also can never reach the >= 3 circuit_broken branch.

    Impact (matches yours)

    tasks.status stays ready/blocked, rendering identically to never-dispatched work in any task-list-style view; completion stats are wrong; a supervising "unfinished tasks" audit false-positives on 15% of the ledger. We only found it by reading the DB by hand (via a read-only audit tool we wrote).

    Repro (read-only, cross-platform)

    SELECT t.status, d.status, d.failure_count, t.created_at
    FROM tasks t JOIN dispatch_contexts d ON d.task_id = t.id
    WHERE t.status IN ('ready','blocked') AND d.status = 'failed';

    Expected (same as your list): propagate to tasks.status, and/or retry/reap on stale last_heartbeat_at, and/or surface failure_count / last_failure in task-list so a dead-dispatch task is distinguishable from a queued one. Plus: don't gate the escalation on if (run) — a settled Run's dead dispatches are exactly the ones a human most needs told about.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions