openclaw - 💡(How to fix) Fix [agents/loop-detection]: downgrade Loop warning log level to info for isolated sessions with lifetime <= cron interval

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…

Error Message

Loop detector emits warn level for all loop warnings regardless of session context. This produces substantial noise in gateway.err.log for legitimate isolated-session use. const level = shouldWarn ? "warn" : "info"; Post-fix sample shows warn-level loop-detection entries drop by >80% for isolated-session cron jobs. Info-level entries still present for audit trail, but not in the err log.

Code Example

const shouldWarn = (
  sessionContext.target !== "isolated"
  || sessionContext.lifetimeMs > cronIntervalMs
);
const level = shouldWarn ? "warn" : "info";
logger[level](`Loop warning: ${tool} called ${n} times`);

---

# 1. Register an isolated-target cron job that issues 5+ exec calls
#    (any retry-heavy job, e.g., Code Red Watchdog is a known example)

# 2. Run for 1h

# 3. Count warnings
grep -c '\[agents/loop-detection\] Loop warning' ~/.openclaw/logs/gateway.err.log
# Expect 4+ warnings per hour; all are false positives for isolated sessions
RAW_BUFFERClick to expand / collapse

Version: v2026.4.19-beta.1

Symptom

[agents/loop-detection] Loop warning: exec called Ntimes fills gateway.err.log with ~50 warnings per 48h, roughly 4 per 15min cron tick. The warnings come from isolated-session cron jobs (each run is a fresh ephemeral session), not from stale or polluted interactive channel sessions. The loop detector flags repeated exec calls within a run as potential runaway, but for isolated sessions with lifetime shorter than the cron interval, re-tries within the same run are the intended behavior (retry-on-fail, exhaust-before-fallback pattern).

Current behavior

Loop detector emits warn level for all loop warnings regardless of session context. This produces substantial noise in gateway.err.log for legitimate isolated-session use.

Proposed fix

In agents/loop-detection.ts (or wherever the warning is emitted), check the session context:

const shouldWarn = (
  sessionContext.target !== "isolated"
  || sessionContext.lifetimeMs > cronIntervalMs
);
const level = shouldWarn ? "warn" : "info";
logger[level](`Loop warning: ${tool} called ${n} times`);

Where cronIntervalMs comes from the registered cron job metadata (not available? use a hardcoded 5min default as a cheap proxy).

Rationale: isolated sessions cannot accumulate cross-run state, so a "loop" within a single isolated run is bounded by that run's lifetime. If the run completes within its cron interval, the loop is self-bounded and not a leak.

Reproduction

# 1. Register an isolated-target cron job that issues 5+ exec calls
#    (any retry-heavy job, e.g., Code Red Watchdog is a known example)

# 2. Run for 1h

# 3. Count warnings
grep -c '\[agents/loop-detection\] Loop warning' ~/.openclaw/logs/gateway.err.log
# Expect 4+ warnings per hour; all are false positives for isolated sessions

Acceptance

Post-fix sample shows warn-level loop-detection entries drop by >80% for isolated-session cron jobs. Info-level entries still present for audit trail, but not in the err log.

Alternative (if upstream declines)

Accept as out-of-scope; downstream gateway operators can tail -f gateway.err.log | grep -v '\[agents/loop-detection\]' for local log filtering.

extent analysis

TL;DR

Modify the loop detection logic in agents/loop-detection.ts to check the session context and only emit warnings for non-isolated sessions or sessions with a lifetime exceeding the cron interval.

Guidance

  • Review the proposed fix and consider implementing the conditional warning logic based on session context.
  • Verify that the cronIntervalMs value is accurately obtained from the registered cron job metadata or use a reasonable default.
  • Test the modified loop detection logic with the provided reproduction steps to ensure the expected reduction in false positive warnings.
  • Consider implementing the alternative log filtering solution if the proposed fix is not feasible.

Example

The proposed fix provides a clear example of the modified logging logic:

const shouldWarn = (
  sessionContext.target !== "isolated"
  || sessionContext.lifetimeMs > cronIntervalMs
);
const level = shouldWarn ? "warn" : "info";
logger[level](`Loop warning: ${tool} called ${n} times`);

Notes

The effectiveness of this fix relies on the accuracy of the cronIntervalMs value and the correct identification of isolated sessions.

Recommendation

Apply the proposed workaround by modifying the loop detection logic to conditionally emit warnings based on session context, as this approach directly addresses the issue of false positive warnings for isolated sessions.

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