Skip to content

fix(compressor): restore summary_model and reset fallen_back flag on session reset - #21783

Open
nftpoetrist wants to merge 1 commit into
NousResearch:mainfrom
nftpoetrist:fix/compressor-summary-model-reset
Open

fix(compressor): restore summary_model and reset fallen_back flag on session reset#21783
nftpoetrist wants to merge 1 commit into
NousResearch:mainfrom
nftpoetrist:fix/compressor-summary-model-reset

Conversation

@nftpoetrist

Copy link
Copy Markdown
Contributor

What does this PR do?

_generate_summary() clears self.summary_model = "" when the configured auxiliary summary model fails (404, 503, timeout, etc.) and falls back to the main model for that compression call. This mutation is permanent for the lifetime of the ContextCompressor instance.

reset_session_state() in run_agent.py calls on_session_reset() on the same compressor instance on every /new and /reset — the compressor is never recreated. on_session_reset() already resets _summary_failure_cooldown_until to 0 so transient errors do not block a fresh session (fix #15548 / salvage #19622). The same logic applies to summary_model: a per-session fallback should not permanently degrade compression quality for every subsequent session.

Without this fix: after one aux model failure in a long session, every /reset silently leaves summary_model = "". The configured model (e.g. aux_models.compressor.model = "gpt-4o-mini") is never used again — even if the aux model recovered — until the gateway is restarted.

Root cause: on_session_reset() did not include summary_model in its reset list, and _summary_model_fallen_back was also left as True, preventing the one-shot fallback from firing again in the new session.

Fix:

  1. Store the originally configured value in _configured_summary_model at __init__ time.
  2. Restore self.summary_model from it in on_session_reset().
  3. Reset _summary_model_fallen_back = False so the fallback logic can fire once more if the model fails again in the new session.

Symmetric with the _summary_failure_cooldown_until = 0.0 reset already present in the same method.

Related Issue

Companion to #15548 (same lifecycle class — on_session_reset() not resetting a compressor field).

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests
  • ♻️ Refactor
  • 🎯 New skill

Changes Made

  • agent/context_compressor.py: store _configured_summary_model at init (+1 line); restore in on_session_reset() (+2 lines)
  • tests/agent/test_context_compressor.py: 3 new regression tests in TestOnSessionResetSummaryModel (+35 lines)

How to Test

python3.11 -m pytest tests/agent/test_context_compressor.py::TestOnSessionResetSummaryModel -v --override-ini="addopts="

Expected: 3 passed.

Manual reproduction:

  1. Configure aux_models.compressor.model to a model that will fail (wrong name / offline).
  2. Have a long session that triggers compression — the aux model fails, falls back to main.
  3. Run /reset.
  4. Have another long session that triggers compression.
  5. Before fix: main model used (aux model silently absent). After fix: aux model tried again.

Checklist

Code

  • Contributing Guide read
  • Conventional Commits
  • No duplicate PR
  • This fix only
  • pytest run — 72 passed, 0 failed
  • Tests added
  • Platform: macOS

Documentation & Housekeeping

  • Docs updated — N/A
  • cli-config.yaml.example — N/A
  • CONTRIBUTING.md/AGENTS.md — N/A
  • Cross-platform impact — affects all platforms; no platform-specific code
  • Tool descriptions — N/A

@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 P2 Medium — degraded but workaround exists labels May 8, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Revives the fix from #15549 (closed without merge) and #16152 (closed as duplicate of #15549). The bug is confirmed present in main — on_session_reset() does not restore summary_model or reset _summary_model_fallen_back.

…session reset

_generate_summary() clears self.summary_model = "" when the configured aux
model fails (404, 503, timeout) and falls back to the main model for the
current compression call. This mutation is permanent for the lifetime of the
ContextCompressor instance. Because the same instance is reused across /reset
(run_agent.py calls on_session_reset() rather than recreating the compressor),
every subsequent session silently uses the main model for compression instead
of the configured aux model — even after a transient outage resolves.

on_session_reset() already resets _summary_failure_cooldown_until to 0 so
transient errors do not block a fresh session (fix NousResearch#15548). The same logic
applies to summary_model: a per-session failure should not permanently degrade
compression quality for subsequent sessions.

Fix: store the originally configured value in _configured_summary_model at
__init__ time, then restore summary_model from it in on_session_reset().
Also reset _summary_model_fallen_back to False so the one-shot fallback can
fire again if the aux model fails in the new session.

Fixes companion to NousResearch#15548
@nftpoetrist
nftpoetrist force-pushed the fix/compressor-summary-model-reset branch from 847ce2c to 0d4e00f Compare May 10, 2026 00:05
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for preserving this regression fix. The premise still holds on current main: _fallback_to_main_for_compression() sets _summary_model_fallen_back and clears summary_model at agent/context_compressor.py:1733-1745, while on_session_reset() does not restore either value at agent/context_compressor.py:726-745.

Problems

  • The submitted patch no longer applies to current main: git apply --check <(gh pr diff 21783 --repo NousResearch/hermes-agent --patch) fails for both changed files because the compressor and test file have moved substantially.

Suggested changes

  • Salvage the same two state resets into the current ContextCompressor layout, preserving the regression tests; no semantic defect was found in the proposed behavior.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history area/compression Context compression and continuation sessions labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants