fix(compression): pass platform on compression-boundary session_start (#27633) - #27659
fix(compression): pass platform on compression-boundary session_start (#27633)#27659briandevans wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Ensures the compression boundary hook propagates the agent's platform to context engine plugins, preventing per-session source lineage from being reset on compression rollovers.
Changes:
- Pass
platform=agent.platform or "cli"toon_session_startduring compression inagent/conversation_compression.py. - Add two tests verifying the platform is forwarded (and falls back to
"cli"when unset).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agent/conversation_compression.py | Forwards platform (with "cli" fallback) to the compression boundary on_session_start call. |
| tests/run_agent/test_compression_boundary_hook.py | Adds tests covering platform propagation and the "cli" fallback. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bbernstein616
left a comment
There was a problem hiding this comment.
Reviewed diff and verified locally with scripts/run_tests.sh tests/run_agent/test_compression_boundary_hook.py (5 passed). CI checks are green. I attempted to merge but GitHub denied MergePullRequest permission for bbernstein616.
c238541 to
814de91
Compare
|
Rebased onto current main (was 82 commits behind) and pushed a follow-up commit that pins Background: PR #28102 added a new Fix is one line per setup, same shape as the existing |
39da127 to
d6b116a
Compare
…NousResearch#27633) When _compress_context rotates session_id at the compression boundary, the on_session_start call to the context engine omits the platform kwarg. Plugin engines (e.g. hermes-lcm) that track per-session source lineage via _session_platform get it overwritten with "" on every compression rollover, which normalizes to "unknown". All messages ingested after the boundary are then attributed to source='unknown' instead of the actual platform (discord, telegram, cli, ...). The initial session-start call in agent/agent_init.py:1351 already passes platform=agent.platform or "cli". This change mirrors that pattern on the compression-boundary call so the platform is preserved across the rollover. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ests Rebase onto main showed that PR NousResearch#28117 added a post-compress abort branch that short-circuits before the session-id rotation that the new platform-on-compression-boundary tests assert on. MagicMock attrs are truthy by default, so the two new tests need to pin the abort flag the same way `test_on_session_start_called_with_compression_boundary` already does after teknium1's PR NousResearch#28465 caught up the older test on main.
d6b116a to
2ead25b
Compare
|
Closing to focus the queue on security/file-safety work where civilian merges are landing. Happy to reopen if maintainers want this picked up. |
What does this PR do?
Adds
platform=agent.platform or "cli"to the context-engineon_session_startcall fired at the compression boundary inagent/conversation_compression.py. Mirrors the canonical pattern already used by the initial session-start atagent/agent_init.py:1351. Two new regression tests cover the explicit-platform andclifallback paths.Root cause: when
_compress_contextrotatessession_idbecause of compression, the boundary notification atagent/conversation_compression.py:373omitsplatform. Plugin context engines such ashermes-lcmcache per-session source lineage in_session_platform, and_apply_session_start_metadataunconditionally overwrites that field fromkwargs.get("platform"). So whenplatformis absent on the compression call it gets reset to""→ normalized to"unknown". Every message ingested after the compression boundary is then attributed tosource='unknown'instead of the real platform (discord, telegram, cli, …). The reporter saw 806 messages across 4 sessions in a real deployment attributed tosource='unknown'despite originating from Discord;lcm_statussource lineage degrades after each compression;lcm_grepsource filters miss messages.Mirrors
agent/agent_init.py:1354precedence:agent.platform or "cli".Related Issue
Fixes #27633
Type of Change
Changes Made
agent/conversation_compression.py— one-line change at line 377: passplatform=agent.platform or "cli"on the boundaryon_session_startcall, identical to the initial session-start call atagent/agent_init.py:1354.tests/run_agent/test_compression_boundary_hook.py— two new cases:test_on_session_start_passes_platform_on_compression(agent.platform = "discord"flows through) andtest_on_session_start_falls_back_to_cli_when_platform_unset(agent.platform = Nonefalls back to"cli").How to Test
uv run --with pytest --with pytest-xdist --with pytest-asyncio python3 -m pytest tests/run_agent/test_compression_boundary_hook.py -vChecklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/ARelated / Positioning
boundary_reason="compression"signal but omitted theplatformkwarg.agent/agent_init.py:1354precedence:agent.platform or "cli".