Skip to content

The agent that grows with you

docs(agent): say why the extension pass re-renders after the cap pre-check

kshitijk4poorf3642a27d877
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index 99169cd6562..066fe10fcdf 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -3678,7 +3678,10 @@ Summary generation was unavailable, so this is a best-effort deterministic fallb
continue
selected[idx] = grown
new_len = len(_render(_merged(selected)))
- if new_len > cap: # marker widths shrink as records leave a gap; recheck exactly
+ # The pre-check above bounds the added record; the exact re-render catches the
+ # one thing it cannot see — a gap's first index gaining a digit or comma in the
+ # marker (e.g. 999 -> 1,000) when the render is already at cap.
+ if new_len > cap:
selected[idx] = (s, e)
continue
rendered_len = new_len