hermes - ✅(Solved) Fix /usage crashes when agent.context_compressor is None [2 pull requests, 1 participants]

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…
GitHub stats
NousResearch/hermes-agent#14715Fetched 2026-04-24 06:15:04
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×2

Error Message

cd /Users/genie/.hermes/hermes-agent source venv/bin/activate python - <<'PY' from types import SimpleNamespace import cli

obj = object.new(cli.HermesCLI) obj.conversation_history = [] obj.agent = SimpleNamespace( session_api_calls=1, session_input_tokens=1, session_output_tokens=2, session_cache_read_tokens=0, session_cache_write_tokens=0, session_prompt_tokens=3, session_completion_tokens=4, session_total_tokens=5, context_compressor=None, model="x", get_rate_limit_state=lambda: None, )

try: cli.HermesCLI._show_usage(obj) except Exception as e: print(type(e).name, e) PY

Fix Action

Fixed

PR fix notes

PR #14723: fix(cli): /usage with missing context_compressor (#14715)

Description (problem / solution / changelog)

What

  • /usage (HermesCLI._show_usage) no longer assumes agent.context_compressor is non-None.
  • ctx_summary is always set before printing the Current context line (avoids NameError when only the None branch ran).

How verified

  • ast.parse on cli.py in a minimal environment; full import cli needs the repo venv per upstream docs.

Fixes #14715

Made with Cursor

Changed files

  • cli.py (modified, +13/-6)

PR #14887: fix(cli): handle missing compressor in /usage

Description (problem / solution / changelog)

Summary

  • guard /usage against a missing context_compressor
  • default context/compression metrics to zero when the compressor is absent
  • add a CLI regression test covering context_compressor=None

Closes #14715

Testing

  • python3 -m pytest -o addopts= tests/cli/test_cli_status_bar.py

Changed files

  • cli.py (modified, +4/-4)
  • tests/cli/test_cli_status_bar.py (modified, +26/-0)

Code Example

cd /Users/genie/.hermes/hermes-agent
source venv/bin/activate
python - <<'PY'
from types import SimpleNamespace
import cli

obj = object.__new__(cli.HermesCLI)
obj.conversation_history = []
obj.agent = SimpleNamespace(
    session_api_calls=1,
    session_input_tokens=1,
    session_output_tokens=2,
    session_cache_read_tokens=0,
    session_cache_write_tokens=0,
    session_prompt_tokens=3,
    session_completion_tokens=4,
    session_total_tokens=5,
    context_compressor=None,
    model="x",
    get_rate_limit_state=lambda: None,
)

try:
    cli.HermesCLI._show_usage(obj)
except Exception as e:
    print(type(e).__name__, e)
PY
RAW_BUFFERClick to expand / collapse

Bug Description

/usage assumes agent.context_compressor is always present and crashes with AttributeError when it is None.

Affected files / lines

  • cli.py:6417-6421 — dereferences compressor.last_prompt_tokens, compressor.context_length, and compressor.compression_count without a guard
  • Contrast: cli.py:1919-1928 already guards if compressor: in the status-bar path

Why this is a bug

Hermes already has code paths that tolerate a missing context compressor, so /usage is inconsistent. Agents/tests/providers that do not attach a compressor object can crash the command instead of showing partial usage stats.

Minimal reproduction

cd /Users/genie/.hermes/hermes-agent
source venv/bin/activate
python - <<'PY'
from types import SimpleNamespace
import cli

obj = object.__new__(cli.HermesCLI)
obj.conversation_history = []
obj.agent = SimpleNamespace(
    session_api_calls=1,
    session_input_tokens=1,
    session_output_tokens=2,
    session_cache_read_tokens=0,
    session_cache_write_tokens=0,
    session_prompt_tokens=3,
    session_completion_tokens=4,
    session_total_tokens=5,
    context_compressor=None,
    model="x",
    get_rate_limit_state=lambda: None,
)

try:
    cli.HermesCLI._show_usage(obj)
except Exception as e:
    print(type(e).__name__, e)
PY

Observed output:

  • AttributeError 'NoneType' object has no attribute 'last_prompt_tokens'

Expected Behavior

/usage should handle a missing compressor and print whatever usage data is available.

Actual Behavior

The command crashes on None.

Suggested investigation direction

Mirror the existing status-bar guard pattern: treat compressor-derived metrics as optional and default them safely when context_compressor is missing.

extent analysis

TL;DR

Add a guard to check if agent.context_compressor is not None before accessing its attributes in the /usage command.

Guidance

  • Introduce a conditional check for agent.context_compressor before dereferencing its attributes, similar to the existing guard in cli.py:1919-1928.
  • Update the /usage command to handle the case where context_compressor is None and provide default values for compressor-derived metrics.
  • Review other parts of the code that access agent.context_compressor to ensure they also handle the None case.
  • Test the updated code with the provided minimal reproduction script to verify the fix.

Example

if obj.agent.context_compressor:
    # access compressor attributes
    last_prompt_tokens = obj.agent.context_compressor.last_prompt_tokens
    context_length = obj.agent.context_compressor.context_length
    compression_count = obj.agent.context_compressor.compression_count
else:
    # provide default values
    last_prompt_tokens = 0
    context_length = 0
    compression_count = 0

Notes

This fix assumes that the existing guard pattern in cli.py:1919-1928 is the correct approach to handle missing context_compressor objects. Additional testing and review may be necessary to ensure the updated code behaves as expected in all scenarios.

Recommendation

Apply the workaround by adding a guard to check for agent.context_compressor and providing default values for compressor-derived metrics when it is None, as this approach is consistent with existing code patterns and allows the /usage command to handle missing compressors gracefully.

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

hermes - ✅(Solved) Fix /usage crashes when agent.context_compressor is None [2 pull requests, 1 participants]