Skip to content

fix(compression): deterministic fallback when summary LLM fails (salvages #31242)#34310

Merged
teknium1 merged 3 commits into
mainfrom
hermes/hermes-cb38d90d
May 29, 2026
Merged

fix(compression): deterministic fallback when summary LLM fails (salvages #31242)#34310
teknium1 merged 3 commits into
mainfrom
hermes/hermes-cb38d90d

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Salvages #31242 onto current main: when context compression's summary LLM fails (e.g. Codex 429 usage_limit_reached), the dropped-window placeholder is now a deterministic locally-extracted handoff instead of a content-free N messages were removed marker.

Cherry-picked 3 commits from @Hinotoi-agent's fix/deterministic-compression-fallback onto current main, authorship preserved.

What it does

Adds _build_static_fallback_summary() to agent/context_compressor.py. Only fires on the existing failure path (abort_on_summary_failure=False AND aux LLM returned empty/errored). From the compacted window it extracts:

  • recent user asks
  • assistant tool calls (name + args, dict and object shapes)
  • file paths (path-mention regex + path/workdir/file_path/output_path keys in tool args)
  • error / blocker snippets (error|failed|exception|traceback|timeout)
  • bounded last-dropped-turn excerpts

Output is capped (8KB total, 700 chars/turn), deduped, and run through redact_sensitive_text + an extra gh-token-prefix scrub before insertion. Normal LLM-summarized compression is unchanged.

Why this matters

Reference incident: Discord user @damien hit Codex Plus usage_limit_reached mid-compression on a 145k-token session. The aux compressor 429'd → 142 messages dropped → the content-free placeholder gave the next turn nothing to work with → continuity collapsed. With this PR the same failure still drops the window, but the model gets back user asks, file paths, tool activity, and error snippets so it can keep going.

compression.abort_on_summary_failure=true remains the alternative — freeze the session instead of dropping. This PR only improves the drop path that runs when that flag is false (default).

Scope

  • agent/context_compressor.py — new _build_static_fallback_summary(), helper extractors, fallback-branch wiring
  • tests/agent/test_context_compressor.py — coverage for dict/object tool calls, path extraction (POSIX + Windows), gh-token redaction, bounded output, protected-tail exclusion, dropped-turn snippet behaviour

No provider, gateway, loop, CLI, or storage changes.

Validation

Check Result
agent/context_compressor.py + tests compile OK
scripts/run_tests.sh tests/agent/test_context_compressor.py 88/88 pass
scripts/run_tests.sh tests/acp/test_server.py 78/78 pass
Cherry-pick on current main clean, 3 commits, authorship preserved

Notes on the ACP test failure on the original PR

Upstream PR #31242 had test (3) red on tests/acp/test_server.py::test_model_switch_uses_requested_provider with 'custom' == 'anthropic'. That was an unrelated xdist-worker flake caused by another test in the same worker mutating _KNOWN_PROVIDER_NAMES / _PROVIDER_ALIASES. Already pinned on current main by commits 3127a41 and 2b76853 (monkeypatch parse_model_input, drop the brittle tail-position assertion). Re-running 78/78 green here confirms.

Infographic

Deterministic compression fallback

Credits

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-cb38d90d 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: 9581 on HEAD, 9582 on base (✅ -1)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5050 pre-existing issues carried over.

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

@teknium1 teknium1 merged commit 042c1d6 into main May 29, 2026
25 checks passed
@teknium1 teknium1 deleted the hermes/hermes-cb38d90d branch May 29, 2026 03:34
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder 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.

3 participants