openclaw - ✅(Solved) Fix Bug: runs can terminate with only '[max turns exceeded]' and no actionable context [2 pull requests, 1 comments, 2 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#78145Fetched 2026-05-06 06:16:33
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Author
Timeline (top)
cross-referenced ×2commented ×1

OpenClaw can end an agent/session run with the terse message:

[max turns exceeded]

When this happens, the user-facing output does not include enough context to understand which turn loop exhausted the limit, what the agent was doing, whether work was partially completed, or how to recover.

Error Message

  • Debugging requires digging through session logs instead of having a useful terminal/session error. Improve the max-turn-exceeded error path to emit a structured, user-facing diagnostic. For example:

Root Cause

OpenClaw can end an agent/session run with the terse message:

[max turns exceeded]

When this happens, the user-facing output does not include enough context to understand which turn loop exhausted the limit, what the agent was doing, whether work was partially completed, or how to recover.

Fix Action

Fixed

PR fix notes

PR #78148: fix: explain max-turn run stops

Description (problem / solution / changelog)

Fixes #78145

Summary

  • replace terse [max turns exceeded] payloads with a structured diagnostic
  • include session key, session id, run id, and provider/model when available
  • add regression coverage for max-turn sentinel normalization

Tests

  • PATH="/tmp/openclaw-pnpm-shim:$PATH" node scripts/run-vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/agents/pi-embedded-runner/run/payloads.errors.test.ts
  • PATH="/tmp/openclaw-pnpm-shim:$PATH" pnpm format:check src/agents/pi-embedded-runner/run.ts src/agents/pi-embedded-runner/run/payloads.ts src/agents/pi-embedded-runner/run/payloads.errors.test.ts
  • git diff --check
  • PATH="/tmp/openclaw-pnpm-shim:$PATH" node scripts/check-changed.mjs (fails only in pre-existing unrelated src/agents/model-fallback.test.ts expectedReason type errors at lines 1091/1093; core production typecheck passed)

Changed files

  • src/agents/pi-embedded-runner/run.ts (modified, +2/-0)
  • src/agents/pi-embedded-runner/run/payloads.errors.test.ts (modified, +20/-0)
  • src/agents/pi-embedded-runner/run/payloads.ts (modified, +51/-9)

PR #78149: fix: explain max-turn run stops

Description (problem / solution / changelog)

Fixes #78145.

Summary

  • replace raw [max turns exceeded] sentinel with an actionable diagnostic
  • include session, session id, run id, provider/model context when available
  • pass session/run identifiers into embedded payload construction

Tests

  • PATH="/tmp/openclaw-pnpm-shim:$PATH" node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-pi-embedded.config.ts src/agents/pi-embedded-runner/run/payloads.errors.test.ts
  • git diff --check origin/main...HEAD
  • PATH="/tmp/openclaw-pnpm-shim:$PATH" node scripts/check-changed.mjs

Changed files

  • src/agents/pi-embedded-runner/run.ts (modified, +2/-0)
  • src/agents/pi-embedded-runner/run/payloads.errors.test.ts (modified, +20/-0)
  • src/agents/pi-embedded-runner/run/payloads.ts (modified, +51/-9)

Code Example

[max turns exceeded]

---

[max turns exceeded]

---

Run stopped: max turns exceeded
Session: <session key / label>
Limit: <N turns>
Last task: <summary if available>
Recovery: inspect session logs or retry with a higher maxTurns / narrower task.
RAW_BUFFERClick to expand / collapse

Summary

OpenClaw can end an agent/session run with the terse message:

[max turns exceeded]

When this happens, the user-facing output does not include enough context to understand which turn loop exhausted the limit, what the agent was doing, whether work was partially completed, or how to recover.

Expected behavior

When the max-turn guard trips, OpenClaw should surface an actionable failure message, ideally including:

  • the session/run identifier or agent label
  • the configured max-turn limit that was hit
  • the last visible task/phase if available
  • whether the run was aborted safely vs. still has background work running
  • suggested next steps, e.g. retry with a higher turn limit, inspect logs, or resume from the last checkpoint

Actual behavior

The visible result is only:

[max turns exceeded]

This is hard to diagnose and easy to mistake for an issue-specific failure rather than the runtime guardrail firing.

Impact

  • Users cannot tell what failed or how far the agent got.
  • Agents/orchestrators cannot reliably write a good completion report after the guard trips.
  • Debugging requires digging through session logs instead of having a useful terminal/session error.

Suggested fix

Improve the max-turn-exceeded error path to emit a structured, user-facing diagnostic. For example:

Run stopped: max turns exceeded
Session: <session key / label>
Limit: <N turns>
Last task: <summary if available>
Recovery: inspect session logs or retry with a higher maxTurns / narrower task.

If the guard is triggered inside subagent orchestration, also preserve/return the child session key so the parent can inspect and summarize it.

Notes

This ticket was filed from a user report containing the exact symptom: [max turns exceeded].

extent analysis

TL;DR

Improve the max-turn-exceeded error path to emit a structured, user-facing diagnostic message including session identifier, max-turn limit, last task, and suggested recovery steps.

Guidance

  • Modify the error handling code to include more context in the error message, such as session identifier, max-turn limit, and last task.
  • Consider adding a unique session key or label to the error message to help users identify the specific session that exceeded the max-turn limit.
  • Update the error message to provide suggested recovery steps, such as inspecting session logs or retrying with a higher max-turn limit.
  • If the max-turn guard is triggered inside subagent orchestration, preserve and return the child session key to allow the parent to inspect and summarize it.

Example

Run stopped: max turns exceeded
Session: <session_key>
Limit: <max_turns>
Last task: <last_task_summary>
Recovery: inspect session logs or retry with a higher maxTurns / narrower task.

Notes

The suggested fix requires modifications to the error handling code to include more context in the error message. The exact implementation details may vary depending on the specific codebase and requirements.

Recommendation

Apply workaround by modifying the error handling code to include more context in the error message, as this will provide users with more actionable information to diagnose and recover from max-turn exceeded errors.

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…

FAQ

Expected behavior

When the max-turn guard trips, OpenClaw should surface an actionable failure message, ideally including:

  • the session/run identifier or agent label
  • the configured max-turn limit that was hit
  • the last visible task/phase if available
  • whether the run was aborted safely vs. still has background work running
  • suggested next steps, e.g. retry with a higher turn limit, inspect logs, or resume from the last checkpoint

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Bug: runs can terminate with only '[max turns exceeded]' and no actionable context [2 pull requests, 1 comments, 2 participants]