openclaw - ✅(Solved) Fix [Bug]: Pre- compaction memory flush sends empty user message to Anthropic API [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#75305Fetched 2026-05-01 05:35:29
View on GitHub
Comments
1
Participants
2
Timeline
10
Reactions
2
Timeline (top)
cross-referenced ×3mentioned ×2subscribed ×2commented ×1

When a session approaches the context limit and auto-compaction triggers, OpenClaw's pre-compaction memory flush constructs a user message with empty string content (""). The Anthropic API rejects this with a 400 error, causing the session to reset unexpectedly

Error Message

When a session approaches the context limit and auto-compaction triggers, OpenClaw's pre-compaction memory flush constructs a user message with empty string content (""). The Anthropic API rejects this with a 400 error, causing the session to reset unexpectedly

Root Cause

Root Cause (suspected by claude)

The flush prompt text exists in the session trajectory as a system message, but the "messages" array passed to the API contains only an empty string. The flush prompt content appears to not be serialized correctly before the API call.

PR fix notes

PR #75368: fix(agents): keep blank user entries during session repair instead of dropping them (#75313)

Description (problem / solution / changelog)

Summary

Fixes #75313. Session repair previously dropped blank user-role entries entirely, which could leave a session with no user role at all (e.g. [system, assistant, assistant, …]). Strict OpenAI-compatible chat templates (Qwen3.6, mlx-vlm, etc.) reject such message arrays with No user query found in messages. → HTTP 500.

Fix

Instead of { kind: "drop" }, blank user entries are now rewritten with a synthetic "(continue)" text placeholder, preserving the user role in the session transcript.

Changes

  • src/agents/session-file-repair.ts: repairUserEntryWithBlankTextContent returns { kind: "rewrite" } with BLANK_USER_FALLBACK_TEXT = "(continue)" instead of { kind: "drop" }
  • Report field renamed: droppedBlankUserMessagesrewrittenBlankUserMessages
  • Test updates: 10/10 tests pass

Impact

  • Affects all users of repairSessionFileIfNeeded (compaction, session resume)
  • Prevents HTTP 500 from strict providers when session repair encounters blank user messages
  • Related to #75305 (pre-compaction flush sending empty user messages to Anthropic)

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/session-file-repair.test.ts (modified, +69/-9)
  • src/agents/session-file-repair.ts (modified, +55/-20)

PR #75384: fix(memory): send flush prompt as user message to prevent Anthropic 400 (#75305)

Description (problem / solution / changelog)

Summary

When a session approaches the context limit, the memory flush hook runs a special compaction turn. The flush handler was calling session.prompt("") with an empty string, which causes Anthropic's API to reject the request with a 400 error.

Fix

Send the transcriptPrompt as the user-visible message text instead of an empty string. This makes the flush turn look like a normal user message to the API.

Changes

  • src/auto-reply/agent-runner-memory.ts: pass transcriptPrompt as the message body instead of "" when initiating the memory flush turn

Testing

  • Existing memory flush tests pass unchanged
  • The 400 error no longer occurs when sessions approach context limits

Fixes #75305. Thanks @hclsys.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-engine.test.ts (modified, +3/-1)
  • src/agents/pi-embedded-runner/run/attempt.ts (modified, +6/-1)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

When a session approaches the context limit and auto-compaction triggers, OpenClaw's pre-compaction memory flush constructs a user message with empty string content (""). The Anthropic API rejects this with a 400 error, causing the session to reset unexpectedly

Steps to reproduce

Let a session run long enough to approach the auto-compaction threshold. The flush triggers automatically — no user action required.

Expected behavior

The pre-compaction flush completes silently and the session continues or compacts cleanly.

Actual behavior

Telegram User sees: "Something went wrong while processing your request. Please try again, or use /new to start a fresh session." — and the session is reset.

Root Cause (suspected by claude)

The flush prompt text exists in the session trajectory as a system message, but the "messages" array passed to the API contains only an empty string. The flush prompt content appears to not be serialized correctly before the API call.

OpenClaw version

2026.4.27

Operating system

Windows 11

Install method

No response

Model

Anthropic/claude-sonnet-4.6

Provider / routing chain

Telegram > Openclaw Gateway > anthropic/claude-sonnet-4.6

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

This ends up causing issues in sessions that use a fair amount of context, i assume that there are a decent number of people hitting this problem. It happens to me multiple times a day and results in me needing to run /compact if that even works

Additional information

NOT_ENOUGH_INFO

extent analysis

TL;DR

Verify and correct the serialization of the flush prompt content before passing it to the Anthropic API to prevent empty string errors.

Guidance

  • Review the code responsible for constructing the user message in OpenClaw's pre-compaction memory flush to ensure it correctly serializes the flush prompt content.
  • Check the API call to the Anthropic API to confirm that the "messages" array contains the expected content, not an empty string.
  • Test the serialization and API call with a sample session to reproduce and debug the issue.
  • Consider adding error handling or logging to catch and report similar issues in the future.

Notes

The provided information suggests a serialization issue, but without specific code or logs, it's difficult to provide a more detailed solution.

Recommendation

Apply workaround: Modify the code to correctly serialize the flush prompt content before passing it to the Anthropic API, as this is likely 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

The pre-compaction flush completes silently and the session continues or compacts cleanly.

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]: Pre- compaction memory flush sends empty user message to Anthropic API [2 pull requests, 1 comments, 2 participants]