openclaw - 💡(How to fix) Fix Session repair (repairSessionFileIfNeeded) does not sanitize empty text blocks in user messages [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#73472Fetched 2026-04-29 06:19:27
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Timeline (top)
closed ×1commented ×1

Error Message

  • Error log shows the repair running in a loop: repair → API call → reject → repair → repeat

Root Cause

  • #73117 (exec tool empty text block — similar root cause, different trigger)
  • #54192 (orphaned-user-message repair — related repair gap)
  • #58608 (session corruption surviving restart — similar theme)

Code Example

messages: text content blocks must be non-empty

---

// Current: only checks assistant
function isAssistantEntryWithEmptyContent(entry) {
  return entry.message?.role === "assistant" && ...
}

// Suggested: also check user messages for empty text blocks
function hasEmptyTextBlock(entry) {
  const content = entry.message?.content;
  if (!Array.isArray(content)) return false;
  return content.some(block => block.type === "text" && block.text === "");
}
RAW_BUFFERClick to expand / collapse

Bug Description

repairSessionFileIfNeeded in session-file-repair.ts only checks assistant messages for empty content (isAssistantEntryWithEmptyContent), but does not sanitize user messages containing empty text content blocks like {"type": "text", "text": ""}.

When such a block exists in a user message, every subsequent API call that includes the session history is rejected by the Claude API with:

messages: text content blocks must be non-empty

This creates a permanent failure loop: the session is broken, repairSessionFileIfNeeded runs but doesn't detect/fix the user message, and the user gets ⚠️ Something went wrong on every message — even after /new won't help if the old session is still loaded.

Steps to Reproduce

  1. Send an empty message via Telegram (or trigger an empty text block in user content through any channel)
  2. A session JSONL entry is created with: {"type":"message", "message":{"role":"user", "content":[{"type":"text","text":""}]}}
  3. All subsequent messages in this session fail with: ⚠️ Something went wrong while processing your request
  4. /new does not help if the session with the empty block is still loaded
  5. repairSessionFileIfNeeded runs repeatedly but never fixes it — it only checks role === "assistant"

Expected Behavior

repairSessionFileIfNeeded should also sanitize user messages:

  • Detect {"type":"text","text":""} in user message content blocks
  • Either remove the empty text block or replace it with a placeholder
  • Alternatively, add input validation to prevent empty text blocks from being written to session files in the first place

Observed Behavior

  • Repair logic in isAssistantEntryWithEmptyContent() explicitly filters for role === "assistant" only
  • Discord channel has "drop message (empty content)" logic, but Telegram channel does not
  • Error log shows the repair running in a loop: repair → API call → reject → repair → repeat

Environment

  • OpenClaw version: latest (npm global install)
  • Channel: Telegram
  • Model: Claude (Anthropic API)
  • OS: macOS ARM (Apple Silicon)

Related Issues

  • #73117 (exec tool empty text block — similar root cause, different trigger)
  • #54192 (orphaned-user-message repair — related repair gap)
  • #58608 (session corruption surviving restart — similar theme)

Suggested Fix

In session-file-repair.ts, extend the repair logic to cover all roles:

// Current: only checks assistant
function isAssistantEntryWithEmptyContent(entry) {
  return entry.message?.role === "assistant" && ...
}

// Suggested: also check user messages for empty text blocks
function hasEmptyTextBlock(entry) {
  const content = entry.message?.content;
  if (!Array.isArray(content)) return false;
  return content.some(block => block.type === "text" && block.text === "");
}

Additionally, consider adding input validation in the Telegram channel handler (similar to Discord's "drop message (empty content)" logic) to prevent empty messages from being written to session files at all.

extent analysis

TL;DR

The most likely fix is to extend the repairSessionFileIfNeeded function in session-file-repair.ts to sanitize user messages by detecting and handling empty text content blocks.

Guidance

  • Extend the isAssistantEntryWithEmptyContent function to also check user messages for empty text blocks using the suggested hasEmptyTextBlock function.
  • Add input validation in the Telegram channel handler to prevent empty messages from being written to session files, similar to the Discord channel's logic.
  • Consider removing or replacing empty text blocks in user message content blocks to prevent the Claude API from rejecting subsequent API calls.
  • Verify the fix by sending an empty message via Telegram and checking if the session is repaired correctly and subsequent messages are processed without errors.

Example

function hasEmptyTextBlock(entry) {
  const content = entry.message?.content;
  if (!Array.isArray(content)) return false;
  return content.some(block => block.type === "text" && block.text === "");
}

Notes

The suggested fix only addresses the specific issue of empty text blocks in user messages and may not cover other potential issues with session file corruption or invalid content.

Recommendation

Apply the workaround by extending the repairSessionFileIfNeeded function and adding input validation in the Telegram channel handler, as this will fix the immediate issue and prevent similar problems in the future.

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

openclaw - 💡(How to fix) Fix Session repair (repairSessionFileIfNeeded) does not sanitize empty text blocks in user messages [1 comments, 2 participants]