openclaw - 💡(How to fix) Fix Session corruption: truncated streaming tool call stores unescaped newline in partialJson, causing persistent JSON parse error [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#69846Fetched 2026-04-22 07:47:32
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Timeline (top)
commented ×1

When an Anthropic streaming response is interrupted mid-tool-call, OpenClaw stores the incomplete JSON in a partialJson field on the tool call record in the JSONL session file. This field contains a literal (unescaped) newline character — a control character invalid in JSON strings.

On every subsequent message to that session, OpenClaw fails with:

Bad control character in string literal in JSON at position 111 (line 1 column 112)

The session enters a permanent crash loop. Each retry forks a new session (which also fails). The only recovery is manually patching the JSONL files.

Error Message

  1. Any subsequent message to that session triggers the parse error Strip partialJson from tool call records and reset stopReason: error to end_turn in the JSONL.
  • Records with stopReason: error should be handled gracefully on session reload

Root Cause

When an Anthropic streaming response is interrupted mid-tool-call, OpenClaw stores the incomplete JSON in a partialJson field on the tool call record in the JSONL session file. This field contains a literal (unescaped) newline character — a control character invalid in JSON strings.

On every subsequent message to that session, OpenClaw fails with:

Bad control character in string literal in JSON at position 111 (line 1 column 112)

The session enters a permanent crash loop. Each retry forks a new session (which also fails). The only recovery is manually patching the JSONL files.

Fix Action

Fix / Workaround

The session enters a permanent crash loop. Each retry forks a new session (which also fails). The only recovery is manually patching the JSONL files.

  • Session becomes permanently unresponsive
  • Forked recovery sessions inherit the same corrupted data
  • All agent messages fail silently until JSONL is manually patched
  • Reproduced twice in the same day on the same agent

Code Example

Bad control character in string literal in JSON at position 111 (line 1 column 112)
RAW_BUFFERClick to expand / collapse

Summary

When an Anthropic streaming response is interrupted mid-tool-call, OpenClaw stores the incomplete JSON in a partialJson field on the tool call record in the JSONL session file. This field contains a literal (unescaped) newline character — a control character invalid in JSON strings.

On every subsequent message to that session, OpenClaw fails with:

Bad control character in string literal in JSON at position 111 (line 1 column 112)

The session enters a permanent crash loop. Each retry forks a new session (which also fails). The only recovery is manually patching the JSONL files.

Steps to Reproduce

  1. Agent receives a message that triggers a tool call
  2. Anthropic API stream is interrupted before the tool call JSON is fully received
  3. OpenClaw stores the partial JSON in partialJson field with literal control characters
  4. Any subsequent message to that session triggers the parse error
  5. OpenClaw forks a new session — which also fails — creating a crash loop

Impact

  • Session becomes permanently unresponsive
  • Forked recovery sessions inherit the same corrupted data
  • All agent messages fail silently until JSONL is manually patched
  • Reproduced twice in the same day on the same agent

Manual Fix

Strip partialJson from tool call records and reset stopReason: error to end_turn in the JSONL.

Expected Behaviour

  • partialJson should be stored with properly escaped control characters, or not stored at all
  • Records with stopReason: error should be handled gracefully on session reload
  • Recovery should not require manual JSONL surgery

Environment

  • OpenClaw 2026.4.15 (041266a)
  • macOS Darwin 25.4.0 arm64 / Node 22.22.2
  • Agent: anthropic/claude-sonnet-4-6, Slack socket mode

extent analysis

TL;DR

Properly escape control characters in the partialJson field or remove it to prevent JSON parsing errors.

Guidance

  • Verify that the partialJson field is the root cause of the issue by checking the JSONL session file for literal newline characters.
  • Consider implementing a check to escape or remove control characters from the partialJson field before storing it in the JSONL session file.
  • To mitigate the issue, manually patching the JSONL files by stripping the partialJson field and resetting stopReason: error to end_turn can temporarily resolve the problem.
  • Review the error handling mechanism for records with stopReason: error to ensure they are handled gracefully on session reload.

Example

// Example of escaping control characters in a JSON string
const jsonString = '{"partialJson": "Hello\\nWorld"}';

Notes

The provided solution assumes that the issue is solely caused by the unescaped control characters in the partialJson field. Further investigation may be required to ensure that there are no other contributing factors.

Recommendation

Apply a workaround to properly escape or remove control characters from the partialJson field, as upgrading to a fixed version is not explicitly mentioned in the issue. This will help prevent the JSON parsing errors and subsequent crash loop.

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 corruption: truncated streaming tool call stores unescaped newline in partialJson, causing persistent JSON parse error [1 comments, 2 participants]