Markdown Format Inconsistency

Open 💬 2 comments Opened May 19, 2026 by chaitanyamedidar

What version of the Codex App are you using (From “About Codex” dialog)?

26.513.40821

What subscription do you have?

Go

What platform is your computer?

Windows 11

What issue are you seeing?

<img width="982" height="207" alt="Image" src="https://github.com/user-attachments/assets/eb605153-a338-4811-8185-3307acd32e09" />

When the model is prompted to provide the content in markdown format, it ends the markdown content box abruptly whenever the markdown contains fenced code block (```), reverting back to normal text.

What steps can reproduce the bug?

  • Open Codex
  • Prompt the agent to provide any content that includes any fenced code blocks

What is the expected behavior?

  1. The agent should be able to close the fenced code block
  2. The agent should continue to provide the content in markdown, where the user could copy directly

Additional information

_No response_

View original on GitHub ↗

2 Comments

bioinformatist · 2 months ago

I can reproduce what looks like the same failure mode in a narrower workflow: ask Codex to draft a GitHub issue or PR body, but not submit it.

I also checked the raw output through Codex's Alt+R raw transcript view. In that view, the assistant message starts with an outer three-backtick markdown fence and later emits a final closing three-backtick fence, so this does not look like the terminal or transcript storage dropping the closing fence.

The problem appears when the drafted Markdown document itself contains a fenced code block using the same three-backtick delimiter:

````text

## Repro

```bash
npm test

Then continue with inline code and more Markdown.

````

And I'd like to paste a snapshot for more intuitive case:
<img width="1246" height="840" alt="Image" src="https://github.com/user-attachments/assets/6a5607d3-a5df-4ed7-8965-09e7c1772c71" />
while the raw mode displays:
<img width="1254" height="950" alt="Image" src="https://github.com/user-attachments/assets/618dacdb-e040-4501-a14d-d3aaec86196d" />

Under CommonMark fence rules, the inner code block's closing ``` is also a valid closing fence for the outer ```markdown block. So the outer block ends early, and the rest of the draft is parsed as normal assistant Markdown. That matches the visible symptom here: after the first fenced code block, later inline code is rendered as code instead of remaining literal Markdown inside the copied document.

This is standard CommonMark behavior, not a parser bug by itself. The spec defines a code fence as at least three backticks or tildes, and says the closing fence must use the same marker and be at least as long as the opening fence. So an outer four-backtick fence can safely contain inner three-backtick fences.

Reference: https://spec.commonmark.org/0.31.2/#fenced-code-blocks

A small prompt-side fix seems sufficient: when showing a Markdown document meant to be copied, use an outer fence delimiter longer than any fence inside the document, or use a different fence marker. For example, use an outer four-backtick `markdown` fence around a document that contains three-backtick code blocks.

I have a small candidate branch with that exact prompt change here, if useful to maintainers:

https://github.com/openai/codex/compare/main...bioinformatist:codex/avoid-nested-markdown-fences?expand=1

Local validation on that branch:

````text
jq empty codex-rs/models-manager/models.json
git diff --check
nix develop -c nix shell nixpkgs#just nixpkgs#python3 nixpkgs#cargo-nextest -c just test -p codex-models-manager
````
joshka · 2 months ago

Local workaround is to add line in your AGENTS.md to say something like:
Always use four backticks to surround markdown that will contain other code fences
or something similar (YMMV)

Ideally this might be something that's worth pushing back into the training, it impacts both codex and chatgpt pretty often. @celia-oai. It may be worth adding to the system prompts too in the meantime.