fix(compression): notify gateway users when summary generation fails (salvage #16333) - #16771
Merged
Conversation
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.
This was referenced Apr 28, 2026
Closed
This was referenced Jun 21, 2026
Closed
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.
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.loghad the warning.Why the existing warning path didn't catch it
_compress_contextinrun_agent.pyalready callsself._emit_warning(...)on summary failure, but_emit_warningsurfaces via_vprint(silenced by_print_fn = lambda: None) andstatus_callback(not set). Both the gateway hygiene auto-compress path and the/compresscommand build temporaryAIAgentinstances withquiet_mode=True, no-op_print_fn, and nostatus_callback— so the warning never reached the user.Changes
agent/context_compressor.py— track_last_summary_fallback_used+_last_summary_dropped_countper compress call. Cleared at the top ofcompress()and onon_session_reset(). Set when summary generation returns None and the static fallback is inserted.gateway/run.pyhygiene auto-compress — after_compress_contextreturns, inspect the compressor flags and send a visiblethread_idmetadata preserved).gateway/run.py/compresscommand — append the same warning to the manual command reply./compresstest.Acceptance
/compress→ warning appended to the command reply.status_callback/_emit_warningpath untouched (no behavioural regression).Validation
Closes #16333.
Fixes #16650.