Skip to content

Bug: chat.history truncates long assistant messages at 12k chars even when they fit the history budget #53242

@navendugoyal19

Description

@navendugoyal19

Summary

chat.history truncates long assistant text far too aggressively in WebChat / Control UI. Messages that still fit comfortably within the configured history byte budget and the single-message byte cap are being cut at 12,000 chars and returned with ...(truncated)....

This shows up in practice as apparently truncated tutor / teaching responses after upgrading OpenClaw, even when the session is otherwise healthy.

Current behavior

In src/gateway/server-methods/chat.ts, truncateChatHistoryText() applies a hard per-text-field cap of 12_000 chars:

  • content[].text
  • partialJson
  • arguments
  • thinking

That truncation happens before the larger history payload budget is applied. So a single long assistant response can be cut down even though:

  • CHAT_HISTORY_MAX_SINGLE_MESSAGE_BYTES is 128 * 1024
  • overall chat history payload budget defaults to multiple MB

Why this is a bug

The current cap is much smaller than the surrounding byte budgets and causes premature truncation of normal long-form responses in WebChat / Control UI. The UI then only ever receives the already-truncated text.

This is especially visible for workflows that intentionally produce long, structured answers.

Reproduction

  1. Start Gateway / WebChat.
  2. Create a session whose latest assistant message contains ~50k chars of plain text.
  3. Ensure the overall chat.history payload still fits within the configured history byte budget.
  4. Call chat.history.

Actual

The returned message text is truncated at 12k chars and includes ...(truncated)....

Expected

If the message fits within the history byte budget and does not exceed the oversized single-message threshold, chat.history should return the full text.

Proposed fix

Raise CHAT_HISTORY_TEXT_MAX_CHARS to 64_000. This is still conservative relative to the 128 KB single-message cap, but avoids cutting normal long-form assistant answers in half.

I have a companion PR with:

  • the constant bump from 12_000 to 64_000
  • a regression test proving that a 50k-char assistant message is preserved when it still fits the history byte budget

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions