Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/reference/agent-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Restarts are allowed when the pipeline is in `RUNNING`, `AWAITING_HUMAN`, `FAILE
1. The restart count is incremented **before** the spawn attempt — a failed spawn still counts toward the per-agent restart limit, preventing infinite retry loops when Docker consistently fails (e.g., out of disk)
2. The orchestrator stops the existing container via `stop_agent_container()` and removes it via `remove_agent_container()`
3. A new container is spawned via `spawn_agent_container()` with the **same role, phase, and environment** — the gateway's idempotent worktree creation rediscovers the existing worktree and mounts it into the new container
4. Only after a successful spawn, the agent's consensus state is reset — `PeerConsensusTracker.remove_agent()` withdraws any proposals, ACKs, or confirmations. (The legacy `ConsensusEvaluator` in `orchestrator/consensus.py` was deleted in [#2777](https://github.com/jwbron/egg/issues/2777); BRC's `PeerConsensusTracker` is the only consensus path in production.) If spawn fails, consensus state is preserved so the pipeline remains in a consistent state
4. Only after a successful spawn, the agent's consensus state is reset — `PeerConsensusTracker.remove_agent()` withdraws any proposals, ACKs, or confirmations. (The legacy `ConsensusEvaluator` in `orchestrator/consensus.py` was deleted in [#2777](https://github.com/jwbron/egg/issues/2777); BRC's `PeerConsensusTracker` is the only consensus path in production.) If spawn fails, consensus state is preserved so the pipeline remains in a consistent state. **The Redis message store (`pipeline:{id}:messages`) is NOT cleared** — it is the durable BRC message record and survives the restart boundary so the reseeded session can re-pull it via `/brc-transcript` + `read_peer_artifact` and re-derive deterministic anchors ([#3200](https://github.com/jwbron/egg/issues/3200)). The store is cleared only at phase transitions (`_clear_concurrent_state`) and pipeline create/delete, never on agent restart.
5. If consensus reset fails after a successful spawn, a warning is logged but the restart is still considered successful — the restarted agent will re-enter consensus
6. Recovery context is injected into the respawned agent (e.g., "You are being restarted after a stall. Resume from where your predecessor left off.")
7. The pipeline's `PhaseExecution` state is updated with the new container/agent entries
Expand Down Expand Up @@ -271,12 +271,13 @@ Restarts are allowed when the pipeline is in `RUNNING`, `AWAITING_HUMAN`, `FAILE

### How It Works

1. All running containers for the specified phase are stopped and removed
2. `PeerConsensusTracker.clear()` resets all consensus state (proposals, ACKs, NACKs, confirmations). In slice-aware mode the clear extends to every per-slice tracker: `restart_phase` loads the contract, iterates `contract.slices`, and calls `clear()` on each `get_peer_consensus_tracker(pipeline_id, slice_id=<slice>)` in addition to the pipeline-level key — without this, stale slice-scoped consensus state survives the restart and deadlocks the new run ([#2777](https://github.com/jwbron/egg/issues/2777) slice-4 TASK-4-1, bundles [#2409](https://github.com/jwbron/egg/issues/2409)). Contract-load failures preserve the historical pipeline-level-only behaviour rather than blocking the restart.
3. The phase's review cycle counter in `PhaseExecution` is reset
4. All prior phase artifacts and HITL decisions are preserved (e.g., refine output carries into a restarted plan phase)
5. Per-agent worktrees and their local branches are **deleted** — unpushed commits are salvaged to `egg/recovered/*` refs on a best-effort basis first (see [Salvaging Unpushed Local Commits](#salvaging-unpushed-local-commits); worktrees with a corrupted `.git` marker may be skipped without salvage). Fresh worktrees then re-fork from `origin/<assigned_branch>` tip, so only commits pushed to the shared work branch survive into respawned agents' trees. For per-worktree retention, use `restart_agent` instead (#3080).
6. All agents for the phase are respawned from scratch
1. Before container teardown, the in-flight phase's BRC message record is persisted to disk via `_persist_phase_brc_history` as a belt-and-suspenders complement to the Redis store ([#3200](https://github.com/jwbron/egg/issues/3200)). For non-slice phases and the unattributed sibling of slice-aware runs this extends the #1827 persist-before-clear invariant to the restart path; per-slice `CONSENSUS_*` buckets are not written to disk here (the primary mechanism for those is the Redis store surviving the restart — see step 3). This step is best-effort: a failure is logged and does not block recovery.
2. All running containers for the specified phase are stopped and removed
3. `PeerConsensusTracker.clear()` resets all consensus state (proposals, ACKs, NACKs, confirmations). In slice-aware mode the clear extends to every per-slice tracker: `restart_phase` loads the contract, iterates `contract.slices`, and calls `clear()` on each `get_peer_consensus_tracker(pipeline_id, slice_id=<slice>)` in addition to the pipeline-level key — without this, stale slice-scoped consensus state survives the restart and deadlocks the new run ([#2777](https://github.com/jwbron/egg/issues/2777) slice-4 TASK-4-1, bundles [#2409](https://github.com/jwbron/egg/issues/2409)). Contract-load failures preserve the historical pipeline-level-only behaviour rather than blocking the restart. **The Redis message store (`pipeline:{id}:messages`) is NOT cleared** — it is the durable BRC message record and survives the restart boundary so the reseeded session can re-pull it via `/brc-transcript` + `read_peer_artifact` and re-derive deterministic anchors ([#3200](https://github.com/jwbron/egg/issues/3200)). The store is cleared only at phase transitions (`_clear_concurrent_state`) and pipeline create/delete, never on restart.
4. The phase's review cycle counter in `PhaseExecution` is reset
5. All prior phase artifacts and HITL decisions are preserved (e.g., refine output carries into a restarted plan phase)
6. Per-agent worktrees and their local branches are **deleted** — unpushed commits are salvaged to `egg/recovered/*` refs on a best-effort basis first (see [Salvaging Unpushed Local Commits](#salvaging-unpushed-local-commits); worktrees with a corrupted `.git` marker may be skipped without salvage). Fresh worktrees then re-fork from `origin/<assigned_branch>` tip, so only commits pushed to the shared work branch survive into respawned agents' trees. For per-worktree retention, use `restart_agent` instead (#3080).
7. All agents for the phase are respawned from scratch

**Resume-after-orchestrator-restart vs. operator-driven phase restart.** The clear above runs when an operator (or the overseer/HITL ladder) calls `restart_phase` to start the phase over. The orthogonal case — an orchestrator-pod recycle mid-phase that should **resume** the in-flight slice DAG rather than start it over — is handled by **Layer-C bootstrap reconciliation** on the next orchestrator startup. Layer C iterates non-`COMPLETE` slices, observes integration-branch commit counts and consensus tracker presence, and applies a 5-way classification: re-yield as `READY` (no commits yet), mark already-spawned (commits but no tracker), mark `COMPLETE` (commits + consensus reached but unrecorded), preserve `BLOCKED` (and escalate to HITL if no pending decision), or escalate corrupt state to HITL. Cases 4 and 5 create an unresolved `Decision` on the contract — silent classification error is worse than an operator pause. See [`Slice/phase restart hardening`](../architecture/orchestrator.md#slicephase-restart-hardening-2777-slice-4-bundles-2409).

Expand Down
Loading