Skip to content

fix: signal compression boundary to context engine#16306

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-c372633b
Apr 27, 2026
Merged

fix: signal compression boundary to context engine#16306
teknium1 merged 2 commits into
mainfrom
hermes/hermes-c372633b

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

External context engine plugins (e.g. hermes-lcm) now receive boundary_reason="compression" when Hermes rotates session_id during context compression, so they can preserve DAG / store lineage across the split instead of treating it as a fresh /new.

Changes

  • run_agent.py (+16): after the compression-split rotates session_id, fire self.context_compressor.on_session_start(new_sid, boundary_reason="compression", old_session_id=<old>). Guarded with hasattr + try/except so built-in ContextCompressor (which accepts **kwargs and ignores them) is unaffected.
  • tests/run_agent/test_compression_boundary_hook.py (new): three tests — boundary hook fires on rollover, no hook when session_db is absent (no rotation happens), plugin exception does not break compression.

Root cause

Closes hermes-lcm#68 symptom: after Hermes compressed and minted a new physical session, LCM saw the new session_id and reset per-session state, giving compression_count: 1, store_messages: 0, dag_nodes: 0. The built-in compressor had no way to tell plugins that the rotation was a compression-boundary continuation rather than a fresh user-initiated /new. This adds that signal.

Validation

Before After
tests/run_agent/test_compression_boundary_hook.py (new) 3 passed
tests/run_agent/test_compression_persistence.py + tests/cli/test_manual_compress.py 10 passed 10 passed

Credit

Salvaged from @Tosko4's PR #13370 — scope minimized to the boundary_reason signal only. The broader session-lifecycle refactor (new _transition_context_engine_session helper, off-thread memory flush on /new, HERMES_SESSION_ID contextvar, conversation_session_id field on ProcessSession, inspect.signature introspection for focus_topic, plugin discovery re-ordering) will be taken in separate PRs if justified by concrete plugin need. Contributor authorship preserved on the fix commit.

Tosko4 and others added 2 commits April 26, 2026 19:06
When _compress_context rotates session_id (compression split), fire
on_session_start(new_sid, boundary_reason="compression",
old_session_id=<old>) on the active context engine. Plugin engines
(e.g. hermes-lcm) use this to preserve DAG lineage across the rollover
instead of re-initializing fresh per-session state.

Built-in ContextCompressor.on_session_start accepts **kwargs and ignores
them — no behavior change for default users.

Closes hermes-lcm#68 symptom: after Hermes compressed and minted a new
physical session, LCM was treating the split as a fresh /new and losing
continuity (compression_count: 1, store_messages: 0, dag_nodes: 0).

Credit: @Tosko4 (PR #13370) — minimized scope to the boundary_reason
signal only; the broader session-lifecycle refactor will be taken in
separate PRs if justified by concrete plugin need.
@teknium1 teknium1 merged commit cb51bae into main Apr 27, 2026
11 of 12 checks passed
@teknium1 teknium1 deleted the hermes/hermes-c372633b branch April 27, 2026 02:07
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants