Skip to content

fix(#766): recovered phase failure no longer reports failed - #772

Merged
admarble merged 2 commits into
mainfrom
feature/766-fix-recovered-phase-failure-still-reports-failed-l
Jul 16, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/766-fix-recovered-phase-failure-still-reports-failed-l

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

A run whose phase failed and then recovered on a later quality-loop iteration disagreed across all three outputs — live card ✘ failed, summary table ✔ passed, JSON log 0 passed · 0 failed / status: partial. This fixes the three independent bugs behind that (#766).

  1. Sticky failed never recovers — both status state machines (run-orchestrator + run-renderer) pinned failed on any phase failure and never de-escalated. They now derive the verdict from the current phase slots via a shared pipelineHasFailed helper. Phase slots are keyed by name, so a retried phase already holds its latest attempt; the one phase not overwritten on recovery is the auxiliary loop, which is excluded from the verdict (excluding it never hides a genuine failure — an unrecovered pipeline failure always leaves a non-loop phase failed too).
  2. partial counted in neither bucket — the log pinned partial on any timeout and finalizeRunLog counted only success/failure. Issue status now derives from the latest attempt of each phase (deriveIssueLogStatus, so a timeout a later iteration recovers from clears), and partial gets its own summary bucket (surfaced in sequant logs and the MCP run response).
  3. Loop phases never logged — the loop result was pushed into the phase results but never written to the run log. It's now logged with phase, status, duration, and error.

A #762-style run where all attempts die with no verdict stays failed across all three outputs (locked in by a negative test).

Acceptance Criteria

AC Status Evidence
AC-1 recovered phase → card not failed ✅ run-state.test.ts recovery test; pipelineHasFailed
AC-2 both copies consolidated onto one source of truth ✅ shared status-derivation.ts#pipelineHasFailed used by orchestrator + renderer
AC-3 card, table, log agree ✅ recovered-failure.integration.test.ts (all three → passed)
AC-4 all-partial run not 0 passed · 0 failed ✅ new partial bucket; integration test + finalizeRunLog
AC-5 partial not pinned by a recovered timeout ✅ deriveIssueLogStatus; log-writer de-escalation test
AC-6 loop phases in the run log ✅ batch-executor.ts loop logPhase; integration test
AC-7 qa fails twice then succeeds → passed everywhere ✅ integration test
AC-8 loop failure then success → not-failed ✅ orchestrator + renderer recovery tests
Non-goal: #762 all-failed stays red ✅ negative guards in all three suites

Test plan

  • npm run build, npm run lint clean
  • New: status-derivation.test.ts, recovered-failure.integration.test.ts, orchestrator/renderer/log-writer recovery + negative tests
  • src/lib/workflow/, src/lib/cli-ui/, src/mcp/, src/commands/ suites pass (pre-existing unrelated flake in prompt-wait.test.ts, fails identically on base tree)

Notes

Loose end from the issue (#762 detail cell showed Timeout after 1800s vs the API-drop last failure) was not reproducible — failureReason is already last-wins at run-renderer.ts:283. Left untouched.

Closes #766

Derive the issue verdict from the current phase slots instead of pinning
`failed`/`partial` forever, so a run that fails a quality-loop phase and
recovers on a later iteration reads passed on the live card, the summary
table, and the JSON log alike.

- Shared `pipelineHasFailed` helper (status-derivation.ts) drives both the
  orchestrator card and the renderer; `loop` is excluded from the verdict.
- `deriveIssueLogStatus` derives the log's issue status from the latest
  attempt of each phase; `partial` gets its own summary bucket so an
  all-partial run isn't `0 passed · 0 failed`.
- Loop phases are now written to the run log (phase/status/duration/error).
- A #762-style all-failed run with no verdict stays failed everywhere.

Entire-Checkpoint: aceb380aa394
… producer

Closes the two QA gaps on #766.

1. `run-display.ts` picked the summary detail cell's reason with `.find()` over
   `phaseResults`, which accumulates every attempt across every quality-loop
   iteration — so it rendered the FIRST failure and pinned a stale reason. This
   is the loose end in #766's Notes: #762's cell read `Timeout after 1800s`
   when its real last failure was an API drop. The Notes attributed the cell to
   `run-renderer.ts:288` (genuinely last-wins, but it feeds the live card, not
   the summary), so the actual line was never looked at.

   It now scans back for the last failing non-loop attempt, excluding `loop`
   via the shared LOOP_PHASE rule the card and log already use — a trailing
   loop failure must not mask the phase that actually failed. `qaVerdict` and
   `unmetCount` hang off the same entry and were stale for the same reason.

   Reverse scan rather than `findLast`: tsconfig pins `lib: ES2022` and
   `findLast` is ES2023 (TS2550), though the >=22.12 engine would run it.

2. AC-6's producer had no coverage: the test named "(AC-6)" hand-writes the
   loop entry via `writer.logPhase`, so it passed even with the batch-executor
   call site deleted (verified by mutation — the mutant survived 57 tests).
   Added three cases driving `runIssueWithLogging` through a real
   fail -> loop -> recover sequence, asserting the loop log reaches `logPhase`
   with phase/status/duration/error, plus the timeout status mapping. Renamed
   the integration test to describe what it actually covers.

Both fixes verified by re-running the mutations: each now fails, including with
#762's exact symptom ("expected 'Timeout after 1800s' to be 'API Error:
Connection closed mid-response'").

Suites: 52 files / 1230 tests pass. Build and lint clean.
@admarble
admarble merged commit 0afc89a into main Jul 16, 2026
5 checks passed
@admarble
admarble deleted the feature/766-fix-recovered-phase-failure-still-reports-failed-l branch July 16, 2026 03:05
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.

fix: recovered phase failure still reports failed — live card, summary, and log disagree

1 participant