Skip to content

fix(roadmap): refine keeps the angle-bracket text of a code span #3504

Closed

Description

@dan-petty

Problem

The refine sanitizer deletes each <word> as an HTML tag, also inside a code span. Requirements and commands in the refine section then lose their placeholders and values. A reader of the section sees a damaged requirement.

The evidence is a state at the end of the window 2026-11-03T15:05Z to 2026-11-04T15:05Z. A scan of openspec/changes/*/*.md found none of these damaged spans, so this issue claims no damage in a plan.

Expected

The sanitizer keeps a code span as it is. Outside code, each < that opens a tag becomes &lt;, so no raw tag renders and no text is lost. A comment opener stays neutralized also in code (refine.py:1365), because the record block and the markers are found in the raw text (#2478). This change does not repair a section that refine already wrote.

Acceptance criteria

  • A test: <section>.<option> in a code span survives.
  • A test: <read command> in a code span survives.
  • A test: <read command> outside a span renders as text, does not act as a tag, and loses no word.
  • A test: a text with a stray backtick, where spans_are_code is false and a span is not treated as code, renders no raw tag.
  • A test: an end marker or a comment opener is still neutralized, also in a code span (tests/roadmap/test_roadmap_refine.py:3076).
  • A test: the input A tag <<b></b>!-- rebuilt builds no comment opener.
  • The tests at tests/roadmap/test_roadmap_refine.py:653 and :3010 assert the removal of a tag today. They change to the new form.

Existing tool considered

Existing project code: _replace_outside_code (refine.py:1273) is the code-aware path, and it reads the tokens of markdown-it-py, which is already in uv.lock. No new parse and no new regex for code are necessary.

Related

Related: #2613, #2478, #2525

Proposed design

Problem statement

The refine sanitizer deletes each `` as an HTML tag, also inside a code span. Requirements and commands in a refine section then lose placeholders and values. The change makes the sanitizer code-aware: it keeps code spans, escapes < outside code, and neutralizes a comment opener also in code. It does not repair a section that refine already wrote.

Acceptance criteria

Requirement: Code span keeps section and option placeholder

The sanitizer SHALL keep the text of a code span unchanged, including each <...> placeholder.

Scenario: Section and option placeholder survives

  • WHEN sanitize_text receives . in a code span.
  • THEN The result still contains ..

Requirement: Code span keeps command placeholder

The sanitizer SHALL keep an angle-bracket placeholder in a code span when the span holds a command.

Scenario: Read command placeholder survives

  • WHEN sanitize_text receives devops --help in a code span.
  • THEN The result still contains devops --help.

Requirement: Outside code escapes tag opener

The sanitizer SHALL escape each < that opens a tag outside a code span to &lt; and SHALL keep every word.

Scenario: Read command outside code renders as text

  • WHEN sanitize_text receives use here outside a code span.
  • THEN The result contains &lt;read command, the words use and here, and no raw `` tag.

Requirement: Stray backtick does not mark code

The sanitizer SHALL escape a tag opener outside code when spans_are_code is false, even if a stray backtick is present.

Scenario: Stray backtick renders no raw tag

  • WHEN sanitize_text receives a text with a stray backtick, and spans_are_code is false, so the span is not code.
  • THEN The result contains no raw HTML tag and keeps every word of the text.

Requirement: Comment opener neutralized in code

The sanitizer SHALL neutralize a comment opener and an end marker in a code span as it does outside code.

Scenario: Code span keeps markers neutralized

  • WHEN sanitize_text receives a code span that contains a comment opener or an end marker.
  • THEN The result contains no raw comment opener and no raw end marker.

Requirement: Combined brackets build no comment opener

The sanitizer SHALL prevent the input A tag &lt;!-- rebuilt from forming a comment opener.

Scenario: Combined brackets do not form a comment opener

  • WHEN sanitize_text receives A tag &lt;!-- rebuilt.
  • THEN The result contains no &lt;!-- sequence.

Requirement: Existing tag-removal tests assert escaping

The tests at tests/roadmap/test_roadmap_refine.py:653 and tests/roadmap/test_roadmap_refine.py:3010 SHALL assert the escaped form instead of the removal of a tag.

Scenario: Tag-removal assertions change

  • WHEN The test suite runs the two sanitizer tests.
  • THEN Both tests pass and assert the escaped form with no text loss.

Existing Tool Considered

No alternatives check has run. The open, maintained library markdown-it-py is already in uv.lock, and the project code _replace_outside_code (src/devops_cli/roadmap/refine.py:1273) reads its tokens to find code spans. markdown-it-py lacks HTML escaping and comment-opener neutralization, so the change adds those two steps to the existing helper and builds no new parser.

Key questions

  • Which code-aware path should sanitize_text use to tell a code span from text?: Reuse _replace_outside_code, which reads markdown-it-py tokens, and add the escape and neutralization steps there. Add no second regex or parser for code. (best practice) [sources: src/devops_cli/roadmap/refine.py:1273, src/devops_cli/roadmap/refine.py:1343, src/devops_cli/roadmap/refine.py:1363, uv.lock]
    • Chosen: Reuse _replace_outside_code with markdown-it-py tokens. The library is already in the lockfile and already gives code-aware token positions.
    • Rejected: Add a regex for code spans. A stray backtick and nested spans make a regex fragile, and the issue says no new regex for code.
    • Rejected: Parse the whole text as HTML. An HTML parse loses markdown code spans and can remove text.
  • How should sanitize_text treat < outside a code span?: Escape each < that opens a tag to &lt; and keep the tag text. Do not delete the tag or its words. (best practice) [sources: src/devops_cli/roadmap/refine.py:1215, src/devops_cli/roadmap/refine.py:1343, src/devops_cli/roadmap/refine.py:1363]
    • Chosen: Escape the tag opener to &lt;. The text stays visible and no raw tag renders.
    • Rejected: Delete the tag as today. Deletion removes placeholders and values from the requirement.
    • Rejected: Leave the raw tag. GitHub hides or renders a raw tag, and a comment opener can hide text.
  • How should sanitize_text treat a code span?: Keep the span content unchanged, except neutralize a comment opener and an end marker because the record block and the markers are found in raw text. (best practice) [sources: src/devops_cli/roadmap/refine.py:1365, tests/roadmap/test_roadmap_refine.py:3076]
    • Chosen: Keep the span and neutralize comment openers. It preserves placeholders and commands and still protects raw markers.
    • Rejected: Keep the span with no neutralization. A comment opener in code hides text in the issue body.
    • Rejected: Escape all angle brackets inside code. It changes the command or requirement and loses the placeholder form.
  • Which existing tests change from tag removal to the new escaped form?: The tests at tests/roadmap/test_roadmap_refine.py:653 and tests/roadmap/test_roadmap_refine.py:3010 change. [sources: tests/roadmap/test_roadmap_refine.py:653, tests/roadmap/test_roadmap_refine.py:3010]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 4, 2026
  2. dan-petty commented on Nov 4, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. The sanitizer corrupts requirement and command text in ten open items, but the damage is cosmetic and the fix path is clear.
    • Value: Medium. Users read damaged requirements and commands in refine sections, which reduces trust in the tool output.
    • Effort: Low. The code-aware path _replace_outside_code already exists in the same file and the acceptance criteria are well scoped.
    • Related: fix(roadmap): refine sanitizing breaks the model's code spans and misses references that GitHub links #2525, which asks for a different change. Both target sanitize_text in refine.py and both involve code spans, but the candidate stops _HTML_TAG_RE from deleting angle-bracket text while #2525 stops link and reference rewrites.
  3. added
    priority/p2-medium
    on Nov 4, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 5, 2026
  5. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at f481be8 (see proposed design in issue body).

  6. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 6, 2026
  7. removed
    status/in-review
    on Nov 6, 2026
  8. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-06 02:22 UTC

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

    effort/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions