Affected Component
Memory System (Vector Store/Knowledge Base)
Describe the bug
Several backend writers wrap text PentAGI does not control in a fixed three-backtick fence. If that text contains a line of three or more backticks, CommonMark treats it as the closing fence, so the block ends early and everything after it is mis-structured. The writers are renderCode in backend/pkg/tools/code.go (stored code samples), the "Source Preview" in backend/pkg/tools/searchers/sploitus.go, and three formatters in backend/pkg/tools/graphiti_search.go (temporal results, episode context, successful tools).
You can see the broken version in the flow's Vector Store tab (the result is rendered as Markdown), on the Knowledge page where the stored document is shown and edited, and in the text an agent gets back from search_code. The Sploitus preview shows up in the flow's Searches tab. The Graphiti episodes show up in what the graphiti search tool returns to the agent, which the flow's message log also renders as Markdown.
This is related to #361 but not the same: there the input is valid Markdown that renders as the spec says, here PentAGI generates the broken structure itself.
Steps to Reproduce
Call store_code with lang markdown, explanation Shows how to fence a shell command and this code:
Run it like this:
```
id
```
Done.The document that is stored, logged and embedded is:
Shows how to fence a shell command
```markdown
Run it like this:
```
id
```
Done.
```The first block ends at the second line of backticks. id becomes a plain paragraph, the next line of backticks opens a new block that holds Done., and the last one closes it. With the fence sized to the content it would be:
Shows how to fence a shell command
````markdown
Run it like this:
```
id
```
Done.
````System Configuration
Found by reading the code on main at cffed94 (v2.2.0). It does not depend on the deployment, provider or enabled features.
Logs and Artifacts
No response
Screenshots or Recordings
No response
Additional Notes
The frontend editor already guards against this: markdown-editor-extensions.ts makes the fence one backtick longer than the longest line of backticks that could close it, never fewer than three. I would apply the same rule on the backend, a little more conservatively. One small helper, used by all five places, would count every run of backticks, not only whole lines. Its fence can come out longer than the editor's would, but it is always valid, and content without a run of three or more backticks renders exactly as it does today. I have the change ready and can open a PR if that works for you.
Verification
- I have checked that this issue hasn't been already reported
- I have provided all relevant configuration files (with sensitive data removed)
- I have included relevant logs and error messages
- I am running the latest version of PentAGI
This is a real problem: PentAGI generates the broken structure itself, so it breaks stored docs, the Sploitus source preview and Graphiti tool output all at once. Sizing the fence to the content (fence length = max run of backticks in the content + 1) is the right fix, and it's what CommonMark expects. Nice to see #472 covering all four writers.