Skip to content

feat(run): the quality loop halts on a second consecutive AC_NOT_MET — its own counter, no ladder needed; maxIterations stays 3 #1646

Closed

Description

@admarble

Epic: graph-2026-11-simplify Tier: judgment Execution: split Blocked by: #1645

Problem

D-2: keep maxIterations 3 and halt when AC_NOT_MET repeats (the #1162 rule). On matcha-maps #1162 the loop ran four exec passes into four AC_NOT_MET verdicts and fixed nothing; on fixture #34 (E7) one fix pass turned the verdict's named catch into a commit in 8 of 8 pairs. One pass on a refusal is supported; a second pass after a second refusal is not.

Today the only stop on that pattern is the divergence-suspect halt in batch-executor.ts (two consecutive divergence-suspect iterations), and its own comment says it is "reachable only with a ladder configured". D-1 removes the ladder in #1647, which deletes the halt's feed. qa-stagnation.ts stops a re-run at the same SHA with no diff, which is not #1162's pattern (each pass made a diff). Founding doc §4, P-1, P-2, P-3.

Decisions

ID Decision Rejected
H-1 A counter on the QA verdict in the quality loop: two consecutive AC_NOT_MET verdicts stop the loop before the next /loop spawn. Any other verdict, or no parsed verdict, resets it reusing consecutiveDivergenceSuspect (fed only with a ladder; #1647 deletes the feed)
H-2 The run log records the stop the way #1254 records a ladder halt: the issue's abortReason begins ac_not_met_repeated, its evidenceBundle carries both verdicts' SHAs and failed AC ids, and the error category enum gains ac_not_met_repeated beside ladder_halt (additive, version: 1) a new bundle format or top-level field
H-3 sequant run and MCP sequant_run (same executor) only; the ready gate's loop is unchanged (D-2) applying it to the ready gate

Prior fixes / producers

Acceptance Criteria

  • AC-1: Two consecutive AC_NOT_MET verdicts stop the loop with halt reason ac_not_met_repeated, with no ladder configured, and a single AC_NOT_MET followed by a passing verdict does not; a null verdict between two refusals resets the count. Evidence: npx vitest run src/lib/workflow/batch-executor.repeat-halt.test.ts → ≥ 4 passed, 0 failed
  • AC-2: The run log schema accepts the ac_not_met_repeated category with its abortReason and evidenceBundle, and every existing run log fixture still validates. Evidence: npx vitest run src/lib/workflow/run-log-schema.test.ts -t "ac_not_met_repeated" → ≥ 1 passed, 0 failed
  • AC-3: The default stays 3. Evidence: grep -c 'maxIterations: z.number().positive().default(3)' src/lib/settings.ts → 1 (constraint)
  • AC-4: The run command reference documents the halt. Evidence: grep -c 'ac_not_met_repeated' docs/reference/run-command.md → ≥ 1
  • AC-5: The changelog records the change. Evidence: awk '/^## \[Unreleased\]/,/^## \[[0-9]/' CHANGELOG.md | grep -c 'ac_not_met_repeated' → ≥ 1
  • AC-6: No skill-directory edits. Evidence: git diff --name-only $(git merge-base origin/main HEAD)..HEAD | grep -cE '^(plugin/|\.claude/skills/|templates/skills/)' → 0 (constraint)

isGateTestEvidence classifies none of these ACs as a gate (parse-check, 2026-11-04). AC-1 is behaviour; its real-run half is #1655 (Execution: split).

May touch

src/lib/workflow/batch-executor.ts (the quality loop and its iteration state only), src/lib/workflow/batch-executor.repeat-halt.test.ts (new), src/lib/workflow/run-log-schema.ts and test, src/lib/workflow/log-writer.ts, src/lib/workflow/types.ts, docs/reference/run-command.md (the quality-loop section only), CHANGELOG.

Non-Goals

Done when

A sequant run -Q whose QA refuses twice in a row stops after the second refusal and says why in the run log, with no ladder configured.

Activity

  1. added
    graph-2026-11-simplify
    on Nov 7, 2026
  2. admarble commented on Nov 8, 2026

    @admarble
    ContributorAuthor

    Runner context (graph-2026-11-simplify W1, 2026-11-07). Read this before planning.

    • Founding doc: docs/internal/graph-2026-11-simplify/PROJECT-DISCUSSION.md on main (7337cdd39). Invariants I-1 to I-7 bind this issue. I-1: no edits under plugin/, .claude/skills/ or templates/skills/. The freeze lifted on 2026-11-06, but I-1 stays this graph's scope.
    • Exec phase and qa phase, both: run the full suite at most once, in the foreground, with timeout, after a WIP commit. Run targeted npx vitest run <file> for everything else. Every MCP or CLI phase has a 30-minute wall.
    • Each AC's Evidence: command is run verbatim by QA and by the runner. Run them yourself before reporting done; don't reason them done.
    • Gate tests ship with the Mutation-verified: record in the PR body (CLAUDE.md). Use sequant mutation begin | check | render where it fits.
    • Changelog: PR feat(#1351): improve(release): changelog fragments instead of a shared [Unreleased] block — 121/192 main commits touch CHANGELOG.md #1370 (changelog fragments under changelog.d/) is open and active. If it has merged on main when you start, follow changelog.d/README.md instead of editing CHANGELOG.md, and say in the PR body that the changelog AC needs rewording. The runner rewords it on the issue; don't skip the entry.
    • This issue: the halt is a counter on the QA verdict, independent of ladderState and iterationStartSnapshot (founding doc P-1, P-2). chore(cli)!: remove the model ladder and effort escalation — modules, --model-ladder and --escalate-effort on run and ready, their settings and docs; old logs and settings still load #1647 deletes the ladder next and needs this halt to stand on its own. The ready gate's loop is out of scope (H-3). If the cleanest owner of "stop the loop" turns out to be somewhere other than the quality loop in batch-executor.ts, stop and surface it in the spec comment; don't patch locally.
    • OQ-2: count the run logs in .sequant/logs/ that hold two consecutive AC_NOT_MET qa verdicts in one issue's loop, and put the count and the command in the PR body. No AC depends on it.
  3. admarble commented on Nov 8, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (6 ACs, 3 directories)

    AC Quality Check

    lintAcceptanceCriteria: 6/6 pass. All six declare Evidence:. Baseline on main 7337cdd39: AC-1 fails today (the test file does not exist). AC-2 fails today (-t "ac_not_met_repeated" matches 0 tests, so 83 are skipped). AC-4 and AC-5 return 0. AC-3 and AC-6 are constraints that pass today, as the issue says. None of the Evidence commands is vacuous.

    Scope Assessment

    Non-Goals: present (no change to the maxIterations default, the ready gate or qa-stagnation.ts; no ladder removal; no skill edits).

    Metric Value Status
    Feature count 1 ✅
    AC items 6 ✅
    Directory spread 3 (src/lib/workflow, docs/reference, root) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: two consecutive AC_NOT_MET verdicts halt the loop; a recovery or a null verdict resets the count

    Verification: Unit Test (batch-executor.repeat-halt.test.ts, new, using runIssueWithLogging with a mocked phase executor and no modelLadder)
    Scenarios (≥ 4 cases):

    1. Given qa returns AC_NOT_MET, AC_NOT_MET → the run stops after the 2nd verdict. /loop is dispatched once, not twice. failureCategory === "ac_not_met_repeated", abortReason starts with ac_not_met_repeated, and the bundle has 2 iterations with SHAs and failed AC ids.
    2. Given AC_NOT_MET and then READY_FOR_MERGE → success, with no halt fields.
    3. Given AC_NOT_MET, then a qa result with no parsed verdict, then AC_NOT_MET (with maxIterations: 4) → no halt. The count was reset.
    4. Given no ladder → the snapshot function is never called (keeps feat(run): model escalation ladder on capability-bound non-convergence #971 AC-D2 true).
      Assumptions: /loop dispatch can be counted through the injected executor, as batch-executor.model-ladder.test.ts does.

    AC-2: the run-log schema accepts ac_not_met_repeated

    Verification: Unit Test in run-log-schema.test.ts, with a describe/it title that contains ac_not_met_repeated. It parses an IssueLog with that abortReason and the new bundle, and an errorContext.category of ac_not_met_repeated. The existing fixtures and the ERROR_CATEGORIES parity test (:479) stay green.

    AC-3: the default stays 3

    Verification: constraint grep. Do not touch src/lib/settings.ts:598.

    AC-4 / AC-5: docs and changelog

    Verification: grep. Add one paragraph under ### Quality Loop Mode in docs/reference/run-command.md, and one ### Changed entry in CHANGELOG.md [Unreleased] (#1370 is still open).

    AC-6: no skill-directory edits

    Verification: constraint grep (I-1).

    Implementation Plan

    Phase 1: types and schema (additive, version: 1)

    1. error-classifier.ts: add "ac_not_met_repeated" to ERROR_CATEGORIES, and update its doc comment. run-log-schema.ts: add the same value to the inline category enum (:144). metrics-schema.ts derives from ERROR_CATEGORIES, so it needs no edit.
    2. divergence-halt.ts: add "AC_NOT_MET_REPEATED" to the halt-reason union, and add its REASON_HEADLINE and REASON_NEXT_STEP strings. Add an optional failedAcs?: string[] to DivergenceIterationRecord. run-log-schema.ts EvidenceBundleSchema: add the reason to the enum and add failedAcs as optional on iterations[]. The bundle format does not change, and no top-level field is added (H-2).

    Phase 2: the counter (batch-executor.ts, quality loop only)

    1. IssueRunState: add consecutiveAcNotMet: number, plus repeatHaltBundle: EvidenceBundle | null (set means halted). Neither depends on ladderState, iterationStartSnapshot or iterationRecords.
    2. In recordLoopPhaseOutcome, for phase === "qa":
      • Reuse the verdictCommitHash that is already computed for the verdict comment (:2522), so no git call is added.
      • Use the acs that recordAcStatuses returns. The failed ACs are the ones with status === "not_met".
      • On AC_NOT_MET: push {iteration, sha, verdict, failedAcs} to a dedicated list and increment the counter. At 2, build the bundle (reason: "AC_NOT_MET_REPEATED", phase: "qa", the last two records, escalationHistory: []) and warn(formatEvidenceBundle(...)).
      • Any other verdict, or none, resets the counter and the list.
      • A qa result with no output still resets the counter.
    3. One predicate, loopHalted(state), replaces the duplicated OR lists in the outer-loop break (:2170) and in the /loop spawn guard in handlePhaseFailure (:2727). Add the new flag there only. The 2nd refusal then stops before the 2nd /loop spawn (P-1).
    4. Result building (:3293): add repeatHaltOutcome(bundle), a sibling of ladderHaltOutcome. It returns failureCategory: "ac_not_met_repeated", abortReason: "ac_not_met_repeated: AC_NOT_MET twice in qa at <sha1>, <sha2> (failed: AC-1, AC-3)" and evidenceBundle. recordIssueCompletion already forces failure and persists both fields whenever evidenceBundle is set, so log-writer.ts needs no change. Also update the doc comments on IssueResult.abortReason/evidenceBundle in types.ts.

    Phase 3: tests and docs

    1. AC-1 test file, the AC-2 schema case, the docs paragraph and the changelog entry. Run batch-executor.model-ladder.test.ts and batch-executor.test.ts with targeted vitest. Neither should change.

    Design Review

    1. Where does this belong? In the quality loop of batch-executor.ts, because it alone owns the decision to stop. The ready gate has its own loop and is out of scope (H-3). The runner's question "is the owner somewhere else?" gets the answer no. qa-stagnation.ts is a classifier for the same SHA with no diff, and divergence-halt.ts only formats. Neither one decides to stop.
    2. Simplest correct approach: a counter on the parsed qa verdict, updated in the step that already holds the verdict, the commit SHA and the AC rows. Rejected: (a) dropping the ladder condition from consecutiveDivergenceSuspect (P-2: it counts diff-producing iterations and chore(cli)!: remove the model ladder and effort escalation — modules, --model-ladder and --escalate-effort on run and ready, their settings and docs; old logs and settings still load #1647 deletes its feed); (b) setting haltedByDivergence = "AC_NOT_MET_REPEATED" (it would tie the halt to the ladder family that chore(cli)!: remove the model ladder and effort escalation — modules, --model-ladder and --escalate-effort on run and ready, their settings and docs; old logs and settings still load #1647 removes); (c) a counter at iteration level in runQualityLoop (it runs after handlePhaseFailure has already spawned /loop, which is too late for P-1).
    3. Pattern and re-patch count: "a halt flag on IssueRunState, ORed at the break and at the spawn guard". It has been re-patched 4 times: feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739 (turn cap), fix(run): -Q quality loop retries after an "Out of credits" exec instead of failing fast (billing cascades into "unparseable verdict") #799 (billing), feat(run): SPEC_DIVERGENCE escape hatch, ladder halts with evidence bundles, docs, rigged real run (#971 part B) #995/feat(run): model escalation ladder on capability-bound non-convergence #971 (divergence), fix(run): a ladder halt is recorded nowhere: the halting phase reads success, failureCategory is empty, and the bundle exists only on stdout #1254 (recording). That is ≥ 2, so the class gets fixed: step 5 collapses the two duplicated OR lists into one loopHalted(state) predicate. The lists already disagree today: the guard checks result.capped and the break checks state.haltedByCap. A full single-halt-record rework is deliberately local, reason: chore(cli)!: remove the model ladder and effort escalation — modules, --model-ladder and --escalate-effort on run and ready, their settings and docs; old logs and settings still load #1647 deletes haltedByDivergence next, class tracked in chore(cli)!: remove the model ladder and effort escalation — modules, --model-ladder and --escalate-effort on run and ready, their settings and docs; old logs and settings still load #1647.
    4. Senior-reviewer challenge: "Why not count at iteration end?" Because that is too late (see 2c). "Why extend EvidenceBundle instead of a new type?" H-2 says so, and IssueResult, markIssueFailed and MCP abortReason already carry it. chore(cli)!: remove the model ladder and effort escalation — modules, --model-ladder and --escalate-effort on run and ready, their settings and docs; old logs and settings still load #1647 must keep EvidenceBundle, the formatter and the new reason when it deletes the ladder.
    5. Producers and consumers (whole repo).
      • Category value: ERROR_CATEGORIES and the inline enum in run-log-schema.ts. These are 2 producers with a parity test that already exists (run-log-schema.test.ts:479). FailureCategorySchema is derived.
      • failureCategory producers: deriveFailureCategory, the pr_creation fallback, ladderHaltOutcome, the new repeatHaltOutcome, and the abort path at :1950.
      • Consumers: run-orchestrator.ts:2457 (metrics), stats.ts:423, run-display.ts:124 (abortReason), mcp/tools/run.ts:298, log-writer.markIssueFailed, ci/outputs.ts, shutdown.ts. All of them pass strings through, so none needs a branch.

    Feature Quality Planning

    All standard checks pass. Notable items:

    Open Questions

    1. divergence-halt.ts is not on the "May touch" list. It owns EvidenceBundle and the reason union. Recommendation: the additive edit in step 2. Impact if that is wrong: a parallel bundle type, which H-2 rejects.
    2. Where do the failed AC ids go? Recommendation: per-iteration failedAcs (an optional array on iterations[]), so each of the two verdicts keeps its own list. The alternative is to overload declaredAcs, which means "the agent named these impossible". Impact: what readers of the bundle see.
    3. ADR? Recommendation: none. The design choices are recorded as founding doc P-1/P-2 and issue H-1–H-3, and this plan adds no choice beyond them.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: AC-1/AC-2 declare unit-test evidence, but the issue names the exact test file and cases. Testgen would only produce a stub of a file exec has to write anyway, so this overrides the testgen default. There is no UI and the change is not security-sensitive.

    Label Review

    Current: graph-2026-11-simplify. Recommended: add enhancement and planned. Quality Loop: it will not auto-enable (SCOPE_OK).

  4. added
    planned
    enhancement
    on Nov 8, 2026
  5. admarble commented on Nov 8, 2026

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 6/6 met

    Gaps:

    • Two new exports are unused outside batch-executor.ts — import in a test or drop the export — dropped: polish, non-blocking
    • Streak is not reset by an iteration that never reaches qa; no test pins this — dropped: consistent with consecutive-verdict semantics in H-1

    Suggestions:

    • repeatHaltOutcome and AC_NOT_MET_REPEAT_HALT_THRESHOLD are exported, one marked "exported for testing", but nothing outside batch-executor.ts imports either. Import them in a test or drop the export.
    • The streak isn't cleared when an iteration stops before QA runs (for example, exec fails). So refusal, then an exec failure, then refusal counts as two in a row. That fits "consecutive verdicts", and at the default of 3 iterations it only changes the failure label, but no test covers it.

    Needs human review:

    • Required CI check test still pending; re-run QA after it reports

    Reviewed in a separate session by claude-code (claude-opus-5-5); the change was written by claude-code (claude-opus-5-5).

  6. added a commit that references this issue on Nov 8, 2026
  7. admarble commented on Nov 8, 2026

    @admarble
    ContributorAuthor

    Runner, W1: QA NEEDS_VERIFICATION (CI pending only). All six ACs re-run by the runner pass. Runner fix 997ae80da makes the two unused exports file-local. Dropped on purpose: a streak reset by an iteration that never reaches qa (QA test_gap). H-1 counts consecutive QA verdicts only. OQ-2: one historical run held two consecutive AC_NOT_MET verdicts (#1297, 2026-10-04; command in PR #1660). PR #1660 is waiting for CI and the owner's merge.

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

    enhancementgraph-2026-11-simplifyplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions