Skip to content

fix(qa): a SEQUANT_MUTATION marker whose text contains "}" parses to nothing — renderMutationMarker and the parser do not round-trip #1305

Closed

Description

@admarble

Epic: graph-2026-10-freeze-b Tier: mechanical Execution: sequant_run

Found: 2026-10-04, runner of #1289 (PR #1303). A hand-written mutation marker whose mutation text contained a regex quantifier (/\$[0-9]{9}/) parsed to [].

Problem. MUTATION_MARKER_REGEX (src/lib/workflow/mutation-marker.ts:28) is /<!-- SEQUANT_MUTATION: (\{[^}]+\}) -->/g. It stops the JSON at the first }. So any field containing } makes the marker disappear silently, and that is common in a mutation description of a regex or code change. renderMutationMarker is documented as "the inverse of the parser", but it isn't:

renderMutationMarker({ac:"AC-2", mutation:"regex changed to /x{9}/", failedTest:"a.test.ts > d > c"})
  → <!-- SEQUANT_MUTATION: {"ac":"AC-2","mutation":"regex changed to /x{9}/",…} -->
parseMutationMarkers(that)               → []
parseMutationMarkersFromExecOutput(that) → []

The failure is silent at both ends. #1297's carry-over drops the marker, so the PR body has no marker. §6i then reads the gate-test AC as unrecorded and floors the verdict, even though exec did the mutation work.

Freeze check (2026-10-16): /qa §6i calls parseMutationMarkers through npx tsx; it doesn't embed the regex. The fix needs no skill edit.

Acceptance Criteria

  • AC-1: A marker whose ac, mutation or failedTest contains } (or -->-free text with braces) round-trips: parseMutationMarkers(renderMutationMarker(m)) returns m, through both the PR-body and exec-output entry points. Evidence: npx vitest run src/lib/workflow/mutation-marker.test.ts with a brace-bearing case, mutation-verified by restoring the [^}]+ regex
  • AC-2: The property-based round-trip test (if present) generates field text that includes { and }. Evidence: the same test file

Prior fixes / producers

May touch

src/lib/workflow/mutation-marker.ts, src/lib/workflow/mutation-marker.test.ts, CHANGELOG.md.

Non-Goals

  • The marker's JSON fields or the <!-- SEQUANT_MUTATION: … --> wrapper (every existing marker must still parse).
  • The ~~~-seed property-test flake (pre-existing, separate).
  • Any edit under plugin/, .claude/skills/ or templates/skills/ (plugin freeze).

Refs #939, #1297

Activity

  1. added
    bug
    on Oct 4, 2026
  2. admarble commented on Oct 8, 2026

    @admarble
    ContributorAuthor

    Start here (good first issue)

    In plain terms: Sequant writes a small JSON record into PR descriptions (an HTML comment starting <!-- SEQUANT_MUTATION:). The code that reads it back stops at the first } character. So if the text inside contains a }, for example a regex like /x{9}/, the whole record silently disappears. The task is to make writing and reading agree.

    Where to look:

    • src/lib/workflow/mutation-marker.ts, about 180 lines. The regex at line 28 is the bug, and renderMutationMarker is the writer.
    • src/lib/workflow/mutation-marker.test.ts and mutation-marker.property.test.ts are the tests to extend.

    Setup and check:

    npm install          # Node 22.13 or newer
    npx vitest run src/lib/workflow/mutation-marker

    A good first step: add a failing test with the example in the issue body (renderMutationMarker → parseMutationMarkers returns []), then fix the parser until it passes. The markers never contain --> inside a value, which is a useful boundary to match on.

    Size: one source file and its tests. Comment here if you pick it up, and ask anything.

  3. added
    graph-2026-10-freeze-b
    on Oct 16, 2026
  4. admarble commented on Oct 16, 2026

    @admarble
    ContributorAuthor

    Runner context (graph-2026-10-freeze-b, tracker #1452), for the exec and qa phases:

    • exec and qa: do not run the full suite (npm test / npx vitest run with no file filter). Six phase agents run at once and the MCP phase wall is 30 minutes (graph doc I-5). Full-suite evidence comes from CI. Run only the targeted test files, in the foreground, under timeout 600, after a WIP commit. Do not use run_in_background or Monitor.
    • No edit under plugin/, .claude/skills/ or templates/skills/ (plugin freeze, I-1).
    • Gate-test ACs need the mutation record in the PR body (CLAUDE.md, Testing).
  5. admarble commented on Oct 16, 2026

    @admarble
    ContributorAuthor

    Complexity: Simple (2 ACs, 1 directory)

    AC Quality Check

    Both ACs have an Evidence: clause on one line. Two notes:

    • AC-1's evidence (npx vitest run src/lib/workflow/mutation-marker.test.ts with a brace case) is not vacuous: it fails on today's [^}]+ regex. The first AC-1 mutation check must fail the new case before the fix.
    • AC-2 says "(if present)". The property test is present: mutation-marker.property.test.ts. It is a different file from the one AC-2's evidence names ("the same test file"). Read AC-2 as that file.

    Scope Assessment

    Non-Goals: present (wrapper and JSON fields unchanged, ~~~ flake, no plugin/ or skill edits).
    Verdict: ✅ SCOPE_OK (1 source file, 2 test files, CHANGELOG)

    Acceptance Criteria

    AC-1: brace-bearing fields round-trip through both entry points

    Verification: Unit Test
    Scenario: Given a marker whose mutation is regex changed to /x{9}/ → When renderMutationMarker output goes through parseMutationMarkers and parseMutationMarkersFromExecOutput → Then each returns the original marker. Add cases for } in ac and in failedTest.
    Assumptions: Existing markers (flat JSON, one line, --> terminator) still parse.

    AC-2: property test generates { and }

    Verification: Unit Test
    Scenario: Given the property generator no longer filters out } → When it runs → Then parse(render(x)) equals x for all x.
    Assumptions: The backtick and newline filters stay. Inline-code stripping and the one-line grammar still need them.

    Implementation Plan

    Phase 1: parser and writer (src/lib/workflow/mutation-marker.ts)

    1. Change line 28 to a lazy single-line match anchored on the terminator, /<!-- SEQUANT_MUTATION: (\{[^\n]*?\}) -->/g. JSON.parse plus the zod schema still decide validity.
    2. renderMutationMarker escapes > as > (JSON.stringify(...).replace(/>/g, "\\u003e")). A value containing --> or } --> then cannot end the comment early or truncate the match. This is also the correct HTML-comment behaviour. The JSON decodes to the same string, so the round trip is exact.
    3. Update the header comment (it says "matched with the {[^}]+} family… payload must stay flat"). Keep the flat-payload point and drop the claim that } is unsafe.

    Phase 2: tests

    1. mutation-marker.test.ts: add the issue's example, plus } in each field and a --> in mutation, through both entry points.
    2. mutation-marker.property.test.ts: import renderMutationMarker in place of the local format copy, and drop } from the generator filter. Replace the "known lossy input" boundary test with a positive case.
    3. CHANGELOG.md: one Fixed line.
    4. Mutation record for the PR body: restore [^}]+, confirm the new case in mutation-marker.test.ts fails, restore. Use failedTest in src/lib/workflow/mutation-marker.test.ts > <describe> > <case> form.

    Design Review

    1. Where does this logic belong? mutation-marker.ts. It already owns the grammar. QA §6i reaches it through npx tsx, so no skill edit is needed (freeze-safe, as the issue says).
    2. Simplest correct approach? Lazy match to --> plus escaping > on render. Rejected: a brace-balancing scanner (more code, no benefit once --> cannot occur in rendered values). Rejected: base64 payload (breaks every existing marker, a Non-Goal).
    3. Existing pattern / recurrence: the {[^}]+} family is shared with SEQUANT_SPEC and SEQUANT_PHASE. git log -S MUTATION_MARKER_REGEX shows feat(qa): mutation-verification becomes a parseable §7 gate instead of honor-system prose #939 only, with no earlier fix, so this is not a repeat patch. The same flaw exists in the sibling markers' regexes, but their values are enums and not free text. That is a possible follow-up, not in scope here.
    4. Reviewer challenge: "Why not fix hand-written markers that contain a raw -->?" Those are ambiguous by construction and out of scope. Only markers produced by renderMutationMarker are guaranteed.
    5. Producers and consumers: producers are exec output, renderMutationMarker, hand-written markers, and the test-local format in the property test. Consumers are parseMutationMarkers and parseMutationMarkersFromExecOutput, both through the one regex. Step 5 collapses the test-local producer into renderMutationMarker.

    Feature Quality Planning

    All standard checks pass. Notable:

    • Check for other repo readers of the marker text: grep -rn SEQUANT_MUTATION src scripts during exec. Skill prose may carry its own regex (the freeze check says §6i does not).

    Open Questions

    1. Should the > escape be in scope? Recommendation: yes. It makes the lazy match safe for renderer output. If wrong, the cost is one extra line.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Small bug fix with a unit test. Testgen is skipped (bug label, test is specified above). Runner context: no full suite; run only the two marker test files.

    Label Review

    Current: bug, good first issue, graph-2026-10-freeze-b. Recommended: add planned. No change otherwise.

  6. added
    planned
    on Oct 16, 2026
  7. admarble commented on Oct 16, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 2/2 met

    Gaps:

  8. added a commit that references this issue on Oct 16, 2026
  9. admarble commented on Oct 16, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 1/2 met

    Gaps:

    • AC-1 round-trip fails for brace text containing <!-- because the renderer does not escape it and the regex forbids it
    • Existing marker no longer parses, contradicting the Non-Goal and the CHANGELOG claim that existing markers parse as before
    • No test covers values containing <!--, so the regression passed 27/27 tests
    • The (?!<!--) guard drops valid markers whose values contain <!-- (AC-1 failure and Non-Goal regression above).
  10. added a commit that references this issue on Oct 16, 2026
  11. admarble commented on Oct 16, 2026

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 2/2 met

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

    buggood first issuegraph-2026-10-freeze-bplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions