hermes - 💡(How to fix) Fix [Hardening] session_search surfaces stored content to the model without ANSI stripping [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

tools/session_search_tool.py returns stored message text — content (via _shape_message), the FTS5 snippet, browse preview, and title — verbatim into the tool result the model consumes. None of it passes through strip_ansi.

tools/ansi_strip.py exists precisely to keep ANSI control sequences out of the model's context (its docstring: "prevents ANSI codes from entering the model's context — which is the root cause of models copying escape sequences into file writes") and is applied to terminal_tool / code_execution_tool / process_registry / file reads. Search / browse / scroll results are a parallel path into context that currently bypasses it: a stored message containing real ANSI/OSC control bytes is re-surfaced to the model intact.

Root Cause

tools/ansi_strip.py exists precisely to keep ANSI control sequences out of the model's context (its docstring: "prevents ANSI codes from entering the model's context — which is the root cause of models copying escape sequences into file writes") and is applied to terminal_tool / code_execution_tool / process_registry / file reads. Search / browse / scroll results are a parallel path into context that currently bypasses it: a stored message containing real ANSI/OSC control bytes is re-surfaced to the model intact.

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

Summary

tools/session_search_tool.py returns stored message text — content (via _shape_message), the FTS5 snippet, browse preview, and title — verbatim into the tool result the model consumes. None of it passes through strip_ansi.

tools/ansi_strip.py exists precisely to keep ANSI control sequences out of the model's context (its docstring: "prevents ANSI codes from entering the model's context — which is the root cause of models copying escape sequences into file writes") and is applied to terminal_tool / code_execution_tool / process_registry / file reads. Search / browse / scroll results are a parallel path into context that currently bypasses it: a stored message containing real ANSI/OSC control bytes is re-surfaced to the model intact.

Proposed fix

Strip ANSI from the surfaced copy only — the on-disk transcript stays raw (paste-to-analyze is intentional). A small _clean_surfaced_text() helper applying strip_ansi to content / snippet / preview / title at the result-shaping points.

strip_ansi matches only genuine ESC-anchored / C1 sequences, so this is zero-false-positive: ordinary text that merely describes escape codes (documentation, code samples — e.g. a message containing the literal text \x1b]11;…) is left untouched, so search stays useful for exactly those messages.

Scope / notes

  • Defensive hardening, consistent with how command/file output is already cleaned.
  • Web / x / browser search tools surface external content through the same pattern and could get the same treatment in a follow-up; this covers the internal session search.
  • Related title-sink fix: #40103 / #40105.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING