Skip to content

fix(ac-parser): fenced code-block AC examples get parsed as real ACs, silently shadowing the real one #947

Closed

Description

@admarble

Motivation

parseACLine (src/lib/ac-parser.ts) runs its ID-prefixed patterns on every line of the issue body, including lines inside fenced code blocks. An issue that documents an AC-authoring example inside a fence — showing what - [ ] **AC-1:** ... syntax looks like — has that example line parsed as a real AC.

Because parseAcceptanceCriteria dedupes on first occurrence (seenIds), whichever comes first — the fenced example or the real AC with the same ID — wins, and the other is silently dropped.

This is not hypothetical: it happened live to issue #938's own body. #938's Proposal section included a fenced example:

- [ ] **AC-1:** Reset link expires after 24h. Evidence: `npm test -- reset-expiry` (mutation-verified)

...which appeared before the issue's real ## Acceptance Criteria section. extractAcceptanceCriteria(#938's body) parsed this fenced example as AC-1, and the real AC-1 ("parseACLine extracts a trailing Evidence: clause...") was silently dropped by the dedupe. This was caught by chance during /spec planning (the agent noticed the mismatch), not by any automated check — a less careful read would have planned against the wrong AC-1 text.

Proposal

Track fenced-code-block state (``` toggles) while scanning lines in parseAcceptanceCriteria, and skip AC-pattern matching (both ID-prefixed and bare-checkbox) for lines inside a fence — mirroring how AC_HEADING_RE/HEADING_RE already track inAcSection state across lines.

Acceptance Criteria

Non-Goals

  • No change to how AC patterns are detected outside of fences — only the fence-boundary tracking is new.
  • No attempt to parse or validate the content of fenced examples (e.g. flagging that a fence "looks like" AC syntax) — this is purely about excluding fenced lines from the real-AC scan.

Context

Follow-up from #938 (PR #945) — found live while /spec-planning #938 itself, documented in that PR's QA review rather than fixed there since it's a parser-behavior change beyond the Evidence-clause feature's scope.

Activity

  1. added
    bug
    on Aug 13, 2026
  2. added 2 commits that reference this issue on Aug 13, 2026
  3. admarble commented on Aug 17, 2026

    @admarble
    ContributorAuthor

    Spec: Plan for #947

    Complexity: Standard (3 ACs, 1 directory)

    Bug confirmed live — on this issue's own body

    extractAcceptanceCriteria(#947's body) currently returns AC-1 = "Reset link expires after 24h." — the fenced example quoted from #938 in the Motivation section — silently shadowing this issue's real AC-1. The issue reproduces itself. (Corrected ACs have been stored in .sequant/state.json; anything that re-parses the live body before the fix lands will still see the wrong AC-1.)

    AC Quality Check

    • AC-1, AC-2: pass.
    • AC-3: linter flags "correctly" as vague — false positive; the AC pins the exact assertion (criteria[0].description starts with `parseACLine`).
    • All three ACs declare Evidence: clauses resolving to unit_test (npm test -- ac-parser).
    • ⚠️ AC-1's evidence mentions "fixture" → isGateTestEvidence fires → /qa §6i will require a Mutation-verified: AC-1 — ... record in the PR body (delete the fence-skip logic, confirm the test fails, restore, record). Commit before mutation-testing.

    Scope Assessment

    Non-Goals: present (no detection changes outside fences; no fenced-content validation).

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 1 (src/lib/) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: Fenced AC-pattern lines not parsed as real ACs (fence before or after real AC section).
    Verification: Unit Test (declared: npm test -- ac-parser).
    Scenario: Given a body with ```-fenced - [ ] **AC-1:** example before/after the real AC section → When parseAcceptanceCriteria runs → Then only real ACs are returned; fenced lines contribute nothing (including to the explicitIds pre-scan).

    AC-2: All existing fixtures (#686/#703/#745/#750) parse identically — zero diffs.
    Verification: Unit Test (declared: full existing ac-parser suite).
    Scenario: Given the existing suite → When run post-change → Then green with no fixture-expectation edits.

    AC-3: #938's verbatim body extracts the real AC-1 ("parseACLine extracts a trailing Evidence: clause...").
    Verification: Unit Test (declared: regression test on verbatim #938 body).
    Scenario: Given src/lib/__fixtures__/ac-parser/938.md (verbatim gh issue view 938 --json body) → When parsed → Then criteria[0].description starts with `parseACLine`.
    Assumption: fixture captured verbatim per the existing __fixtures__/ac-parser/ convention (real, unmodified bodies).

    Implementation Plan

    Phase 1 — fence tracking in src/lib/ac-parser.ts

    1. In parseAcceptanceCriteria, add fence state (toggle on /^\s*(```|~~~)/, tracking the opening fence's char + length so a longer closing fence isn't required but an inner shorter fence inside a 4-backtick outer fence doesn't desync; unclosed fence runs to EOF per CommonMark). While inside a fence, skip parseACLine, the bare-checkbox fallback, and the HEADING_RE/AC_HEADING_RE section toggling (see Open Q1).
    2. Apply the same fence state to the explicitIds pre-scan loop (ac-parser.ts:436-439) — a fenced **AC-1:** example must not reserve AC-1 there either, or bare-checkbox ID synthesis shifts.

    Phase 2 — tests (AC-1..3)
    3. Synthetic-fence unit tests: fence before real AC section, fence after, fence inside the AC section containing a bare checkbox, unclosed fence.
    4. Add 938.md verbatim fixture + regression test per AC-3; run full suite for AC-2.
    5. Mutation-verify the AC-1/AC-3 gate tests (revert fence-skip, confirm exactly those tests fail, restore, record marker in PR body).

    Design Review

    1. Where does this logic belong? parseAcceptanceCriteria's line loop in src/lib/ac-parser.ts — alongside the existing inAcSection state it explicitly mirrors.
    2. Simplest correct approach? Stateful fence toggle in the existing single pass. Rejected: pre-stripping fences with a multiline regex (mispairs on unclosed fences, diverges from the line-state model); full CommonMark (indented code blocks — out of scope per Non-Goals).
    3. Existing pattern? Cross-line scanner state, same as AC_HEADING_RE/HEADING_RE → inAcSection.
    4. Senior-reviewer challenge? "Why not strip fences once up front?" — the pre-scan and main loop must agree on fence state; one shared line-classification keeps them consistent and handles unclosed fences deterministically.

    Feature Quality Planning

    All standard checks pass. Notable:

    • The explicitIds pre-scan (ac-parser.ts:436) is a second, easy-to-miss consumer of parseACLine — covered by plan step 2.
    • Sibling (follow-up, not scope expansion): parseNonGoals in src/lib/scope/analyzer.ts:297 uses the same fence-blind line scanning; a fenced example under ## Non-Goals is read as real non-goal lines. Recommend a follow-up issue.

    Open Questions

    1. Skip heading detection inside fences too? A # comment line in a fenced bash block currently toggles inAcSection off, dropping subsequent bare checkboxes. Recommendation: yes — same root cause, trivially co-located, still "fence-boundary tracking" per Non-Goals. Impact if skipped: bare-checkbox ACs after an in-section fence are silently dropped.
    2. Tilde fences (~~~)? Recommendation: handle both — one character-class change. Impact if skipped: same bug survives for tilde-fence authors.

    Recommended Workflow

    Phases: spec → testgen → exec → qa
    Quality Loop: disabled
    Reasoning: All 3 ACs carry declared unit-test evidence (npm test -- ac-parser) — declared evidence is the primary testgen signal (#938) and outranks the bug-label skip heuristic; SCOPE_OK single-file fix needs no quality loop.

    Label Review

    Current: bug → Recommended: bug, planned. Quality loop won't auto-enable (SCOPE_OK).

  4. added
    planned
    on Aug 17, 2026
  5. admarble commented on Aug 17, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #947
    Status: READY_FOR_MERGE

    AC Coverage

    AC Description Status Evidence
    AC-1 Fenced AC-pattern lines not parsed as real ACs (before/after AC section) ✅ MET computeFenceMask + 6 new tests; npm test -- ac-parser → 83 passed
    AC-2 All existing fixtures (#686/#703/#745/#750) parse identically — zero diffs ✅ MET Full existing suite green, no fixture-expectation changes
    AC-3 Re-parsing #938's verbatim body extracts the real AC-1 ✅ MET src/lib/__fixtures__/ac-parser/issue-938.md + regression test

    Coverage: 3/3 AC items MET

    Mutation Verification

    AC Gate Test? Marker Status
    AC-1 Yes ac-parser.test.ts > AC Parser > fenced code blocks (#947) > ignores a fenced AC example that appears BEFORE the real AC section Verified
    AC-2 No — N/A
    AC-3 No — N/A

    Quality Checks (sub-agents)

    Check Result
    Type safety / deleted tests ✅ Pass — 0 any issues, 0 deleted tests
    Scope / size ✅ Pass — 4 files, 234+/3-
    Security scan ✅ Pass — 0 critical/warning/info

    Trust-Boundary Check

    Finding: Clean — diff implements only the product requirement (fence-tracking fix); issue body/comments scanned for agent-directed instructions, none found.

    Behavior-Rule Survival Check

    Status: N/A — no AC triggers the behavior-rule heuristic.

    CHANGELOG Verification

    ✅ [Unreleased]/### Fixed entry present, references #947, follows format.

    CI Status

    Check Result
    build (22.x) ✅ pass
    typecheck ✅ pass
    node-floor-guard ✅ pass
    validate-skills ✅ pass
    validate-plugin ✅ pass

    Mergeable: CLEAN

    Sibling-site follow-up (not fixed here, flagged in /spec)

    parseNonGoals (src/lib/scope/analyzer.ts:297) has the same fence-blindness — a fenced example under ## Non-Goals would be read as real non-goal lines. Recommend a follow-up issue; out of scope for #947 per its own Non-Goals.

    Progress Table

    Phase Iterations Status
    Spec 1/1 Complete
    Exec 1/1 Complete
    Test Skipped (no UI labels) —
    QA 1/1 Complete — READY_FOR_MERGE

    PR: #951


    All ACs met, mutation-verified, CI green, mergeable. Ready for merge.

  6. added
    ready-for-review
    on Aug 17, 2026
  7. admarble commented on Aug 18, 2026

    @admarble
    ContributorAuthor

    Gap Fix Applied

    Per follow-up request, the sibling gap flagged during QA is now fixed in the same PR (not deferred to a separate issue):

    • parseNonGoals (src/lib/scope/analyzer.ts) had the identical fence-blindness bug as the original AC-1 — a fenced example under ## Non-Goals was read as a real non-goal item.
    • Fence-tracking is now extracted into shared src/lib/markdown-fence.ts (computeFenceMask / stripFencedLines), used by both ac-parser.ts and parseNonGoals, so the two scanners can't independently drift on fence-boundary rules.
    • Mutation-verified: disabling stripFencedLines in parseNonGoals failed exactly the 2 new fenced-Non-Goals tests; restored and reconfirmed 42/42 passing in scope.test.ts.
    • Full suite: 267 test files, 5491 passed, 0 regressions.

    Updated CI Status

    Check Result
    build (22.x) ✅ pass
    typecheck ✅ pass
    node-floor-guard ✅ pass
    validate-skills ✅ pass
    validate-plugin ✅ pass

    Mergeable: CLEAN

    PR: #951 (updated body includes both mutation-verification markers)


    No remaining known gaps. Ready for merge.

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

    bugplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions