Compare commits

...

1 Commits

Author SHA1 Message Date
6af855ab94 fix: context pressure warning fires at 85% of context_length, not threshold (#538)
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 1m7s
_emit_context_pressure computed compaction_progress as
real_tokens / threshold_tokens. With threshold_percent=0.50,
this fires at 85% of 50% = 42.5% of total context.

Fix: compute progress relative to context_length so the
warning fires at 85% of actual context capacity.
Same fix applied to the post-compression reset check.

Closes #538
2026-04-14 02:04:32 +00:00

View File

@@ -6006,7 +6006,7 @@ class AIAgent:
# 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
_post_progress = _compressed_est / self.context_compressor.context_length if self.context_compressor.context_length else 0
if _post_progress < 0.85:
self._context_pressure_warned = False
@@ -8996,7 +8996,7 @@ class AIAgent:
# 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
_compaction_progress = _real_tokens / _compressor.context_length if _compressor.context_length else 0
if _compaction_progress >= 0.85 and not self._context_pressure_warned:
self._context_pressure_warned = True
self._emit_context_pressure(_compaction_progress, _compressor)