## 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).

Command icon 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

paulsheldrake created an issue. See original summary.

  • paulsheldrake committed 0264252a on 1.x
    Issue #3591379: Strip [SOURCES_USED] marker and markdown from session...
paulsheldrake’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.