Skip to content

fix(ai): a web_fetch budget cut inside a code block closes the fence before the truncation note and boundary tag #1298

Closed

Description

@dan-petty

Problem

Copilot thread 0 on #1283, verified at 61f9b67. _apply_blank_line_cut cuts the rendered Markdown at a blank line or newline without regard to fences [code: src/devops_cli/ai/common_tools.py:395-407]. A budget cut inside a <pre> block therefore leaves its fence open, and the truncation note and </untrusted_web_page> land inside the code block. Page text still cannot forge the boundary, and the tag stays the last line of the tool result, so this is hardening rather than a v0.2.28 defect. It came in with #896 (878fe3f).

Acceptance criteria

  • A cut inside a fenced block closes the fence, using markdown-it-py (already a dependency), before the truncation note and the boundary tag. A test parses the result and finds the tag outside every fence.
  • changelog.d/<n>.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
  • uv run devops ci passes.

Strategic alignment

Activity

  1. added
    type/bug
    scope/ai
    priority/p2-medium
    on Oct 7, 2026
  2. added this to the v0.2.30 milestone on Oct 8, 2026
  3. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to v0.2.30: a critical fix can join v0.2.30 after it starts.

    • Priority: P0-Critical. P0: the regression commit 878fe3f is evidence GitHub confirms, from a trusted source.
    • Value: Medium. Malformed output could confuse the model reading the tool result, but the security boundary and tag position are preserved.
    • Effort: Low. A targeted fix in one function using markdown-it-py, which is already a dependency, plus one test.
  4. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1462, merged into release/v0.2.30 as eadfaa0.

    Summary

    • A web_fetch page cut by its budget inside a code block left the block open, so the truncation note and the closing </untrusted_web_page> tag landed inside the code. _apply_blank_line_cut now closes the block first.
    • After choosing the cut point as before, it parses the text with markdown-it (already a dependency). If the cut falls inside a code block, it keeps the block's own closing line, including any blockquote or list prefix. If the cut falls on the opening line, it drops the block. The closing line can go over the budget by its own length.
    • Line endings are converted first: "\r\n" and a lone "\r" become "\n", CommonMark's own rule. markdownify keeps a lone "\r" in <pre> content and in link titles, and without the conversion the parser's line numbers would point at the wrong lines. That raised IndexError, or added a stray fence that opened a new block.
    • No change to the converter, the sanitizer, the wrapper, web_fetch_tool or DEFAULT_TRUNCATION_SUFFIX.
    • Adds changelog.d/1298.md and docs/agent/tasks/task-1298-web-fetch-cut-closes-open-fence.md. CHANGELOG.md and docs/ROADMAP.md are not edited.

    Closes #1298

    4 file(s) changed.

    How it was verified

    Check runs at bf350d5:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1298-web-fetch-cut-closes-open-fence.md:

    • A cut inside a fenced block closes the fence, using markdown-it-py, before the truncation note and the boundary tag. test_render_untrusted_page_budget_cut_inside_code_block_closes_the_fence in tests/test_common_tools.py parses the result and finds neither the tag nor the note inside any fence: a block after a paragraph, a block that starts the page (cut mid-listing, on the opening line, and part way through the opening line), a block in a blockquote, a block in a list item, and a block after \r line endings.
    • changelog.d/1298.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
    • uv run devops ci passes.
  5. added a commit that references this issue on Oct 9, 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

    priority/p2-mediumscope/aitype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions