Skip to content

fix(run): status, PR-body QA note and MCP result use the first qa verdict — a looped AC_NOT_MET→NEEDS_VERIFICATION records ready_for_merge #1245

Closed

Description

@admarble

Tier: mechanical Found: 2026-09-30, QA of #1223 (PR #1240) and #1233 (PR #1239); tracker #1236 (closed). Revised the same day after a root-cause investigation: a third site was found and the impact statement was corrected.

Root cause. Two lists record one entry per attempt with no iteration index: phaseResults in runIssueWithLogging (every phaseResults.push: batch-executor.ts:1198, :1745, :2042) and the run log's issues[].phases[] (log-writer.ts:172; PhaseResult has no iteration field, types.ts:403-467). A quality-loop iteration re-runs the whole phase list (while at batch-executor.ts:1554), so a looped run holds [spec, exec, qa, loop, exec, qa]. Each consumer picks "first" or "latest" for itself. Several were already fixed one at a time with a hand-rolled reverse scan: deriveFailureCategory (batch-executor.ts:628-630), #1223's exec output (:2368-2370) and #766's scan in src/commands/run-display.ts. Three consumers still take the first match.

The three stale sites:

  1. batch-executor.ts:2235: const qaVerdict = phaseResults.find((p) => p.phase === "qa")?.verdict; decides the terminal status.
  2. batch-executor.ts:2363: the same expression, feeding the PR-body QA note (fix(run): AC_MET_BUT_NOT_A_PLUS QA verdict misrouted into quality loop → fails with no PR (should break to PR) #749).
  3. src/mcp/tools/run.ts:253: issue.phases.find((p) => p.phase === "qa") in the run log feeds the MCP sequant_run result's verdict, acMet/acTotal, gaps and findings (feat(mcp): sequant_run result carries each issue's QA summary and findings #1200).

Impact, which is worse than "stale". AC_NOT_MET fails the qa phase and triggers the loop. NEEDS_VERIFICATION counts as success (phase-executor.ts:1251-1269) and ends it (batch-executor.ts:2177-2179). So the sequence qa AC_NOT_MET → loop → qa NEEDS_VERIFICATION is reachable, and it:

No real log on this machine has a looped run with two qa entries, so reachability rests on reading the code. The ACs below prove it with fixtures.

AC

Deliberately unchanged: stats.ts:894 measures the first-pass qa rate on purpose, and ready-gate.ts:811-833 tracks its own final verdict.

Optional: tag PhaseResult/PhaseLog with iteration, so readers of the run log (for example jq '.issues[].phases[]|select(.phase=="qa")') stop inferring it from position.

Graph metadata

May touch

Activity

  1. added
    bug
    on Sep 30, 2026
  2. changed the title [-]fix(run): status and PR-body QA note use the first qa verdict, stale after a quality-loop iteration[/-] [+]fix(run): status, PR-body QA note and MCP result use the first qa verdict — a looped AC_NOT_MET→NEEDS_VERIFICATION records ready_for_merge[/+] on Sep 30, 2026
  3. admarble commented on Oct 3, 2026

    @admarble
    ContributorAuthor

    Runner context (2026-10-03, main @ 52395ca)

    The line numbers moved after #1247 and #1249 merged. Current sites:

    Prior fixes / producers: the issue already names the class (three hand-rolled fixes plus three stale sites) and the one-accessor owner. That is the right scope. The optional iteration field stays optional; if you add it, say so in the PR.

    Launch constraints:

    • No full npm test in exec or QA, since it hits the 30-minute phase wall and CI runs it. Run the AC's test files, npm run build and npx tsc --noEmit.
    • batch-executor.test.ts / run.test.ts queue child_process mocks in order. A new git call shifts them.
    • Commit WIP about every 10 minutes.
    • PR body: the closing line references this issue only. Every other issue gets Refs, with no closing keyword, even in examples.
    • If you add a gate-test AC, the mutation marker's failedTest starts with the test file path.
  4. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (4 ACs, 4 directories)

    AC Quality Check

    All four ACs are single-line with an Evidence: clause. Two notes:

    • AC-1's Evidence names a whole test file. Its fixture must fail on today's main and pass only after the fix. The [qa AC_NOT_MET, loop, qa NEEDS_VERIFICATION] run records ready_for_merge today, so that part is non-vacuous.
    • AC-4's "single-pass behaviour is unchanged" passes on current code by construction. It is a regression guard, not a gate. The new-accessor part is gated only by a structural check (see Derived ACs).

    Scope Assessment

    Non-Goals: ⚠️ No ## Non-Goals heading. "Deliberately unchanged" (stats.ts:894, ready-gate.ts:811-833) serves as the boundary. The optional iteration field is out of scope unless added deliberately.

    Metric Value Status
    Feature count 1 ✅
    AC items 4 ✅
    Directory spread 4 (lib/workflow, mcp/tools, commands, shared helper) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: Shared accessor; terminal status uses the latest qa verdict

    Verification: Unit + Integration Test (batch-executor.test.ts)
    Scenario: Given phaseResults [qa AC_NOT_MET, loop, qa NEEDS_VERIFICATION] → When the issue finishes → Then status is awaiting_verification.
    Assumptions: latestPhaseResult already exists (#1249, batch-executor.ts:660). The work is to move and generalize it, not to write a second one.

    AC-2: PR-body QA note carries the latest verdict

    Verification: Integration Test
    Scenario: Same fixture → Then the post-QA createPR call's qaVerdict argument is NEEDS_VERIFICATION. The after-exec call passes none. batch-executor.test.ts already models the two-call shape in its #1247 AC-5 block.

    AC-3: MCP result uses the latest qa entry

    Verification: Unit Test (run.test.ts)
    Scenario: Given a RunLog issue with two qa PhaseLogs → Then verdict, acMet/acTotal, gaps and findings come from the second entry.

    AC-4: Hand-rolled reverse scans use the shared helper

    Verification: Regression Test (existing suites) plus a structural grep
    Scenario: deriveFailureCategory, the run-display.ts failed-phase scan (~:105), and buildRateLimitHaltNotice (~:160) call the shared helper. #972, #749 and #1200 tests stay green.

    Implementation Plan

    Phase 1: Shared helper

    1. Create a small module (for example src/lib/workflow/latest-phase.ts) holding a generic latestPhaseResult<T extends { phase: string }>(items: readonly T[], phase). Add a latestWhere(items, predicate) sibling for the "last failing non-loop" scans. Both use a reverse scan, since findLast is ES2023 and the tsconfig pins ES2022.
    2. batch-executor.ts: import it and re-export latestPhaseResult so the feat(qa): enforce the follow-up ledger — every deferred item resolves to filed/fixed/dropped; sibling scans search the defect class #1249 call sites and tests keep working. Add a unit test file for the helper.

    Phase 2: Switch the stale readers (order matters, batch-executor.ts regions overlap #1246)

    1. batch-executor.ts:2394 (terminal status) and :2513 (PR-body QA note) use the latest qa result.
    2. src/mcp/tools/run.ts:253 uses the helper on issue.phases, so verdict and summary come from one entry.
    3. Replace the hand-rolled scans in deriveFailureCategory and in run-display.ts (both sites).

    Phase 3: Tests

    1. Add the loop fixture to batch-executor.test.ts (AC-1 and AC-2). Do not add git calls, because child_process mocks are queued in order.
    2. Add the two-qa-entry RunLog case to run.test.ts (AC-3).
    3. Run npx vitest run on the AC files, npm run build and npx tsc --noEmit. Skip the full npm test (30-minute wall; CI runs it).

    Design Review

    1. Where does this belong? A leaf helper in src/lib/workflow/, imported by batch-executor, mcp/tools and commands. It must not live in batch-executor.ts, because run.ts importing the whole orchestrator is the wrong dependency direction.
    2. Simplest correct approach? One generic reverse-scan helper plus a predicate form. Rejected: tagging every result with iteration (the issue marks it optional, and positional "latest" is enough for all consumers).
    3. Pattern and recurrence? The "first vs latest attempt" class was already fixed by hand in fix: recovered phase failure still reports failed — live card, summary, and log disagree #766 (display), fix(pr): sequant run PRs double the conventional prefix in the title and ship a placeholder body #1223 (exec output), feat(qa): enforce the follow-up ledger — every deferred item resolves to filed/fixed/dropped; sibling scans search the defect class #1249 (accessor) and deriveFailureCategory. That is ≥2 prior fixes, so this issue fixes the class with one helper rather than adding another local patch. This matches the issue's scope. The leftover class members, stats.ts:894 and ready-gate.ts, are deliberate and named.
    4. Reviewer challenge? "Why not findLast?" ES2022 target. "Why does AC-4 need a predicate form?" See Open Questions.
    5. Producers and consumers. Producers of the two lists: three phaseResults.push sites in batch-executor.ts and log-writer.ts:172, which maps one to the other. Consumers: the three stale sites plus the four scans above. A whole-repo grep for .find((p) => p.phase === should be re-run in exec to catch stragglers outside the listed files.

    Feature Quality Planning

    Standard checks pass. Notable items:

    • Mutation verification: if the helper test or loop fixture is a gate test, record the Mutation-verified: marker with failedTest starting with the test file path.
    • Reachability rests on code reading. The fixtures are the proof, so they must be built from real PhaseResult shapes.

    Derived ACs

    Source Derived AC Priority
    Class fix AC-5: No phaseResults.find((p) => p.phase === "qa") or phases.find(... "qa") remains in src/ outside the "deliberately unchanged" files. Evidence: grep -rn 'find((p) => p.phase === "qa")' src/ --include=*.ts returns only stats.ts Medium

    Open Questions

    1. AC-4 says the scans "use the same accessor", but they are not per-phase lookups. They find the last failing non-loop result across all phases. Recommendation: add the predicate-form helper (latestWhere) next to latestPhaseResult in the same module, and treat that as satisfying AC-4. Impact if wrong: forcing them through a per-phase accessor changes behaviour.
    2. Optional iteration field on PhaseResult/PhaseLog. Recommendation: skip it. It changes the run-log schema for no consumer in this fix. Impact: none for the ACs.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Mechanical bug fix with unit and integration ACs. There is no UI, and testgen adds little because the fixtures are specified in the ACs. The #1249 accessor already exists, so the change is small. Tell exec to skip the full suite.

    Label Review

    Current: bug
    Recommended: bug (no change)
    Reason: Matches the plan.
    Quality Loop: Won't auto-enable.

  5. added
    planned
    on Oct 4, 2026
  6. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 5/5 met

    Gaps:

    • latestPhaseResult's phase parameter is (was ), so a misspelled phase name type-checks — dropped: polish only, no runtime effect

    Needs human review:

    • Required CI check was still pending at review time; re-run QA after it reports
  7. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Runner verification and follow-up ledger (PR #1294)

    • Tests: the AC test files pass (46 files, 921 tests), and tsc is clean.
    • Reversion checks: reverting each of the three fixed sites to .find() fails exactly that AC's new test. Details are in the PR body.
    • QA's NEEDS_VERIFICATION came from the CI test check still running at review time (see the CI result on the PR).

    Ledger

  8. added a commit that references this issue on Oct 19, 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

    bugplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions