[codex] Fix CJK context compression budgeting - #52517
Closed
plainOldCode wants to merge 1 commit into
Closed
Conversation
plainOldCode
marked this pull request as ready for review
June 25, 2026 14:23
teknium1
reviewed
Jul 15, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for tracing both compression paths. The two reported defects are present on current main: agent/model_metadata.py:2458-2467 still applies chars / 4, and agent/context_compressor.py:3061-3073 copies a protected handoff before adding the replacement summary.
Problems
- The proposed dense-character predicate omits ordinary Hiragana (
U+3040–U+309F) and Katakana (U+30A0–U+30FF), although the PR describes Kana-aware budgeting. Kana-only Japanese text would still use the Englishchars / 4path. Please cover these ranges with regression tests. compression.hygiene_thresholdis only read ingateway/run.py; it is not declared with the other compression settings inhermes_cli/config.py:1412-1422or documented alongside the existing gateway hygiene setting inwebsite/docs/user-guide/configuration.md:738-758.
Suggested changes
- Add the missing Kana ranges and tests for estimator and tail-budget behavior.
- Add the default/config documentation and a gateway configuration-path test for valid override and invalid fallback.
Automated hermes-sweeper review.
| or 0x2E80 <= code <= 0x9FFF # CJK radicals/ideographs | ||
| or 0xA960 <= code <= 0xA97F # Hangul Jamo Extended-A | ||
| or 0xAC00 <= code <= 0xD7AF # Hangul Syllables | ||
| or 0xF900 <= code <= 0xFAFF # CJK compatibility ideographs |
Contributor
There was a problem hiding this comment.
This does not include standard Hiragana (U+3040–U+309F) or Katakana (U+30A0–U+30FF); FF00–FFEF only covers halfwidth kana/fullwidth forms. Please add those ranges and Japanese-script regression coverage before calling this Kana-aware.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix context compression for CJK-heavy conversations and make gateway hygiene compression configurable.
This PR addresses two compression issues observed in long Korean Telegram gateway sessions:
chars / 4heuristic, which substantially undercounted Hangul/CJK text. That made the compressor preserve too much recent tail context and report much lower request sizes than providers reported.Changes
compression.hygiene_thresholdsupport for gateway pre-agent hygiene compression while preserving the existing 85% default when unset.Root Cause
The compressor's tail selection depended on rough token estimates. For Korean/CJK text, the old
len(text) / 4estimate was too low, so the protected tail was much larger than intended. As a result, manual or automatic compression could report a small rough request size while the next provider API call still had a large prompt.Additionally, resumed in-place compaction could rehydrate a persisted handoff into
_previous_summarybut still copy the old handoff into the new compressed transcript. Repeated compactions then retained old summaries in live context.Validation
Also tested against a live Korean gateway session: