feat(compression): add configurable warn_after_compressions threshold (#53876) - #53958
feat(compression): add configurable warn_after_compressions threshold (#53876)#53958IsshikiSenn wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new compression.warn_after_compressions configuration knob to control (or disable) the “Session compressed N times…” repeated-compression warning, making long-running sessions less noisy without requiring source edits.
Changes:
- Introduces
compression.warn_after_compressions(default2,0disables) in the default config and user-facing config examples/docs. - Threads the config value into agent initialization (
agent.compression_warn_after_compressions) and uses it inconversation_compression.pyinstead of the hardcoded>= 2. - Extends the existing regression test to cover custom thresholds and the disabled (
0) case.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
agent/agent_init.py |
Reads compression.warn_after_compressions from config and stores it on the agent. |
agent/conversation_compression.py |
Uses the agent-configured threshold to decide when to emit the repeated-compression warning. |
hermes_cli/config.py |
Adds the new key to DEFAULT_CONFIG (preserving existing default behavior). |
cli-config.yaml.example |
Documents the new config key and its intended behavior. |
website/docs/user-guide/configuration.md |
Adds the new key to the compression reference and describes its behavior. |
tests/agent/test_compression_count_warning_36908.py |
Adds coverage for custom thresholds and 0 = disabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| `warn_after_compressions` controls when Hermes shows the repeated-compression warning ("Session compressed N times — accuracy may degrade. Consider /new to start fresh."). Default `2` — the warning appears starting at the second compaction and on every subsequent compaction. Set to `0` to disable it entirely, or raise it (e.g. `5`) for long-running sessions where multiple compactions are expected. | ||
|
|
||
| :::tip Gateway hot-reload of compression and context length | ||
| As of recent releases, editing `model.context_length` or any `compression.*` key in `config.yaml` on a running gateway takes effect on the next message — no gateway restart, no `/reset`, no session rotation required. The cached-agent signature includes these keys, so the gateway transparently rebuilds the agent when it sees a change. API keys and tool/skill config still require the usual reload paths. |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Clean feature: adds a configurable warn_after_compressions threshold (default 2, 0 to disable). The config plumbing is correct through agent_init.py -> agent.compression_warn_after_compressions -> conversation_compression.py. Test coverage is thorough with the _build_agent_with_db helper updated to accept the new parameter. The CLI config example is well-documented.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment — Clean configuration enhancement
Adds a configurable compression.warn_after_compressions threshold to control when the repeated-compression warning fires. Default 2 (existing behavior), 0 disables entirely.
Changes:
agent/agent_init.py: Reads config value and stores on agentagent/conversation_compression.py: Uses configured threshold instead of hardcoded>= 2hermes_cli/config.py: Adds default to DEFAULT_CONFIGcli-config.yaml.example: Documents new keywebsite/docs/user-guide/configuration.md: User-facing docstests/agent/test_compression_count_warning_36908.py: 3 new tests for custom threshold, fire-at-threshold, and disabled cases
Assessment:
- Well-scoped: 6 files, 80 additions
- Backward-compatible (default matches existing behavior)
- Test coverage for all edge cases
- Docs and config examples updated
- No security concerns
Reviewed by Hermes Agent
Make the repeated-compression warning threshold configurable via compression.warn_after_compressions (default 2, 0 disables). Long-running sessions can raise the threshold without patching source. Closes NousResearch#53876
2f66450 to
b30529a
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused configuration addition. The underlying request remains valid on current main: agent/conversation_compression.py:935-942 still warns at a hardcoded count of two.
Problems
agent/agent_init.pyreads this value only during construction, butgateway/run.py:15743-15754omitscompression.warn_after_compressionsfrom cached-agent invalidation. A running gateway therefore retains the old setting, whilewebsite/docs/user-guide/configuration.md:762-764promises hot reload forcompression.*.- The added
int(...)coercion can raise onnullor non-numeric YAML and prevent agent construction. The PR tests bypass this path by assigning the agent attribute directly.
Suggested changes
- Add the new key to
_CACHE_BUSTING_CONFIG_KEYSand cover a changed gateway signature intests/gateway/test_agent_cache.py. - Fall back to
2for invalid values and add a config-to-agent construction regression covering custom, disabled, and invalid input.
This is an automated hermes-sweeper review.
Guard invalid config coercion and include the key in gateway cache-busting so hot-reload matches the documented compression.* behavior.
|
Thanks for the review — addressed both points on the latest commit:
Left |
Resolve conflicts after DEFAULT_CONFIG moved to config_defaults: keep warn_after_compressions there and in docs alongside in_place. Update the config-coercion test to patch load_config_readonly.
Resolve agent_init.py conflict by keeping both warn_after_compressions and main's micro-compaction config plumbing.
Make the repeated-compression warning threshold configurable via
compression.warn_after_compressions(default2,0disables). Long-running sessions can raise the threshold without patching source.Closes #53876
What does this PR do?
The repeated-compression warning ("Session compressed N times — accuracy may degrade. Consider /new to start fresh.") was hardcoded to fire when
compression_count >= 2. That is too aggressive for long-running sessions (multi-agent orchestration, research tasks) where multiple compactions are normal, and there was no way to tune or disable the warning without editing source.This PR adds
compression.warn_after_compressionsunder the existingcompression:config section. Default2preserves current behavior; set to0to disable the warning entirely, or raise it (e.g.5) for sessions that expect many compactions. The value is read at agent construction time inagent_init.pyand consumed incompress_context()— same pattern as other agent-level compression settings likecompression_in_place.Related Issue
Fixes #53876
Type of Change
Changes Made
hermes_cli/config.py— addcompression.warn_after_compressions: 2toDEFAULT_CONFIGagent/agent_init.py— read config and setagent.compression_warn_after_compressions(max(0, int(...)))agent/conversation_compression.py— replace hardcoded>= 2with configurable threshold checkcli-config.yaml.example— document the new keywebsite/docs/user-guide/configuration.md— add to Context Compression referencetests/agent/test_compression_count_warning_36908.py— extend coverage for custom threshold, boundary, and0= disabledIntentionally out of scope: gateway cache-busting (change takes effect on next agent construction / new session), Desktop curated settings allowlist, warning deduplication, CLI status-bar compression styling.
How to Test
warn_after_compressionsunset or at2; after the 2nd compaction, the warning should appear via_emit_status/ gateway status callback.compression.warn_after_compressions: 5in~/.hermes/config.yaml, start a new session (or restart gateway), compress 4 times — no warning; on the 5th compaction — warning fires.compression.warn_after_compressions: 0; no repeated-compression warning regardless of count.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass — runscripts/run_tests.sh tests/agent/test_compression_count_warning_36908.pylocally before mergeDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
N/A — config-only change; behavior verified via unit tests.