Skip to content

bug: Quality loop never triggers - QA verdict not parsed #218

Closed

Description

@admarble

Summary

The quality loop (--quality-loop) never triggers because QA phase success is determined by whether the SDK query completed, not whether the QA verdict passed.

Related Issues

Issue Status What it addressed Why insufficient
#143 CLOSED Made QA skill require execution evidence Skill outputs better verdicts, but CLI doesn't parse them
#171 CLOSED Made QA skill stricter about verdict criteria Same - skill is stricter, but CLI ignores the verdict

Root cause: Those fixes made the QA skill stricter, but run.ts never parses the verdict. Even if QA correctly outputs "AC_NOT_MET", the CLI marks it as success because the SDK query completed.

Design Assumption

The workflow assumes:

  1. exec either completes or errors out
  2. QA is the gate that catches incomplete/poor work
  3. loop fixes issues QA finds

The broken link is between QA and loop - QA finds issues but loop never triggers.

Root Cause

In src/commands/run.ts line ~1012:

if (resultMessage.subtype === "success") {
  return {
    phase,
    success: true,  // Always true if SDK query completed
    ...
  };
}

The SDK's subtype: "success" means "the query finished without errors" - it says nothing about whether QA found gaps or the verdict was passing.

Current Behavior

QA Output SDK Status Phase Result Loop Triggers?
"READY_FOR_MERGE" success success No (correct)
"AC_MET_BUT_NOT_A_PLUS" success success ❌ No ❌
"AC_NOT_MET" success success ❌ No ❌

Evidence

From logs (.sequant/logs/run-2026-01-31*.json):

  • qualityLoop: true is enabled
  • All phases show status: "success"
  • No loop phase ever appears
  • User reports always finding gaps when running /qa manually after sequant run

This matches the evidence from #143: "34 run logs: zero show /loop triggered"

Expected Behavior

For QA phase specifically, parse the output for verdict and only mark as success if READY_FOR_MERGE:

QA Verdict Phase Result Loop Triggers?
"READY_FOR_MERGE" success No
"AC_MET_BUT_NOT_A_PLUS" failure Yes
"AC_NOT_MET" failure Yes

Proposed Fix

Add verdict parsing after QA phase in executePhase or the calling code:

// After executePhase for QA
if (phase === "qa" && phaseResult.success && phaseResult.output) {
  const verdict = parseQaVerdict(phaseResult.output);
  if (verdict && verdict !== "READY_FOR_MERGE") {
    phaseResult.success = false;
    phaseResult.error = `QA verdict: ${verdict}`;
  }
}

Parse function:

function parseQaVerdict(output: string): string | null {
  // Look for "### Verdict: X" or "**Verdict:** X" or "Verdict: X"
  const verdictMatch = output.match(
    /(?:###?\s*)?(?:\*\*)?Verdict(?:\*\*)?:?\s*\**\s*(READY_FOR_MERGE|AC_MET_BUT_NOT_A_PLUS|AC_NOT_MET)/i
  );
  return verdictMatch?.[1]?.toUpperCase().replace(/_/g, '_') || null;
}

Acceptance Criteria

  • AC-1: Add parseQaVerdict() function to parse QA output for verdict
  • AC-2: QA phase only marked as success if verdict is READY_FOR_MERGE
  • AC-3: Non-passing verdict triggers quality loop when --quality-loop is enabled
  • AC-4: Add unit tests for verdict parsing (various formats)
  • AC-5: Log files show loop phase when QA verdict is not READY_FOR_MERGE
  • AC-6: Logs include the parsed verdict in phase metadata

Test Cases for Verdict Parsing

// Should parse
"### Verdict: READY_FOR_MERGE" → "READY_FOR_MERGE"
"**Verdict:** AC_NOT_MET" → "AC_NOT_MET"
"Verdict: AC_MET_BUT_NOT_A_PLUS" → "AC_MET_BUT_NOT_A_PLUS"

// Edge cases
"verdict: ready_for_merge" → "READY_FOR_MERGE" (case insensitive)
"No verdict found" → null (don't fail, just don't trigger loop)

Priority

High - This is a fundamental feature that has never worked. Users expect quality loop to catch gaps but it never does. Previous fixes (#143, #171) addressed the symptom in the skill but not the root cause in the CLI.

Activity

  1. admarble commented on Jan 31, 2026

    @admarble
    ContributorAuthor

    📋 Implementation Plan for #218

    Acceptance Criteria

    • AC-1: Add parseQaVerdict() function to parse QA output for verdict
    • AC-2: QA phase only marked as success if verdict is READY_FOR_MERGE
    • AC-3: Non-passing verdict triggers quality loop when --quality-loop is enabled
    • AC-4: Add unit tests for verdict parsing (various formats)
    • AC-5: Log files show loop phase when QA verdict is not READY_FOR_MERGE
    • AC-6: Logs include the parsed verdict in phase metadata

    Verification Methods

    AC Method Key Scenario
    AC-1 Unit Test Parse "### Verdict: X" → returns verdict string
    AC-2 Unit + Integration QA with AC_NOT_MET verdict → success: false
    AC-3 Integration Non-passing verdict + --quality-loop → /loop executes
    AC-4 Unit Test All formats from issue body parsed correctly
    AC-5 Integration Log JSON contains "phase": "loop" entry
    AC-6 Unit + Integration PhaseLog.verdict field populated

    Implementation Steps

    Phase 1: Verdict Parser

    1. Add parseQaVerdict() in src/commands/run.ts
    2. Unit tests for all verdict formats

    Phase 2: Integration
    3. Modify executePhase() to parse verdict for QA phase
    4. Mark QA as failure when verdict ≠ READY_FOR_MERGE

    Phase 3: Logging
    5. Extend PhaseLogSchema with verdict field
    6. Update createPhaseLogFromTiming() to include verdict
    7. Pass verdict through logging calls

    Phase 4: Verification
    8. Integration test: verify loop triggers on non-passing verdict

    Files to Modify

    • src/commands/run.ts - Add parser, modify executePhase
    • src/commands/run.test.ts - Add verdict parsing tests
    • src/lib/workflow/run-log-schema.ts - Add verdict field
    • src/lib/workflow/log-writer.ts - Pass verdict to logs

    Assumptions

    • NEEDS_VERIFICATION verdict treated as success (no loop trigger)
    • Missing verdict treated as success (backwards compatible)

    Plan generated by /spec

  2. added
    bug
    cli
    planned
    on Jan 31, 2026
  3. added a commit that references this issue on Jan 31, 2026
  4. admarble commented on Jan 31, 2026

    @admarble
    ContributorAuthor

    QA Review Complete ✅

    Verdict: READY_FOR_MERGE

    All 6 acceptance criteria are met. The implementation correctly fixes the root cause by parsing the QA verdict from output rather than relying on SDK completion status.

    AC Coverage

    AC Status
    AC-1: Add parseQaVerdict() function ✅ MET
    AC-2: QA phase success based on verdict ✅ MET
    AC-3: Non-passing verdict triggers loop ✅ MET
    AC-4: Unit tests for parsing ✅ MET
    AC-5: Log files show loop phase ✅ MET
    AC-6: Logs include verdict metadata ✅ MET

    Quality Metrics

    • Type issues: 0
    • Deleted tests: 0
    • Files changed: 5
    • Lines: +234/-4
    • Test coverage: All changed files with logic have tests

    CI Status

    5/6 checks passed, 1 pending (build 18.x)

    Highlights

    • Well-documented parseQaVerdict() with comprehensive regex
    • 15 unit tests covering all verdict formats
    • Backwards compatible (missing verdict = success)
    • Properly extends TypeScript types throughout

    PR: #221


    QA generated by /qa

  5. added
    ready-for-review
    on Jan 31, 2026
  6. admarble commented on Jan 31, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete ✅

    Issue: #218
    Status: READY_FOR_MERGE

    Summary

    • AC: 6/6 met
    • Tests: 92 passed (run.test.ts + log-writer.test.ts)
    • CI: 6/6 checks passed
    • Build: ✅ Succeeded

    Iterations

    • Spec: 1
    • Exec: 1
    • QA: 1 (lint fix required)

    Key Changes

    1. Added parseQaVerdict() function to parse verdict from QA output
    2. Modified executePhase() to check verdict for QA phase
    3. Extended PhaseResult, PhaseLogSchema with verdict field
    4. Added 15 unit tests for verdict parsing

    PR: #221


    Ready for human review and merge.

  7. admarble commented on Feb 1, 2026

    @admarble
    ContributorAuthor

    Merged & Verified ✅

    PR #221 merged and smoke tested.

    Post-Merge Verification

    Check Status
    PR merged ✅ Squash merged
    Build passes ✅ npm run build succeeds
    parseQaVerdict() works ✅ 3/3 runtime tests pass
    CLI functional ✅ sequant doctor passes

    What's Fixed

    When running sequant run --quality-loop, the CLI now:

    1. Parses QA verdict from output (e.g., ### Verdict: AC_NOT_MET)
    2. Marks QA as failure if verdict is not READY_FOR_MERGE or NEEDS_VERIFICATION
    3. Triggers /loop phase to fix issues (was never triggering before)
    4. Logs verdict to .sequant/logs/*.json for debugging

    Breaking Change?

    No. Backwards compatible:

    • Missing verdict → treated as success (same as before)
    • READY_FOR_MERGE / NEEDS_VERIFICATION → success
    • AC_NOT_MET / AC_MET_BUT_NOT_A_PLUS → failure (triggers loop)

    Closing issue.

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