Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander Whitestone
2c8848b2f1 fix: context pressure warning fires at 85% of context_length, not threshold
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 51s
The _emit_context_pressure warning was firing at 85% of threshold_tokens
(the configurable compaction threshold), not 85% of context_length.
This caused it to fire at 42.5% of actual context when threshold_percent=0.50,
confusing users who expected alignment with the poka-yoke WARNING signal.

Fix: compare against context_length (0.85 * context_length) instead of
threshold_tokens. The compaction_progress passed to _emit_context_pressure
still uses threshold_tokens for the display bar, but the trigger condition
now matches the poka-yoke signal.

Closes #538
2026-04-13 22:24:40 -04:00

View File

@@ -6005,9 +6005,9 @@ class AIAgent:
# can't reduce enough (e.g. threshold is very low, or system prompt
# alone exceeds the warning level), keep the flag set to prevent
# spamming the user with repeated warnings every loop iteration.
if self.context_compressor.threshold_tokens > 0:
_post_progress = _compressed_est / self.context_compressor.threshold_tokens
if _post_progress < 0.85:
if self.context_compressor.context_length > 0:
_context_fill = _compressed_est / self.context_compressor.context_length
if _context_fill < 0.85:
self._context_pressure_warned = False
# Clear the file-read dedup cache. After compression the original
@@ -8991,14 +8991,15 @@ class AIAgent:
# ── Context pressure warnings (user-facing only) ──────────
# Notify the user (NOT the LLM) as context approaches the
# compaction threshold. Thresholds are relative to where
# compaction fires, not the raw context window.
# compaction threshold. Fires at 85% of context_length so
# it aligns with the poka-yoke WARNING signal (#538).
# Does not inject into messages — just prints to CLI output
# and fires status_callback for gateway platforms.
if _compressor.threshold_tokens > 0:
_compaction_progress = _real_tokens / _compressor.threshold_tokens
if _compaction_progress >= 0.85 and not self._context_pressure_warned:
if _compressor.context_length > 0:
_context_fill = _real_tokens / _compressor.context_length
if _context_fill >= 0.85 and not self._context_pressure_warned:
self._context_pressure_warned = True
_compaction_progress = _real_tokens / _compressor.threshold_tokens if _compressor.threshold_tokens > 0 else 1.0
self._emit_context_pressure(_compaction_progress, _compressor)
if self.compression_enabled and _compressor.should_compress(_real_tokens):