## Problem
The `[SOURCES_USED]` marker from the RAG source relevance system leaks into session titles displayed in the chat sidebar. Additionally, the title generation LLM
sometimes returns markdown-formatted text (e.g., **bold**, `code`), which appears as raw markdown in the UI.
### Root causes
1. `parseSourceRelevance()` only strips `[SOURCES_USED]` when `$sources` is non-empty, so the marker can survive when no sources are provided.
2. `generateSessionSummary()` passes the raw answer (including the marker) to the title generation LLM.
3. The title generation LLM output is only processed with `strip_tags()`, which doesn't handle markdown.
## Fix
Three layers of protection:
1. Always strip `[SOURCES_USED]` from `$assistantMessage` after the `parseSourceRelevance` block (safety net).
2. Strip the marker from the answer before building the title generation prompt.
3. In title cleanup: strip marker from output, convert markdown to HTML via CommonMark, then `strip_tags()` for clean plain text.
Requires `league/commonmark` (already a dependency of the module).
Issue fork ai_rag_search_chat-3591379
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
paulsheldrake commented