Skip to content

Orchestrator-driven on-demand agent spawning: lift the event pump out of the pod so idle agents don't exist #3023

Closed as not planned

Description

@jwbron

Summary

Today the orchestrator spawns the full agent team for a phase up front, and
each agent pod then runs a long-lived in-pod event-pump loop
(orchestrator/consensus_wrapper.py) that long-polls the message bus and
invokes the agent process one-shot per actionable BRC event. The pod stays
alive — idle, heartbeating — for the whole phase, even while it has nothing to
do, until global consensus fires.

This issue proposes inverting that lifecycle: the orchestrator owns the event
loop and spawns an agent pod only when that role has an actionable event; the
pod handles the one event and exits.
No idle pods. The orchestrator is the
active party that reacts to events and spawns work, rather than a fleet of
pods passively waiting on a bus.

Two goals:

  1. Reduce resource use. An idle pod blocked on egg-orch message wait-loop
    still holds its CPU/memory reservation, a gateway session, and a 30s
    heartbeat cadence for the entire phase. On a resource-constrained cluster
    that idle reservation is pure waste — pods sit in wait well past the
    WS7-observed 10–13 min legitimate-idle ceiling, up to the 30-min idle budget
    and beyond.
  2. Make the system truly event-driven. The current model is poll-based
    dressed as event-driven: the orchestrator already computes when a role is
    actionable (_derive_next_action in orchestrator/routes/consensus.py), but
    that signal is consumed by an in-pod bash loop that long-polls for it. The
    orchestrator should push — spawn the agent in direct response to the event
    — instead of every pod pulling.

Current state (what exists today)

  • Spawn: at phase start, concurrent_executor.spawn_all →
    kubernetes_spawner.spawn_agent_job spawns one Job per role
    simultaneously, each wrapped by build_consensus_wrapped_command
    (orchestrator/consensus_wrapper.py).
  • Run: the wrapper is a deterministic bash loop. Each iteration calls
    egg-orch brc get-state / brc next-action; on propose/ack/nack it
    invokes the agent process one-shot, and on wait it blocks on
    egg-orch message wait-loop (60s inner timeout) while a background heartbeat
    (30s cadence) keeps the gateway session alive. The pod does not exit
    between events.
  • Terminate: only when global consensus completes (is_complete=True) does
    each wrapper see complete/consensus_is_complete() and exit; the
    orchestrator stops any stragglers. The 30-min idle budget raises an
    OVERSEER_ALERT but does not terminate the pod.

So the agent invocation is already one-shot-per-event — but the pod is
long-lived, and the event loop lives inside it.

The foundation that makes this feasible (already built)

The #2908 BRC event-pump work (notably PR #2949 / slice-3) already did the
hard part that an on-demand model depends on — it severed per-event invocation
from in-process continuity:

  • Stateless per-event invocation. compose_event_prompt
    (orchestrator/routes/event_prompt.py) builds the entire single-event prompt
    the agent is invoked with — role banner, event description, per-producer
    git log {last_reviewed_commit_sha}..HEAD --not origin/{base} -p delta,
    open-NACK section, and a tail-positioned memory excerpt. The agent no longer
    needs to stay running to keep its context.
  • Durable per-role continuity. The BRC memory artifact
    (.egg-state/agent-outputs/<role>/brc-memory.md, written by the
    brc_ack/brc_nack handlers, carrying last_reviewed_commit_sha per
    producer) externalizes the agent's working memory so it survives across
    stateless invocations rather than living in a running process.
  • Cache-preserving prompt shape. The prefix cache is server-side
    (Anthropic / LiteLLM), keyed on the stable prompt prefix, with a ≥60-min TTL
    — it is not pinned to a pod or session. compose_event_prompt
    deliberately keeps the event framing in the cacheable prefix and appends the
    changing memory excerpt at the tail (architect od-6 Option B). A fresh pod
    that composes the same stable prefix hits the same warm cache.

In other words, the only thing still keeping a pod alive is the in-pod bash
loop and the session keep-alive heartbeat — neither is fundamental to
correctness or to caching.

Desired model

Lift the event loop from inside the pod up to the orchestrator:

  • The orchestrator already derives, per role, whether there is an actionable
    event (_derive_next_action: propose / ack / nack / confirm /
    complete / wait). Make that derivation the spawn trigger: when a role
    transitions from wait to an actionable verb, spawn a pod for it; otherwise
    no pod exists for that role.
  • An agent pod becomes a one-shot event handler: it is spawned with the
    composed per-event prompt, does the single unit of work (propose / re-propose
    after NACK / review / confirm), and exits. Every spawn corresponds to real
    actionable work — there is no idle second cycle of containers.
  • The "wait" lives in the orchestrator (which already polls consensus state on
    a short cadence), not in a fleet of blocked pods.

Motivating examples of the events that should spawn a pod (illustrative, not an
exhaustive spec — the actionable-event set is exactly what _derive_next_action
already enumerates):

  • consensus is proposed and an assigned reviewer now has a review to do;
  • a reviewer NACKed a producer's work and the producer must re-propose;
  • an overseer alert or a resolved HITL decision is relevant to a specific role.

Open considerations (for refine/plan to work through — not pre-decided here)

  • Cold-start vs. cache TTL. Per-event pod spawn adds pod/worktree
    startup latency that the long-lived model amortized. Need to confirm the
    end-to-end latency budget and that consecutive events for a role land inside
    the ≥60-min cache TTL.
  • Gateway session model. Today a long-lived pod holds one gateway session
    alive via heartbeat; a per-event pod implies session setup/teardown per
    spawn. Worth checking the per-session cost and whether sessions can be
    reused across a role's successive spawns.
  • Where the event loop / wait actually moves. The orchestrator already runs
    a consensus poll loop and the next-action derivation; this is about wiring
    that to pod lifecycle rather than to an in-pod consumer.
  • Interaction with the in-pod event pump. This supersedes the
    consensus_wrapper.py bash loop's reason for keeping the pod alive; the
    wrapper's responsibilities (heartbeat, idle budget, per-event invocation)
    need to be re-homed or retired.

Out of scope

  • The agent primitive itself (pod image / worktree / Agent SDK / permissions /
    gateway restrictions) is untouched.
  • The BRC protocol semantics (propose/ack/nack/confirm, Delphi redaction,
    multi-reviewer NACK barrier) are unchanged — only when a pod exists changes.

Related

Activity

  1. added
    enhancement
    sdlc-candidate
    on Jun 8, 2026
  2. added 12 commits that reference this issue on Jun 8, 2026
  3. 33 remaining items

  4. added a commit that references this issue on Jun 9, 2026
  5. jwbron commented on Jun 9, 2026

    @jwbron
    OwnerAuthor

    Re-run from scratch

    The first SDLC run of this issue is being abandoned and re-run from scratch. It shipped only the prerequisites + wrapper teardown — the headline feature (the orchestrator-driven on-demand spawner) never landed.

    Why this run is being scrapped

    Closed PRs (this run's debris)

    The issue-3023 pipeline task is already cancelled.

    Before re-submitting (clean-slate checklist)

    1. Delete the stale remote branches so the new run starts clean: egg/issue-3023/work, egg/issue-3023/slice-1, egg/issue-3023/slice-2, egg/issue-3023/slice-3.
    2. Prune the leftover host agent worktrees (egg/issue-3023-*/work and any egg/recovered/issue-3023/*).
    3. Re-submit this issue (full refine → plan → implement). The feature spec above is unchanged and stands as the input.

    Scope note for the re-plan

    #3041 was opened to track the slice-2 spawner that this run dropped. With a from-scratch re-run, that scope returns to this issue — the re-plan should produce the full on-demand spawner, not just the prereqs. Two things the prior run learned that the re-plan should bake in: (a) the coexistence guard and the spawner must land together (guard-alone deadlocks), and (b) #3040 should be fixed first (or the run watched closely) so a descope can't merge unseen again.

  6. jwbron commented on Jun 10, 2026

    @jwbron
    OwnerAuthor

    Closing in favor of #3064, a cleaned-up re-submission. What changed there:

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

    agent:orchestratorenhancementsdlc-candidate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions