Skip to content

fix(compression): exclude completion tokens from compression trigger (#12026)#13006

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-bd16abe6
Apr 20, 2026
Merged

fix(compression): exclude completion tokens from compression trigger (#12026)#13006
teknium1 merged 1 commit into
mainfrom
hermes/hermes-bd16abe6

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Compression trigger no longer includes completion/reasoning tokens, preventing premature session splits on thinking models.

Cherry-picked from PR #12481 by @Sanjays2402 onto current main.

Changes

  • run_agent.py: Use only last_prompt_tokens (not + last_completion_tokens) for compression trigger
  • tests/run_agent/test_compression_trigger_excludes_reasoning.py: 3 regression tests
  • scripts/release.py: AUTHOR_MAP entry for @Sanjays2402

Validation

Before After
GLM-5.1 (202K ctx) at 85K prompt + 20K reasoning Compresses (105K > 101K threshold) No compression (85K < 101K)
Self-correcting No — premature compression cascades Yes — next API call reports real prompt_tokens

3/3 new tests pass, py_compile clean.

Closes #12026
Supersedes #12028, #12071, #12481, #12783

…12026)

Cherry-picked from PR #12481 by @Sanjays2402.

Reasoning models (GLM-5.1, QwQ, DeepSeek R1) inflate completion_tokens
with internal thinking tokens. The compression trigger summed
prompt_tokens + completion_tokens, causing premature compression at ~42%
actual context usage instead of the configured 50% threshold.

Now uses only prompt_tokens — completion tokens don't consume context
window space for the next API call.

- 3 new regression tests
- Added AUTHOR_MAP entry for @Sanjays2402

Closes #12026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Compression trigger includes reasoning tokens, causing premature session splits for thinking models (GLM-5.1, QwQ, etc.)

2 participants