Skip to content

fix(server): tell agents how to nest fenced code inside code blocks - #10908

Open
pc-style wants to merge 1 commit into
pingdotgg:mainfrom
pc-style:t3code/fix-markdown-code-blocks
Open

fix(server): tell agents how to nest fenced code inside code blocks#10908
pc-style wants to merge 1 commit into
pingdotgg:mainfrom
pc-style:t3code/fix-markdown-code-blocks

Conversation

@pc-style

@pc-style pc-style commented Sep 9, 2026

Copy link
Copy Markdown

What Changed

One sentence added to the shared runtime instructions that every provider adapter appends (Codex, Claude, Cursor, Grok, OpenCode, Antigravity): a code block that itself contains triple backticks must be fenced with four backticks or ~~~. No parser or renderer change.

Why

When an agent replies with a code block containing a fenced block (a prompt to paste, a README snippet), the chat renders it broken: the inner closing fence ends the outer block and the rest spills out as prose. The renderer is right, that is standard CommonMark. The agent just never knew it needed a longer fence. Diverging from CommonMark in the renderer would break copy and paste round trips with GitHub and every other markdown surface, so the fix is to tell the agent.

UI Changes

The change is in what the agent emits, so the visible effect is in how replies render. Both captures below use the same ordinary prompt in a fresh thread with Codex (GPT-5.6), nothing about fences in the prompt:

Write a README.md for a tiny Python CLI called todo that can add and list tasks. Show me the whole file so I can copy it. Do not create or change any files.

Before, server on main: the reply opened with a triple-backtick markdown fence. The first inner bash fence closes it, the rest of the README renders as prose, and a stray empty text block is left at the end.

Before: README spills out of the code block

After, server on this branch: the reply opened with a four-backtick fence and renders as one block with all six inner fences intact.

After: one block, inner fences intact

Streaming the after reply, sped up:

after-readme-streaming-fast2.mp4

Validation:

  • vp test run apps/server/src/provider/RuntimeInstructions.test.ts passes (6 tests, including a new one for the guidance)
  • Raw replies checked in the state database: before starts with ```markdown, after starts with markdown ````

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots
  • I included a video for the streaming render

A code block whose body contains triple backticks was rendered broken in
chat: the inner closing fence ended the outer block, and the rest spilled
out as prose. That is correct CommonMark, so the fix is to tell every
provider up front to use a longer fence in that case.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Sep 9, 2026
@pc-style
pc-style marked this pull request as ready for review September 9, 2026 10:05
@macroscopeapp

macroscopeapp Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at f4a9b2b

Macroscope's review found this PR approvable — The change adds a focused sentence to shared agent instructions so nested fenced code renders correctly, plus a test verifying the guidance. It affects response formatting across existing providers but introduces no new workflow, schema, deployment, security, or static-analysis behavior.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 50c855df-e2a2-492b-b755-c7e259e7c050

📥 Commits

Reviewing files that changed from the base of the PR and between 6c58362 and f4a9b2b.

📒 Files selected for processing (2)
  • apps/server/src/provider/RuntimeInstructions.test.ts
  • apps/server/src/provider/RuntimeInstructions.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

buildRuntimeInstructions now includes CommonMark guidance for nesting fenced code blocks. A test verifies that the output recommends a longer fence.

Changes

Runtime instruction guidance

Layer / File(s) Summary
Nested fence guidance
apps/server/src/provider/RuntimeInstructions.ts, apps/server/src/provider/RuntimeInstructions.test.ts
The runtime instructions explain that code blocks containing triple backticks must use four backticks or a ~~~ fence. The test verifies this guidance.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to f4a9b

Runtime instructions now explain safe nested CommonMark fencing, reducing malformed code-block rendering without changing parser or renderer behavior. The change is ready to merge.

Suggested reviewers: juliusmarminge

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: informing agents how to nest fenced code blocks.
Description check ✅ Passed The description covers what changed, why it changed, UI evidence, validation results, and the required checklist. It is focused and complete.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant