openclaw - 💡(How to fix) Fix Feature: Make HARD_MAX_TOOL_RESULT_CHARS configurable [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#60817Fetched 2026-04-08 02:46:50
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Error Message

An exec command returning 200K chars (~100-133K tokens) plus existing conversation + system prompt can push total tokens past the context window in one turn. Auto-compaction only triggers after the overflow error.

Code Example

{
  "tools": {
    "maxToolResultChars": 100000
  }
}
RAW_BUFFERClick to expand / collapse

Problem

Large tool results (e.g. exec returning 200K+ chars from grep on big files) can exceed the context window in a single turn, causing model_context_window_exceeded before auto-compaction can kick in.

Current behavior:

  • MAX_TOOL_RESULT_CONTEXT_SHARE = 0.3 (30% of context window) — only enforced during compaction
  • HARD_MAX_TOOL_RESULT_CHARS = 400,000 — enforced at write time, but 400K chars ≈ 100-130K tokens can still overflow smaller context windows
  • No config option to lower these limits

Example

An exec command returning 200K chars (~100-133K tokens) plus existing conversation + system prompt can push total tokens past the context window in one turn. Auto-compaction only triggers after the overflow error.

Proposed solution

Add a config option:

{
  "tools": {
    "maxToolResultChars": 100000
  }
}

This would override the hardcoded HARD_MAX_TOOL_RESULT_CHARS = 4e5 at write time.

Environment

  • OpenClaw 2026.4.2
  • Model: zai/glm-5-turbo (contextWindow: 202,800)
  • Source: pi-embedded → tool-result-truncation.ts

extent analysis

TL;DR

To prevent the model_context_window_exceeded error, consider adding a configuration option to limit the maximum number of characters allowed in tool results.

Guidance

  • Review the proposed solution to add a maxToolResultChars configuration option to override the hardcoded limit.
  • Verify that the contextWindow size of the model (202,800) is sufficient for the expected conversation and system prompt lengths.
  • Test the effect of reducing the maxToolResultChars value on the tool results and conversation flow.
  • Consider the trade-off between limiting tool result length and potentially truncating important information.

Example

The proposed configuration option can be added as follows:

{
  "tools": {
    "maxToolResultChars": 100000
  }
}

This would limit the maximum number of characters in tool results to 100,000.

Notes

The effectiveness of this solution may depend on the specific use case and the importance of preserving long tool results. Further testing and evaluation may be necessary to determine the optimal value for maxToolResultChars.

Recommendation

Apply the proposed workaround by adding the maxToolResultChars configuration option to limit the maximum number of characters in tool results, as it provides a flexible way to prevent the model_context_window_exceeded error without modifying the underlying code.

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