Skip to content

Quality loop retries misclassified as cold-start failures, wasting retry budget #488

Closed

Description

@admarble

Problem

When QA returns AC_NOT_MET, the quality loop retries consistently fail and burn the entire retry budget on doomed invocations. This was observed on a real run (bf4b66d0, issue #125 in the workout project) and is reproducible for any issue where QA finds unimplemented ACs.

Failure chain

  1. QA fails with AC_NOT_MET (5m 19s — genuine work)
  2. Quality loop invokes /loop with bare prompt: "Parse test/QA findings for GitHub issue #N and iterate until quality gates pass."
  3. /loop runs for ~51s — Claude Code starts, skill tries to parse QA findings from GitHub comments, but exits with code 1
  4. 51s < 60s cold-start threshold → executePhaseWithRetry misclassifies this as a cold-start failure and retries
  5. Cold-start retries fail the same way → MCP fallback fires → also fails
  6. Loop phase exhausted → next quality loop iteration starts from testgen
  7. testgen also fails in ~47-49s with exit code 1 → same misclassification cascade
  8. All 3 iterations burned on retries that can never succeed

Root causes

1. The /loop prompt has no context (phase-executor.ts:36)

The prompt is a single line. The /loop skill must reconstruct all context by fetching QA findings from GitHub comments via gh issue view, but it's running in a new Claude Code subprocess with no prior session. If the gh call fails or comment format doesn't match, it crashes. The QA verdict, failed ACs, and specific findings should be passed directly in the prompt or via env vars.

2. Cold-start threshold catches real failures (phase-executor.ts:105,570)

The 60s threshold was tuned for initialization failures (empirically 15-39s). But loop/testgen retries that fail at 47-51s fall in the same bucket, triggering up to 2 cold-start retries + 1 MCP fallback = 3 extra doomed invocations per phase. For a 3-iteration quality loop, that's 9+ wasted Claude Code spawns.

Impact

  • Users see a wall of ✖ failures with unhelpful "Claude Code process exited with code 1" errors
  • Entire quality loop budget wasted — no fixes are ever attempted
  • Each wasted spawn costs ~50s of wall time + API usage
  • The "retrying without MCP" message is misleading — MCP isn't the problem

Proposed fixes

1. Enrich the loop prompt (high impact)

At batch-executor.ts:853, pass the QA verdict and failed ACs directly into the prompt. The QA phase result already has the verdict field; the issue comment body could be fetched once and injected as context. This eliminates the round-trip through GitHub that causes the skill to crash.

2. Distinguish loop failures from cold-starts (medium impact)

Options:

  • Skip cold-start retries for loop phase (it's always a re-run, never a first boot)
  • Use a phase-aware threshold (loop/testgen retries in quality loop context aren't cold-starts)
  • Track whether the failure is a retry of a previously-failed phase

3. Pass last phase result via env vars (low effort)

Add SEQUANT_LAST_VERDICT and SEQUANT_FAILED_ACS env vars so the loop skill doesn't need to reconstruct context from GitHub comments.

Relevant code

  • Phase prompts: src/lib/workflow/phase-executor.ts:25-39
  • Cold-start threshold: src/lib/workflow/phase-executor.ts:105
  • Cold-start retry logic: src/lib/workflow/phase-executor.ts:548-587
  • MCP fallback: src/lib/workflow/phase-executor.ts:592-636
  • Quality loop invocation: src/lib/workflow/batch-executor.ts:830-898
  • Loop skill: .claude/skills/loop/SKILL.md

Acceptance Criteria

  • /loop phase receives QA findings directly (verdict + failed ACs) rather than reconstructing from GitHub
  • Quality loop retry failures (47-51s) are not misclassified as cold-start failures
  • Wasted Claude Code spawns reduced from 9+ to ≤1 per quality loop iteration
  • MCP fallback does not trigger for non-MCP failures
  • Quality loop can actually fix issues when ACs are unmet (the core purpose of the feature)

Activity

  1. added
    bug
    on Apr 5, 2026
  2. added a commit that references this issue on Apr 6, 2026
  3. admarble commented on Apr 6, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #488
    Status: READY_FOR_MERGE

    AC Coverage

    AC Status
    /loop receives QA findings directly (verdict + gaps) ✅ MET
    Quality loop retry failures (47-51s) not misclassified as cold-start ✅ MET
    Wasted Claude Code spawns reduced from 9+ to ≤1 per quality loop iteration ✅ MET
    MCP fallback does not trigger for non-MCP failures ✅ MET
    Quality loop can actually fix issues when ACs are unmet ✅ MET

    Summary

    • executePhaseWithRetry now skips cold-start retry loop and MCP fallback for loop phase
    • Loop prompt enriched with QA verdict, gaps, suggestions, and output tail via promptContext
    • SEQUANT_LAST_VERDICT and SEQUANT_FAILED_ACS env vars propagated to skills
    • 4 new tests added, 72/72 total passing

    Quality Metrics

    • Build: PASS
    • Type safety: No issues
    • Tests: 72/72 passed
    • Scope: 4 files, +211/-26

    Iterations

    • Test loop: 0 (all passed first try)
    • QA loop: 0 (all passed first try)

    PR: #489


    Ready for human review and merge.

  4. admarble commented on Apr 6, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #488

    PR: #489 — fix(#488): prevent loop phase retry misclassification as cold-start
    Commit: 9bfea4d | Branch: feature/488-quality-loop-retry-misclassification
    Scope: 4 files, +211/-26 lines


    Size Gate

    Check Value
    Diff size 237 lines (threshold: 100)
    package.json changed No
    Security-sensitive paths No
    Decision Sub-agents

    AC Coverage

    AC Description Status Notes
    AC-1 /loop receives QA findings directly (verdict + gaps) MET buildLoopContext() enriches prompt with verdict, gaps, suggestions, error, output tail. SEQUANT_LAST_VERDICT and SEQUANT_FAILED_ACS env vars also set.
    AC-2 Quality loop retry failures (47-51s) not misclassified as cold-start MET skipColdStartRetry = phase === "loop" gates single-attempt path. Test at line 952 verifies.
    AC-3 Wasted Claude Code spawns reduced from 9+ to ≤1 per quality loop iteration MET Single attempt per loop iteration — no cold-start retries, no MCP fallback.
    AC-4 MCP fallback does not trigger for non-MCP failures MET !skipColdStartRetry guard at line 637 prevents MCP fallback for loop phase. Test at line 973 verifies.
    AC-5 Quality loop can actually fix issues when ACs are unmet MET Enriched prompt passes verdict, gaps, suggestions, error, and output tail directly to /loop skill — no round-trip through GitHub.

    Coverage: 5/5 AC items fully met


    Quality Plan Verification

    N/A — No quality plan found in issue comments


    CI Status

    Check State Bucket Impact
    build (22.x) FAILURE fail Pre-existing (same failure on main 733bf55)
    build (20.x) CANCELLED cancel Pre-existing
    typecheck SUCCESS pass ✅
    validate-plugin SUCCESS pass ✅
    validate-skills SUCCESS pass ✅

    CI Summary: 3 passed, 2 pre-existing failures (verified against main)
    CI-related AC items: None


    Build Verification

    Check Status
    Feature branch build (tsc) ✅ Passed
    Feature branch tests ✅ 72/72 passed
    Main branch build ❌ Failed (same src/mcp/tools/run.ts errors)
    Regression No (pre-existing on main)

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 4 OK
    Lines added +211 -
    Lines deleted -26 -
    Security patterns 0 OK

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/phase-executor.ts Standard ✅ Yes phase-executor.test.ts (4 new tests)
    src/lib/workflow/batch-executor.ts Standard ✅ Yes batch-executor.test.ts (existing)
    src/lib/workflow/types.ts Optional N/A Types-only, no runtime logic
    src/lib/workflow/phase-executor.test.ts N/A - Test file itself

    Coverage: All changed source files have corresponding tests
    Critical paths without tests: None


    Code Review

    Strengths:

    • Clean architecture: buildLoopContext() is a pure function composing prompt context from PhaseResult
    • Defensive coding: null checks on verdict, summary.gaps, summary.suggestions, error, output
    • Prompt bloat prevention: slice(-2000) truncates output tail
    • Three new tests cover all key behaviors: skip cold-start retry, skip MCP fallback, success on first attempt
    • getPhasePrompt test verifies end-to-end context propagation
    • Good comments referencing Quality loop retries misclassified as cold-start failures, wasting retry budget #488 throughout — clear audit trail

    Issues: None blocking.

    Suggestions:

    • The 2000-char output tail limit is hardcoded (slice(-2000)). Consider extracting to a named constant for discoverability — not blocking.

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on call counts and result shape, not internals
    Coverage Depth ✅ OK Covers failure (no retry), success, and MCP skip paths
    Mock Hygiene ✅ OK Only executePhaseFn injected — minimal mocking
    Test Reliability ✅ OK No timing deps; mock-based, deterministic

    Anti-Pattern Detection

    No anti-patterns detected:

    • No N+1 queries
    • No empty catch blocks
    • No hardcoded secrets
    • No security-sensitive patterns in added lines

    CLI Registration Verification

    Option files modified: Yes (types.ts — ExecutionConfig interface)

    Interface Field Runtime Usage CLI Registered Status
    promptContext config.promptContext (internal) N/A ⏭️ SKIP (internal-only, no mergedOptions usage)
    lastVerdict config.lastVerdict (internal) N/A ⏭️ SKIP (internal-only, no mergedOptions usage)
    failedAcs config.failedAcs (internal) N/A ⏭️ SKIP (internal-only, no mergedOptions usage)

    Verification Status: N/A — all new fields are internal-only (set programmatically in batch-executor.ts, not user-facing)


    Call-Site Review

    N/A — No new exported functions. buildLoopContext() is module-private.


    Self-Evaluation

    • Verified working: Yes — build passes (tsc --noEmit), 72/72 tests pass, reviewed all code paths
    • Test efficacy: High — tests directly verify the core behavior (single attempt for loop, no MCP fallback)
    • Likely failure mode: If a future phase is added that also shouldn't retry (like a hypothetical "merge" retry), the hardcoded phase === "loop" check wouldn't cover it. A set/config approach would be more extensible, but YAGNI for now.
    • Verdict confidence: High — the fix is surgical and well-tested

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: commit — affects quality loop behavior)
    [Unreleased] entry ❌ Missing

    CHANGELOG: Missing entry for user-facing bug fix. Add to ## [Unreleased] → ### Fixed section before merging.


    Verdict: AC_MET_BUT_NOT_A_PLUS

    All 5 ACs are fully met. Code is clean, well-tested, and architecturally sound. The fix is surgical — only the loop phase behavior changes, existing retry logic for other phases is untouched.

    Blocking merge: Missing CHANGELOG entry for this user-facing bug fix.

    Next Steps

    1. Add CHANGELOG entry under ## [Unreleased] → ### Fixed:
      - Fix quality loop retry misclassification — loop phase failures no longer trigger cold-start retries or MCP fallback, reducing wasted Claude Code spawns from 9+ to 1 per iteration (#488)
      
    2. Merge after CHANGELOG is added

    Documentation: Before merging, run /docs 488 to generate feature documentation.

  5. added
    needs-improvement
    on Apr 6, 2026
  6. added a commit that references this issue on Apr 6, 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

    bugneeds-improvement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions