Skip to content

fix(compression): notify gateway users when summary generation fails (salvage #16333) - #16771

Merged
teknium1 merged 5 commits into
mainfrom
hermes/hermes-1614870f
Apr 28, 2026
Merged

fix(compression): notify gateway users when summary generation fails (salvage #16333)#16771
teknium1 merged 5 commits into
mainfrom
hermes/hermes-1614870f

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #16333 by @iamagenius00 onto current main (223 commits behind at submission). Contributor authorship preserved via cherry-pick + rebase merge.

Summary

Gateway users now see a visible ⚠️ warning when context compression's summary LLM call fails. Previously the compressor would drop the selected turns, insert a static fallback placeholder, and leave the user with silently-truncated context — only agent.log had the warning.

Why the existing warning path didn't catch it

_compress_context in run_agent.py already calls self._emit_warning(...) on summary failure, but _emit_warning surfaces via _vprint (silenced by _print_fn = lambda: None) and status_callback (not set). Both the gateway hygiene auto-compress path and the /compress command build temporary AIAgent instances with quiet_mode=True, no-op _print_fn, and no status_callback — so the warning never reached the user.

Changes

  • agent/context_compressor.py — track _last_summary_fallback_used + _last_summary_dropped_count per compress call. Cleared at the top of compress() and on on_session_reset(). Set when summary generation returns None and the static fallback is inserted.
  • gateway/run.py hygiene auto-compress — after _compress_context returns, inspect the compressor flags and send a visible ⚠️ message to the originating chat (with thread_id metadata preserved).
  • gateway/run.py /compress command — append the same warning to the manual command reply.
  • Tests: 2 new compressor tests + 1 gateway hygiene test + 1 /compress test.

Acceptance

  • Summary success → no user-visible warning (unchanged).
  • Summary failure on gateway hygiene → user receives TG/Discord message with dropped count, underlying error, and remediation hint.
  • Summary failure on /compress → warning appended to the command reply.
  • CLI status_callback / _emit_warning path untouched (no behavioural regression).
  • Warning delivery is try/except-wrapped so a send failure can't break the compression result.

Validation

scripts/run_tests.sh tests/agent/test_context_compressor.py tests/gateway/test_session_hygiene.py tests/gateway/test_compress_command.py
81 passed in 1.75s

Closes #16333.
Fixes #16650.

iamagenius00 and others added 5 commits April 27, 2026 19:17
When auxiliary compression's summary LLM call fails (e.g. model 404,
auxiliary model misconfigured), the compressor still drops the selected
turns and inserts a static fallback placeholder — the dropped context
is unrecoverable.

Previously the only signal of this was a WARNING in agent.log. Gateway
users (Telegram/Discord/etc.) had no way to know context was lost
because the existing _emit_warning path requires a status_callback,
and the gateway hygiene path uses a temporary _hyg_agent with
quiet_mode=True and no callback wired up.

Changes:
- ContextCompressor: track _last_summary_fallback_used and
  _last_summary_dropped_count on each compress() call. Cleared at the
  start of compress() and on session reset.
- gateway/run.py hygiene: after auto-compress, inspect the temp
  agent's compressor; if fallback was used, send a visible ⚠️ warning
  to the user via the platform adapter (TG/Discord/etc.) including
  dropped count and the underlying error.
- gateway/run.py /compress: append the same warning to the manual
  compress reply so users running /compress see the failure too.

Acceptance:
- Summary success: no user-visible warning (unchanged).
- Summary failure on gateway hygiene: user receives a TG/Discord
  message with dropped count + error + remediation hint.
- Summary failure on /compress: warning appended to the command reply.
- CLI status_callback / _emit_warning path is untouched.
- Test coverage: two new tests verify the tracking fields are set on
  failure and cleared on subsequent success.
…ing delivery

Address review feedback on PR #16333:

1. The hygiene-path warning send was missing metadata=_hyg_meta. On
   Telegram topics / Slack threads / Discord threads the warning would
   land in the main channel instead of the originating thread. Now
   reuses the same _hyg_meta dict already computed for the hygiene
   compaction itself.

2. New gateway-level test
   test_session_hygiene_warns_user_when_summary_generation_fails
   verifies end-to-end:
   - When the compressor's _last_summary_fallback_used flag is True,
     the gateway invokes adapter.send() exactly once.
   - The warning message includes the dropped count and the underlying
     error string.
   - metadata={'thread_id': ...} is propagated so the warning lands
     in the originating topic/thread.

Tests: 20 gateway hygiene + 54 context_compressor — all pass.
…ning

The fallback placeholder said "N conversation turns were removed" while the
gateway warning said "N historical message(s) were removed". Use "messages"
in both so users don't wonder if the two counters refer to different things.
The per-call reset block at the top of compress() cleared
_last_summary_dropped_count and _last_summary_fallback_used but
not _last_summary_error. Functionally this didn't break the
gateway warning path (callers gate on _last_summary_fallback_used
first, and _last_summary_error is overwritten on the next failure),
but it left the three tracking fields inconsistent — anyone
reading _last_summary_error standalone after a successful compress
would see a stale value from a previous failed compress.

Reset all three together so the per-call contract is uniform.
PR #16333 added a warning to the manual /compress reply when the
auxiliary summariser fails and the static fallback placeholder is
used, but only the gateway-hygiene path had a test
(test_session_hygiene_warns_user_when_summary_generation_fails).
The /compress branch in _handle_compress_command was uncovered.

New test test_compress_command_appends_warning_when_summary_generation_fails
mocks the compressor's _last_summary_fallback_used /
_last_summary_dropped_count / _last_summary_error fields and
verifies the /compress reply contains the ⚠️ marker, the underlying
error string, the dropped message count, and the 'historical
message(s) were removed' wording — i.e. the same contract the
hygiene-path test enforces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery 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.

Gateway users not notified when compression summary generation fails and history is dropped

3 participants