Skip to content

[Bug]: Triple backticks inside code blocks break markdown rendering #361

Description

@psyray

Affected Component

Core Services (Frontend UI/Backend API)

Describe the bug

Description:

When markdown content contains a code block (fenced with triple backticks) and that code block itself contains triple backticks as part of its content, the inner triple backticks are interpreted as closing the code block instead of being displayed as literal characters. This breaks the entire rendering of the page — everything after the premature code block closure is misinterpreted as markdown, corrupting all subsequent formatting.

This is especially problematic for PentAGI because agents frequently produce output that explains markdown syntax or shows command examples containing triple backticks (e.g. instructions on how to write code blocks, or shell commands wrapped in triple backticks inside documentation).

Expected behavior:

Triple backticks that appear inside a fenced code block should be treated as literal text and displayed as-is, not interpreted as code block delimiters. The markdown renderer should properly handle nested or escaped triple backticks.

Actual behavior:

Triple backticks inside a code block close the code block prematurely. All content after the inner triple backticks is rendered as regular markdown instead of staying inside the code block, breaking the entire page layout.

Steps to Reproduce

  1. Open PentAGI UI and navigate to any flow where an agent has produced markdown output containing a code block with triple backticks inside it.
  2. Observe that the rendered markdown is broken — the inner triple backticks close the code block, and everything after is misformatted.
  3. Paste the following markdown into any markdown field in the UI:
To run a network scan, the command is ```nmap -sV 10.0.1.50``` then check the results.

The markdown syntax for a code block is: open with ```bash, write your code, then close with ```.

For example, to display JSON:

```json
{"flowId": 85, "action": "finish"}

And here is the server response:

{"errors": [{"message": "flow not found"}]}

The command psql -U pentagi -d pentagi -c "SELECT * FROM flows" checks the database state. If the result shows waiting for a flow that should be finished, it means the provider was renamed.

To fix it, run UPDATE flows SET model_provider_name = 'OllamaC GLM' WHERE model_provider_name = 'Ollama cloud GLM'; then restart with systemctl restart pentagi.


4. Observe that the rendering is completely broken — text after the first inner ``` is no longer inside the code block.


### System Configuration

- PentAGI Version: v2.1.0-879e87c (image `vxcontrol/pentagi:latest`)
- Deployment Type: Docker Compose
- Browser: (any modern browser — the issue is renderer-side)


### Logs and Artifacts

No server-side logs — this is a frontend rendering issue.

The bug is reproducible with any markdown content containing backticks. See the example in "Steps to Reproduce" above.


### Screenshots or Recordings

<img width="871" height="603" alt="Image" src="https://github.com/user-attachments/assets/a79fdfa3-97c1-41f3-b927-85fd6ab19cba" />

### Verification

- [x] I have checked that this issue hasn't been already reported
- [x] I have provided all relevant configuration files (with sensitive data removed)
- [x] I have included relevant logs and error messages
- [x] I am running the latest version of PentAGI

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions