You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(harness): detect and break out of repetitive text-generation loops #94
The agent model can enter a text-generation loop where it repeats the same output verbatim without ever calling a tool. For example:
The file I need is packages/core/src/fs-util.ts. Let me read it: The file I need is packages/core/src/fs-util.ts. Let me read it: The file I need is packages/core/src/fs-util.ts. Let me read it: ... (hundreds of times)
This burns tokens at a high rate and eventually crashes or stalls the harness until manually terminated. The model never reaches a tool call because it keeps regenerating the same prefix.
Root Cause
The text-generation loop repeats identical or near-identical output tokens without converging on a tool-call boundary. The harness has no mechanism to detect this stall and break out.
Proposed Solution
Add a repetition-detection guard at the harness level:
Track the last N assistant text deltas — buffer recent output chunks (or full accumulated text since the last tool call).
Detect repeated substrings — if the same n-gram or line appears K times consecutively (e.g. the same 20+ character substring repeated 5+ times), flag it as a loop.
Break the stream — inject a system-level interruption or stop the generation, surfacing a diagnostic message to the user so they can retry or rephrase.
Make thresholds configurable — default to reasonable limits (e.g. 5 consecutive identical lines, or 3 repetitions of the same 50+ char substring).
Acceptance Criteria
Repetitive text output is detected mid-generation before token budget is exhausted.
The harness breaks out of the loop and surfaces a clear message.
Normal non-looping output (including legitimate repetition like code blocks) is unaffected.
Thresholds are configurable and sensible by default.
Activity
feat(opencode): detect and break out of repetitive text-generation loops