hermes - 💡(How to fix) Fix ACP adapter: _cmd_reset does not reset token counters, causing stale context usage after /new [2 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…

Root Cause

acp_adapter/server.py _cmd_reset only clears state.history but never resets the agent session token counters or the context compressor state:

# acp_adapter/server.py:1791
def _cmd_reset(self, args: str, state: SessionState) -> str:
    state.history.clear()
    self.session_manager.save_session(state.session_id)
    return "Conversation history cleared."
    # Missing: agent.session_prompt_tokens = 0
    # Missing: agent.session_total_tokens = 0
    # Missing: agent.context_compressor.on_session_reset()
    # Missing: reset of session_input/output/cache/reasoning tokens

As a result, tui_gateway/server.py _get_usage() reads stale/accumulated values:

ctx_used = getattr(comp, "last_prompt_tokens", 0) or usage["total"] or 0

When last_prompt_tokens is 0 or comp is unavailable, it falls back to session_total_tokens which keeps growing across sessions because _cmd_reset never zeroes it.

Fix Action

Fixed

Code Example

# acp_adapter/server.py:1791
def _cmd_reset(self, args: str, state: SessionState) -> str:
    state.history.clear()
    self.session_manager.save_session(state.session_id)
    return "Conversation history cleared."
    # Missing: agent.session_prompt_tokens = 0
    # Missing: agent.session_total_tokens = 0
    # Missing: agent.context_compressor.on_session_reset()
    # Missing: reset of session_input/output/cache/reasoning tokens

---

ctx_used = getattr(comp, "last_prompt_tokens", 0) or usage["total"] or 0

---

# tui_gateway/server.py:587
_notify_session_boundary("on_session_reset", key)

---

def _cmd_reset(self, args: str, state: SessionState) -> str:
    state.history.clear()
    agent = state.agent
    agent.session_prompt_tokens = 0
    agent.session_completion_tokens = 0
    agent.session_total_tokens = 0
    agent.session_input_tokens = 0
    agent.session_output_tokens = 0
    agent.session_cache_read_tokens = 0
    agent.session_cache_write_tokens = 0
    agent.session_reasoning_tokens = 0
    agent.session_api_calls = 0
    agent.session_estimated_cost_usd = 0.0
    if hasattr(agent, "context_compressor") and agent.context_compressor:
        agent.context_compressor.on_session_reset()
    self.session_manager.save_session(state.session_id)
    return "Conversation history cleared."
RAW_BUFFERClick to expand / collapse

What happened

After running /new (or /reset) in an ACP session (VS Code / Zed), the context usage bar continues to show the accumulated token count from the old session instead of resetting. Over time the displayed value balloons (e.g. 1.4M / 1.0M -> 5.2M / 1.0M) even though the conversation history was cleared and individual API calls report normal prompt_tokens.

Root cause

acp_adapter/server.py _cmd_reset only clears state.history but never resets the agent session token counters or the context compressor state:

# acp_adapter/server.py:1791
def _cmd_reset(self, args: str, state: SessionState) -> str:
    state.history.clear()
    self.session_manager.save_session(state.session_id)
    return "Conversation history cleared."
    # Missing: agent.session_prompt_tokens = 0
    # Missing: agent.session_total_tokens = 0
    # Missing: agent.context_compressor.on_session_reset()
    # Missing: reset of session_input/output/cache/reasoning tokens

As a result, tui_gateway/server.py _get_usage() reads stale/accumulated values:

ctx_used = getattr(comp, "last_prompt_tokens", 0) or usage["total"] or 0

When last_prompt_tokens is 0 or comp is unavailable, it falls back to session_total_tokens which keeps growing across sessions because _cmd_reset never zeroes it.

Contrast with TUI gateway

The native TUI gateway handles session reset correctly:

# tui_gateway/server.py:587
_notify_session_boundary("on_session_reset", key)

This triggers ContextCompressor.on_session_reset() which zeroes last_prompt_tokens, compression_count, and related state. The TUI also creates a fresh AIAgent on /new, which initialises session_prompt_tokens = 0 et al. in agent_init.py:1544.

Expected behavior

/new in ACP should produce a clean token slate, matching the TUI behavior: all session counters at 0, context compressor reset, and the usage bar showing 0 / 1.0M until the first API call populates real values.

Steps to reproduce

  1. Start an ACP session (VS Code with Hermes extension)
  2. Have a long conversation (multiple API calls)
  3. Run /new
  4. Observe the context usage bar - it shows accumulated tokens from the old session
  5. Send a message - usage continues growing from the old accumulated value

Proposed fix

In _cmd_reset, reset all session token counters on the agent and call the compressor reset:

def _cmd_reset(self, args: str, state: SessionState) -> str:
    state.history.clear()
    agent = state.agent
    agent.session_prompt_tokens = 0
    agent.session_completion_tokens = 0
    agent.session_total_tokens = 0
    agent.session_input_tokens = 0
    agent.session_output_tokens = 0
    agent.session_cache_read_tokens = 0
    agent.session_cache_write_tokens = 0
    agent.session_reasoning_tokens = 0
    agent.session_api_calls = 0
    agent.session_estimated_cost_usd = 0.0
    if hasattr(agent, "context_compressor") and agent.context_compressor:
        agent.context_compressor.on_session_reset()
    self.session_manager.save_session(state.session_id)
    return "Conversation history cleared."

Environment

  • Hermes Agent v0.15.1
  • ACP adapter (VS Code extension)
  • Any model/provider - the bug is in the ACP reset path, independent of backend

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…

FAQ

Expected behavior

/new in ACP should produce a clean token slate, matching the TUI behavior: all session counters at 0, context compressor reset, and the usage bar showing 0 / 1.0M until the first API call populates real values.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix ACP adapter: _cmd_reset does not reset token counters, causing stale context usage after /new [2 pull requests]