fix: signal compression boundary to context engine#16306
Merged
Conversation
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.
This was referenced Apr 27, 2026
This was referenced Apr 27, 2026
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 rotatessession_id, fireself.context_compressor.on_session_start(new_sid, boundary_reason="compression", old_session_id=<old>). Guarded withhasattr+try/exceptso built-inContextCompressor(which accepts**kwargsand ignores them) is unaffected.tests/run_agent/test_compression_boundary_hook.py(new): three tests — boundary hook fires on rollover, no hook whensession_dbis 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
tests/run_agent/test_compression_boundary_hook.py(new)tests/run_agent/test_compression_persistence.py+tests/cli/test_manual_compress.pyCredit
Salvaged from @Tosko4's PR #13370 — scope minimized to the
boundary_reasonsignal only. The broader session-lifecycle refactor (new_transition_context_engine_sessionhelper, off-thread memory flush on/new,HERMES_SESSION_IDcontextvar,conversation_session_idfield onProcessSession,inspect.signatureintrospection forfocus_topic, plugin discovery re-ordering) will be taken in separate PRs if justified by concrete plugin need. Contributor authorship preserved on the fix commit.