fix(compression): preserve -1 post-compression sentinel to stop re-fire (#36718)#40582
Merged
Conversation
… preflight seed (#36718) compress_context() sets last_prompt_tokens=-1 right after compression to mark "no real API usage yet". The preflight display-seed used `_preflight_tokens > (last_prompt_tokens or 0)`, and `(-1 or 0)` is -1 (truthy), so any positive rough estimate clobbered the sentinel with a schema-inflated count — re-triggering compression on the next turn. Treat any negative value as "no real data yet" and skip the seed. Salvaged from #40246 as the minimal root-cause fix. The original also added an `_awaiting_suppression_count` bounded-window state machine to should_compress() across 3 files; left out here to keep blast radius small — the sentinel guard alone fixes the re-fire. The suppression window can be added separately if the usage=None-stub edge case warrants it. Co-authored-by: davidgut1982 <davidgut1982@users.noreply.github.com>
9 tasks
Contributor
🔎 Lint report:
|
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
Stops compression from re-firing immediately after a fresh compression. Closes #36718.
compress_context()setslast_prompt_tokens = -1to signal "no real API usage yet". The preflight display-seed compared_preflight_tokens > (last_prompt_tokens or 0)— but(-1 or 0)is-1(truthy), so any positive rough estimate was greater and overwrote the sentinel with a schema-inflated count, which then re-triggered compression on the next turn.Changes
agent/conversation_loop.py: treat any negativelast_prompt_tokensas "no real data yet" and skip the seed (_last >= 0 and ...).Scope note
The original PR (#40246) also added an
_awaiting_suppression_countbounded-window state machine toshould_compress()acrosscontext_compressor.py+conversation_compression.py. I left that out to keep blast radius minimal on the compression hot path — the sentinel guard alone fixes the root cause. If theusage=Nonepartial-stream edge case (flag never clears) is worth defending, that suppression window can land as a separate, reviewed change.Validation
TestPreflightSentinelGuard3 passed. py_compile OK.Salvaged from #40246 (@davidgut1982), credited; trimmed to the root-cause fix.