Skip to content

[issue-3200][slice-7/10] Mid-phase BRC message-record persistence - #3248

Merged
jwbron merged 10 commits into
mainfrom
egg/issue-3200/slice-7
Jun 25, 2026
Merged

jwbron merged 10 commits into
mainfrom
egg/issue-3200/slice-7

Conversation

@james-in-a-box

Copy link
Copy Markdown
Contributor

Make the BRC message record survive a mid-phase restart so a reseeded session can re-pull it and re-derive the phase-3 anchors (_write_brc_history persists at phase transitions only today). Logical dep: none; serialized after slice 6 (#3046). Must land before the reseed (slice 8) is trusted across restarts.

Base PR: #3234

What's in this PR

Commits (7):

.egg-state/brc-history/3200-implement-slice-7.json     | 2313 +++++++++++++++++++++++++
 .egg-state/brc-history/3200-implement-slice-7.md       | 3308 ++++++++++++++++++++++++++++++++++++
 orchestrator/routes/pipelines.py                       |   69 +
 orchestrator/tests/test_restart_brc_record_survival.py |  252 +++
 orchestrator/tests/test_restart_phase_brc_history.py   |  512 ++++++
 5 files changed, 6454 insertions(+)

This slice

Mid-phase BRC message-record persistence

Files affected:

  • orchestrator/
  • orchestrator/tests/
Tasks (2) + acceptance criteria
  • task-7-1: Ensure the BRC message record survives a mid-phase restart. Choose between (a) reading the live Redis message stream across the restart, or (b) adding a history-persist step to the restart route so _write_brc_history also fires mid-phase. (Architect confirms the mechanism; this task owns the requirement + test.)
    • Acceptance criteria: After a simulated mid-phase restart, the phase's BRC message record is retrievable (Redis stream or persisted history); no message loss across the restart boundary.
  • task-7-2: Tests: a mid-phase restart preserves the message record (proposals, verdicts, open NACKs) so the post-restart session can reconstruct the queryable environment and re-derive the phase-3 anchors.
    • Acceptance criteria: Test simulates mid-phase restart and asserts the message record is intact afterwards; tests pass.

Stack

@james-in-a-box

This comment has been minimized.

@james-in-a-box

Copy link
Copy Markdown
Contributor Author
Autofix tracking
{"Lint/Python": 1}

@james-in-a-box

This comment has been minimized.

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contract Verification — PR #3248 (issue-3200, slice-7/10)

Verdict: Approve. Both slice-7 tasks meet their acceptance criteria; implementation matches the task descriptions; commits map cleanly to tasks; no contract violations found.

task-7-1 — Mid-phase BRC message-record survival

AC: After a simulated mid-phase restart, the phase's BRC message record is retrievable (Redis stream or persisted history); no message loss across the restart boundary. — Verified.

  • orchestrator/routes/pipelines.py restart_agent (~L3277) and restart_phase (~L3779) now document the load-bearing invariant: the restart path resets only the peer consensus tracker (ephemeral ACK/NACK bookkeeping) and must not clear the Redis message store (pipeline:{id}:messages). The store is wiped only at phase transitions (_clear_concurrent_state) and pipeline create/delete — never on restart. This is option (a), the mechanism a reseeded session re-pulls from via /brc-transcript + read_peer_artifact.
  • restart_phase step 3b (L3631–3676) adds a best-effort _persist_phase_brc_history(pipeline, store, phase) before the destructive container/worktree teardown (step 4), wrapped in try/except so a persist hiccup never blocks recovery of a wedged phase. The store arg is the StateStore from _resolve_pipeline; the helper only reads store.repo_path, so the call is correct.
  • The honesty fix (d681326) correctly scopes option (b): _persist_phase_brc_history → _write_brc_history(write_per_slice=False) writes only the {id}-implement-unattributed sibling and skips the per-slice CONSENSUS buckets (avoiding the #2755 add/add conflict). So in-flight slice CONSENSUS records survive via Redis (a), not disk — the comment now states this accurately rather than overclaiming durability. The AC's "Redis stream or persisted history" is satisfied by (a), which is what the tests exercise.

task-7-2 — Tests assert the record survives

AC: Test simulates mid-phase restart and asserts the message record is intact afterwards; tests pass. — Verified.

  • test_restart_brc_record_survival.py: drives the real POST .../agents/coder/restart route with a seeded live store; asserts PROPOSE + ACK + open-NACK survive, the NACK body is verbatim, and proposal_commit_sha is preserved (so the #3189 last-reviewed-SHA anchor is re-derivable). Plus a harness-independent guard that clearing the consensus tracker leaves the message store intact.
  • test_restart_phase_brc_history.py: the restart_phase counterpart — test_restart_phase_preserves_live_brc_record (live-store survival), test_restart_phase_does_not_clear_message_store (asserts store.clear() is never called on the restart path), the _write_brc_history round-trip/empty-store guards, and test_persist_failure_is_nonfatal (mocks the persist seam to raise, asserts 200 + assert_called_once — exercises the real wired guard, not a vacuum).
  • Ran both files locally: 9 passed. The xfail markers from the early tester commits were correctly removed once the coder landed the persist call (0015195), so they are now hard regression guards.

Notes for the human reviewer (non-blocking)

  • Criteria-marking surface unreachable. The orchestrator was unreachable for the entire review (egg-contract show / verify-criterion and the MCP equivalents all return "Orchestrator unreachable"), so I could not programmatically mark criteria. The contract additionally stores criteria as per-task acceptance_criteria strings (top-level acceptance_criteria is empty), so there are no ac-N ids to mark. Both per-task criteria are verified above by inspection + targeted test run.
  • Option (b) durability is narrow by design. _persist_phase_brc_history commits but does not push, and restart_phase deletes per-agent worktrees downstream; for slice runs it captures only the unattributed audit sibling. This is consistent with the (now honest) comments — (b) is belt-and-suspenders cold-start hardening, not the slice record's survival path. Survival of the in-flight slice record rests entirely on option (a) (live Redis), which is load-bearing and tested.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@egg-reviewer egg-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: slice-7 mid-phase BRC message-record persistence

Reviewed the full changeset. The only behavioral change is a single best-effort _persist_phase_brc_history(pipeline, store, phase) call added to restart_phase (orchestrator/routes/pipelines.py:3669); the restart_agent hunk and the second restart_phase hunk are comment-only. I traced the end-to-end mechanism and reviewed both test files against the production code paths.

No blocking issues found. Summary of what I verified:

Correctness / feature functionality (the load-bearing claim holds).

  • Option (a) — the durable mechanism — works by not clearing pipeline:{id}:messages on restart. Confirmed restart_phase only clears the peer consensus tracker (steps 5) and never calls get_message_store().clear() / _clear_concurrent_state. The consumer is real: GET /<pipeline_id>/brc-transcript exists at routes/messages.py:415 and serves the live message store, so a reseeded session can genuinely re-pull. No cross-module dead-end.
  • The new persist call has the correct signature, runs outside the lock before teardown, and uses the mutated pipeline object — which is fine since _persist_phase_brc_history only reads id/issue_number/repo for path + identifier resolution.
  • Staging is safe: _commit_statefiles_to_worktree runs git read-tree HEAD (discards any pre-staged index) and stages only files matching the pipeline-identifier prefix, so a mid-restart commit cannot capture unrelated changes from wedged agents. It targets the shared pipeline worktree, not the per-agent worktrees deleted in step 4b, so the commit is not destroyed by teardown.
  • Best-effort guard is correct: wrapped in try/except Exception with a warning log, so a transcript hiccup cannot block recovery of a wedged phase.

Tests exercise production paths (no blocking test anti-patterns).

  • Live-store survival drives the real restart_phase/restart_agent Flask routes against a real fakeredis-backed get_message_store(); _write_brc_history round-trip tests call the real serializer. No self-seeding goldens (expected values are hand-authored), no fixtures that bypass the production helper, no name-vs-behavior contradictions.
  • test_restart_phase_does_not_clear_message_store patches the store class's clear and asserts it is never called — a correct regression lock for the stated invariant.

Non-blocking observations

  1. TestConsensusResetPreservesMessageStore.test_clearing_consensus_tracker_leaves_message_store_intact is near-vacuous. get_peer_consensus_tracker("issue-777") returns None when no consensus activity has been seeded, so the if tracker is not None: tracker.clear() body is skipped and the test degrades to "seeding survives a no-op" — it does not actually exercise the tracker-clear-vs-store-isolation it claims. Consider creating a real tracker (or asserting one exists) so the clear path is genuinely covered.

  2. TestInFlightBrcRecordSurvivesToDisk validates write_per_slice=True, but the restart path calls write_per_slice=False. These tests prove the _write_brc_history serializer preserves per-slice CONSENSUS records, but that is not the artifact the restart path actually writes (per the comment at pipelines.py:3649-3666, the restart persist writes only the -implement-unattributed.{md,json} sibling for slice phases). The docstrings are honest about this, so it is not misleading in context — but there is no test asserting the restart path's actual write_per_slice=False disk output. Since option (b) is explicitly non-load-bearing this is acceptable, but a small test pinning the unattributed-sibling output of the real restart call would close the gap.

  3. The persist commits but does not push within restart_phase. For non-slice phases the aggregate transcript commit lives on the local work-branch worktree only until a downstream push carries it; on a full pod death before that push it is lost. The comment acknowledges this and scopes option (b) as belt-and-suspenders, so no change is required — flagging only so the narrow durability is understood.

These are all suggestions; none block merge. The core invariant is correct, the consumer route is real, and the tests lock the right behavior.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

This comment has been minimized.

james-in-a-box Bot pushed a commit that referenced this pull request Jun 25, 2026
Address two non-blocking review observations on PR #3248:

- The consensus-reset test now seeds a real PeerConsensusTracker (registered
  agents) so the restart handlers' clear()/remove_agent() paths actually run
  instead of degrading to a no-op when no tracker exists. Adds a remove_agent
  counterpart for the restart_agent reset.
- Add TestRestartPersistDiskShape pinning the restart persist's actual
  write_per_slice=False output: per-slice CONSENSUS files are skipped (#2755)
  and only the cross-cutting unattributed sibling is written.
@james-in-a-box

Copy link
Copy Markdown
Contributor Author

Review feedback addressed

Both reviews approved (contract-verification: approve; review: approve-with-suggestions). The latter raised three non-blocking observations; dispositions below. Pushed in commit b01a66c.

1. test_clearing_consensus_tracker_leaves_message_store_intact was near-vacuous — get_peer_consensus_tracker("issue-777") returned None, so the tracker.clear() body never ran. — fixed-in-PR (commit b01a66c). The test now seeds a real tracker via create_peer_consensus_tracker with registered agents (non-empty _producer_phases), asserts the tracker exists, then runs tracker.clear() and asserts the consensus state is actually gone while the Redis message store is intact. Added a sibling test_removing_agent_from_tracker_leaves_message_store_intact covering the restart_agent reset path (tracker.remove_agent(role)), which the original test didn't exercise at all.

2. No test pins the restart path's actual write_per_slice=False disk output — the existing TestInFlightBrcRecordSurvivesToDisk validates write_per_slice=True, not the artifact the restart persist writes. — fixed-in-PR (commit b01a66c). Added TestRestartPersistDiskShape, which calls _write_brc_history(write_per_slice=False) (the exact call _persist_phase_brc_history makes) and asserts: (a) the per-slice CONSENSUS files are not emitted (the #2755 add/add invariant), (b) the cross-cutting {id}-implement-unattributed.{md,json} sibling is written and contains only the unattributed traffic (no slice CONSENSUS records folded in), and (c) with only slice-attributed CONSENSUS and no cross-cutting traffic, nothing is written at all.

3. The persist commits but does not push within restart_phase — flagged for understanding; the comment already scopes option (b) as belt-and-suspenders. — disagree (no change requested). The reviewer explicitly wrote "the comment acknowledges this and scopes option (b) as belt-and-suspenders, so no change is required — flagging only so the narrow durability is understood." Survival of the in-flight record rests on option (a) (live Redis), which is load-bearing and tested; the local-only commit is intentional cold-start hardening and is already documented at the call site. No code change warranted.

All 13 tests in the two files pass locally; ruff check + ruff format --check clean.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

This comment has been minimized.

@james-in-a-box

This comment has been minimized.

@egg-reviewer egg-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review: slice-7 mid-phase BRC message-record persistence

Re-reviewed against my prior approve-with-suggestions. The delta since then is test-only (commit b01a66ca) — confirmed via gh pr diff, the only non-.egg-state files changed are orchestrator/routes/pipelines.py and the two test files, and the sole non-comment production line in pipelines.py remains the single best-effort _persist_phase_brc_history(pipeline, store, phase) call inside a try/except (pipelines.py:3669–3677) that I already vetted. No new production behavior.

No blocking issues. Both of my prior non-blocking observations are properly addressed; the third was correctly disagreed with.

Observation 1 — near-vacuous consensus-tracker test → fixed

TestConsensusResetPreservesMessageStore now seeds a real tracker via create_peer_consensus_tracker + register_agent and asserts _producer_phases is non-empty before acting (_make_real_tracker, test_restart_brc_record_survival.py:239-261). The clear() path is genuinely exercised — the test asserts not tracker._producer_phases after the clear (L280), so a no-op clear would now fail loudly rather than pass silently. The new sibling test_removing_agent_from_tracker_leaves_message_store_intact (L288) closes the restart_agent gap by exercising tracker.remove_agent("coder") with "coder" in/not in _producer_phases guards around it. Both then assert the Redis store is untouched. This is the real reset-vs-store isolation I asked for.

Observation 2 — no test pinned the restart path's actual write_per_slice=False shape → fixed

TestRestartPersistDiskShape (test_restart_phase_brc_history.py:468) calls the production _write_brc_history(..., write_per_slice=False) seam directly — the exact call _persist_phase_brc_history makes — and pins all three branches:

  • test_per_slice_consensus_files_are_not_written — asserts {id}-implement-{slice}.{md,json} are NOT emitted (the #2755 add/add invariant).
  • test_unattributed_sibling_is_written — asserts the {id}-implement-unattributed.{md,json} sibling IS written and contains only the cross-cutting OVERSEER_ALERT, with CONSENSUS_PROPOSE/CONSENSUS_NACK explicitly absent.
  • test_no_unattributed_sibling_when_only_slice_consensus — asserts nothing is written when only slice-attributed CONSENSUS records exist.

I traced these against the production _write_brc_history (pipelines.py:9375-9463): with write_per_slice=False, unattributed_other is written iff non-empty, the per-slice bucket loop is skipped via the early return, and the all-slice-CONSENSUS case leaves unattributed_other empty so nothing is written. The assertions match the production branches exactly.

Observation 3 — commits-but-no-push → disagreed, correctly

The author declined a change, quoting my own "no change required — flagging only so the narrow durability is understood." Survival rests on option (a) (live Redis, load-bearing and tested); the local-only commit is intentional cold-start hardening, documented at the call site. Agreed, no change warranted.

Test-quality check (no blocking anti-patterns)

  • Fixtures build real message_store.Message objects and drive the real _write_brc_history / real Flask restart routes against a real fakeredis-backed get_message_store() — no hand-built payloads bypassing the production helper, no self-seeding goldens (expected values are hand-authored).
  • TestRestartPhasePersistGuardIsNonFatal.test_persist_failure_is_nonfatal patches the real wired _persist_phase_brc_history to raise and asserts 200 + assert_called_once — exercises the actual guarded call site, not a vacuum.
  • New test names match their assertions (no name-vs-behavior contradictions).
  • The load-bearing AC tests (TestRestartAgentPreservesBrcRecord, TestRestartPhasePreservesLiveBrcRecord, test_restart_phase_does_not_clear_message_store) are intact and still drive the real routes.

Clean approve.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contract Re-Verification — PR #3248 (slice-7, mid-phase BRC message-record persistence)

Verdict: Approve (posted as a comment — self-authored PR).

Incremental re-review of the delta since my last verification at 21a3976a. The only PR-authored change since then is commit b01a66c ("Strengthen slice-7 restart tests per review feedback"). The diff is test-only — no production code changed:

orchestrator/tests/test_restart_brc_record_survival.py  | +85 -12
orchestrator/tests/test_restart_phase_brc_history.py     | +96

What changed

  1. TestConsensusResetPreservesMessageStore now seeds a real PeerConsensusTracker (via create_peer_consensus_tracker + register_agent, asserting _producer_phases is non-empty before the reset), so the reset path genuinely runs instead of degrading to a no-op when no tracker exists. It exercises both reset shapes against the live store: tracker.clear() (the restart_phase path) and the new test_removing_agent_from_tracker_leaves_message_store_intact covering tracker.remove_agent(role) (the restart_agent path). Both assert the Redis message record (count + message types) is intact afterward.
  2. New TestRestartPersistDiskShape pins the actual _write_brc_history(write_per_slice=False) output that the restart persist makes: per-slice CONSENSUS files are skipped (#2755 add/add) and only the cross-cutting {id}-implement-unattributed.{md,json} sibling is written; with only slice-attributed CONSENSUS traffic and nothing cross-cutting, no files are written.

Verification

  • All referenced seams exist in production and the tests mirror the real wiring: restart_phase → _persist_phase_brc_history (before teardown) + tracker.clear() (routes/pipelines.py:3670,3799); restart_agent → tracker.remove_agent (:3301); _write_brc_history(write_per_slice=False) skips per-slice writes (:9450-9458, called at :9536). The new tests are non-vacuous.
  • The disk-shape tests correctly encode the honest scoping from d681326: option (b) durable persist uses write_per_slice=False and is not the slice record's survival path — option (a) live-Redis survival is. The tests assert exactly that (CONSENSUS_PROPOSE/CONSENSUS_NACK absent from the unattributed sibling).
  • Ran the two affected files directly: 13 passed (tests/test_restart_brc_record_survival.py, tests/test_restart_phase_brc_history.py). Did not run the full suite (per review conventions; CI gates HEAD).

Contract impact

  • task-7-1 AC ("after a simulated mid-phase restart the BRC message record is retrievable; no message loss across the restart boundary") — reinforced, no regression. The strengthened real-tracker tests prove the reset evicts ephemeral consensus state while the message store survives.
  • task-7-2 AC ("test simulates mid-phase restart and asserts the message record is intact afterwards; tests pass") — reinforced; tests pass.

No previously-verified criterion is broken. The delta strictly hardens the existing test guards (a real tracker instead of a possible no-op, plus a disk-shape regression guard). No contract violations found.

Note: the orchestrator is currently unreachable, so egg-contract verify-criterion could not be run during this re-review to (re)mark the criteria. The verification above stands on the delta inspection and the local targeted test run; the criterion flags should be (re)confirmed once the orchestrator is reachable.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

This comment has been minimized.

@james-in-a-box

Copy link
Copy Markdown
Contributor Author

Review feedback addressed

The two most recent reviews — both against the current HEAD b01a66c — are clean approvals with no actionable items:

  • egg-reviewer[bot] re-review (b01a66c): APPROVED — "Clean approve." Explicitly confirms all three of its prior non-blocking observations are resolved.
  • james-in-a-box[bot] contract re-verification (b01a66c): Approve. No contract violations; both slice-7 ACs reinforced, 13 targeted tests pass.

The only substantive feedback in this PR was the three non-blocking observations egg-reviewer[bot] raised against the earlier commit 21a3976. Those were already addressed in b01a66c (which is what prompted both re-reviews to approve). Restating dispositions for the record so nothing disappears:

  1. test_clearing_consensus_tracker_leaves_message_store_intact was near-vacuous (tracker was None, so clear() never ran). — fixed-in-PR (commit b01a66c). Now seeds a real PeerConsensusTracker (non-empty _producer_phases), asserts the tracker exists, runs clear(), asserts consensus state is gone while the Redis store is intact; added sibling test_removing_agent_from_tracker_leaves_message_store_intact for the restart_agent reset path. Reviewer confirmed: "This is the real reset-vs-store isolation I asked for."

  2. No test pinned the restart path's actual write_per_slice=False disk output. — fixed-in-PR (commit b01a66c). Added TestRestartPersistDiskShape calling the production _write_brc_history(write_per_slice=False) seam and pinning all three branches (per-slice CONSENSUS files not emitted; unattributed sibling written with only cross-cutting traffic; nothing written when only slice CONSENSUS exists). Reviewer confirmed the assertions match the production branches exactly.

  3. Persist commits but does not push within restart_phase. — disagree (no change requested). The reviewer explicitly wrote "no change is required — flagging only so the narrow durability is understood." Survival rests on option (a) (live Redis, load-bearing and tested); the local-only commit is intentional cold-start hardening, documented at the call site. Reviewer agreed: "disagreed, correctly."

No new code changes in this round — there is no unaddressed actionable feedback. ruff check + ruff format --check clean on all touched files.

— Authored by egg

@james-in-a-box

This comment has been minimized.

egg and others added 4 commits June 25, 2026 15:03
… (slice-7, task-7-2)

Pins task-7-2: the in-flight BRC consensus record (proposals, verdicts,
open NACKs) must survive a mid-phase restart so a reseeded session can
re-pull the queryable environment and re-derive the #3189 phase-3 anchors.

Data-integrity tests (pass today) lock down that the persisted
.egg-state/brc-history/ per-slice artifact round-trips the full record
and that an empty store writes no corrupt stub. Restart-wiring tests pin
restart_phase to persist the in-flight phase's record before the
destructive worktree/container teardown (the #1827 persist-before-clear
invariant, extended to restart) — these fail until task-7-1 lands the
persist step; the assumed _persist_phase_brc_history seam is handed off
to coder for in-cycle convergence.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… (slice-7, task-7-2)

Pins task-7-2: the in-flight BRC consensus record (proposals, verdicts,
open NACKs) must survive a mid-phase restart so a reseeded session can
re-pull the queryable environment and re-derive the #3189 phase-3 anchors.

TestInFlightBrcRecordSurvivesToDisk (PASS): the persisted per-slice
.egg-state/brc-history/ artifact round-trips the full record (PROPOSE +
ACK + open NACK) intact and re-readable; the open-NACK body is preserved;
an empty store writes no corrupt stub (never a wrong resume).

TestRestartPhasePersistsInFlightBrcHistory: restart_phase must persist
the in-flight phase's record before the destructive worktree/container
teardown (the #1827 persist-before-clear invariant, extended to restart).
The two wiring assertions are xfail pending task-7-1 (coder) — assumed
seam _persist_phase_brc_history; the option (a) Redis-survival vs (b)
durable-persist mechanism is handed off to coder/architect, and the xfail
is removed on convergence. The nonfatal-restart assertion stays green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…k-7-1)

Converges with the tester's task-7-2 contract pin on Option (b), kept belt-and-suspenders with Option (a). A mid-phase restart must leave the in-flight BRC consensus record (proposals, verdicts, open NACKs) reconstructable so a reseeded/resumed session can re-pull the queryable environment and re-derive the #3189 anchors.

Option (a) (live Redis survival): the Redis message store (pipeline:{id}:messages) is cleared only at phase transitions (_clear_concurrent_state) and pipeline create/delete (_clear_pipeline_runtime_state), never on restart. restart_agent/restart_phase reset only the ephemeral peer consensus tracker. The reseed JIT re-pull (/brc-transcript + read_peer_artifact) reads this live store, so the record survives a bare restart. Documented this invariant at both restart consensus-reset sites (do NOT add get_message_store().clear() to the restart path).

Option (b) (durable on-disk persist): restart_phase now calls _persist_phase_brc_history(pipeline, store, phase) BEFORE the destructive container/worktree teardown, extending the #1827 persist-before-clear invariant to the restart path. This captures the in-flight transcript to .egg-state/brc-history/ so the record survives even a full Redis loss (orchestrator pod death, the cold-start case task-6-1 covers). Best-effort: a persist failure is logged and never blocks recovery of a wedged phase.

Tests: orchestrator/tests/test_restart_brc_record_survival.py drives the real restart_agent route asserting the Redis record (proposal/ACK/open-NACK + proposal_commit_sha) survives, plus a tracker-clear-vs-store-intact unit test. The tester's test_restart_phase_brc_history.py wiring tests (persist fires, runs before teardown, non-fatal on failure) now pass. All 179 restart/brc-history tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…task-7-1)

Address reviewer_contract NACK on task-7-1: the restart_phase 3b comment
overstated option (b)'s durability. _persist_phase_brc_history calls
_write_brc_history(write_per_slice=False), which for a slice-aware
implement phase writes only the {id}-implement-unattributed sibling and
SKIPS the per-slice CONSENSUS bucket loop. So across a full Redis loss the
in-flight slice's proposals/verdicts/open-NACKs do NOT survive on disk —
only the live Redis stream (a) preserves them.

Rewrite the comment to state (a) as the primary mechanism and the sole
guarantor of slice-scoped record survival, and (b) as a belt-and-suspenders
add-on with a narrow scope (non-slice aggregate transcripts + the
unattributed audit sibling). Documentation-only; no behavior change.
Contract task-7-1 notes reconciled separately to match the delivered (a)+(b).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
egg and others added 6 commits June 25, 2026 15:03
…ards (slice-7, task-7-2)

The coder (task-7-1, commit 6360107) converged on Option (b) durable
persist, belt-and-suspenders with Option (a) live-Redis survival:
restart_phase now calls _persist_phase_brc_history before the destructive
container/worktree teardown. The two wiring tests
(test_restart_persists_in_flight_phase_brc_history,
test_persist_runs_before_worktree_teardown) therefore XPASS, so their
@pytest.mark.xfail(strict=False) markers are removed — they now assert as
real, hard regression guards (a future drop of the persist call from the
restart path fails CI instead of being swallowed as an expected failure).

Resolves reviewer_code_holistic (remove stale xfail markers) and
reviewer_contract (the option-(b) wiring is now the converged mechanism,
not a contradicted/unreachable pin; test_persist_failure_is_nonfatal
exercises the real best-effort guard now that restart_phase invokes the
persist seam). AC for task-7-2 met: the suite drives the real
POST /restart route and asserts the in-flight phase record is persisted.

All 7 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…k-7-2)

Address reviewer_contract NACK v1. The converged task-7-1 mechanism
(commit 6360107, contract-complete) is option (a): restart_phase leaves
the live Redis message store intact (clears only the peer consensus
tracker); the store is the load-bearing BRC record a reseed re-pulls. Its
best-effort _persist_phase_brc_history call uses write_per_slice=False, so
it does NOT capture in-flight per-slice records (#2755) — non-load-bearing
cold-start hardening, not the slice record's survival path.

- Replace the mock-persist-call (option b) tests with a real restart_phase
  live-store survival test asserting proposal+ACK+open-NACK+proposal_commit_sha
  remain retrievable from get_message_store() afterwards, plus a guard that
  restart_phase never calls store.clear() (blockers 1 & 3, the AC).
- Keep TestInFlightBrcRecordSurvivesToDisk as the _write_brc_history seam
  regression guard (reviewer-endorsed).
- Reframe the non-fatal test against the actual wired restart path: persist
  IS invoked under try/except, so mocking it to raise and asserting 200 +
  assert_called_once exercises a real guard, not a vacuum (blocker 2).
- Drop dead _make_agent_worktree helper / AgentWorktree import.

Complements coder's test_restart_brc_record_survival.py (restart_agent);
this covers the restart_phase path. 7 passed, ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address two non-blocking review observations on PR #3248:

- The consensus-reset test now seeds a real PeerConsensusTracker (registered
  agents) so the restart handlers' clear()/remove_agent() paths actually run
  instead of degrading to a no-op when no tracker exists. Adds a remove_agent
  counterpart for the restart_agent reset.
- Add TestRestartPersistDiskShape pinning the restart persist's actual
  write_per_slice=False output: per-slice CONSENSUS files are skipped (#2755)
  and only the cross-cutting unattributed sibling is written.
main's restart_agent reads the count via check_and_increment_restart_count
(#3244), not the retired get_restart_count. Mock it as an int so the
restart_count telemetry stays JSON-serializable.
@jwbron
jwbron force-pushed the egg/issue-3200/slice-7 branch from b01a66c to 1a1195d Compare June 25, 2026 22:04
@jwbron
jwbron merged commit 193c319 into main Jun 25, 2026
11 checks passed

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contract Re-Verification — PR #3248 (slice-7, mid-phase BRC message-record persistence)

Incremental re-review against my prior verification at b01a66ca. That commit was rebased away (the branch was re-based onto a newer main before merge), so I reconstructed the delta from the slice-7 commit set and verified the final merged state of the functional code and tests.

Delta since last review

The post-review changes were test-only and a rebase fixup — no functional regression:

  • f680b43 — strengthened the consensus-reset tests to seed a real PeerConsensusTracker (registered agents) so the clear() / remove_agent() paths actually execute instead of degrading to a no-op; added TestRestartPersistDiskShape.
  • f99e738 — automated formatting only.
  • 1a1195d — mock check_and_increment_restart_count in the survival test after #3244 landed on main (keeps restart_count telemetry JSON-serializable). +4 lines, test-only.

task-7-1 — mid-phase BRC record survival ✅

orchestrator/routes/pipelines.py:

  • Option (a) — both restart_agent and restart_phase reset only the ephemeral peer-consensus tracker and document the load-bearing invariant: do NOT clear the Redis message store (pipeline:{id}:messages); it is cleared only at phase transitions / pipeline create+delete. The live store carries the in-flight slice CONSENSUS record across a bare restart.
  • Option (b) — restart_phase now calls _persist_phase_brc_history(pipeline, store, phase) before the destructive teardown, wrapped best-effort so a persist failure never blocks recovery of a wedged phase. store/pipeline are in scope (loaded at the top of restart_phase); the helper exists at pipelines.py:9495.
  • The f5dcb23 comment correction is accurate and important: _persist_phase_brc_history calls _write_brc_history(write_per_slice=False), which for a slice-aware implement phase writes only the {id}-implement-unattributed sibling and skips the per-slice CONSENSUS bucket (#2755). The comment correctly scopes (b) as a narrow belt-and-suspenders add-on and names (a) as the sole guarantor of slice-scoped record survival — no overstatement.

AC ("after a simulated mid-phase restart, the BRC message record is retrievable; no message loss across the restart boundary") — met.

task-7-2 — tests ✅

Coverage is layered and the test comments are scrupulously honest about what each test does and does not prove:

  • test_restart_agent_preserves_brc_message_record / test_restart_phase_preserves_live_brc_record — drive the real restart routes and assert the live record (proposal + ACK + open-NACK + proposal_commit_sha) survives unchanged.
  • test_restart_phase_does_not_clear_message_store — patches clear and asserts the route never calls it (regression guard).
  • TestConsensusResetPreservesMessageStore — seeds a real tracker so clear() / remove_agent() genuinely run, then asserts the store is untouched.
  • TestRestartPersistDiskShape — pins the write_per_slice=False shape: per-slice CONSENSUS files skipped, only the unattributed sibling written.
  • TestRestartPhasePersistGuardIsNonFatal — mocks the persist to raise on the wired path and asserts the route still returns 200.

AC ("test simulates mid-phase restart and asserts the message record is intact afterwards; tests pass") — met. Unit Tests and Integration Tests are green on the HEAD commit.

Verdict

No contract violations. Both slice-7 tasks are fully implemented and tested; the post-review delta only strengthens tests and fixes a post-rebase mock. No previously-verified behavior is regressed.

Note: the contract's top-level acceptance_criteria list is empty (the ACs are embedded in the slice-7 tasks), so there are no ac-N criteria to mark, and the orchestrator was unreachable from this worktree. This PR is already MERGED; this comment is a retrospective verification record.

— Authored by egg

@egg-reviewer egg-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review: slice-7 mid-phase BRC message-record persistence

Note: this PR is already MERGED (merge commit 193c3193, 2026-06-25 22:05 UTC), so this is a post-merge re-review. My prior review commit b01a66ca was rebased away; I reconstructed the delta from the PR commit list and the canonical gh pr diff.

Delta since my prior approve: three commits — an automated formatting fix, test-strengthening (which both reviewers already adjudicated as resolving the earlier non-blocking observations), and a rebase-fix for the #3244 restart-count seam. No new production behavior beyond the change I already approved.

Production change (orchestrator/routes/pipelines.py) — unchanged, still correct

The only production lines remain the comment-only invariant docs in restart_agent / restart_phase plus the single best-effort, try/except-guarded call:

_persist_phase_brc_history(pipeline, store, phase)

Verified store, pipeline, phase are all in scope at the call site (store, pipeline = _resolve_pipeline(...)), and the arg order matches the helper signature _persist_phase_brc_history(pipeline, store: StateStore, phase) (pipelines.py:9495). The persist front-runs teardown and is swallowed on failure, so a transcript-write hiccup can never block recovery of a wedged phase. Good.

Rebase-fix (1a1195d) — correctly targeted

Post-#3244, production reads the just-incremented count via spawner.check_and_increment_restart_count(...) (pipelines.py:3043, inside restart_agent), while restart_phase uses reset_restart_counts (return value unused). So only the restart_agent-exercising test needed the int mock:

  • test_restart_brc_record_survival.py:198 now sets mock_spawner.check_and_increment_restart_count.return_value = 1, keeping the restart_count telemetry JSON-serializable through the real route. Exactly the right place.
  • test_restart_phase_brc_history.py hits the restart_phase route with a bare MagicMock() spawner — fine, since that route never reads the count. No missing mock there.

Test quality — clean, non-vacuous

  • _seed_brc_record builds real message_store.Message objects and seeds them via the production store.add_message(); assertions read back through store.get_messages(). No hand-built payload bypassing the production helper, no self-seeding golden.
  • get_message_store is deliberately left unmocked (only _resolve_pipeline / spawner / lock are patched), so the route runs against the real fakeredis-backed store — a stray get_message_store().clear() on the restart path would fail these tests loudly. Genuine invariant guard.
  • TestConsensusResetPreservesMessageStore seeds a real PeerConsensusTracker (non-empty _producer_phases asserted before acting) and exercises both clear() (restart_phase) and remove_agent() (restart_agent) reset shapes — the reset-vs-store isolation is really run, not a no-op.
  • Test names match their assertions; no name-vs-behaviour contradictions.

Verification

Ran the two affected files directly: 13 passed (tests/test_restart_brc_record_survival.py, tests/test_restart_phase_brc_history.py). Did not run the full suite (per review conventions; CI gates HEAD).

No blocking issues in the delta. The production behavior is exactly what I previously approved; the rebase-fix is correct and the strengthened tests exercise the real production path. Clean.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

13 previous review(s) hidden.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant