The per-stage health verdict counts only non-zero stage-end exit codes, so a stage that exits 0 with an unusable result reads as a success and resets the streak
Id: TD-PPagop-26082504 · Status: resolved · Filed: 2026-08-25 · Resolved: 2026-09-14 · Ref: #1497
Noticed while reviewing PR #774 (issue #662), which added requirement 2.8 and
lib/stage-health.sh. Not a defect in that pull request: issue #662’s own
refinement scopes the computation to log.jsonl’s stage-end records and
their exit_code, and that is exactly what shipped. This records the gap
that scope leaves.
stage_health_verdicts derives consecutive_failures from stage-end
events alone, counting a run of non-zero exit_codes and resetting to 0 on
any exit_code: 0. A stage that exits 0 while its attempt nonetheless
failed — the Script logs an attempt-failed for it, with a detail such as
unparseable final message — therefore reads as a success: it does not
increment the streak, and it clears whatever streak was accumulating.
The reader already loads attempt-failed events; it uses them only for
last_detail, never for the count.
Why it matters
Section titled “Why it matters”On this node’s own log.jsonl (8 777 events, measured 2026-08-25) the
exit-0 failure is the majority failure mode by count:
| count | |
|---|---|
attempt-failed events |
157 |
…whose stage’s stage-end for the same cycle exited 0 |
118 |
non-zero stage-end events |
37 |
…with no matching attempt-failed |
1 |
So roughly three quarters of the recorded stage failures on this node are invisible to the verdict, and each one actively resets the streak that the visible quarter is building.
The reset is the sharper half. A stage failing every cycle in an alternating
mix — one exited 1, one unparseable final message — never accumulates
three in a row, so it reports ok with consecutive_failures: 0 throughout,
which is precisely the “reports healthy while every stage is failing” shape
#662 exists to end.
Why it has not bitten yet
Section titled “Why it has not bitten yet”Both incidents #662 names are caught correctly by what shipped, verified by replaying this node’s real log through the reader:
- 2026-08-21 01:38–12:09Z (
prompt_too_long):coordinator→consecutive_failures: 12,verdict: failing. - 2026-08-01/02 (argv cap,
coordinator exited 126):consecutive_failures: 14,verdict: failing.
Both were clean non-zero-exit outages. The longest run of consecutive
exit-0-but-failed coordinator attempts anywhere in this node’s recorded
history is 2 — below the threshold of 3 — so no historical outage would
have been missed. The gap is latent, not yet realised.
Suggested fix
Section titled “Suggested fix”Count a cycle’s stage attempt as failed if either its stage-end exited
non-zero or an attempt-failed was logged for the same cycle + stage.
Joining on cycle is sound: attempt-failed carries both fields (verified
against the real log), and the two families are near-disjoint per cycle
today, so the join is what makes them one signal rather than two.
That changes what consecutive_failures means, so requirement 2.8’s own
wording in docs/IMPLEMENTATION-PIPELINE-SPEC.md moves with it, along with
lib/stage-health.sh’s header and the test/stage-health.test.sh
assertions that pin “a success resets the streak” — a stage-end exit 0
would no longer be sufficient on its own to be that success.
Worth checking at the same time whether THRESHOLD should stay 3 once the
count includes the commoner failure mode, since streaks will form faster.
last_detail needs the same join, for a reason the count does not make
obvious. It is $fails | last | .detail — the stage’s most recent
attempt-failed anywhere in the log — shown whenever consecutive_failures
is above 0, so it is only guaranteed to describe the current streak while
every non-zero stage-end has an attempt-failed of its own beside it. The
counts above record one non-zero stage-end with no matching
attempt-failed, and on that streak the field reports a detail from before
the last success, which lib/stage-health.sh’s header expressly says it does
not (“this describes the current failure, not a history of every failure
this stage has ever logged”). Rare today and cosmetic — the verdict and the
count are unaffected, and the operator still sees the right stage failing the
right number of times — but the fix above is where it stops being possible,
since joining on cycle + stage gives the detail the same streak boundary
the count gets.
References to remove when this is resolved
Section titled “References to remove when this is resolved”- Nothing cites this record in code; it is named only in the review thread of PR #774.
Migrated to https://github.com/Poetic-Poems/agent-ops/issues/983.