Skip to content

feat(spec): Design Review stops on recurrence and lists producers; spec can halt before exec when the AC's lever is wrong #1250

Closed

Description

@admarble

Tier: judgment Found: 2026-09-30 re-patch retrospective (tracker #1236, closed): the 41 fix commits since v2.15.0, their decision trails, and entire transcripts for four clusters.

Problem. About 78% of the fixes (32 of 41) re-patched an artifact that already had an earlier fix. The design-level causes were visible when they were fixed, but spec's Design Review (.claude/skills/spec/SKILL.md:303-308) confirms whatever site the issue already chose:

Verified mechanism gap. #995's SPEC_DIVERGENCE halt is parsed for any phase (phase-executor.ts:1178, :1418) and halts inside batch-executor's phase loop (batch-executor.ts:1736). But the spec path runs before that loop (:1185-1215) and never checks specDivergence. A spec that finds the AC's lever contradicts the design can't halt the run before exec.

Prior fixes / producers

AC

  • AC-1: Design Review Q3 treats a pattern with ≥2 prior fix issues as a stop, not a precedent. The plan cites them (from git log -S and an issue search) and either fixes the class or records "deliberately local, reason: …, class tracked in #N". Evidence: a gate test in src/lib/__tests__/spec-design-review-skill.test.ts, scoped to the Design Review section in all three copies and mutation-verified
  • AC-2: Design Review adds Q5, "Every producer and consumer of the artifact this changes (whole-repo grep)". With ≥2 producers, the plan collapses them or adds a parity test on every field and records why. Evidence: the AC-1 gate test file, mutation-verified
  • AC-3: When Q3 or Q5 contradicts the issue's prescribed lever, spec emits SPEC_DIVERGENCE in its SEQUANT_PHASE marker, and the spec path in runIssueWithLogging halts before exec with the divergence bundle, as the loop path already does. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts with a spec-phase divergence fixture that asserts exec never runs, mutation-verified
  • AC-4: memory/constitution.md gains one principle: "one producer per artifact; a second producer needs a parity test on every field and a recorded reason". Evidence: a gate test asserting the principle in memory/constitution.md (scoped to the principles section), mutation-verified
  • AC-5: The Q3/Q5 additions stay within the spec skill's tier gating (Simple-tier issues skip them), and the spec skill doesn't grow past its base line count plus 15. Evidence: wc -l .claude/skills/spec/SKILL.md against the base branch, and npm run lint:skill-sync

Non-Goals

Graph metadata

May touch

  • .claude/skills/spec/SKILL.md, skills/spec/SKILL.md, templates/skills/spec/SKILL.md
  • memory/constitution.md (the tracked copy; .claude/memory/ is untracked)
  • src/lib/workflow/batch-executor.ts, src/lib/workflow/batch-executor.test.ts
  • src/lib/__tests__/spec-design-review-skill.test.ts (new)

Activity

  1. added
    enhancement
    on Sep 30, 2026
  2. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Runner context (re-checked against main @ 5e8f0aa)

    Line refs (current):

    • .claude/skills/spec/SKILL.md is 435 lines, so AC-5's cap is 450. Tier table :92 (Simple = "Design Review Q1/Q3 only"); ## Design Review :303; Q1–Q4 :305-308; tier comment :310. Same lines in skills/ and templates/.
    • src/lib/workflow/phase-executor.ts: parseSpecDivergence :1111; attached to the result at :1178-1179 (and :1418) for every phase, spec included.
    • src/lib/workflow/batch-executor.ts: the spec path runs :1133-1215 (executePhaseWithRetry("spec", …) :1163, phaseResults.push(specResult) :1198). It never reads specResult.specDivergence. The loop-path halt to mirror is :1736-1741, with the bundle and halt record at :1473, :1524-1548 and :1937. Reuse that bundle builder; don't write a second one.
    • memory/constitution.md (tracked) has no section called "principles". Its sections are ## 1. Definition of Done, ## 2. AC Authoring Standard, ## 3. Boundaries, ## 4. Budgets & Stop Conditions, ## 5. Stack-Specific Notes and ## Project-Specific Notes. Put AC-4's principle in the section that fits (probably §3 Boundaries), scope the gate test to that section, and say which one in the PR.

    Two design points for spec to settle in the plan (decide them; don't pass them to exec):

    1. The Simple tier is where most re-patches live. Under :92 a bug with ≤2 ACs is Simple, and AC-5 has Simple-tier issues skip the new Q3/Q5 additions. Several of the audited re-patches were small bug fixes. Either justify the skip, or keep a one-line recurrence check (the git log -S count) in Simple's Q3, which still fits the +15 budget. If you choose the second, record it as a deviation from AC-5's parenthetical and explain why.
    2. AC-3's emit path: spec today never emits a SEQUANT_PHASE marker with SPEC_DIVERGENCE. Confirm the parser at :1111-1134 accepts the outcome from a spec-phase marker as is, before adding a new parser.

    Prior fixes / producers (checked)

    Standard block

    • No full npm test in exec or in QA. This applies to the qa phase too. Run the AC test files plus grep -rlE 'specDivergence|SPEC_DIVERGENCE|Design Review' --include='*.test.ts' src __tests__ scripts | xargs npx vitest run.
    • Commit WIP early, and always before a mutation. Use type-preserving mutations, since the global setup builds.
    • The mutation marker's failedTest must start with the test file path, e.g. src/lib/__tests__/spec-design-review-skill.test.ts > … > ….
    • PR body: Closes #1250. Use Refs only for the tracker. Never put a closing keyword next to another real issue number, even in an example; write #<n>.
    • Settings reads must be JSONC-safe.
  3. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs, 4 directories)

    AC Quality Check

    lintAcceptanceCriteria: 5/5 passed. Parser: AC-1 and AC-3 resolve to unit_test, AC-4 and AC-5 to integration_test, all with declared evidence. Three things to note:

    • ⚠️ AC-2 resolves to manual. Its Evidence, "the AC-1 gate test file", names no path or test keyword, so /qa §6i won't treat AC-2 as a gate-test AC. Fix in exec's PR: give AC-2 its own SEQUANT_MUTATION record whose failedTest starts with src/lib/__tests__/spec-design-review-skill.test.ts > …. Treat AC-2 as a gate test even though the parser classifies it as manual.
    • ⚠️ AC-5's wc -l check passes on the base branch already (435 ≤ 450). That is fine for a ceiling. The tier-gating half of AC-5 isn't checked by anything, though, so the AC-1 gate test also asserts the tier gating (see the AC-5 section below).
    • Evidence for AC-1, AC-3 and AC-4 names a new test file or a new fixture, so each check fails on the base branch. None is vacuous.

    Scope Assessment

    Non-Goals: present. Fixing the named clusters (#1245, #1247) and changing /improve are both out of scope.

    Metric Value Status
    Feature count 2 (spec skill design review + spec-path halt) ✅
    AC items 5 ✅
    Directory spread 4 (.claude/skills, skills/templates mirrors, memory/, src/lib/workflow) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: Q3 treats a pattern with ≥2 prior fixes as a stop, not a precedent

    Verification: Unit Test, as a gate test (src/lib/__tests__/spec-design-review-skill.test.ts, new)
    Scenario: Given the three spec SKILL.md copies → When the test reads the Design Review region (from ## Design Review to the next \n---) → Then Q3 names git log -S, an issue search, a ≥2 threshold, and the literal deliberately local, reason: / class tracked in # escape.
    Mutation: revert Q3 to "[Named pattern, confirm it fits]" in one copy, then confirm exactly that copy's case fails.

    AC-2: Q5 lists every producer and consumer

    Verification: Unit Test, as a gate test (same file)
    Scenario: Given the Design Review region → Then a 5. item names producers and consumers, a whole-repo grep, and the ≥2-producer rule (collapse them, or add a parity test on every field and record the reason).
    Mutation: delete the Q5 line, then confirm the Q5 case fails.

    AC-3: Spec can halt the run before exec

    Verification: Unit Test (src/lib/workflow/batch-executor.test.ts, new describe("#1250 …"))
    Scenario: Given autoDetectPhases: true and the mocked spec PhaseResult carrying specDivergence: { acs: "AC-2", message: … } → When runIssueWithLogging runs → Then mockExecutePhase was called only for spec (exec, qa and loop never run), the printed output contains Ladder halt: SPEC_DIVERGENCE and Declared impossible: AC-2, and the result is success: false.
    Two fixtures (required): (a) spec success: true with divergence. This one fails today, because the run proceeds to exec. (b) spec success: false with divergence. Today this case early-returns without printing the bundle, so only the bundle assertion catches it.
    Mutation: delete the new spec-path check, then confirm fixture (a) fails.
    Assumptions (confirmed during planning): parseSpecDivergence (phase-executor.ts:1111) is phase-agnostic. It reuses parsePhaseMarkers, PhaseMarkerSchema.phase is PhaseSchema (which includes spec), and outcome: z.enum(["SPEC_DIVERGENCE"]) doesn't depend on the phase. Both result paths attach it (:1178, :1418). executePhaseWithRetry already short-circuits retries on specDivergence regardless of phase (:2091, :2148). No new parser and no new field. Exec adds one parseSpecDivergence case with "phase":"spec" to pin this.

    AC-4: The constitution states "one producer per artifact"

    Verification: Integration Test, as a gate test (assertion in the new spec-design-review test file, or in a sibling constitution-boundaries.test.ts)
    Decision: put it in §3 Boundaries as a table row. §3 requires a named enforcer for every row, so the row is One producer per artifact; a second producer needs a parity test on every field and a recorded reason with enforcer /spec Design Review Q5 (#1250). Scope the test to the region between ## 3. Boundaries and ## 4..
    Mutation: delete the row, then confirm the test fails. The PR says "§3 Boundaries".

    AC-5: Tier gating and the line budget

    Verification: Integration Test (wc -l vs origin/main ≤ 450, plus npm run lint:skill-sync) and assertions in the AC-1 gate file on the tier table row and the tier comment
    Scenario: The Simple row at :92 still reads "Design Review Q1/Q3 only". The tier comment under Design Review says Q5 is Standard/Complex only. All three copies are byte-identical.


    Implementation Plan

    Phase 1: Spec skill (all 3 copies, kept identical)

    1. .claude/skills/spec/SKILL.md Design Review (:303-310):
      • Rewrite Q3 to: "What existing pattern does this follow, and how often has it been re-patched? (git log -S '<symbol>' --oneline + issue search). ≥2 prior fixes = stop: fix the class, or record deliberately local, reason: …, class tracked in #N." Use one or two lines.
      • Add Q5: "Who produces and consumes this artifact? [whole-repo grep; ≥2 producers → collapse them, or add a parity test on every field and record why]".
      • Update the tier comment: "Simple tier: Q1 and Q3 (the recurrence count included). Standard/Complex: all five."
    2. Add a ≤5-line Halt on divergence note right after the tier comment. When Q3 or Q5 contradicts the lever the issue prescribes, spec posts its plan and appends <!-- SEQUANT_PHASE: {"phase":"spec","status":"failed",…,"outcome":"SPEC_DIVERGENCE","divergenceAcs":"AC-N","error":"…"} --> instead of completed, so sequant run stops before exec. For the full semantics, point to the exec skill's section instead of copying it. The budget is +15 lines in total.
    3. Copy the file byte-for-byte to skills/spec/SKILL.md and templates/skills/spec/SKILL.md. Run npm run lint:skill-sync and wc -l.

    Phase 2: Runtime halt (src/lib/workflow/batch-executor.ts)

    1. Hoist iterationRecords, modelEscalations and buildBundle (currently :1478-1548) above the spec block, so the spec path reuses the one bundle builder. Both arrays are empty at spec time, which is exactly the "no SHA tried, no rung spent" record. Don't write a second builder.
    2. After the spec result has been logged and its state persisted, and before if (!specResult.success) (:1300), add: if (specResult.specDivergence) { log(chalk.yellow(formatEvidenceBundle(buildBundle("SPEC_DIVERGENCE", "spec", specResult.specDivergence)))); deactivate relay; return { success: false, … } }. It goes before the success split for the same reason the loop path's does (:1932-1936): a spec that declares divergence and also emits a valid SEQUANT_SPEC passes the fix(run): spec runs in the main checkout, which the skills pre-flight never checks — a stale checkout silently degrades spec (#933 regression) #1193 guard, and today it would carry on into exec. Factor out the relay-deactivation + return block shared with the !success branch instead of duplicating it.
    3. Tests as described under AC-3, plus the parseSpecDivergence spec-phase case in the phase-executor tests.

    Phase 3: Constitution plus gate tests

    1. Add the memory/constitution.md §3 row (AC-4).
    2. Write src/lib/__tests__/spec-design-review-skill.test.ts, modeled on spec-skill-self-skip-marker.test.ts: describe.each(COPIES) with region-scoped reads. Commit, then mutation-verify AC-1, AC-2, AC-4 and AC-3, recording each with the SEQUANT_MUTATION marker (failedTest begins with the test file path).
    3. Write an ADR in docs/adr/ (next NNNN) covering "spec may halt the run". It records the Simple-tier deviation and the rejected alternatives below.

    Design Review

    1. Where does this logic belong? In two layers that do different jobs. The skill prompt holds the judgment (spotting recurrence and producers, and deciding the lever is wrong). runIssueWithLogging's spec path holds the enforcement (halting). The constitution states the principle and names Q5 as its enforcer.
    2. What's the simplest correct approach? Reuse SEQUANT_PHASE.outcome and parseSpecDivergence, and make the spec path read the field it already gets. That is one producer and two consumers, as the runner's context comment notes. Rejected: (a) a new SPEC_HALT marker or field, which would add a second producer of the same signal; (b) relying on the fix(run): spec runs in the main checkout, which the skills pre-flight never checks — a stale checkout silently degrades spec (#933 regression) #1193 guard to fail the spec phase, which halts only when spec also leaves out SEQUANT_SPEC, prints no bundle, and would let a divergent-but-complete spec through; (c) a separate pure buildEvidenceBundle in divergence-halt.ts, which is a valid alternative but turns a hoist into a refactor. Exec may choose it if hoisting makes the closure awkward.
    3. What existing pattern does this follow, and how often has it been re-patched? It mirrors the loop path's feat(run): SPEC_DIVERGENCE escape hatch, ladder halts with evidence bundles, docs, rigged real run (#971 part B) #995 halt (:1736, :1937). Applying AC-1 to this issue: the Design Review section has three prior fixes (Spec skill: add Design Review section before implementation planning #413 added it, perf(spec): prompt compression and tiered context — reduce spec skill token cost by ~60% #515 compressed it, feat(spec,qa): detect behavior-rule implementations across skill+runtime touchpoints #552 added Rule Touchpoints next to it). That's ≥2, so it's a stop. This issue is the class fix: it changes what the review asks rather than adding another nearby section. It isn't a local patch.
    4. What would a senior reviewer challenge?
      • "Why not skip Q3 in the Simple tier, as AC-5 says?" Decision: Simple keeps the recurrence count in Q3. Only Q5 is Standard/Complex. The audit found many re-patches were small bug issues with ≤2 ACs, which is exactly what the Simple tier covers, so skipping it there misses most of the target. The cost is one git log -S per Simple spec, with no extra lines because it's the same Q3 line. This is a deliberate deviation from AC-5's parenthetical. The PR records it, and the gate test asserts the Simple row still lists Q3.
      • "Won't spec halt too eagerly?" The halt fires only on a contradiction with the prescribed lever. A recurrence that the plan handles by fixing the class, or by recording deliberately local, isn't a divergence.

    ADR required: the plan picks between designs (rejected options a–c, plus the Simple-tier deviation), so exec's PR includes docs/adr/NNNN-spec-can-halt-before-exec.md per docs/adr/README.md.


    Feature Quality Planning

    The standard checks pass. Notable items:

    • Resume after a halt: a spec marker with status:"failed" means the next /spec re-runs (Phase Detection: spec:failed → re-run), so the owner edits the AC text and runs again. Note this in the halt note. A decision comment alone doesn't re-open the work; the AC lines have to be edited.
    • Fenced examples: if the skill shows the marker inside a code fence, parsePhaseMarkers strips it, so documenting the marker can't halt a run. Keep the example fenced.
    • /fullsolve reads spec markers through its own path. Whether it honors a spec-phase divergence is out of scope here (see Open Questions).

    Open Questions

    1. Should /fullsolve also stop on a spec SPEC_DIVERGENCE? Recommendation: file a follow-up, since this AC names runIssueWithLogging only. Impact if this is wrong: a /fullsolve-driven run goes on to exec after spec flagged the lever.

    Conflict Risk

    The open worktree for #1247 changes batch-executor.ts and batch-executor.test.ts in the PR-creation region, which is far from the spec path (:1133-1330). The worktrees for #1223 and #1233 are already merged. Risk is low: merge origin/main before pushing.


    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: The ACs declare unit and integration evidence, but they are gate tests whose shape comes from mutation verification, so testgen stubs would add nothing (and have been left as stubs before). Exec writes them directly. The scope is contained and the runtime change is one check plus a hoist. QA: don't run the full npm test. Run the AC test files plus grep -rlE 'specDivergence|SPEC_DIVERGENCE|Design Review' --include='*.test.ts' src __tests__ scripts | xargs npx vitest run.

    Label Review

    Current: enhancement
    Recommended: enhancement, planned
    Quality Loop: won't auto-enable (SCOPE_OK).

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

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 5/5 met

    Gaps:

    • Required CI test check still pending at review time
    • A spec-divergence halt with a successful spec exit is persisted as spec completed in state, run log and progress
  6. added a commit that references this issue on Oct 1, 2026
  7. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Follow-up ledger: QA's finding 2 ("halt persisted as spec completed") is filed as #1254, which covers all four ladder halts. Open Question 1 (/fullsolve) is dropped: /fullsolve runs spec in-session, and its §1.3 already exits on a failed spec, so there's no orchestrator halt to wire. Runner verification and a fix to the AC-3 marker channel are in PR #1253's body.

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

    enhancementplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions