Skip to content

fix(context): count fallback compactions as ineffective - #63018

Closed
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:fix-63008-compaction-fallback-thrash-guard
Closed

LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:fix-63008-compaction-fallback-thrash-guard

Conversation

@LeonSGP43

Copy link
Copy Markdown

What does this PR do?

Treats deterministic fallback compactions as degraded attempts in the existing anti-thrash guard.

Today, a failed summary call can still shrink the prompt enough that the next real prompt_tokens reading falls below threshold and resets _ineffective_compression_count back to 0. That lets repeated empty-summary fallback rewrites loop indefinitely without ever tripping the existing breaker. This patch keeps the real-usage-based guard intact, but consumes a strike whenever the completed compaction had to fall back to the placeholder summary.

Related Issue

Part of #63008

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/context_compressor.py: preserve anti-thrash strikes when a verified compaction used the deterministic fallback summary, even if the resulting prompt fits under threshold.
  • agent/context_compressor.py: log fallback-marker compactions as degraded attempts through the same ineffective-compression counter.
  • tests/agent/test_context_compressor.py: add coverage for fallback strikes, normal successful reset behavior, and the second-strike suppression path.

How to Test

  1. Run /Users/leongong/Desktop/LeonProjects/worktrees/hermes-agent/.base/.venv/bin/python -m pytest tests/agent/test_context_compressor.py -q
  2. Run /Users/leongong/Desktop/LeonProjects/worktrees/hermes-agent/.base/.venv/bin/python -m py_compile agent/context_compressor.py tests/agent/test_context_compressor.py
  3. Run git diff --check

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 26.4.1

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Proof log: /tmp/hermes-63008-proof.txt

@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the focused regression fix. The R1 premise is present on current main: agent/context_compressor.py:3083 marks a deterministic fallback, while update_from_response() clears the ineffective-attempt count for below-threshold real usage at agent/context_compressor.py:1195 and :1229.

Suggested changes

  • Consider one integration-style regression that drives a failed compress() fallback into update_from_response(). The added unit tests cover the intended counter transitions; exercising the existing fallback producer would also preserve the state-machine connection.

No blocking correctness issue identified. This is an automated hermes-sweeper review.

@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 P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 12, 2026
@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 12, 2026
@kshitijk4poor

Copy link
Copy Markdown

Merged via #63965 — your fallback compaction commit was cherry-picked with authorship preserved and extended with a boundary-scoped persisted breaker that survives ordinary fitting responses, usage-less turns, session rotation, and gateway recreation. Thanks for the fix!

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 P1 High — major feature broken, no workaround 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.

4 participants