Skip to content

Make coordinator lifecycle event-driven and restart-durable #9228

Open

Description

@e-jung

Summary

Orca persists orchestration tasks, dispatches, and messages, but the coordinator run loop is still poll-driven and keeps important campaign state in memory. A successful worker_done, escalation, or decision gate may remain unseen until an explicit inbox check or the next coordinator poll; if the coordinator/runtime restarts, an in-flight campaign does not reconstruct all of its state and resume deterministically.

Introduce a durable, event-driven coordinator contract: lifecycle-message persistence should wake the owning coordinator, and a restarted coordinator should reconstruct its complete campaign state from the orchestration database without manual re-dispatch.

User-visible failures this would unify

These have separate immediate causes, but they violate the same invariant: every terminal lifecycle outcome must deterministically advance the durable task graph and wake its owner.

Source evidence on current main

  • src/main/runtime/orchestration/coordinator.ts runs tick() followed by sleep(pollIntervalMs); messages are read on the next tick rather than waking the loop when persisted.
  • The coordinator's completed tasks, failed tasks, escalations, and stop state are held in process memory.
  • runFromExistingRun() can reopen a coordinator run row, but restart convergence does not reconstruct the complete prior in-memory state, active wait position, and escalation context.
  • lifecycle-reconciliation.ts reconciles lifecycle messages, but it is not a durable process/session supervisor and does not turn every endpoint exit into an authoritative task transition.

Expected invariants

  1. Persisting worker_done, escalation, decision_gate, heartbeat, or endpoint-exit state wakes the owning coordinator immediately.
  2. Every dispatched attempt reaches one durable terminal outcome: completed, failed, retryable, blocked, or explicitly cancelled.
  3. A coordinator restart reconstructs completed/failed sets, active gates, unresolved escalations, attempts, and dependencies from durable state.
  4. Delivery and lifecycle authority are keyed by stable dispatch/pane identity rather than a transient terminal handle.
  5. Duplicate/replayed messages are idempotent.
  6. Aggregate runtime health reflects whether the orchestration subsystem can service a trivial request for the current generation.

Suggested acceptance tests

  • Persist worker_done while the coordinator is sleeping; assert it wakes and advances the dependent task without an explicit inbox poll.
  • Kill a dispatched worker; assert the dispatch and task converge on an explicit failed/retry state and an escalation is emitted.
  • Restart Orca with a three-task DAG containing one completed task, one active decision gate, and one dispatched worker; assert the coordinator resumes exactly once with the same dependency and escalation state.
  • Remint a terminal handle while preserving pane/dispatch identity; assert lifecycle messages still route to the correct coordinator.
  • Replay the same completion message after restart; assert no duplicate completion or worker launch.
  • Make orchestration RPC health fail while the runtime socket remains reachable; assert orca status reports a degraded orchestration subsystem rather than aggregate ready.

Related implementation work

This issue is intended as the durable/event-driven contract tying those paths together, not a replacement for their focused fixes. Prepared with AI assistance from source inspection and live orchestration failures. Reporter: @ericjung.

Activity

  1. seankwon816 commented on Jul 22, 2026

    @seankwon816

    Field data supporting this, from a multi-team deployment (8 concurrently coordinated teams, macOS 1.4.148, heavy orca orchestration use):

    Over the last 3 days we logged 11 incidents/repairs in exactly this failure family ("worker finished; coordinator never learned"), including 5 recurrences of the same pattern across different agent runtimes. Every one ended with the human operator manually waking the coordinator pane — today the operator is effectively the delivery layer.

    Two concrete findings that may sharpen the contract:

    1. The dispatch preamble actively fights the only workaround. The injected worker preamble says "worker_done ends your turn… take no further actions." Until lifecycle-message persistence wakes the owning coordinator, the only reliable surfacing path is the worker injecting a wake line (terminal send --enter) after worker_done — which the preamble forbids. Compliant workers are precisely the ones that strand their coordinators. Filed with a cheap preamble-level fix option as a separate issue.

    2. Delivery semantics are ambiguous across three signals. We have measured messages where delivered_at remains null permanently even after the recipient read and acted on the message (the read flag flips and the pane visibly processes it), while CLI ok:true is only enqueue acceptance. Suggest the event-driven contract expose explicit states — e.g. queued / delivered / surfaced (coordinator woken) — so senders can verify a handoff without screen-scraping.

    Also +1 on restart durability: we hit the adjacent gap where a worker restarted from a handoff (previous dispatch already terminal) has no valid task/dispatch coordinates for its first minutes — honest heartbeats are impossible (reusing the dead dispatch IDs would mask a hung retry). A first-class dispatch reissue/adopt step — coordinates issued before work starts — would close that window.

    Workarounds we currently maintain that this contract would delete outright: mandatory wake-ping rules, an atomic worker_done+wake helper script, spec trailers overriding the preamble, and low-frequency coordinator self-checks. Happy to share traces.

  2. added
    bug
    on Jul 27, 2026
  3. mhingston commented on Oct 4, 2026

    @mhingston

    This contract still looks important, but quite a bit of the surrounding orchestration machinery has landed since the issue was written and #15190 is now tracking the loop in detail.

    Would it be useful to reconcile this issue against current main and turn the acceptance criteria into a remaining-gap checklist? In particular, which of these are still open today:

    • lifecycle persistence immediately wakes the owning coordinator
    • restart reconstructs completed/failed sets, active gates, unresolved escalations and dependencies
    • replay is idempotent across restart
    • lifecycle authority is keyed by stable dispatch/pane identity rather than transient terminal handles
    • orchestration health reflects whether a trivial request can be serviced

    If #15190 now owns most of this contract, linking/closing individual criteria there may be clearer; otherwise this could remain the higher-level durability invariant with the current gaps called out explicitly.

  4. 0xAlbertChen commented on Nov 30, 2026

    @0xAlbertChen

    Strong +1. This is one of the most important requirements for production-grade orchestration.

    I am moving a multi-host agent fleet from an LLM-driven coordinator to a deterministic program coordinator, with a target of supporting up to 100 concurrent agent seats.

    We need:

    • Authenticated program-based coordinators without requiring an AI session or terminal.
    • Durable lifecycle events with stable event IDs and sequence numbers.
    • Explicit ACK after the consumer has persisted its own state.
    • Replay of unacknowledged events after restarts.
    • Idempotent task transitions and dispatch operations.
    • Automatic recovery of in-flight tasks without duplicate execution.

    Reading a message should not be equivalent to successfully processing it.

    This would allow us to eliminate custom polling, terminal inspection, and recovery scripts. Orca should own the execution lifecycle, while external coordinators own business policies.

    Related: #37407, #11229, #15828.

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