Skip to content

Raise chat.history text cap to avoid premature truncation#1286

Open
BingqingLyu wants to merge 2 commits into
mainfrom
fork-pr-53243-codex-fix-chat-history-truncation
Open

Raise chat.history text cap to avoid premature truncation#1286
BingqingLyu wants to merge 2 commits into
mainfrom
fork-pr-53243-codex-fix-chat-history-truncation

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Summary

Raise the chat.history text cap from 12_000 to 64_000 and make truncation UTF-8 byte-aware so long assistant replies stay readable instead of being replaced by the oversized placeholder.

What changed

  • bumped CHAT_HISTORY_TEXT_MAX_CHARS in src/gateway/server-methods/chat.ts from 12_000 to 64_000
  • added a byte-aware fallback inside truncateChatHistoryText() so UTF-8-heavy text is truncated to a safe prefix before the 128 * 1024 single-message byte guard runs
  • added a regression test for a 50k-character ASCII assistant reply that should be preserved intact
  • added a regression test for an emoji-heavy assistant reply that should truncate visibly instead of collapsing to [chat.history omitted: message too large]

Why

Before this change, chat.history truncated content[].text, partialJson, arguments, and thinking at 12k characters before the larger byte-budget logic ran.

Raising the char cap alone fixes premature truncation for long ASCII replies, but it leaves a second failure mode: long UTF-8-heavy text can bypass the char cap and then be replaced entirely by the oversized placeholder during the later byte-budget pass.

This update fixes both paths:

  • long replies that still fit the budget remain visible
  • byte-heavy replies are truncated to a readable prefix instead of being dropped completely

Test

pnpm -C /tmp/openclaw-pr-53243 exec vitest run --config vitest.gateway.config.ts src/gateway/server.chat.gateway-server-chat-b.test.ts

Fixes openclaw#53242

Address the non-ASCII chat.history regression by adding a byte-aware fallback to text truncation. Keep long UTF-8 replies readable instead of replacing them with the oversized placeholder, and cover the behavior with a regression test for emoji-heavy assistant text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants