Skip to content

Fix markdown code region balancer for mismatched fence lengths#11631

Merged
pelikhan merged 3 commits intomainfrom
copilot/debug-markdown-code-balancer
Jan 24, 2026
Merged

Fix markdown code region balancer for mismatched fence lengths#11631
pelikhan merged 3 commits intomainfrom
copilot/debug-markdown-code-balancer

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

The balancer was rejecting valid fixes when a shorter fence cannot close a longer fence (e.g., ``` cannot close ````), leaving markdown unbalanced.

Root cause: isInsideBlock() only checked pairedBlocks, not unclosedFences. This caused inner fences to be incorrectly treated as separate openers requiring their own closing fences.

Changes:

  • Updated isInsideBlock() to check if a line is inside an unclosed block
  • Fences appearing after unclosed openers are now correctly treated as content
  • Added regression test for the specific failure case

Example:

content

Previously: Left unbalanced (quality check rejected fix)
Now: Correctly closes with ```` at end

Original prompt

Reference: https://github.com/githubnext/gh-aw/actions/runs/21314236532/job/61354883889

Debug why the markdown code region balancer messed up this markdown

Custom agent used: agentic-workflows
GitHub Agentic Workflows (gh-aw) - Create, debug, and upgrade AI-powered workflows with intelligent prompt routing


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 24, 2026 11:31
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
The balancer was incorrectly rejecting valid fixes when a shorter fence
cannot close a longer fence. For example, ``` (3 backticks) cannot close
```` (4 backticks), so the ``` should be treated as content inside the
unclosed block, not as a separate unclosed fence.

The bug was in the isInsideBlock helper function which only checked for
paired blocks, not unclosed blocks. This caused the algorithm to add both
fences to unclosedFences, which resulted in incorrect quality check
rejection.

Fix: Updated isInsideBlock to also check if a line is inside an unclosed
block, preventing inner fences from being treated as separate openers.

Added regression test for the bug found in workflow run #21314236532.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix markdown code region balancer issue Fix markdown code region balancer for mismatched fence lengths Jan 24, 2026
Copilot AI requested a review from pelikhan January 24, 2026 11:45
@pelikhan pelikhan marked this pull request as ready for review January 24, 2026 11:48
@pelikhan pelikhan merged commit 0c7279f into main Jan 24, 2026
145 checks passed
@pelikhan pelikhan deleted the copilot/debug-markdown-code-balancer branch January 24, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants