The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent): drop the stream watch's redundant pre-trim
kshitijk4poor77c373ac5fbb
diff --git a/agent/repetition_guard.py b/agent/repetition_guard.pyindex 7f544acb391..95ea347ee66 100644--- a/agent/repetition_guard.py+++ b/agent/repetition_guard.py@@ -169,13 +169,14 @@ class RunawayStreamWatch:and the gap doubles until it reaches one tail window, then stays there. A fixed stride keeps aloop that starts late in a long reply from streaming as long as the reply already was beforea check sees it; each check reads only the tail, so the total work stays linear in the output.+ Each check also trims the held text to the tail, and checks are at most one tail window apart,+ so the watch never holds more than two tail windows plus the latest delta."""- __slots__ = ("_parts", "_held", "_chars", "_next_check")+ __slots__ = ("_parts", "_chars", "_next_check")def __init__(self) -> None:self._parts: list[str] = []- self._held = 0self._chars = 0self._next_check = STOP_PATH_MIN_CHARS@@ -184,18 +185,10 @@ class RunawayStreamWatch:if not text:return Falseself._parts.append(text)- self._held += len(text)self._chars += len(text)- # Text held between checks is bounded by trimming every tail's worth of new text.- if self._held >= 2 * _STREAM_TAIL_CHARS:- self._trim()if self._chars < self._next_check:return Falseself._next_check = self._chars + min(self._chars, _STREAM_TAIL_CHARS)- return is_runaway_repetition(self._trim())-- def _trim(self) -> str:tail = "".join(self._parts)[-_STREAM_TAIL_CHARS:]self._parts = [tail]- self._held = len(tail)- return tail+ return is_runaway_repetition(tail)