Skip to content

feat(harness): detect and break out of repetitive text-generation loops #94

Closed

Description

@mdev34-lab

Problem

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:

  1. Track the last N assistant text deltas — buffer recent output chunks (or full accumulated text since the last tool call).
  2. 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.
  3. 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.
  4. 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

  1. added a commit that references this issue on Sep 12, 2026
    27f8e37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions