Skip to content

fix-handoff-render.ts doesn't guard against a suggestion breaking its own code fence #6632

Description

@JSONbored

Context

src/review/fix-handoff-render.ts renders each finding's suggestion text into a fenced code block for AI-agent-ready fix handoff, in buildFixHandoffBlock (~line 54-61) and fixHandoffAggregateItem (~line 103-110):

const suggestionBlock = suggestedChange ? `\n\nSuggested change:\n\`\`\`\n${suggestedChange}\n\`\`\`` : "";

Neither function checks whether suggestion/suggestedChange itself contains a triple-backtick sequence before splicing it into the outer fence. The sibling renderer src/review/inline-suggestion-anchor.ts's safeSuggestionBlock already guards against exactly this hazard:

if (!suggestion || suggestion.includes("```")) return "";

fix-handoff-render.ts has no equivalent guard, so a finding whose suggestion text contains a fenced code example (e.g. a suggestion demonstrating "replace this code block with...") breaks the rendered markdown by closing the outer fence early.

Requirements

  • buildFixHandoffBlock and fixHandoffAggregateItem must not render suggestion/suggestedChange text unmodified into a fenced block when that text itself contains a ``` sequence.
  • Follow the existing precedent in src/review/inline-suggestion-anchor.ts's safeSuggestionBlock — either skip the suggestion block entirely when unsafe (matching that function's behavior), or escape/neutralize the embedded fence, whichever keeps behavior consistent between the two renderers. Do not invent a third distinct convention.
  • The fix must apply to both call sites (buildFixHandoffBlock and fixHandoffAggregateItem), not just one.

Deliverables

  • Guard added to both buildFixHandoffBlock and fixHandoffAggregateItem in src/review/fix-handoff-render.ts
  • Regression test in test/unit/fix-handoff-render.test.ts covering a suggestion containing a ``` fence (existing tests only cover present/absent/whitespace-only suggestions)

Test Coverage Requirements

This repo's Codecov patch gate is 99%+ patch coverage, hard, for src/**. The new guard branch and its test must both be covered.

Expected Outcome

A finding suggestion containing a fenced code example no longer breaks the rendered fix-handoff markdown block, in both buildFixHandoffBlock and fixHandoffAggregateItem.

Links & Resources

  • src/review/fix-handoff-render.ts (buildFixHandoffBlock ~line 54-61, fixHandoffAggregateItem ~line 103-110)
  • src/review/inline-suggestion-anchor.ts (safeSuggestionBlock, the precedent to follow)
  • test/unit/fix-handoff-render.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions