Skip to content

fix(compression): abort + preserve context on transient network summary failure (#29559, #25585) - #51881

Merged
kshitijk4poor merged 1 commit into
mainfrom
fix/29559-compression-abort-on-network-failure
Jun 24, 2026
Merged

fix(compression): abort + preserve context on transient network summary failure (#29559, #25585)#51881
kshitijk4poor merged 1 commit into
mainfrom
fix/29559-compression-abort-on-network-failure

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Closes #29559 and #25585 (same root cause / same code path) — context compaction destroys the compacted turns when summary generation fails on a transient network error.

When the auxiliary summary call fails and compression.abort_on_summary_failure is at its default (False), compress() falls through to the fallback path: it inserts a static "summary unavailable" marker and drops the middle window anyway.

Verified still live on current main by default (the abort-and-keep path exists but is opt-in).

Fix

compress() already carves out an always-abort exception for auth failures (401/403) regardless of the config flag — rotating into a placeholder-summary child on a broken credential strands the user. A transient network/connection error is the same logic in reverse: it will recover, so retrying then is strictly better than discarding context for a momentary blip.

Extend that carve-out to terminal connection/network failures:

  • new _last_summary_network_failure flag, set in _generate_summary's terminal failure branch when _is_connection_error(e) (reached only after any main-model fallback is exhausted), reset alongside the auth flag;
  • compress() aborts when it's set — returns messages unchanged, _last_compress_aborted=True — independent of abort_on_summary_failure;
  • a network-specific operator warning (distinct from the auth + config-flag messages).

Scoped to connection errors only: a generic 400/500 still takes the historical fallback-drop path (test_non_auth_failure_still_uses_fallback_path stays green). This mirrors an existing house pattern (the auth carve-out) rather than flipping the global default.

Tests

tests/agent/test_context_compressor.py:

  • test_generate_summary_flags_network_failure — a ConnectionError flags _last_summary_network_failure (not auth);
  • test_compress_aborts_on_network_failure_despite_flag_false — with the default flag off, a connection error aborts (messages unchanged, _last_compress_aborted=True, no fallback-drop).

Both mutation-checked (removing the flag-set fails detection; removing the carve-out fails the abort). Full test_context_compressor.py suite: 120 passed.

Attribution

Thanks to @MattChen1981 (#29559) for the field report + repro and @franksong2702 (#25585) for the precise failure-mode writeup and proposed approach.

Fixes #29559
Fixes #25585

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/29559-compression-abort-on-network-failure vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11180 on HEAD, 11180 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5906 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/desktop Electron desktop app (apps/desktop/*) P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jun 24, 2026
…ry failure (#29559, #25585)

When context compaction's summary generation fails, the compressor's default
path (abort_on_summary_failure=False) drops the middle window and inserts a
static 'summary unavailable' marker — destroying the compacted turns. #29559
reported the field impact: a Connection error at the compaction moment dropped
124->15 messages (110 lost) for a long browser-automation task; #25585 is the
same failure mode (failed summary commits a destructive compaction anyway).

compress() already has an EXCEPTION to the historical drop default: auth
failures (401/403) ALWAYS abort and preserve the session, because rotating into
a placeholder-summary child on a broken credential strands the user. A transient
network/connection error is the same situation in reverse: it WILL recover, and
retrying then is strictly better than discarding context for a momentary blip.

Extend the always-abort carve-out to terminal connection/network failures:
- new _last_summary_network_failure flag, set in _generate_summary's terminal
  failure branch when _is_connection_error(e) (reached only after any main-model
  fallback is exhausted), reset alongside the auth flag;
- compress() aborts when it's set (returns messages unchanged,
  _last_compress_aborted=True), independent of abort_on_summary_failure;
- a network-specific operator warning (distinct from the auth + config-flag
  messages).

Scoped to connection errors only: a generic 500/400 still takes the historical
fallback-drop path (test_non_auth_failure_still_uses_fallback_path stays green).

Tests: network-failure detection + abort-despite-flag-false, both mutation-checked
(removing the flag-set fails detection; removing the carve-out fails the abort).
@kshitijk4poor
kshitijk4poor force-pushed the fix/29559-compression-abort-on-network-failure branch from 05f3082 to ac822e4 Compare June 24, 2026 13:01
@kshitijk4poor
kshitijk4poor enabled auto-merge June 24, 2026 13:02
@kshitijk4poor
kshitijk4poor merged commit 7fb2027 into main Jun 24, 2026
48 of 50 checks passed
@kshitijk4poor
kshitijk4poor deleted the fix/29559-compression-abort-on-network-failure branch June 24, 2026 14:24
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…pression-abort-on-network-failure

fix(compression): abort + preserve context on transient network summary failure (NousResearch#29559, NousResearch#25585)
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…pression-abort-on-network-failure

fix(compression): abort + preserve context on transient network summary failure (NousResearch#29559, NousResearch#25585)
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…pression-abort-on-network-failure

fix(compression): abort + preserve context on transient network summary failure (NousResearch#29559, NousResearch#25585)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…pression-abort-on-network-failure

fix(compression): abort + preserve context on transient network summary failure (NousResearch#29559, NousResearch#25585)
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…pression-abort-on-network-failure

fix(compression): abort + preserve context on transient network summary failure (NousResearch#29559, NousResearch#25585)
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/desktop Electron desktop app (apps/desktop/*) P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

3 participants