Skip to content

[Bug]: CLI status bar shows ctx -- when LCM context engine is active — context_length never resolved #9071

Description

@strueman

Bug Description

When context.engine: lcm is configured and hermes-lcm is the active context engine, the CLI status bar displays ctx -- with an empty progress bar ([░░░░░░░░░░]) instead of the actual context fill percentage. The bar never shows meaningful data, even after the first API response.

⚕ minimax-m2.7 │ ctx -- │ [░░░░░░░░░░] -- │ 9m

References

  • run_agent.py:~1306 — plugin engine initialization (fix location)
  • run_agent.py:~1550switch_model path (reference for correct pattern)
  • run_agent.py:~1340on_session_start call site with broken kwargs fallback
  • plugins/context_engine/lcm/engine.py — LCMEngine (affected plugin)

Steps to Reproduce

  1. Install hermes-lcm into ~/.hermes/hermes-agent/plugins/context_engine/lcm/
  2. Configure context.engine: lcm in ~/.hermes/config.yaml
  3. Start a new Hermes CLI session: hermes
  4. Observe the status bar — it shows ctx -- with [░░░░░░░░░░] even after sending message

Expected Behavior

Context size and usage updates after api calls
minimax-m2.7 │ 101K/204.8K │ [█████░░░░░] 50% │ 53m

Actual Behavior

Status bar (broken):

⚕ minimax-m2.7 │ ctx -- │ [░░░░░░░░░░] -- │ 9m

Affected Component

CLI (interactive chat)

Messaging Platform (if gateway-related)

No response

Operating System

Debian 13

Python Version

3.13.5

Hermes Version

latest

Relevant Logs / Traceback

Root Cause Analysis (optional)

In run_agent.py, the built-in ContextCompressor resolves context_length in its __init__ by calling get_model_context_length():

# run_agent.py — built-in path (works correctly)
self.context_compressor = ContextCompressor(
    model=self.model,
    context_length=get_model_context_length(...),  # ← resolves here
    ...
)

However, external (plugin) context engines are instantiated via a different path that skips this:

# run_agent.py — plugin engine path (broken)
_selected_engine = load_context_engine(engine_name)
self.context_compressor = _selected_engine  # ← no context_length set!

on_session_start() is called later with context_length=getattr(self.context_compressor, "context_length", 0) — but since update_model was never called on the plugin engine, context_length is 0. The status bar's calculation context_tokens / context_length * 100 produces 0 / 0 = Nonectx --.

Proposed Fix (optional)

In run_agent.py (~line 1306), immediately after loading an external context engine, call update_model() with the resolved context_length:

_selected_engine = load_context_engine(engine_name)
self.context_compressor = _selected_engine
if not self.quiet_mode:
    logger.info("Using context engine: %s", _selected_engine.name)

# FIX: Resolve context_length for external engines
from agent.model_metadata import get_model_context_length
_init_ctx_len = get_model_context_length(
    self.model,
    base_url=self.base_url,
    api_key=getattr(self, "api_key", ""),
    config_context_length=_config_context_length,
    provider=self.provider,
)
self.context_compressor.update_model(
    model=self.model,
    context_length=_init_ctx_len,
    base_url=self.base_url,
    api_key=getattr(self, "api_key", ""),
    provider=self.provider,
)

This mirrors what switch_model already does correctly. After the fix, the status bar shows the correct context_length from session start.

Are you willing to submit a PR for this?

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions