Repository navigation
Description
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:
- 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 inwaitwell past the
WS7-observed 10–13 min legitimate-idle ceiling, up to the 30-min idle budget
and beyond. - 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_actioninorchestrator/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_jobspawns one Job per role
simultaneously, each wrapped bybuild_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; onpropose/ack/nackit
invokes the agent process one-shot, and onwaitit 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 seecomplete/consensus_is_complete()and exit; the
orchestrator stops any stragglers. The 30-min idle budget raises an
OVERSEER_ALERTbut 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} -pdelta,
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_nackhandlers, carryinglast_reviewed_commit_shaper
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 fromwaitto 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.pybash 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
- BRC consensus: replace agent-held waits with deterministic event-pump + durable agent memory (durable fix for #2906) #2908 (closed) — BRC event-pump + durable agent memory; the foundation this
builds on (PR [issue-2908][slice-3/6] Delta-scoped re-analysis + prompt collapse #2949 addedcompose_event_prompt+ the cache-preserving
prompt shape). - Genericize the SDLC pipeline into a declarative, config-driven workflow (custom phases + agents + per-phase slicing) #3017 — declarative phase/stage abstraction (adjacent: phase model).
- Stream per-task commits: durability + incremental review without stopping the producer #2958 — streaming per-task commits / producer lifecycle (adjacent: producer
keeps working). - Simplify PR agentic workflows: run the Agent SDK directly in CI, make k3s the sole runtime, remove all Docker orchestration #2866 — k3s as the sole runtime (adjacent: pod-lifecycle infra).
Activity
refine(#3023): on-demand agent spawning analysis + HITL decisions
plan(#3023): task_planner — 3 slices, 14 tasks for on-demand agent sp…
risk_analyst plan #3023: risk assessment for orchestrator-driven on-d…
plan(#3023): task_planner re-propose — address reviewer_plan v1 blockers
architect: plan-phase analysis for #3023 (on-demand BRC spawning)
plan(#3023): task_planner re-propose v2 — address reviewer_plan + ris…
architect v2 #3023: re-propose addressing risk_analyst NACK on AC-R1.…
test(orchestrator): TDD test scaffold for #3023 slice-1 PhaseIdleBudg…
feat(orchestrator): phase-level idle-budget alert + wrapper coexisten…
feat(orchestrator): expose derive_next_action as module-level callable (
docs(#3023 slice-3 task-3-4): retire consensus_wrapper.py from archit…
test(#3023 slice-3): TDD scaffold for TASK-3-2 + TASK-3-3 (tester v2)
33 remaining items
Address #3034 review: fix TypeError emitter + false-positive alert + …
jwbron commentedon Jun 9, 2026
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
derive_next_actionalias, a pure-addition prereq symbol) shipped, as "slice-2a." The core —OnDemandSpawner, the per-event_spawn_agent/KubernetesSpawnerfactory, session keep-alive, the orchestrator tick, orphan-commit detection — was deferred and never picked up.EGG_EVENT_LOOP_OWNERpassive-wrapper guard) was committed then reverted, because shipping it without the spawner makes the in-pod loop go quiet with nothing to replace it → BRC consensus deadlock.Closed PRs (this run's debris)
egg/issue-3023/work→main(context/base PR)egg/issue-3023/slice-1→work(phase-level idle-budget alert)egg/issue-3023/slice-2→work(slice-2a:derive_next_actionalias only)egg/issue-3023/slice-3→slice-1(retireconsensus_wrapper.py)The
issue-3023pipeline task is alreadycancelled.Before re-submitting (clean-slate checklist)
egg/issue-3023/work,egg/issue-3023/slice-1,egg/issue-3023/slice-2,egg/issue-3023/slice-3.egg/issue-3023-*/workand anyegg/recovered/issue-3023/*).Scope note for the re-plan
#3041was 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.fix(orchestrator): reject overlapping-but-unordered slices at plan in…
fix(ci): run contract verification on sliced PRs (#3040) (#3048)
jwbron commentedon Jun 10, 2026
Closing in favor of #3064, a cleaned-up re-submission. What changed there:
egg/issue-3023/*/egg/recovered/issue-3023/*branches were never deleted, but they don't collide with Orchestrator-driven on-demand agent spawning: lift the event pump out of the pod so idle agents don't exist #3064's branch namespace — deleting them is now optional cleanup, not a blocker.refine(issue-3064): analysis for orchestrator-driven on-demand agent …
feat(orchestrator): EGG_EVENT_LOOP_OWNER flag + dormant one-shot wrap…
test(issue-3064): slice-1 tester tests — pod-default golden + one-sho…
test(issue-3064): align slice-1 tester tests to coder's task-1-1 cont…
refine(issue-3064): analysis for orchestrator-driven on-demand agent …
feat(docs): add on-demand agent lifecycle architecture document (#3064 …
refine(issue-3064): analysis for orchestrator-driven on-demand agent …
Restore byte-identity of pod wrapper to main; fix accessor docstrings
[issue-3064][slice-1/6] Ownership flag + one-shot wrapper arm... (#3167)