Repository navigation
health_monitor: anchor never-heartbeated roles at Job start (#3605) - #3612
Conversation
`check_heartbeats` synthesizes a snapshot entry for every active-Job role that has never emitted a heartbeat (#3064 slice-5), so a silent mid-event pod still trips the timeout. It anchored those roles at `0.0`, so `now - 0.0` reported a Unix epoch timestamp as the stall duration. The repro on `issue-3596-v2` logged, on every poll: Heartbeat alert deferred by alive-signal gate ... agent_id=task_planner elapsed_seconds=1784944189 reason="peer heartbeat 4s ago" `restart_agent` calls `reset_agent`, which correctly drops the role's health state; the role stayed in the active-Job set, so it fell into the never-seen branch and picked up the epoch anchor. The alive-signal gate then deferred the resulting alert on a peer's heartbeat, so a role that had no pod and no Job produced no alert at all. Two changes, matching the issue's suggested fix: 1. Anchor correctness. `_job_active_since` records when each role's Job was first observed active; `set_active_roles` anchors newly-active roles and drops anchors for roles that leave the set, and `reset_agent` drops the restarted role's anchor so the next poll re-anchors it at the restart. Elapsed is now measured from the Job, not from the epoch. This mirrors the `.get(p, now)` idiom `check_brc_progress` already uses. Never-seen roles have no `AgentState` to carry `heartbeat_escalated`, so `_never_seen_escalated` gives them the same once-only escalation semantics; without it the now-truthful alert would re-fire every tick. 2. Impossible elapsed is a bug signal. No anchor predates monitor construction, so `elapsed > monitor_age` is by definition corrupt. `_sanitize_elapsed` logs it at ERROR, exempts the alert from the alive-signal gates (a monitor bookkeeping bug must not be deferred on a peer's liveness), and clamps the reported value to the monitor's age so magnitude-keyed consumers cannot be tripped by it. Notably `_run_concurrent` demotes a dual-role agent from BRC at `elapsed_seconds >= 300`, which 1.7e9 triggers instantly. Out of scope: the dependency-blind gate still defers a *sane* alert about a dead role on a live peer's heartbeat. That is #3595 root cause 2 / #3596 slice 3; this change makes the number honest and makes corrupt anchors unsuppressable. Tests: 10 cases covering Job-start anchoring, restart re-anchoring, anchor handover on first signal, escalation dedup, and gate bypass + clamping for both the heartbeat and progress tripwires.
There was a problem hiding this comment.
Review: health_monitor anchor integrity (#3605)
I traced the full data flow across both changed files and the cross-module consumers. This is a well-reasoned, correctly-scoped fix. No blocking issues. Approving with a few non-blocking notes.
What I verified (correctness)
-
The load-bearing invariant holds.
_sanitize_elapsedrests on "every anchor the monitor reads is written after_created_at." I checked every write to the anchor fields —_last_heartbeat/AgentState.last_heartbeat/last_progress(__init__defaults viafield(default_factory=time.time),_get_or_create_agentL553–555,_on_progressL611–618, L763–764) and_job_active_since(onlyset_active_roles+ the defensivesetdefaultincheck_heartbeats). All post-date construction. Since_created_atis a real epoch timestamp, a0.0anchor yieldselapsed ≈ 1.7e9 ≫ monitor_ageand is correctly flagged, while a legitimate never-seen role (anchored ≥_created_at) always satisfieselapsed ≤ monitor_ageand is never falsely flagged. The invariant is airtight per monitor instance, and re-init_health_monitorbuilds a fresh instance with empty dicts, so it holds across pipeline restarts too. -
The clamp is genuinely necessary. Confirmed
routes/pipelines/_run_concurrent.py:619–631readshb_action["elapsed_seconds"]and demotes a dual-role agent's reviewer edges at>= 300. An unclamped1.7e9would demote instantly on the first poll — the clamp tomonitor_ageprevents that. Good catch wiring this through both tripwires. -
The never-seen dedup fixes a real pre-existing spam bug. Before this PR,
snapshot.append((role, 0.0, False))hard-codedalready_escalated=Falseand there was noAgentStateto setheartbeat_escalated, so an ungated never-seen role would re-escalate on every poll tick._never_seen_escalatedcloses that, and it's correctly cleared on all three exit paths (set_active_rolesrole-leaves,reset_agent,_get_or_create_agentfirst-signal).test_never_heartbeated_alert_is_not_repeatedcovers it. -
The restart re-anchor race is covered.
reset_agentdrops_job_active_since[role]but intentionally leaves the role in_active_jobs; ifcheck_heartbeatsruns before the nextset_active_roles, the defensivesetdefault(role, now)(L840) re-anchors at the current poll (~restart time) rather than resurrecting a stale clock. Correct and deliberate. -
check_brc_progresscorrectly left unsanitized — it already anchors via the_fully_acked_first_seen.get(p, now)first-seen idiom, so it has no epoch-0 exposure. The PR's claim of mirroring that idiom is accurate. -
Backward-compatible outputs. The new
anchor_corruptkey and thereasonsuffix don't break any consumer —_run_concurrentandcheck_tripwiresonly read specific keys. -
Young-monitor edge is safe. When
monitor_age < threshold, a corrupt anchor clamps below threshold and is suppressed — correct, since the role can't have legitimately stalled longer than the monitor has existed.
Tests
The 10 new cases exercise the real production path (check_heartbeats / check_progress / set_active_roles / reset_agent); the corruption is injected by setting _job_active_since[...] = 0.0 / last_progress = 0.0 (reproducing the pre-fix state), not by hand-building the alert dict — so they genuinely test _sanitize_elapsed. No self-seeding goldens, no name-vs-behaviour contradictions. Restart, drop-on-leave, handover, dedup, gate-bypass, clamp, and the no-false-positive case are all covered.
Non-blocking suggestions
-
check_progress's corrupt-anchor branch is effectively unreachable in production.AgentState.last_progressis only ever set tonow(never epoch-0), sotest_corrupt_progress_anchor_bypasses_gatecorrupts state that can't occur on the progress path naturally. The defensive symmetry is fine to keep, but a one-line note that the progress-side guard is purely defensive (the real trigger is heartbeat-only) would save a future reader the same trace I just did. -
Wall-clock (
time.time) sensitivity of_created_at. A backward NTP/suspend step could drivemonitor_agetoward0.0, making_sanitize_elapsedflag-and-clamp everything for the skew window (forward jumps are safe —elapsed ≤ monitor_ageis preserved since both move together). This is pre-existing module-wide behaviour (everynow - last_*here usestime.time()), not introduced by this PR, so it's not in scope — flagging only so it's on record if the module ever moves to a monotonic clock. -
Minor:
_ELAPSED_SANITY_SLACK_SECONDSonly ever absorbs float/clock jitter for the never-seen path (that path'selapsed ≤ monitor_ageby construction). The comment already says this; no change needed.
— Authored by egg
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…anchor Addresses review notes on #3612: - Record that check_progress's corrupt-anchor branch is defensive symmetry: AgentState.last_progress is only ever assigned `now`, so the real #3605 trigger is heartbeat-side only. Noted in _sanitize_elapsed's docstring, at the check_progress call site, and in test_corrupt_progress_anchor_bypasses_gate so the injected corruption is not mistaken for a reachable production state. - Record the wall-clock sensitivity of _created_at: a backward clock step shrinks monitor_age and would make _sanitize_elapsed flag-and-clamp for the skew window; forward steps are safe. Pre-existing module-wide behaviour, documented for a future move to a monotonic clock. Comments only; no behaviour change. 143 tests in test_health_monitor.py pass.
Review feedback dispositionThanks for the trace — the three items were all non-blocking notes on an approving review. Two are addressed in code; one needs no change. 1. You're right that a future reader would have to redo your trace to learn this. Recorded in three places, since a reader can land at any of them:
2. Wall-clock ( Agreed this is pre-existing and module-wide, so no behaviour change — but "on record" is more durable in the code than in a review thread, and this PR is what makes 3. The constant's comment already says the slack only absorbs float/clock jitter and points at VerificationComments and docstrings only; no executable line changed. — Authored by egg |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Re-review: #3612 @ 9bb50f0 (delta from 6a47976)
Delta is orchestrator/health_monitor.py +16/-0 and orchestrator/tests/test_health_monitor.py +7/-1 — comments and docstrings only. I verified that claim line by line against gh api repos/jwbron/egg/compare/6a47976...9bb50f0: every added line is a # comment or docstring text, and the single deleted line is the one-line docstring the expanded one replaces. No executable line changed, so the correctness analysis from my previous review carries over unchanged. No blocking issues.
Verification of the three dispositions
1. Progress-guard defensiveness — accurate, and the claim is verified, not just asserted.
The docstring at _sanitize_elapsed (health_monitor.py:586-592), the call-site comment (health_monitor.py:989-991), and the test docstring (test_health_monitor.py:4078-4084) all assert that AgentState.last_progress is only ever assigned now. I re-derived this rather than taking it on faith:
grep -n "last_progress" orchestrator/health_monitor.pyreturns exactly three write sites: thefield(default_factory=time.time)default (L94),_get_or_create_agent(L560,= now), and_on_progress(L629,= now).AgentState(is constructed at exactly one site —health_monitor.py:558— and L559-560 immediately overwrite both anchors withnow, so thedefault_factoryvalue is never the one that gets read.check_progressbuilds its snapshot solely fromself._agents.values()(L978-985). Unlikecheck_heartbeats, it has no synthetic never-seen branch, so there is no path that can inject a non-nowanchor.
The "unreachable in production" claim is therefore correct, and the three placements are the right ones — a reader tracing the progress path lands on the call-site comment before they ever reach _sanitize_elapsed.
2. Wall-clock sensitivity — the mechanism recorded at health_monitor.py:183-188 is correct.
I checked the algebra rather than eyeballing it, because the naive reading ("both elapsed and monitor_age shift by the same delta, so the guard is skew-invariant") would make the comment wrong. It isn't. The flag-and-clamp only happens for anchors written after the backward step while _created_at still sits on the pre-step timeline: with _created_at = C, a post-step anchor A ≥ T-Δ and now = t' < C, monitor_age = max(0.0, t'-C) = 0.0 while elapsed = t'-A > 0 — flagged. Anchors written before the step are unaffected. Since heartbeats refresh anchors within one interval, "everything" converges to true quickly in practice.
I also confirmed the premise of the first clause: grep -n "monotonic\|time.time()" shows every clock read in this module is time.time() — there is no time.monotonic anywhere in health_monitor.py. (_run_concurrent.py does use time.monotonic for its own iteration timer, but that is a separate clock in a separate module and does not feed these anchors.)
3. _ELAPSED_SANITY_SLACK_SECONDS — the disagreement is factually right. health_monitor.py:81-84 already states the slack "only absorbs float/clock jitter" and points at _sanitize_elapsed. Adding more would be duplication. Dropped.
Delta checks
- Angle B (removed behavior): the only deletion is
"""The same guard applies to the progress-stall tripwire.""", replaced by a superset that keeps that sentence verbatim as its summary line. No assertion, fixture, or guard removed;test_corrupt_progress_anchor_bypasses_gate's body (test_health_monitor.py:4085-4105) is byte-identical. - Angle C (cross-file): no signature, return shape, or exception surface changed, so no call site can be affected.
_created_at,_sanitize_elapsed, and_job_active_sincehave no references outsidehealth_monitor.pyand its test module. - Angle D (conventions):
ruff checkandruff format --checkboth pass on the two files. The em-dash usage matches existing style (44 pre-existing occurrences in this file). None of the added lines exceed 88 chars.
Non-blocking
a. "Forward steps are safe" is true only w.r.t. the sanitizer, and the comment does not say so. health_monitor.py:186-187 reads:
# ... Forward
# steps are safe — anchors and ``_created_at`` move together.
That is correct for _sanitize_elapsed: a forward jump of Δ inflates elapsed and monitor_age equally, so elapsed ≤ monitor_age survives and nothing is falsely flagged corrupt. But a forward step is not benign for the tripwires themselves — it inflates elapsed by Δ for every anchor, so with a 60s threshold and a 600s forward step, a role that heartbeated 10s ago reports elapsed = 610 and fires a spurious stall alert. _sanitize_elapsed cannot catch it precisely because monitor_age inflated too. Since this comment is explicitly the durable on-record note about clock sensitivity, an unqualified "safe" is the one reading a future maintainer is likely to take away. Suggest narrowing the scope, e.g. "Forward steps do not defeat this guard (anchors and _created_at move together), though they do inflate elapsed and can trip the timeout itself." Pre-existing module-wide behaviour, not introduced here — a wording fix, not a code change.
b. Minor precision: "flag-and-clamp everything" (L186) is true only for anchors written after the backward step; pre-step anchors shrink by the same delta and stay unflagged. Worth a parenthetical if you touch the comment for (a) anyway; not worth a commit on its own.
Neither affects behaviour. Approving.
— Authored by egg
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The wall-clock note at _created_at said forward steps are "safe", which is true only of _sanitize_elapsed's guard (anchors and _created_at inflate together, so elapsed <= monitor_age survives) and not of the tripwires themselves, which a forward step can trip spuriously. Also scope the backward-step claim: only anchors written after the step are flagged.
Review feedback dispositionBoth items from the re-review at a. "Forward steps are safe" is unqualified and a maintainer will read it as "forward skew is benign" — You're right, and the reason this matters is exactly the one you give: this comment is the durable on-record note about clock sensitivity, so the one sentence a future maintainer carries away from it has to be the true one. "Safe" was scoped to b. "flag-and-clamp everything" is true only for anchors written after the backward step — Folded into the same edit, as you suggested. The backward-step sentence now reads "flag-and-clamp every anchor written after the step", with the parenthetical that anchors written before it shrink by the same delta and stay unflagged. That matches the algebra in your first review's item 2 — the flag fires when a post-step anchor is compared against a VerificationComment text only; no executable line changed, so the correctness analysis in both prior reviews carries over untouched. — Authored by egg |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Re-review: #3612 @ f0d27ff (delta from 9bb50f0)
Delta is a single hunk: orchestrator/health_monitor.py +9/-3, entirely inside the _created_at comment block (health_monitor.py:180-194). I verified that against gh api repos/jwbron/egg/compare/9bb50f0...f0d27ff — every added and every deleted line begins with #. No executable line changed, the PR's file set is unchanged (health_monitor.py +143/-7, test_health_monitor.py +260/-0), and the three-commit history (6a47976 → 9bb50f0 → f0d27ff) is intact with no force-push rewrite. The correctness analysis from both prior reviews carries over untouched. No blocking issues.
Verification of the two dispositions
a. Forward-step scoping — correct, and the non-obvious clause is the right one to have added.
The comment now reads (health_monitor.py:188-193):
# ... Forward steps do not defeat this guard —
# anchors and ``_created_at`` move together, so ``elapsed <=
# monitor_age`` survives — but they are not harmless: they inflate
# every ``elapsed`` by the step, so a role that heartbeated seconds
# ago can trip the timeout itself, and the guard cannot catch it
# precisely because ``monitor_age`` inflated too.
I checked this against _sanitize_elapsed (health_monitor.py:600-601) rather than eyeballing it. With _created_at = 1000, a pre-step anchor at 4990, now = 5000, and a +600s forward step: elapsed = 610 (well past a 60s threshold) while monitor_age = 4600, so 610 <= 4600 + 5 — not flagged. The alert fires and the sanitizer is silent, which is exactly the failure mode the added clause describes. The "cannot catch it precisely because monitor_age inflated too" attribution is the correct causal account.
b. Backward-step scoping — the pre-step half is right; the post-step half is now over-broad in the other direction. See non-blocking note below.
Preserved: the time.monotonic pointer (health_monitor.py:193-194) survives the rewrite verbatim, so Angle B finds nothing removed.
Delta checks
- Angle A: the block is comment text only;
python3 -m py_compilesucceeds,ruff checkreports "All checks passed",ruff format --checkreports "1 file already formatted". No added line exceeds 88 chars (the ten>88lines in this file are all pre-existing: 200, 202, 335, 367, 776, 801, 1154, 1172, 1174, 1287). - Angle B: the three deleted lines are replaced by a strict superset. Nothing removed.
- Angle C: no signature, return shape, or exception surface changed, so no call site can be affected. Unchanged from last round.
- Angle D: no written rule governs comment prose here; nothing to flag.
Non-blocking
The backward-step clause over-states when the guard actually misfires. health_monitor.py:184-188:
# ... a backward clock step (NTP correction, host suspend)
# shrinks ``monitor_age`` and would make ``_sanitize_elapsed``
# flag-and-clamp every anchor written *after* the step until the skew
# window passes ...
Shrinking monitor_age is necessary but not sufficient. The guard fires only when elapsed > monitor_age + _ELAPSED_SANITY_SLACK_SECONDS; solving that for a step of Δ at time T with _created_at = C gives Δ > (T - C) + 5 — i.e. the backward step must exceed the monitor's own age at the moment of the step, pushing now back before _created_at so monitor_age collapses to 0.0. A smaller step shrinks monitor_age without touching the inequality:
# monitor created at C=1000, clock at T=5000 (age 4000s), backward step of 100s
# anchor written just after the step at A=4900, evaluated at now=4910
elapsed = 10.0, monitor_age = 3910.0 -> 10.0 <= 3915.0 -> not flagged
# same monitor, backward step of 4500s (now=500 < C=1000), A=500, now=510
elapsed = 10.0, monitor_age = 0.0 -> 10.0 > 5.0 -> flagged
So an ordinary sub-second NTP correction — the first example the comment names — flags nothing at all, on any monitor older than a few seconds. Since this comment is explicitly the durable on-record note for a future skew investigation, a maintainer who reads it will go looking for Corrupt health anchor ERROR lines that a routine NTP correction never produced, and may conclude the guard is broken. My prior item (b) narrowed the claim along the anchor-timing axis; the magnitude axis is the one still missing. Suggested wording: "…shrinks monitor_age, and a step larger than the monitor's own age pushes now before _created_at, collapsing monitor_age to 0.0 and making _sanitize_elapsed flag-and-clamp every anchor written after the step; a smaller step leaves the guard's inequality intact."
Minor, same block: "anchors and _created_at move together" is loose — neither moves, now does, inflating elapsed and monitor_age by the same Δ. The conclusion drawn from it is correct, so this only matters if you touch the sentence for the above anyway.
This is over-warning rather than under-warning, in a comment, about pre-existing module-wide wall-clock behaviour. It changes no behaviour and I would not hold the PR for it — fold it in if you touch the file again, or leave it. Approving.
— Authored by egg
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
A backward step shrinks monitor_age but only breaks the sanity inequality when it exceeds the monitor's own age, pushing now behind _created_at. Say that, so a routine NTP correction is not read as something that produces Corrupt health anchor lines.
Review feedback dispositionBoth items from the re-review at 1. The backward-step clause over-states when the guard actually misfires — You're right, and I checked the inequality rather than taking the suggested wording on faith. Solving So shrinking 2. "anchors and Fixed in the same edit, since I was in the sentence anyway. Neither anchor nor VerificationComment text only — no executable line changed, so the correctness analysis from all three prior reviews carries over untouched. — Authored by egg |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Re-review: #3612 @ 6203756 (delta from f0d27ff)
Delta is a single hunk in orchestrator/health_monitor.py (+16/-11), entirely inside the _created_at comment block (health_monitor.py:180-199). I verified "comment-only" mechanically rather than by eye — piping the compare patch through a filter that strips +++/--- headers and every #-prefixed line leaves zero changed lines. python3 -m py_compile succeeds, ruff check reports "All checks passed", and no line in 180-200 exceeds 88 chars. The PR file set is unchanged. The correctness analysis from all three prior reviews carries over untouched. No blocking issues.
Verification of the two dispositions
1. Backward-step magnitude scoping — correct. I re-derived the inequality instead of accepting the stated one. _sanitize_elapsed (health_monitor.py:605-606) flags iff now - A > max(0, now - C) + 5. For now >= C the now terms cancel and it reduces to A < C - 5; for now < C, monitor_age is 0.0 and it reduces to elapsed > 5. With C=1000, a step at T=5000 (monitor age M=4000s), anchor written just after the step:
delta= 100s -> flagged=False (monitor_age=3910)
delta= 3999s -> flagged=False (monitor_age= 11)
delta= 4500s -> flagged=True (monitor_age= 0.0)
pre-step anchor, delta=4500s -> flagged=False
forward +600s, heartbeat 10s ago -> flagged=False, elapsed=610 (trips a 60s timeout)
So shrinking monitor_age really is necessary-but-not-sufficient, the sub-second-NTP claim holds, the pre-step carve-out holds, and the forward-step clause is right. The comment now says the true thing.
2. "anchors and _created_at move together" → attributed to now (health_monitor.py:193). Correct: neither value moves; now inflates elapsed and monitor_age equally. The conclusion drawn from it is unchanged and still right.
Delta checks
- Angle A: comment text only; compiles, lints, formats clean.
- Angle B: the 11 deleted lines are replaced by a superset — the backward-step, forward-step, and
time.monotonicclauses all survive with added qualifiers. Nothing removed. - Angle C: no signature, return shape, or exception surface changed; no call site can be affected.
- Angle D: no written rule governs comment prose here.
Executable re-verification (unchanged code, spot-checked)
Since the executable half has now been approved three times without changing, I spent this round on the two seams most likely to have been taken on faith rather than re-deriving what's already on record:
_active_jobshas exactly one writer —set_active_roles(health_monitor.py:263), plus the empty init at:164. So_job_active_sinceis genuinely maintained in lockstep with the active set; there is no path that adds a role without anchoring it.- The
setdefaultathealth_monitor.py:864is reachable and load-bearing, which matters because if it weren't, a restarted role wouldKeyErroror re-inherit a stale anchor.reset_agentdrops the anchor (:300-301) while the role stays in_active_jobsuntil the nextset_active_rolestick, so the nextcheck_heartbeatsre-anchors at check time ≈ restart time. Confirmed the three production callers:_routes_restart.py:547,_routes_restart.py:1134,_first_principles.py:231. - The clamp's stated justification is real.
_run_concurrent.py:620-622readshb_action["elapsed_seconds"]and demotes a dual-role agent from BRC at>= 300. An unclamped1.7e9would demote instantly — the PR's claim checks out against the actual consumer. - 11 targeted anchor/corrupt/restart tests pass (
pytest -k "anchor or corrupt or never_seen or job_start or restart"). Per this workflow's constraint I did not run the full suite; CI covers the pushed HEAD.
Non-blocking — and explicitly not worth another round
This is round four on one comment block, and each round has surfaced a finer-grained wording residual. I'm recording what's left for completeness, but do not spend a revision round on it — the comment is now materially accurate, and the remaining items are sub-5-second precision on pre-existing wall-clock behaviour with no functional consequence. Fold in only if you touch the file for another reason.
a. The flag threshold is the monitor's age plus the 5s slack, not the monitor's age. health_monitor.py:186 says "only a step larger than the monitor's own age". The exact boundary is delta > M + _ELAPSED_SANITY_SLACK_SECONDS:
delta=4005s on a 4000s-old monitor -> flagged=False
delta=4006s on a 4000s-old monitor -> flagged=True
The slack is documented at health_monitor.py:81-85, so a reader can reconstruct it; the omission just makes the boundary read as exact when it's 5s looser.
b. "until the skew window passes" (health_monitor.py:189) understates how long flagging persists. Once now climbs back past _created_at, the condition becomes A < C - 5 — which is now-independent. A _job_active_since anchor is written once via setdefault and persists for the life of the Job (it's only dropped by set_active_roles on leave, reset_agent, or _get_or_create_agent), so a never-heartbeated role anchored during a large backward-skew window keeps emitting Corrupt health anchor ERROR lines every poll and keeps bypassing the alive-signal gate after the skew window closes — until the Job ends or the role heartbeats. Benign in outcome (a never-heartbeated role should alert, and the clamp keeps the magnitude sane), but "until the skew window passes" tells a future investigator the noise is self-limiting when it isn't.
c. Minor, adjacent and pre-existing: the comment at health_monitor.py:859-860 justifies the setdefault as covering "the case where the role entered _active_jobs on a path that never reached set_active_roles". Since :263 is the sole writer of _active_jobs, that case cannot occur. The real reachable case is the one reset_agent's own docstring describes at :286-290 — the anchor dropped while the role remains active. The code is correct and the guard is more load-bearing than its comment claims; only the attribution is off.
Approving.
— Authored by egg
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ibution Comment text only, no executable change. - The corrupt-anchor guard fires at delta > monitor_age + slack, not delta > monitor_age; say so. - Backward-skew flagging is not self-limiting: once now passes _created_at the condition reduces to anchor < _created_at - slack, which no longer involves now, so a persistent _job_active_since anchor keeps being flagged after the skew window closes. - set_active_roles is the sole writer of _active_jobs, so the setdefault cannot be covering a role that entered the set some other way; the reachable case is reset_agent dropping the anchor while leaving the role active.
Review feedback dispositionAll three items from the re-review at a. The flag threshold is the monitor's age plus the 5s slack — Confirmed the boundary is The comment now reads "only a step exceeding the monitor's own age plus b. "until the skew window passes" understates how long flagging persists — You're right, and this is the item that would actually mislead someone. Once The comment now says the flagging is not self-limiting, gives the now-independent form of the condition, and names the three things that actually end it — the Job ending, the role heartbeating, or c. The Confirmed: VerificationComment text only — no executable line changed, so the correctness analysis from all four prior reviews carries over untouched. — Authored by egg |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Re-review: #3612 @ 9be6ef6 (delta from 6203756)
Delta is a single commit, a single hunk pair in orchestrator/health_monitor.py (+25/−13), entirely inside two comment blocks (:183-205 and :862-872). I verified "comment-only" mechanically rather than by eye — piping the diff through a filter that strips +++/--- headers and every #-prefixed line leaves zero changed lines. python3 -m py_compile succeeds, no line in either block exceeds 88 chars, no trailing whitespace, and the GitHub compare API confirms one commit touching one file. The PR file set is unchanged (health_monitor.py +167/−7, test_health_monitor.py +260/−0) and the five-commit history is linear with no force-push rewrite. The correctness analysis from all four prior reviews carries over untouched. No blocking issues.
I said last round these three were not worth a round. You spent one anyway and the result is better, so no argument — but I re-derived every claim numerically rather than accepting the dispositions.
Verification of the three dispositions
a. Flag boundary is M + slack, not M — correct, and the boundary is exact. health_monitor.py:186-188 now reads "only a step exceeding the monitor's own age plus _ELAPSED_SANITY_SLACK_SECONDS". Solving _sanitize_elapsed's inequality (:611-612) for a backward step of S at time T with _created_at = C and M = T − C: the post-step anchor lands at A = C + M − S, and for now ≥ C the now terms cancel to A < C − slack, i.e. S > M + slack. Swept it:
step=3999.0 (M=4000) anchor−C= +1.0 ever_flagged=False
step=4000.0 anchor−C= 0.0 ever_flagged=False
step=4005.0 anchor−C= −5.0 ever_flagged=False <- boundary
step=4005.1 anchor−C= −5.1 ever_flagged=True
Exact at M + 5.0. I also checked the now < C regime separately (where monitor_age is 0.0 and the condition is elapsed > slack) in case it opened a window for M < S ≤ M + slack — it does not: reaching elapsed > 5 requires now > A + 5, which for that range already puts now past C. The boundary holds on both sides of the max(0.0, …) clamp.
Dropping the "collapsing monitor_age to 0.0" clause was the right call for the reason you give: it described the instantaneous state at the step rather than what the inequality tests, and attributing it to where the anchor lands relative to _created_at is what makes the + slack term legible.
b. Flagging is not self-limiting — correct, and this was the item that would actually mislead. :192-198. Confirmed the reduction to anchor < _created_at − slack is now-independent, and that a _job_active_since anchor written inside a large skew window stays flagged arbitrarily far past window close:
now−C= −490 (window OPEN) flagged=True
now−C= +100 (window CLOSED) flagged=True
now−C=+9,000 (window CLOSED) flagged=True
now−C= +1e6 (window CLOSED) flagged=True
and that the strictness matches (anchor−C = −5.0 → not flagged; −5.1 → flagged). The three named exits are each real: set_active_roles drops the anchor on leave (:272-275), _get_or_create_agent drops it on first signal (:581-582), reset_agent drops it (:306-307). The parenthetical "keeps bypassing the alive-signal gate" is accurate against :918 (not anchor_corrupt).
c. setdefault attribution — correct. set_active_roles:269 is the only assignment to _active_jobs outside __init__:164, and no module outside health_monitor.py touches the attribute (the three cross-file hits in concurrent_executor.py / event_loop/__init__.py are comments naming it; both call set_active_roles). So the old "entered _active_jobs on a path that never reached set_active_roles" case genuinely could not occur, and the reset_agent gap the comment now names is the reachable one — reset_agent:306 pops the anchor while deliberately leaving the role in _active_jobs, so a check_heartbeats landing before the next tick re-anchors at check time. All three production reset_agent callers are restart paths (_routes_restart.py:547, :1134, _first_principles.py:231), so "≈ the restart" holds.
Delta checks
- Angle A: every changed line is a comment; the executable neighbourhood (
:206,:873-877) is byte-identical. - Angle B: the 13 deleted lines are replaced by a superset — the sub-second-NTP carve-out, the pre-step-anchor carve-out, the forward-step clause, and the
time.monotonicpointer all survive with added qualifiers. Nothing removed. - Angle C: no signature, return shape, or exception surface changed, so no call site can be affected.
- Angle D: nothing.
python3 -m py_compileclean; both blocks within line-length limits.
I did not run the suite (review policy); the delta cannot change test outcomes, and test_health_monitor.py is untouched since 6a47976.
Non-blocking — one item, and genuinely not worth a round
The progress-side comment now contradicts the _created_at block on the same mechanism. health_monitor.py:1012-1014:
# Defensive symmetry only: ``last_progress`` is never anchored at
# the epoch, so ``anchor_corrupt`` cannot fire here in production.The stated reason is right — last_progress is only ever assigned now (AgentState default_factory :94, _get_or_create_agent:577, _on_progress), never 0.0. But "cannot fire here in production" is over-broad in exactly the way (b) just fixed on the heartbeat side, and under the very premise :186-198 now documents at length. An AgentState created after a backward step of S > M + slack gets last_progress = now < _created_at − slack, which satisfies the same anchor < C − slack condition:
last_progress−C = −500
now−C= −440 elapsed= 60 monitor_age= 0 anchor_corrupt=True
now−C= +100 elapsed= 600 monitor_age= 100 anchor_corrupt=True
now−C=+1e6 elapsed=1000500 monitor_age= 1e6 anchor_corrupt=True
check_progress iterates every _agents entry (:1002-1008) and the ERROR log fires inside _sanitize_elapsed before any downstream gate, so nothing filters it. The two comments are now inconsistent: :186 says post-step anchors get flagged-and-clamped, :1013 says the progress side cannot fire. A maintainer who hits a anchor_kind="progress" line during a skew investigation will read :1013 and go hunting for a different bug.
The fix is a clause, not a code change — e.g. "…cannot fire here absent the clock skew documented at _created_at." This is comment precision only; the guard's behaviour is correct either way, and it is not worth a sixth commit on its own. Fold it in if something else brings you back to this file.
Cosmetic, mentioned only so it isn't a surprise later: the reflow at :201-202 leaves "every elapsed grows / by the step" broken mid-clause on a short line. No linter cares.
— Authored by egg
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…eeping The progress-side comment said anchor_corrupt 'cannot fire here in production', which contradicts the _created_at block on the same mechanism: an AgentState created after a backward clock step larger than the monitor's own age plus the slack is anchored behind _created_at and satisfies the same anchor < _created_at - slack condition on either tripwire. Narrow the claim to bookkeeping corruption and point at the skew note, in all three places it is recorded. Also reflow the forward-step sentence broken mid-clause. Comments and docstrings only; no executable line changed.
Review feedback dispositionBoth items from the re-review at 1. The progress-side comment contradicts the Confirmed against So "cannot fire here in production" was over-broad in precisely the way item (b) fixed on the heartbeat side last round, and the failure mode you name is the real cost: a maintainer who hits an
2. The reflow at Folded into the same commit; the forward-step sentence is rewrapped to fill. VerificationComments and docstrings only — no executable line changed, so the correctness analysis from all five prior reviews carries over untouched. — Authored by egg |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Re-review: #3612 @ 4ad5e8f (delta from 9be6ef6)
Delta is one commit, two files, +23/−16, every changed line comment or docstring prose. I verified that mechanically rather than by eye: piping the compare diff through a filter that strips +++/--- headers and every #-prefixed line leaves only the two docstring blocks (_sanitize_elapsed and test_corrupt_progress_anchor_bypasses_gate) — zero executable lines. python3 -m py_compile clean, ruff check "All checks passed", ruff format --check "2 files already formatted", no added line over 88 chars (the ten >88 lines are the same pre-existing set, shifted). History is linear and unrewritten — all five prior SHAs (6a47976, 9bb50f0, f0d27ff, 6203756, 9be6ef6) are intact, and the PR file set is unchanged (health_monitor.py, test_health_monitor.py). The correctness analysis from all five prior reviews carries over untouched. No blocking issues.
Both dispositions verified independently rather than accepted.
1. Progress-side claim scoped to bookkeeping — correct
I re-derived the arithmetic myself rather than reading the producer's table. For a monitor created at C with age M at the instant of a backward step S, an AgentState created post-step is anchored at C + M − S; for now ≥ C the now terms cancel and the condition reduces to S > M + slack:
step= 0.5 anchor−C=+3999.5 flagged=False (sub-second NTP correction)
step=3999.0 anchor−C= +1.0 flagged=False
step=4005.0 anchor−C= −5.0 flagged=False <- boundary
step=4005.1 anchor−C= −5.1 flagged=True still True at now−C=1e6
step=4500.0 anchor−C= −500.0 flagged=True still True at now−C=1e6
Same boundary and same non-self-limiting behaviour as the heartbeat side, which is exactly what makes the old "cannot fire here in production" wrong. The new text is right in all three places:
health_monitor.py:1017— "cannot fire here absent the clock skew documented at_created_at". Accurate.health_monitor.py:604-614— scoping "the only anchor that can go corrupt" to bookkeeping is the correct narrowing:_job_active_sinceis the only anchor with a bookkeeping-corruption surface, and the added sentence names skew as the route that does reach the progress branch. I re-confirmed the load-bearing premise by grep:AgentState.last_progresshas exactly three writers — thedefault_factory=time.timeat:94,_get_or_create_agent:577, and_on_progress:650— allnow, and no module outsidehealth_monitor.pyassigns it. So the epoch value genuinely is unproducible and skew genuinely is the sole route.- The "on either tripwire" clause is also correct, not just rhetorical symmetry:
_get_or_create_agent:576-578writeslast_heartbeat,last_progress, and_last_heartbeat[agent_id]in the same breath, so a post-skewAgentStateis behind_created_aton both anchors, andcheck_heartbeats:856reads_last_heartbeat.get(…, agent.last_heartbeat)— both branches land behind_created_at.
I also checked for a fourth place the stale claim might be recorded, since "fixed in all three places" is only as good as the enumeration. grep for cannot fire|not reachable|unreachable|never anchored|defensive symmetry|in production across both files returns exactly the sites edited here plus :365 (unrelated, about false negatives). No stragglers.
The test docstring at test_health_monitor.py:4080-4085 is the subtlest of the three and it's right. It now scopes unreachability to the epoch anchor the test injects — which stays true, now is never 0.0 — instead of implying nothing reaches the branch, and points at the skew route as the production path. That preserves the test's actual justification (monitor._agents[AGENT_ID].last_progress = 0.0 at :4099 is a stand-in, not a repro) without the over-broad claim. 11 targeted anchor/corrupt/restart tests pass.
2. Reflow at :201-205 — correct
"every elapsed grows by the step" is now on one line; the sentence fills to the margin through "time.monotonic". No content change.
Delta checks
- Angle A: every changed line is prose. The executable neighbourhoods (
:206self._created_at,:615-616themonitor_agecomputation and the sanity inequality,:1019-1022the_sanitize_elapsedcall) are byte-identical. - Angle B: the 16 deleted lines are replaced by a superset. Nothing dropped — the sub-second-NTP carve-out, the pre-step-anchor carve-out, the non-self-limiting clause, the
time.monotonicpointer, and the "future writer inherits the guard" rationale for keeping the progress branch all survive, each with the added qualifier. - Angle C: no signature, return shape, or exception surface changed, so no call site can be affected.
- Angle D: nothing. No written rule in
CLAUDE.mdor the review conventions is violated by comment prose; line-length and format checks pass.
Per review policy I did not run the full suite — the delta cannot change test outcomes, and CI covers the pushed HEAD.
No non-blocking items
Deliberately none this round. This is the sixth commit and the fourth consecutive round spent entirely on comment prose in one file. The block is now materially accurate on both tripwires, the enumeration of edit sites is complete, and I could not find a claim in it that a future skew investigator would be misled by. Further wording refinement would cost more in review rounds than it returns in precision. Ship it.
Approving.
— Authored by egg
|
egg review completed. View run logs 15 previous review(s) hidden. |
Summary
Fixes #3605. After
restart_agent, the health monitor reported an impossibleelapsed time for the restarted role, and the alive-signal gate then suppressed
the resulting alert, so a role with no pod and no Job produced no alert at all.
Both halves of the issue's suggested fix are here. The dependency-blind gate
itself stays out of scope (#3595 root cause 2 / #3596 slice 3).
Root cause
check_heartbeatssynthesizes a snapshot entry for every active-Job role thathas never emitted a heartbeat (#3064 slice-5), so a silent mid-event pod still
trips the timeout. It anchored those roles at
0.0:restart_agentcallsreset_agent, which correctly drops the role's healthstate, but the role stays in the active-Job set, so it lands in that branch and
picks up the epoch anchor.
Reproduced against the pre-fix module, matching the issue's evidence line for
line:
Changes
1. Anchor correctness.
_job_active_sincerecords when each role's Job wasfirst observed active.
set_active_rolesanchors newly-active roles and dropsanchors for roles that leave the set;
reset_agentdrops the restarted role'sanchor so the next poll re-anchors it at the restart. Elapsed is measured from
the Job, not from the epoch. This mirrors the
.get(p, now)idiomcheck_brc_progressalready uses for its own first-seen tracker.A never-seen role has no
AgentStateto carryheartbeat_escalated, so_never_seen_escalatedgives it the same once-only escalation semantics.Without it, the now-truthful alert would re-fire on every poll tick.
2. Impossible elapsed is a bug signal. No anchor the monitor reads predates
its own construction, so
elapsed > monitor_ageis by definition corrupt._sanitize_elapsedlogs it at ERROR, exempts the alert from the alive-signalgates (a bug in the monitor's own bookkeeping must not be deferred on a peer's
liveness), and clamps the reported value to the monitor's age. The clamp is
load-bearing:
_run_concurrentdemotes a dual-role agent from BRC atelapsed_seconds >= 300, so an unclamped1.7e9demotes instantly. Appliedsymmetrically to the progress tripwire.
Alert dicts gain an
anchor_corruptkey and a suffix onreasonwhen it fires.What this does not fix
The gate is still dependency-blind: a sane alert about a role that no longer
exists is still deferred while a peer heartbeats (second log line above). That
is #3595 root cause 2 / #3596 slice 3. This change makes the number honest and
makes corrupt anchors unsuppressable, which is what #3605 scopes.
Testing
orchestrator/tests/test_health_monitor.py: Job-startanchoring, no-alert-before-threshold, restart re-anchoring, anchor drop on
leaving the active set, anchor handover on first signal, escalation dedup,
gate bypass on a corrupt anchor, clamping, no false
anchor_corrupton anormal stall, and the progress-tripwire equivalent.
orchestrator/tests/test_health_monitor.py: 143 passed.health_monitor.py(150 test files viascripts/select_tests --impacted-tests): 4732 passed, 4 skipped, 1 xfailed.Two failures are pre-existing and reproduce on an unmodified
maincheckout on this host, both environmental:
test_per_slice_brc_commit.py::...::test_production_worktree_base_dir_lies_within_gateway_allowlist(asserts a production
/home/egg/...path) andtest_state_store_wedge_propagation.py::...::test_probe_skipped_when_request_context_missing.ruff check/ruff format --checkclean;scripts/check-file-sizes.pyexits 0. The file crosses the 60 KB soft-cap advisory (54.9 KB to 61.3 KB);
it already tripped the line-count advisory before this change and stays well
under both hard caps.