Skip to content

Harden consensus-stall recovery against slice and phase blindness - #3554

Merged
jwbron merged 4 commits into
mainfrom
egg/consensus-stall-slice-phase-hardening-3542
Jul 8, 2026
Merged

jwbron merged 4 commits into
mainfrom
egg/consensus-stall-slice-phase-hardening-3542

Conversation

@jwbron

@jwbron jwbron commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Follow-ups to #3544 for #3542. Two remaining ways the consensus-stall watchdog could still kill a live phase:

1. Phase-scope the message fallback (both tier-1 checks)

Refine, plan, and implement share the default review graph, so an earlier phase's untagged CONSENSUS_CONFIRMED messages satisfy the current phase's expected role set verbatim. #3544 scoped the fallback by slice tag only, so a legitimately completed refine/plan round on the bus could still make the fallback report "consensus complete" for the whole implement phase, and aggressive recovery would kill it (the same failure mode as issue-3523, different message source).

Every confirm emitter sets Message.phase (routes/signals), so pipeline_level_confirmed_roles now takes a phase argument and both ConsensusStallCheck and IncompleteConsensusStallCheck pass the current phase. A confirmation with a null phase conservatively matches, mirroring the convention in reconstruct_tracker_from_messages.

2. Slice-aware Track 1 in the monitor

KubernetesMonitor._attempt_tracker_reconstruction looked up only the bare-pipeline-id tracker, which cannot see slice trackers registered under {pipeline_id}/{slice_id}. During a slice-DAG implement phase that lookup returns None, and Track 1 either reconstructs a pipeline-level cross-slice tracker nothing consumes or falls through to Track 2 aggressive recovery, which marks the phase COMPLETE over a live slice round (the issue-3523 14-hour stall; under the event-loop model phase_exec.agents is empty, so the #2441 sibling-slice guard cannot hold the phase open).

Track 1 now consults get_slice_trackers(): any live slice tracker means a slice round is in flight and the slice executor is driving it, so recovery reports "handled" and Track 2 never fires. Reconstruction also passes phase= (the parameter added for exactly this in reconstruct_tracker_from_messages) so restart-time replay cannot fold an earlier phase's round into the current phase's tracker.

Not addressed here (still tracked in #3542)

Bridging agent-registered contract questions (cq-N) into the decision queue mid-phase. #3374 already surfaces them in get_status as pending_contract_decisions and they are directly resolvable via provide_input; moving them into the queue proper changes the documented post-gate two-wave resolve flow, so it needs a design decision.

Testing

  • New regression tests: prior-phase confirms are ignored by both checks, null-phase confirms conservatively count, live slice trackers block aggressive recovery, reconstruction is phase-scoped.
  • Existing recovery/fallback tests updated for the new seams (get_slice_trackers on the mock registry, phase on mock messages).
  • make lint clean (includes a drive-by import-sort fix in test_cli.py that was failing on main); make test green (152 tests across the touched files).

Refs #3542

jwbron added 2 commits July 7, 2026 15:54
test_overseer_max_turns.py, test_overseer_spawn.py, and
test_phase_scoped_overseer.py import
routes.pipelines._check_and_respawn_overseer and exercise
ContainerSpawner.spawn_overseer_container, both deliberately deleted
by the #2270 slice-5 overseer-lifecycle overhaul (task-5-1), which
folded the bespoke overseer respawn loop into the general
agent-restart machinery. The sentinel contract tests
(test_overseer_lifecycle.py, test_overseer_repo_resolution.py) pin
that deletion as the shipped design.

Since the fold landed, all three files skip unconditionally at module
level via their ImportError guards, so they contribute zero coverage
while masking real import regressions behind a generic "modules not
available" skip. The files' own skip-guard comments already declared
this outcome: once the machinery is folded, "these respawn-specific
tests no longer apply (the path is exercised via the normal
agent-spawn tests)."

Also refresh the two prose references to the deleted modules in
test_overseer_repo_resolution.py and test_overseer_model.py.

The surviving overseer surface keeps its coverage in
test_overseer_lifecycle.py, test_overseer_repo_resolution.py,
test_corrective_executor.py, test_overseer_model.py, and
test_restart_overseer.py (114 tests, all passing).
)

Follow-ups to the merged message-fallback slice scoping (#3544):

- Phase-scope the message fallback in ConsensusStallCheck and
  IncompleteConsensusStallCheck. Refine, plan, and implement share the
  default review graph, so an earlier phase's untagged
  CONSENSUS_CONFIRMED messages satisfy the current phase's role set
  verbatim; the same consensus-complete false positive that killed
  issue-3523, just sourced from a legitimately completed phase. Every
  confirm emitter sets Message.phase, so the fallback now filters on
  it (null phase conservatively matches, mirroring
  reconstruct_tracker_from_messages).

- Make the monitor's Track 1 slice-aware. The bare-id
  get_peer_consensus_tracker lookup cannot see slice trackers
  registered under {pipeline_id}/{slice_id}; a live slice tracker
  means a slice round is in flight and the slice executor is driving
  it, so pipeline-level reconstruction (a cross-slice soup nothing
  consumes) and Track 2 aggressive recovery must not run. Also pass
  phase= to reconstruct_tracker_from_messages so restart-time
  reconstruction does not replay an earlier phase's round.

Also fixes a pre-existing import-sort lint error in test_cli.py.
@james-in-a-box

This comment has been minimized.

@james-in-a-box

james-in-a-box Bot commented Jul 7, 2026

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

@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: Harden consensus-stall recovery against slice and phase blindness

Verdict: Approve. No blocking issues. The two hardening changes are correct, well-scoped, and cover both remaining false-positive paths that the aggressive stall watchdog could use to kill a live phase. I traced the data flow across the changeset and ran the two modified test files (57 tests pass).

What I verified

1. Phase-scoped message fallback (_consensus_messages.py, consensus_stall.py, incomplete_consensus_stall.py)

  • pipeline_level_confirmed_roles(messages, phase=None) is backward-compatible — the new kwarg defaults to None and the only two callers are the two updated checks. Unscoped behavior is preserved when phase is omitted.
  • The filter phase is None or message_phase(m) in (None, phase) is right: a None-phase message conservatively counts (matches the reconstruct_tracker_from_messages and routes/signals idempotency-probe convention), an off-phase message is dropped.
  • message_phase() handles both the str case (production: Message.phase: str | None) and a stray enum via getattr(phase, "value", phase).
  • Consistency check that matters: the confirm emitters set Message.phase through _resolve_pipeline_phase() which returns pipeline.current_phase.value, and both checks filter on pipeline.current_phase.value. Same string on both sides, so phase-scoping never spuriously suppresses a legitimate current-phase confirmation.

2. Slice-aware Track 1 (kubernetes_monitor.py)

  • get_slice_trackers() and the phase= param on reconstruct_tracker_from_messages() both exist with the assumed signatures.
  • Ordering is correct: the bare-id get_peer_consensus_tracker() lookup returns None during a slice-DAG implement phase (trackers live under {pid}/{slice_id}), so control reaches the new get_slice_trackers() guard, which reports "handled" and prevents Track 2 from flipping the phase COMPLETE over a live slice round. sorted(slice_trackers) correctly logs the slice-id keys.

3. Deleted overseer tests (#3513, bundled)

  • spawn_overseer_container / spawn_overseer_job / _check_and_respawn_overseer no longer exist anywhere outside tests, so all three deleted files were skipping unconditionally at module import — zero coverage, only masking real import regressions. Deletion is a net improvement. The surviving overseer surface keeps coverage in the files the commit lists. Prose-only edits to test_overseer_model.py / test_overseer_repo_resolution.py are harmless.

Tests exercise the real production path (ConsensusStallCheck(...).run(ctx), IncompleteConsensusStallCheck, monitor._handle_consensus_stall_recovery(...)), not hand-built fixtures. Name-vs-behavior is consistent (test_null_phase_confirmations_still_count → counts → consensus complete → DEGRADED; test_prior_phase_confirmations_do_not_trigger_stall → plan confirms dropped → HEALTHY).

Non-blocking

  1. Mixed concerns. This PR bundles the #3513 dead-test deletion (~3,100 deletions) with the #3542 hardening. CLAUDE.md prefers separate concerns in separate PRs. The commit history separates them cleanly and the deletion is well-justified, so this is a process nit, not a correctness issue — flagging only because the large deletion count could distract a merger from the substantive change.

  2. Belt-and-suspenders vs. the real trigger. _clear_concurrent_state() already clears the message bus and the bare tracker on every phase transition, so the "earlier-phase confirmations linger on the bus" scenario should be rare in the normal path. The phase-scoping is still correct and worth having (it survives cases where the transition-time clear is skipped or a best-effort Redis clear fails), but it may be worth a one-line comment noting the primary defense is the transition-time clear, so a future reader doesn't assume this filter is load-bearing on the happy path.

  3. Stale-slice-tracker edge (advisory, not confirmed). The get_slice_trackers() guard treats any live in-memory slice tracker as "the slice executor is driving it." If a slice executor died leaving a stale tracker in the registry, pipeline-level recovery would be suppressed. I checked this is mitigated by the per-slice consensus timeout / handle_timeout path (slice-level recovery is the correct layer, and post-restart the in-memory registry is empty until reconstructed), so it's low-risk — but it does rest on the slice-level timeout actually firing. No change requested.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

This comment has been minimized.

Address review feedback: add a comment noting that the transition-time
_clear_concurrent_state() is the load-bearing defense against
earlier-phase confirmations lingering on the bus, and the phase filter
is a belt-and-suspenders backstop for when that clear is skipped or a
best-effort Redis clear fails.
@james-in-a-box

james-in-a-box Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the thorough review and the approval. Dispositions for the three non-blocking items:

1. Mixed concerns (bundling #3513 dead-test deletion with #3542 hardening) — disagree (valid observation, no change warranted). As you noted, the commit history separates the two concerns cleanly and the deletion is well-justified. Splitting an already-approved PR into two at this stage would add churn and a second review cycle for no correctness gain; the large deletion count is dead-test removal that a merger can verify from the commit boundary. Flagging this back rather than deferring, since there's no code change to make.

2. Belt-and-suspenders vs. the real trigger (one-line comment) — fixed-in-PR (commit 43f11bf). Added a comment at both phase-scoping filter sites (consensus_stall.py, incomplete_consensus_stall.py) noting that the transition-time _clear_concurrent_state() is the load-bearing defense against earlier-phase confirmations lingering, and this phase filter is the backstop for when that clear is skipped or a best-effort Redis clear fails — so a future reader doesn't assume the filter is load-bearing on the happy path.

3. Stale-slice-tracker edge (advisory) — disagree (no change requested; risk already mitigated). You explicitly marked this "No change requested" and confirmed it's mitigated by the per-slice consensus timeout / handle_timeout path (slice-level recovery is the correct layer, and the in-memory registry is empty post-restart until reconstructed). No code change here.

make lint passes (ruff clean); the 3 mypy errors reported locally are pre-existing in shared/egg_agent/client.py, which this PR does not touch (confirmed by stashing my changes — they reproduce identically).

— 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.

Re-review: Harden consensus-stall recovery against slice and phase blindness

Verdict: Approve. The only change since my prior review (985f92d) is commit 43f11bf, which adds the explanatory comment I requested in non-blocking suggestion #2. No behavior changed. I re-verified the delta and the disposition of all three prior items.

Delta reviewed

43f11bf adds a comment at both phase-scoping filter sites — consensus_stall.py:170-176 and incomplete_consensus_stall.py:262-266 — noting that the transition-time _clear_concurrent_state() is the load-bearing defense against earlier-phase confirmations lingering, and the phase filter is a belt-and-suspenders backstop for when that clear is skipped or a best-effort Redis clear fails.

I verified the comment's factual claim rather than taking it at face value: _clear_concurrent_state() (routes/phases/_transitions.py:56-73) does clear the message store (get_message_store().clear(pipeline_id)) and remove the bare peer-consensus tracker (remove_peer_consensus_tracker(pipeline_id)) on every phase transition. So the comment correctly describes the primary-defense/backstop relationship — a future reader will not mistake the filter for the happy-path guard. The wording is consistent across both sites.

Prior feedback dispositions confirmed

  1. Mixed concerns (#3513 bundled with #3542) — author disagreed; no change. Acceptable: it was a flagged process nit, not a correctness issue, and the commit boundary keeps the dead-test deletion auditable.
  2. Belt-and-suspenders comment — fixed in 43f11bf. Verified correct and accurate (above).
  3. Stale-slice-tracker edge — I marked this advisory / no-change-requested originally; correctly left as-is.

The substantive hardening (phase-scoped message fallback + slice-aware Track 1) was already verified in my prior review and is unchanged in this delta. Comment-only change, no new code paths, nothing to re-test.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

egg review completed. View run logs

5 previous review(s) hidden.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant