openclaw - 💡(How to fix) Fix [Bug]: Persisted `toolResult.details.aggregated` bypasses tool-result truncation and token estimation, causing durable transcript bloat and repeated compaction in OpenAI-Codex sessions [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#68679Fetched 2026-04-19 15:08:42
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

In OpenClaw 2026.4.11, heavy tool-use sessions on the openai-codex lane can get stuck in repeated compaction because oversized tool-result payloads are still being persisted in toolResult.details.aggregated even when visible tool-result text is truncated.

The key problem is:

  • message.content[*].text is capped
  • but message.details.aggregated still persists very large payloads
  • token estimation and compaction planning appear to ignore that persisted details.aggregated payload
  • so the session transcript on disk stays much larger than the runtime thinks it is

This creates a durable pollution problem, not just a live-context problem.

Root Cause

This breaks the simple expected behavior of:

  • session grows
  • around ~80% it compacts
  • session becomes usable again

Instead, the session can compact repeatedly while still carrying oversized persisted tool-result baggage forward.

This is especially painful on mobile, where the user needs a minimal and reliable “context is healthy / context is not healthy” behavior, not a diagnostic dashboard.

RAW_BUFFERClick to expand / collapse

Summary

In OpenClaw 2026.4.11, heavy tool-use sessions on the openai-codex lane can get stuck in repeated compaction because oversized tool-result payloads are still being persisted in toolResult.details.aggregated even when visible tool-result text is truncated.

The key problem is:

  • message.content[*].text is capped
  • but message.details.aggregated still persists very large payloads
  • token estimation and compaction planning appear to ignore that persisted details.aggregated payload
  • so the session transcript on disk stays much larger than the runtime thinks it is

This creates a durable pollution problem, not just a live-context problem.

Environment

  • OpenClaw version: 2026.4.11
  • Install method: global npm
  • OS: Ubuntu on WSL2
  • Provider/model lane: openai-codex/gpt-5.4
  • Session type: normal direct user chat with heavy built-in tool usage, especially exec

What I observed

In large tool-result turns, especially with exec:

  • message.content[*].text is truncated to around 40k chars
  • but message.details.aggregated can still persist around 150k to 200k chars

This means the built-in truncation only half-fixes the problem.

From local source inspection, the relevant behavior appears to be:

  • capToolResultSize(msg) calls truncateToolResultMessage(msg, DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS, ...)
  • DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS = 40000
  • getToolResultTextLength(msg) appears to count only msg.content[*].text
  • message.details.aggregated is not included in that sizing path

Related downstream logic also appears to rely on the same limited measurement:

  • truncateOversizedToolResultsInSessionManager(...)
  • estimateToolResultReductionPotential(...)
  • buildToolResultReplacementPlan(...)

Those seem to only “see” content text, not the large persisted details.aggregated payload.

There also seems to be a second mismatch:

  • estimateMessagesTokens(messages) uses stripToolResultDetails(messages)
  • so token/compaction estimation ignores tool-result details
  • but the stored transcript still keeps those huge details.aggregated payloads

Expected behavior

One of these needs to happen:

  1. toolResult.details.aggregated should be stripped or hard-capped before transcript persistence, especially for exec
  2. or tool-result sizing / compaction planning / token estimation must include persisted details
  3. ideally both

If a large tool result is too big for durable history, it should not remain on disk in a form that keeps poisoning future turns.

Actual behavior

  • visible tool-result text is truncated
  • oversized details.aggregated still persists
  • compaction/retry logic underestimates how much transcript pressure actually exists
  • session continues to hit compaction pressure again
  • the transcript remains polluted until reset / cleanup, even though the user-facing context signal suggests compaction should have relieved it

Why this matters

This breaks the simple expected behavior of:

  • session grows
  • around ~80% it compacts
  • session becomes usable again

Instead, the session can compact repeatedly while still carrying oversized persisted tool-result baggage forward.

This is especially painful on mobile, where the user needs a minimal and reliable “context is healthy / context is not healthy” behavior, not a diagnostic dashboard.

Repro direction

  1. Start a normal openai-codex session
  2. Trigger several heavy built-in tool calls, especially exec
  3. Let the session approach compaction pressure
  4. Inspect stored tool-result entries in the session transcript
  5. Compare:
    • truncated content[*].text
    • still-large details.aggregated
  6. Observe that compaction happens, but future turns still re-enter pressure faster than expected

Impact

  • repeated compactions
  • degraded session stability
  • transcript stays polluted after compaction
  • effective context window feels much smaller than it should
  • user experience regresses from “compact and continue” to “compact spiral / unhealthy session”

Additional context

This feels like a regression in transcript hygiene. Earlier behavior seemed to sanitize transcript pollution more aggressively, while the current lane appears to allow large persisted tool-result details to survive even when visible content is capped.

Proposed fix direction

Best fix:

  • strip or hard-cap toolResult.details.aggregated before transcript write

Minimum acceptable fix:

  • make all tool-result size estimation, reduction planning, and compaction logic account for persisted details.aggregated

extent analysis

TL;DR

The most likely fix is to modify the tool-result sizing and compaction logic to account for the persisted details.aggregated payload, or strip/hard-cap it before transcript persistence.

Guidance

  • Review the capToolResultSize(msg) function to ensure it considers the size of message.details.aggregated in addition to msg.content[*].text.
  • Update getToolResultTextLength(msg) to include the length of message.details.aggregated in its calculation.
  • Modify estimateMessagesTokens(messages) to account for tool-result details by removing the stripToolResultDetails(messages) call or adjusting it to only strip details after sizing.
  • Consider adding a hard cap to toolResult.details.aggregated to prevent oversized payloads from being persisted.

Example

// Example of updated getToolResultTextLength function
function getToolResultTextLength(msg) {
  const contentTextLength = msg.content.reduce((acc, item) => acc + item.text.length, 0);
  const detailsLength = msg.details.aggregated ? msg.details.aggregated.length : 0;
  return contentTextLength + detailsLength;
}

Notes

The proposed fix direction suggests stripping or hard-capping toolResult.details.aggregated before transcript write, but this may have unintended consequences. A more comprehensive solution would involve updating the tool-result sizing and compaction logic to account for persisted details.

Recommendation

Apply a workaround by modifying the tool-result sizing and compaction logic to account for persisted details.aggregated payload, as this is a more comprehensive solution that addresses the root cause of the issue.

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

One of these needs to happen:

  1. toolResult.details.aggregated should be stripped or hard-capped before transcript persistence, especially for exec
  2. or tool-result sizing / compaction planning / token estimation must include persisted details
  3. ideally both

If a large tool result is too big for durable history, it should not remain on disk in a form that keeps poisoning future turns.

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 - 💡(How to fix) Fix [Bug]: Persisted `toolResult.details.aggregated` bypasses tool-result truncation and token estimation, causing durable transcript bloat and repeated compaction in OpenAI-Codex sessions [1 participants]