openclaw - 💡(How to fix) Fix Streaming repetition loops bypass idle timeout; no semantic circuit breaker or context sanitization [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63411Fetched 2026-04-09 07:54:03
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Root Cause

Incident Overview

On 2026-04-08, an architectural gap was identified when google/gemini-3-flash-preview entered a repetition loop within its <think> block. Despite the loop continuing for an extended period, the OpenClaw idle timeout (60s) failed to trigger because the stream remained technically active with continuous token generation.

RAW_BUFFERClick to expand / collapse

Streaming repetition loops bypass idle timeout; no semantic circuit breaker or context sanitization

Incident Overview

On 2026-04-08, an architectural gap was identified when google/gemini-3-flash-preview entered a repetition loop within its <think> block. Despite the loop continuing for an extended period, the OpenClaw idle timeout (60s) failed to trigger because the stream remained technically active with continuous token generation.

Issues Identified

  1. Idle Timeout Evasion: The current idle timeout monitors stream activity (the presence of incoming data) rather than progress. Continuous repetitive output satisfies the "active stream" condition, allowing runaway sessions to persist until maxTokens is reached.
  2. Session Poisoning: Repetitive or aborted turns are currently retained in the session history. This "poisons" the context for subsequent turns, often leading the model back into the same loop or degraded reasoning states.
  3. Lack of Semantic Circuit Breakers: There is no mechanism to detect n-gram repetition or structural loops within the streaming content in real-time.

Proposed Requirements

  1. Semantic Repetition Breaker: Implement an n-gram detector (or similar heuristic) to identify and kill runaway streams that exhibit high repetition, even if the stream is technically active.
  2. Context Sanitization: Implement a mechanism to sanitize or "roll back" the session history when a turn is aborted or detected as looping, preventing the corrupted output from poisoning future reasoning.
  3. Enhanced Defense-in-Depth: While maxTokens prevents total cost runaway, it is a blunt instrument that does not address the degraded state of the persistent session.

Reference

This issue refers to the incident report dated 2026-04-08.

extent analysis

TL;DR

Implement a semantic repetition breaker to detect and terminate streams with high repetition, addressing the idle timeout evasion issue.

Guidance

  • Identify and prioritize the implementation of an n-gram detector or similar heuristic to detect repetitive patterns in the streaming content.
  • Develop a context sanitization mechanism to prevent session history poisoning by rolling back or sanitizing the history when a turn is aborted or detected as looping.
  • Consider enhancing the defense-in-depth strategy to complement the maxTokens limit, focusing on preventing degraded session states.
  • Review the current idle timeout mechanism to ensure it monitors progress rather than just stream activity.

Example

A simple n-gram detector could be implemented using a sliding window approach, tracking the frequency of repeated sequences in the output stream.

Notes

The proposed solution focuses on addressing the identified issues, but its effectiveness may depend on the specific implementation details and the complexity of the streaming content.

Recommendation

Apply a workaround by implementing a semantic repetition breaker, as it directly addresses the idle timeout evasion issue and provides a foundation for further enhancements, such as context sanitization and defense-in-depth strategies.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING