From fb112d6a73a57115540e1919a36450b04df0c77b Mon Sep 17 00:00:00 2001 From: ygd58 Date: Fri, 24 Apr 2026 20:50:47 +0200 Subject: [PATCH] fix(cli): pass None as system_message in manual compress to prevent duplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _manual_compress() passed self.agent._cached_system_prompt to _compress_context() as the system_message argument. _compress_context calls _build_system_prompt(system_message), which appends system_message to prompt_parts that already contain the agent identity block — causing the identity to appear twice in the new session's system prompt (20,957 -> 42,303 chars, +102% as reported in issue #15281). Fix: pass None instead of _cached_system_prompt. _build_system_prompt(None) rebuilds the system prompt correctly from scratch without appending a pre-built prompt on top of the identity layers. Fixes #15281 --- cli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cli.py b/cli.py index d65dc05c06..da7a745cbc 100644 --- a/cli.py +++ b/cli.py @@ -7099,9 +7099,15 @@ class HermesCLI: else: print(f"🗜️ Compressing {original_count} messages (~{approx_tokens:,} tokens)...") + # Pass None as system_message so _compress_context rebuilds + # the system prompt from scratch via _build_system_prompt(None). + # Passing _cached_system_prompt caused duplication because + # _build_system_prompt appends system_message to prompt_parts + # which already contain the agent identity — resulting in the + # identity block appearing twice (issue #15281). compressed, _ = self.agent._compress_context( original_history, - self.agent._cached_system_prompt or "", + None, approx_tokens=approx_tokens, focus_topic=focus_topic or None, )