fix(compression): don't overwrite the -1 post-compression sentinel in 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>
This commit is contained in:
parent
3763355f08
commit
3c8f1dee8d
2 changed files with 44 additions and 1 deletions
|
|
@ -641,7 +641,14 @@ def run_conversation(
|
|||
# Skipped when deferring — a deferred estimate is known to over-count
|
||||
# vs the last real provider prompt, so trusting it for the display
|
||||
# would re-introduce the very desync we're avoiding.
|
||||
if _preflight_tokens > (_compressor.last_prompt_tokens or 0):
|
||||
_last = _compressor.last_prompt_tokens
|
||||
# Do NOT overwrite the -1 sentinel. compress_context() sets
|
||||
# last_prompt_tokens=-1 right after compression to mark "no real API
|
||||
# usage yet". `(x or 0)` evaluates to -1 (truthy) for the sentinel,
|
||||
# so the old comparison was always True and clobbered the sentinel
|
||||
# with a schema-inflated rough estimate — re-triggering compression
|
||||
# on the next turn (#36718). Treat any negative value as "no data".
|
||||
if _last >= 0 and _preflight_tokens > _last:
|
||||
_compressor.last_prompt_tokens = _preflight_tokens
|
||||
|
||||
if _preflight_deferred:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue