Skip to content

[Bug]: /clear and /new leave stale compression summary and turn counter across sessions #2635

@dusterbloom

Description

@dusterbloom

Bug Description

/clear and /new call new_session() which resets conversation_history, session_id, token counters, and the todo store — but two pieces of state survive and pollute the new session:

  1. ContextCompressor._previous_summary is never cleared by reset_session_state(). If compression ran in the previous session, the old summary persists and seeds the next iterative compression in the new session (context_compressor.py line 252–257). This means context from a prior conversation leaks into the new session's compression.

  2. _user_turn_count is initialized to 0 in __init__ (line 1065) but never reset in reset_session_state(). After /clear, the counter keeps accumulating, which affects flush_min_turns guard behavior in the new session.

Steps to Reproduce

  1. Start a hermes session, have a long conversation that triggers context compression
  2. Type /clear or /new
  3. Start a new conversation on a completely different topic
  4. When compression triggers again, observe that the summary references content from the previous session

Expected Behavior

/clear and /new should produce a fully clean slate. The compression summary and turn counter should be reset alongside everything else.

Actual Behavior

_previous_summary from the old session survives and is used to seed the next compression, causing cross-session context pollution.

Root Cause Analysis

In run_agent.py, reset_session_state() (line ~1119–1125) resets:

  • compression_count
  • _total_prompt_tokens / _total_completion_tokens
  • _context_probed
  • _last_flushed_db_idx
  • _todo_store

But does NOT reset:

  • self._previous_summary (or the compressor's _previous_summary)
  • self._user_turn_count

Proposed Fix

Add to reset_session_state():

self._user_turn_count = 0
if hasattr(self, 'context_compressor') and self.context_compressor:
    self.context_compressor._previous_summary = None

Or alternatively, re-instantiate the ContextCompressor in reset_session_state().

Affected Component

Agent Core (conversation loop, context compression, memory)

Operating System

Ubuntu 24.04

Python Version

3.12

Hermes Version

0.4.0

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions