Skip to content

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

Closed

Description

@admarble

Problem

A run whose phase fails and then recovers on a later quality-loop iteration is reported as failed in the live card, passed in the summary table, and neither in the JSON log. All three disagree about the same run.

Observed on sequant run 760 -q (run 49298cbd-af1b-49ed-a944-61a9f6848c22):

Output Said Reads
Live card ✘ failed (✗ loop 34:11) sticky state.status
Summary table ✔ passed · 1 passed · 0 failed batch result (completedSuccessfully)
JSON log 0 passed · 0 failed, status: "partial" issue.status === "success" only

Ground truth: #760 succeeded. QA posted AC_MET_BUT_NOT_A_PLUS, PR #765 opened, mergeable, all 5 checks green. The red card was wrong.

This matters because recovering-after-failure is precisely what the quality loop exists to do, so the reporting is wrong on the loop's success path — the case it was built for. A green run that prints failed trains us to ignore the status line.

Root cause

Three independent bugs, each confirmed by reading the code and the run log.

1. Phase failure is sticky and never recovers (the main one)

state.status = "failed" is set on any phase failure and nothing ever unsets it:

  • src/lib/workflow/run-orchestrator.ts:416
  • src/lib/cli-ui/run-renderer.ts:280 (second copy of the same bug)

findOrAppendPhase keys phases by name, so retries overwrite the same slot. #760's loop phase failed on an early iteration; iteration 3 ran clean and shipped the PR, but the card stayed red for the remaining ~34 minutes — showing a green ✓ qa 11:05 (the successful third attempt) next to a permanently red ✗ loop.

The recompute at run-orchestrator.ts:446-450 only runs inside the allDone branch and still ORs in any historically-failed phase, so it can't clear the flag either.

2. "partial" is counted as neither passed nor failed

src/lib/workflow/log-writer.ts:145 pins the issue to "partial" on any timeout — also sticky, also never cleared on a successful retry. finalizeRunLog (src/lib/workflow/run-log-schema.ts:403-408) then counts only success and failure, so "partial" falls into neither bucket and the run vanishes from both columns: 0 passed · 0 failed for a 1-issue run.

3. Loop phases are never written to the run log

src/lib/workflow/batch-executor.ts:1055 pushes loopResult into phaseResults but never calls logWriter.logPhase() — unlike spec (:655) and the regular phases (:982). #760's log records 7 phases (spec, exec, qa, exec, qa, exec, qa) and no loop entry, even though the card tracked a loop phase that failed. The phase that decided the card's verdict is absent from the log you'd use to debug it.

Acceptance Criteria

  • A phase that fails and later succeeds on a subsequent quality-loop iteration does not leave the issue in failed — the live card reflects the recovered state
  • The sticky-status fix covers both copies (run-orchestrator.ts:416 and run-renderer.ts:280), or the two are consolidated onto one source of truth
  • Live card, summary table, and JSON log agree on pass/fail for the same run
  • A run whose issues are all "partial" does not report 0 passed · 0 failed — "partial" is counted in exactly one bucket, or surfaced as its own column
  • "partial" is not pinned by a timeout that a later iteration recovers from
  • Loop phases appear in the run log with phase, status, duration, and error
  • Regression test: quality-loop run where qa fails twice then succeeds → asserts passed in all three outputs
  • Regression test: loop phase failure followed by a successful iteration → asserts not-failed

Notes

Run log: .sequant/logs/run-2026-07-15T05-16-04-49298cbd-af1b-49ed-a944-61a9f6848c22.json

For contrast, sequant run 762 (06927df2-0cc2-40b8-ae2e-4412f0aaa5ed) reported failed correctly — all three QA attempts died (two 1800s timeouts, then API Error: Connection closed mid-response), no verdict was ever produced, and no QA comment exists on the issue. Any fix must keep that case red: PR #764 exists and is green, but it's unreviewed exec output, not an approved change. Don't infer success from PR existence.

One loose end not diagnosed: #762's summary detail cell read Timeout after 1800s, but its last failure was the API drop. failureReason is last-wins at run-renderer.ts:283, so the displayed reason should have been the API error. Worth a look while in here; not reproduced.

Activity

  1. added
    bug
    cli
    on Jul 15, 2026
  2. admarble commented on Jul 15, 2026

    @admarble
    ContributorAuthor

    Assessment

    → PROCEED — All three root causes confirmed by reading the code and the cited run log.

    • Run log run-2026-07-15T05-16-04-49298cbd...json exists.
    • log-writer.ts:145 pins partial on timeout and never clears it; run-log-schema.ts:403-408 counts only success/failure, so partial lands in neither bucket.
    • logWriter.logPhase() is called only at batch-executor.ts:655 and :982 — no loop-phase call site, matching the "loop phases never logged" finding.

    Workflow: spec → exec → qa with quality loop

    Spec added despite the bug label: three distinct bugs across five files, plus an explicit design call in AC-2 ("or the two are consolidated onto one source of truth").

    npx sequant run 766 -Q
    

    Order: before #767 — shared file batch-executor.ts.

  3. admarble commented on Jul 16, 2026

    @admarble
    ContributorAuthor

    📋 Plan — recovered phase failure still reports failed

    Complexity: Standard (8 ACs, 2 source dirs) · verified all three root causes against the code.


    AC Quality Check

    ACs are unnumbered checkbox items (parser found 0 — analyzed inline). Quality is high: each is measurable and names the disagreeing outputs. AC-7/AC-8 are explicit regression tests with clear pass conditions. No vague/unmeasurable/open-ended flags. Numbered them AC-1..AC-8 below in body order.


    Scope Assessment

    Non-Goals: No explicit section, but the Notes carve out a hard boundary: #762's all-failed run must stay red — don't infer success from PR existence. Treat as a Non-Goal / negative test.

    Metric Value Status
    Feature count 3 bug fixes ✅
    AC items 8 (2 are regression tests) ✅
    Directory spread 2 (workflow/, cli-ui/) ✅

    Verdict: ✅ SCOPE_OK — three tightly-related bugs on one symptom (status disagreement); cohesive single PR.


    Root-Cause Confirmation (read the code)

    # Bug Confirmed at
    1 Sticky failed, never recovers run-orchestrator.ts:477 + :509 OR-in; run-renderer.ts:280 (second copy)
    2 "partial" counted in neither bucket log-writer.ts:145 pins it; run-log-schema.ts:403-408 counts only success/failure
    3 Loop phases never logged batch-executor.ts:1055 pushes loopResult but no logWriter.logPhase() (cf. :655 spec, :982 phases)

    Note both status machines only ever escalate (start→running, failed→failed) and never de-escalate a stale failure/partial when a later attempt of the same phase recovers.


    Acceptance Criteria

    AC-1: Recovered phase → live card reflects recovered state

    Verification: Unit Test · Scenario: Given a phase marked failed, When a later iteration of the same phase completes → Then issue status is not failed.

    AC-2: Sticky-status fix covers both copies (or consolidated)

    Verification: Unit Test · Scenario: Given both run-orchestrator and run-renderer state machines, When the same failure→recovery sequence is applied → Then both derive the identical non-failed status. Design decision — see Open Questions.

    AC-3: Card, summary table, and JSON log agree

    Verification: Integration Test · Scenario: Given a run that recovers, When it finalizes → Then state.status, batch completedSuccessfully, and issue.status all report passed.

    AC-4: All-partial run isn't 0 passed · 0 failed

    Verification: Unit Test (finalizeRunLog) · Scenario: Given a run whose only issue is "partial", When finalized → Then it lands in exactly one bucket (or its own partial column), never neither.

    AC-5: "partial" not pinned by a timeout a later iteration recovers

    Verification: Unit Test (log-writer) · Scenario: Given an issue pinned "partial" by a timeout, When a later phase of the same issue succeeds → Then status clears (unless a real failure exists).

    AC-6: Loop phases appear in the run log

    Verification: Unit Test · Scenario: Given a quality-loop run with a loop phase, When the log is written → Then a loop entry exists with phase, status, duration, and error.

    AC-7: Regression — qa fails twice then succeeds → passed in all three outputs

    Verification: Integration Test · Scenario: Given qa failing iterations 1-2 then passing iteration 3 → Then card, summary, and log all read passed.

    AC-8: Regression — loop phase failure then successful iteration → not-failed

    Verification: Unit/Integration Test · Scenario: Given a loop phase failure followed by a successful iteration → Then issue is not failed.

    Negative test (Non-Goal guard): #762-style run where all attempts die with no verdict → must stay failed.


    Implementation Plan

    Phase 1: Derive status instead of pinning it (Bugs 1 & 2 — AC-1/2/4/5)

    1. Add a shared pure helper deriveIssueStatus(phases) (e.g. in run-log-schema.ts or a small status-derivation.ts) → returns failed only if a phase's latest slot is failed, else passed/running. Keys already dedupe by name (findOrAppendPhase), so the slot holds the last attempt.
    2. run-orchestrator.ts: on phase_failed keep the emit, but compute state.status via the helper on both the failed and allDone branches (:477, :504-511) so a recovered phase clears.
    3. run-renderer.ts:280: replace the direct state.status = "failed" with the same helper — one source of truth satisfies AC-2.
    4. log-writer.ts:143-147: when a success phaseLog arrives, de-escalate issue.status from partial (only when no failure phase exists) — mirrors the card fix (AC-5).
    5. run-log-schema.ts:403-408 (finalizeRunLog): stop dropping partial — either count it in passed when the run recovered, or add a partial summary field/column (AC-4). Recommend own column — most honest, keeps #762 distinguishable.

    Phase 2: Log loop phases (Bug 3 — AC-6)

    1. batch-executor.ts after :1055: build a PhaseLog for the loop (phase=loop, status from loopResult.success, duration loopDurationSec, error loopResult.error) and call logWriter.logPhase(...), mirroring the :982 construction.

    Phase 3: Tests (AC-7, AC-8, negative guard)

    1. Unit tests on both state machines + finalizeRunLog/log-writer de-escalation; integration test for the qa-fails-twice-then-succeeds path; negative test that a no-verdict all-failed run stays failed.

    Design Review

    1. Where does this logic belong? Status truth belongs in one derivation function consumed by both state machines and the finalizer — not duplicated across run-orchestrator/run-renderer.
    2. Simplest correct approach? Derive-from-latest-slot rather than sticky-set-and-OR. Rejected: threading "recovered" booleans through events — leaves the same drift risk.
    3. Existing pattern? Same shape as maybeMarkIssueDone (run-renderer.ts:299) which already derives from phases and guards on failed — extend that idea to un-pin, don't invent a new mechanism.
    4. What a senior reviewer challenges? "Does de-escalating partial/failed risk hiding a genuine terminal failure?" — Guard: only clear when the latest attempt of every phase is non-failed and a verdict/PR exists; the feat: lightweight content pre-flight for --chain (AC presence, dependency-order sanity) #762 negative test locks this in.

    Open Questions

    1. AC-2: consolidate vs fix-both-copies? — Recommendation: shared deriveIssueStatus helper called by both machines (functional consolidation without merging the two IssueState types). Impact if wrong: a full state-machine merge is far larger and risks regressing the renderer.
    2. AC-4: partial → own column or fold into passed? — Recommendation: own partial column. Impact if wrong: folding into passed would blur the feat: lightweight content pre-flight for --chain (AC presence, dependency-order sanity) #762 all-failed case the Notes insist must stay visible.
    3. Loose end (Notes): feat: lightweight content pre-flight for --chain (AC presence, dependency-order sanity) #762 detail cell showed Timeout after 1800s but last failure was the API drop (run-renderer.ts:283 is last-wins). Recommendation: investigate opportunistically in Phase 1 while touching that line; file a follow-up only if not a one-liner. Not reproduced — don't block on it.

    Recommended Workflow

    Phases: spec → exec → qa · Quality Loop: enabled

    Reasoning: Matches the /assess recommendation. Bug fix across 5 files with an explicit design call (AC-2) → spec justified. AC-7/AC-8 regression tests are tightly coupled to the state transitions the implementer builds, so they're exec deliverables rather than pre-stubbed — testgen not recommended (would leave loosely-coupled stubs; bug-label default also skips it). Quality loop on: multi-file status logic benefits from the QA→fix iteration. Order: land before #767 (shared batch-executor.ts).

  4. added
    planned
    on Jul 16, 2026
  5. admarble commented on Jul 16, 2026

    @admarble
    ContributorAuthor

    ✅ Exec complete — PR #772

    All three root causes fixed; the live card, summary table, and JSON log now agree on the same run.

    AC coverage

    AC Status Evidence
    AC-1 recovered phase → card reflects recovered state ✅ shared derive-from-slots; run-state.test.ts recovery test
    AC-2 both copies consolidated onto one source of truth ✅ status-derivation.ts#pipelineHasFailed consumed by orchestrator and renderer
    AC-3 card + table + log agree ✅ recovered-failure.integration.test.ts
    AC-4 all-partial run ≠ 0 passed · 0 failed ✅ new partial summary bucket + finalizeRunLog
    AC-5 partial not pinned by a recovered timeout ✅ deriveIssueLogStatus (latest-per-phase); log-writer 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

    Design

    Both status machines used to pin failed/partial and only ever escalate. Introduced a single pure source of truth, pipelineHasFailed(phases), consumed by the orchestrator card and the renderer (satisfies AC-2 without merging the two IssueState types). loop is excluded from the verdict — it's auxiliary recovery, and an unrecovered failure always leaves a non-loop phase failed, so excluding it never hides a real failure. The log mirrors this with deriveIssueLogStatus (latest attempt of each phase wins) and gains a partial column (surfaced in sequant logs + the MCP run response).

    Key files changed

    • src/lib/workflow/status-derivation.ts (new) — pipelineHasFailed shared helper
    • src/lib/workflow/run-orchestrator.ts — card derives (failed-event + allDone recompute)
    • src/lib/cli-ui/run-renderer.ts — renderer derives; maybeMarkIssueDone can de-escalate
    • src/lib/workflow/run-log-schema.ts — deriveIssueLogStatus + partial bucket
    • src/lib/workflow/log-writer.ts — derive issue status per phase log
    • src/lib/workflow/batch-executor.ts — log the loop phase
    • src/mcp/tools/run.ts, src/commands/logs.ts — surface partial

    Checks

    • npm run build ✅ · npm run lint ✅ (0 warnings)
    • src/lib/workflow/, src/lib/cli-ui/, src/mcp/, src/commands/ suites pass. One pre-existing unrelated flake (prompt-wait.test.ts, relay-inbox timer race) fails identically on the base tree.

    Known gaps / notes

    • Loose end from the issue (feat: lightweight content pre-flight for --chain (AC presence, dependency-order sanity) #762 detail cell Timeout after 1800s vs the API-drop last failure): not reproducible — run-renderer.ts:283 is already last-wins. Left untouched.
    • The live summary table counts a partial issue as failed (IssueResult.success === false); AC-4's 0 passed · 0 failed symptom was specific to the JSON log summary, which is fixed. Live-table partial styling was out of scope.
  6. admarble commented on Jul 16, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #766

    Verdict: AC_MET_BUT_NOT_A_PLUS — all 8 ACs functionally met, CI fully green, clean well-documented code. One concrete test-coverage improvement recommended (AC-6 call site) before this is A+.

    AC Coverage

    AC Description Status Evidence
    AC-1 Recovered phase → live card not failed MET pipelineHasFailed derive; run-state.test.ts recovery test → passed
    AC-2 Both copies covered / one source of truth MET Shared status-derivation.ts#pipelineHasFailed used by both run-orchestrator (failed-event + allDone) and run-renderer (failed-event + maybeMarkIssueDone); grep confirms no other issue-status pin sites
    AC-3 Card, table, log agree MET recovered-failure.integration.test.ts asserts card=passed, renderer=done, log=success for one sequence
    AC-4 All-partial run ≠ 0 passed · 0 failed MET New partial summary bucket (finalizeRunLog), surfaced in logs.ts + MCP run response; integration test
    AC-5 partial not pinned by a recovered timeout MET deriveIssueLogStatus latest-per-phase; log-writer de-escalation test
    AC-6 Loop phases in run log (phase/status/duration/error) MET* batch-executor.ts loop logPhase + integration test asserts fields — see coverage note below
    AC-7 qa fails twice then succeeds → passed everywhere MET Integration test
    AC-8 Loop failure then success → not-failed MET Orchestrator + renderer recovery tests
    Non-Goal #762 all-failed run stays red MET Negative guards in orchestrator, renderer, and integration suites

    Coverage: 8/8 ACs met + Non-Goal guarded.

    Quality Metrics

    Metric Value Status
    Type issues (any) added 0 OK
    Deleted tests 0 OK
    Files changed 16 (8 source, rest tests) OK
    Lines +646 / −23 (majority tests) OK

    CI Status (PR #772)

    Check State Impact
    build (22.x) SUCCESS MET
    typecheck SUCCESS MET
    validate-skills / validate-plugin / node-floor-guard SUCCESS MET

    All checks green. Local npm run build, npm run lint clean; 298 tests pass across the 8 affected suites.

    Test Coverage Analysis

    Changed source Has direct test?
    status-derivation.ts ✅ status-derivation.test.ts
    run-orchestrator.ts ✅ run-state.test.ts (recovery + #762 guard)
    run-renderer.ts ✅ run-renderer.test.ts (recovery + #762 guard)
    run-log-schema.ts ✅ run-log-schema.test.ts + status-derivation.test.ts
    log-writer.ts ✅ log-writer.test.ts
    batch-executor.ts (loop logPhase) ⚠️ No direct test — see below
    mcp/tools/run.ts ✅ run.test.ts
    commands/logs.ts (partial display) ⚠️ cosmetic; no logs.test.ts

    All changed files are Standard tier (workflow / cli-ui / logging) — no auth/payment/security/admin paths.

    Code Review

    Strengths:

    • AC-2 solved cleanly: one pure pipelineHasFailed helper is the single source of truth for both live state machines; the loop-exclusion rationale is documented and correct (an unrecovered failure always leaves a non-loop phase failed, so excluding loop never hides a real failure).
    • deriveIssueLogStatus (latest-per-phase, failure > timeout > success) mirrors the live-card rule, giving genuine three-way agreement rather than three ad-hoc fixes.
    • partial added with .default(0) — backward-compatible with logs written before the field (verified: validRunLog fixture without partial still parses).
    • Comments state intent + the specific bug each guards against.

    Issues: None blocking.

    Risk Assessment

    • Likely failure mode: A loop failure transiently sets the orchestrator card running (from the failed-event branch); safe because a loop only runs when iteration < maxIterations, so a subsequent iteration always fires a terminal event. Traced — no stuck-running path.
    • Not tested: The batch-executor loop-logging call site (AC-6). The integration test validates a loop entry at the writer/schema layer by calling writer.logPhase directly, but nothing drives runIssueWithLogging through a fail→loop→recover sequence and asserts the loop was logged — so deleting the new block would not fail any test.
    • Sibling sites considered: none — the "pin failed, never de-escalate" pattern lived only in the two named state machines + the log-writer, all three fixed. The metrics writer and summary table derive from IssueResult.success (completedSuccessfully), which was already correct; no third sticky-status machine exists.
    • Sibling-line audit: none — within each file, start sets running, and every terminal/allDone path now routes through the shared helper.

    Adversarial Re-Read

    Findings: Traced loop-exclusion correctness end-to-end (loop always followed by a terminal iteration; qa failure always logged before its loop, so deriveIssueLogStatus never mislabels a loop-only log); confirmed partial/passed/failed partition totalIssues exactly (IssueStatus is a 3-value enum) so no consumer invariant breaks; verified the #762 Non-Goal is guarded in all three suites and the fix never infers success from PR existence. One gap: AC-6's producer (the batch-executor.ts logWriter.logPhase(loopPhaseLog) block) is not exercised by any test — the mock infrastructure to assert it already exists in batch-executor.test.ts (logPhase / createPhaseLogFromTiming spies, lines 598/685).

    Status: Gaps Found

    Documentation

    Next Steps

    1. (Recommended before A+) Add a batch-executor.test.ts case that drives runIssueWithLogging through a qa-fail → loop → recover sequence (script mockExecutePhase fail-then-succeed) and asserts createPhaseLogFromTiming/logPhase was called with phase: "loop" — locks AC-6's call site, not just the writer-level behavior.
    2. Optional: a small logs.ts display test for the , N partial rendering.
    3. Run /docs 766 if desired (internal fix — likely N/A).

    Neither item blocks merge; both are polish that would take this to READY_FOR_MERGE.

  7. added
    needs-improvement
    on Jul 16, 2026
  8. admarble commented on Jul 16, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #766 (second pass — fresh session)

    Verdict: AC_MET_BUT_NOT_A_PLUS — confirms the prior verdict, but the AC-6 coverage gap is now proven by mutation test rather than asserted, and it is sharper than previously described: the test labelled (AC-6) does not exercise AC-6's production code at all.

    What I re-verified independently (not taken from the prior QA)

    The load-bearing claim of this PR is the loop-exclusion rule — "excluding loop never hides a genuine failure, since an unrecovered pipeline failure always leaves a non-loop phase failed too." If that claim is wrong, this fix turns red runs green, which is worse than the bug it fixes. I traced it end-to-end against batch-executor.ts rather than trusting the comment:

    • The loop only ever runs inside the else branch of if (result.success) (:1018), so a non-loop phase's slot is already failed at the moment any loop event fires. The nowFailed ? "failed" : "running" fallback in both machines is therefore unreachable for a loop failure — it cannot strand a card in running.
    • completedSuccessfully (:1119) is set only when an iteration completes with !phasesFailed — precisely when every non-loop slot is done and every phase's latest log entry is success. So the summary table cannot disagree with the two derived verdicts.
    • Loop-on-final-iteration (loop succeeds, while exits, work unverified) → qa slot stays failed → red on card, table, and log. Correct.
    • Turn-capped phases (feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739) skip the loop entirely and log failure → stays red.
    • IssueStatus is a 3-value enum, so passed + failed + partial === totalIssues exactly — the new bucket doesn't break the partition.

    The claim holds. The loop-exclusion rule is sound, and the three-way agreement is real rather than three coincidentally-aligned fixes.

    Also confirmed locally: build ✅, lint ✅ (0 warnings), 255 tests pass across the 7 affected suites, CI 5/5 green, PR #772 MERGEABLE, 0 commits behind main.

    AC Coverage

    AC Status Basis
    AC-1 recovered phase → card not failed MET pipelineHasFailed derive; run-state.test.ts recovery test
    AC-2 both copies on one source of truth MET status-derivation.ts#pipelineHasFailed consumed by orchestrator (:481, :517) and renderer (:282, :310); no other issue-status pin site remains
    AC-3 card + table + log agree MET Traced above; recovered-failure.integration.test.ts
    AC-4 all-partial ≠ 0 passed · 0 failed MET partial bucket in finalizeRunLog; logs.ts already labels this run PARTIAL and now prints , 1 partial
    AC-5 partial not pinned by a recovered timeout MET deriveIssueLogStatus latest-per-phase
    AC-6 loop phases in the run log MET (code) / untested (call site) Production code correct by reading; see finding below
    AC-7 qa fails twice → passed everywhere MET Integration test
    AC-8 loop failure then success → not-failed MET Orchestrator + renderer recovery tests
    Non-Goal: #762 all-failed stays red MET Guarded in all three suites; verified no path infers success from PR existence

    Coverage: 8/8 met.

    Finding — AC-6's producer is unverified (proven, not suspected)

    I commented out the one new line in batch-executor.ts that satisfies AC-6:

    -            logWriter.logPhase(loopPhaseLog);
    +            void loopPhaseLog; // MUTATION
    

    and re-ran batch-executor.test.ts + recovered-failure.integration.test.ts + status-derivation.test.ts:

    Test Files  3 passed (3)
         Tests  57 passed (57)
    

    The mutant survives. Deleting AC-6's entire implementation breaks nothing. (File restored; tree clean.)

    The reason is worth naming, because it's the more useful half of the finding: the test named it("logs the loop phase with phase/status/duration/error (AC-6)") calls writer.logPhase(phaseLog(issue, "loop", ...)) by hand. It asserts the schema round-trips a loop entry the test itself wrote — it never invokes the batch-executor block that is supposed to write one in production. The test's name claims coverage the test does not provide, which is worse than a plainly absent test: it makes the gap invisible to the next reader.

    The mock infrastructure to close this already exists in batch-executor.test.ts (logPhase / createPhaseLogFromTiming spies at :598 / :685).

    Secondary note (non-blocking)

    recovered-failure.integration.test.ts hand-drives the event sequence into the three machines rather than running them through batch-executor. I checked the assumed order against the real emission order (qa failure logged at :982 before the loop entry at :1057) and it matches, so the model is faithful today — but it would not catch a future divergence in batch-executor's emission order. Reasonable as-is; noting it so the coverage boundary is on record.

    On AC-3 and partial: a timeout-only run reads partial in the log but failed on the card and table. That is not a disagreement about pass/fail — all three agree the run did not pass — and AC-4 explicitly permits partial as its own column, so I score AC-3 as met.

    Self-Evaluation

    • Verified working: Yes — build/lint/tests executed, loop-exclusion soundness traced through the real control flow, AC-6 gap proven by mutation rather than inferred.
    • Test efficacy: High for the core fix (mutating pipelineHasFailed would fail status-derivation.test.ts immediately); zero for AC-6's call site.
    • Likely failure mode: A future refactor of the batch-executor loop block silently drops the loop logPhase and no test notices — reintroducing bug Doctor: Add Claude Code CLI check #3 exactly as it shipped originally.
    • Verdict confidence: High. The one gap is coverage, not correctness; the shipped behavior is right.

    Next Steps

    1. (Blocks A+) Add a batch-executor.test.ts case driving runIssueWithLogging through qa-fail → loop → recover, asserting createPhaseLogFromTiming/logPhase was called with phase: "loop". Verify it by re-running the mutation above — it must fail.
    2. Rename or fold the misleading (AC-6) integration test so it no longer claims producer coverage it doesn't have.
    3. Optional: a logs.ts display test for the , N partial rendering.

    Neither the code nor the design needs changing — this is test-coverage polish that would take #766 to READY_FOR_MERGE.

  9. admarble commented on Jul 16, 2026

    @admarble
    ContributorAuthor

    QA addendum — correcting my previous comment

    My prior comment ended with "neither the code nor the design needs changing — this is test-coverage polish." That was wrong, and I'm correcting it. Pushing on the one thing I'd left as inherited-by-default — the loose end in the issue's own Notes — turned up a real bug in a file this PR never touched.

    The loose end is real, and it was mis-dispositioned

    The issue asked:

    #762's summary detail cell read Timeout after 1800s, but its last failure was the API drop. failureReason is last-wins at run-renderer.ts:283, so the displayed reason should have been the API error. Worth a look while in here; not reproduced.

    Exec dispositioned this as "not reproducible — run-renderer.ts:283 is already last-wins. Left untouched." That conclusion is correct about run-renderer.ts:288 and irrelevant to the symptom, because the summary detail cell is not fed by that line. There are two independent failureReason paths:

    Path Feeds Semantics
    run-renderer.ts:288 the live card (:1236, :1273) last-wins ✅ (what exec checked)
    run-display.ts:87 → toIssueSummary the summary table cell (:1496) first-wins ❌ (the actual source)
    // src/commands/run-display.ts:87
    const failedPhase = r.phaseResults.find((p) => !p.success);

    .find() returns the first failing entry, and phaseResults accumulates every attempt across every quality-loop iteration (pushed at batch-executor.ts:582, :888, :1055). So for #762 — qa timeout, qa timeout, qa API-drop — the cell renders the first timeout and the last failure is never shown. That reproduces the reported symptom exactly. The issue author mis-attributed the cell to the renderer; exec then investigated that attribution rather than the symptom, and the real line was never looked at.

    This is the same bug family as #766 itself — stale first-attempt data surviving later attempts — in a fourth location, sitting in the summary table this PR is specifically making trustworthy. Fixing three sticky-status sites while the summary cell still prints a stale first-iteration reason leaves the headline goal ("all three outputs agree") half-delivered in practice.

    failedPhase also drives qaVerdict and unmetCount (:101-106), so those are stale first-iteration values too — and when the first failure is an exec (no verdict), a later qa's verdict is dropped from the summary entirely.

    The fix is small but not the one-liner the spec assumed

    The spec said "file a follow-up only if not a one-liner." Two constraints make findLast unavailable:

    1. findLast does not typecheck here. tsconfig.json sets "lib": ["ES2022"]; findLast is ES2023. Verified:
      error TS2550: Property 'findLast' does not exist on type '{ success: boolean; }[]'.
      Try changing the 'lib' compiler option to 'es2023' or later.
      
      (Node engine is >=22.12.0, so it's fine at runtime — this is purely the TS lib floor. Bumping lib is a wider change than this PR should make; a reverse scan keeps it local.)
    2. loop must be excluded, or a trailing loop failure becomes the displayed reason. This PR already owns that rule — reuse LOOP_PHASE from status-derivation.ts so the summary cell obeys the same loop-exclusion as the card and the log.

    Roughly:

    const failedPhase = [...r.phaseResults]
      .reverse()
      .find((p) => !p.success && p.phase !== LOOP_PHASE);

    run-display.test.ts already exists and currently asserts nothing about failureReason, so there's a home for the regression test.

    Either land it here (it's in scope — the issue asked, and it's the same bug family) or file a follow-up. What shouldn't stand is the current record saying "not reproducible," because it is reproducible and now root-caused.

    Revised A+ gap list

    1. run-display.ts:87 first-wins failureReason — real bug, root-caused above. Fix or file a follow-up with this attribution.
    2. AC-6's producer is untested — proven by mutation (mutant survives 57 tests); the test named (AC-6) hand-writes the loop entry and never invokes the batch-executor block.
    3. Cosmetic: no test for logs.ts's , N partial rendering.

    Verdict unchanged: AC_MET_BUT_NOT_A_PLUS (all 8 ACs still met — none of the above is an AC failure; #1 is a Notes item, #2 is coverage). But #1 means this is no longer "test polish only."

  10. added a commit that references this issue on Jul 16, 2026
  11. admarble commented on Jul 16, 2026

    @admarble
    ContributorAuthor

    Both gaps closed — 8d77d19 (PR #772)

    Verdict: READY_FOR_MERGE.

    1. run-display.ts:87 — first-wins failure reason (the real bug)

    -  const failedPhase = r.phaseResults.find((p) => !p.success);
    +  const failedPhase = [...r.phaseResults]
    +    .reverse()
    +    .find((p) => !p.success && p.phase !== LOOP_PHASE);

    Two details worth recording:

    • loop is excluded, reusing this PR's own LOOP_PHASE constant. Without it, a trailing loop failure becomes the displayed reason and masks the phase that actually failed — the summary would contradict the card and log, which already exclude loop. The fix now obeys one rule in all four places.
    • Reverse scan, not findLast. findLast is ES2023 and tsconfig.json pins "lib": ["ES2022"], so it doesn't compile (TS2550) even though the >=22.12.0 engine runs it fine. This is why the spec's "one-liner" estimate didn't hold.

    qaVerdict/unmetCount read from the same entry, so they tracked the first iteration too — a run that closed 2 of 3 gaps still reported 3. Fixed by the same change.

    2. AC-6's producer — now actually covered

    Three cases in batch-executor.test.ts drive runIssueWithLogging through a real fail → loop → recover sequence and assert the loop log reaches logPhase with phase/status/duration/error, plus the Timeout → timeout status mapping. The misleading integration test is renamed to "round-trips a hand-written loop entry through the writer and schema" — what it actually does — with a pointer to the producer test.

    Verified by mutation, not assertion

    Both fixes were re-mutated to confirm the new tests fail:

    × shows the last failing attempt's reason, not the first (#762's cell)
      AssertionError: expected 'Timeout after 1800s' to be 'API Error: Connection closed mid-resp…'
    × carries the latest attempt's qa verdict and unmet count, not the first
      AssertionError: expected 3 to be 1
    × logs a failed loop with phase, status, duration, and error
    × maps a timed-out loop to `timeout`, not `failure`
    × logs a successful loop on the recovery path (#760's shape)
    

    The first assertion is #762's reported symptom, now reproduced in a test — the loose end the issue asked about is no longer just root-caused, it's locked.

    Checks

    Remaining (non-blocking)

    Only the cosmetic item from before: no test for logs.ts's , N partial rendering. Not worth holding the PR.

  12. added
    ready-for-review
    and removed
    needs-improvement
    on Jul 16, 2026
  13. added 2 commits that reference this issue on Jul 16, 2026
  14. added 2 commits that reference this issue on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions