VPN07

OpenClaw Session Broken After Restart: Fix Thinking Block 400 Errors

March 10, 2026 18 min read Bug Fix OpenClaw Session Recovery

The Problem: You restarted your OpenClaw gateway — maybe after a system update, a config change, or a crash — and now every session that was using Claude's extended thinking mode throws a 400 Bad Request error. Your agent is completely unresponsive. The session history is still there, but OpenClaw can't replay it. This is one of the most disruptive bugs affecting OpenClaw users in 2026, and this guide covers every available fix.

You probably discovered this bug the hard way. You were in the middle of a long, complex task with your OpenClaw agent — maybe a research session, a coding project, or a multi-step automation — and you needed to restart the gateway. Either the system rebooted, you ran openclaw gateway restart, or you updated your configuration. When you came back and sent a message, instead of picking up where you left off, OpenClaw returned a cryptic 400 error. The session appeared stuck in a permanent broken state.

This is a known and documented bug filed as Issue #40512 in the OpenClaw GitHub repository. The root cause is a specific incompatibility between Anthropic's extended thinking feature and OpenClaw's session persistence mechanism. The bug affects any session that used the /think directive or had extended thinking enabled by default, and has been seen across macOS, Windows, and Linux deployments.

What Are Thinking Blocks and Why Do They Break?

To understand this bug, you first need to understand what thinking blocks are. When you use Claude with extended thinking enabled (via /think medium, /think high, or /think xhigh), the model generates an internal reasoning chain before producing its final response. This reasoning chain is called a thinking block. It looks like a special message type in the conversation history: it has a type of thinking rather than the usual text.

The problem is that thinking blocks are ephemeral by design in Anthropic's API. They are generated fresh each time the model reasons. When OpenClaw saves your session to disk and later tries to reload it, it includes these thinking blocks in the conversation history it sends back to the Anthropic API. Anthropic's API rejects this — thinking blocks from previous turns cannot be re-submitted as part of conversation history. The API returns a 400 error with a message like: "messages: thinking blocks cannot appear in previous turns".

// Exact error you will see in openclaw logs
Error: 400 {"type":"error","error":{"type":"invalid_request_error", "message":"messages: thinking blocks cannot appear in previous turns"}} Session failed to replay. History contains unsupported content type. Gateway: disconnected Agent: offline

Once this happens, the session is stuck. Every time OpenClaw tries to continue the conversation, it loads the full session history (including the thinking blocks) and sends it to the API, which rejects it again with the same 400 error. You're in a loop. The session is effectively dead unless you intervene manually.

How to Confirm This Is Your Problem

Before applying any fix, confirm the error is caused by thinking blocks rather than a different issue (like a gateway auth failure or a rate limit). Here's how to diagnose:

Diagnosis Commands

# Step 1: Check gateway status openclaw gateway status # Step 2: Check the session log for 400 errors openclaw session log --last 50 # Step 3: Run the doctor tool openclaw doctor # Step 4: Check raw session file for thinking blocks cat ~/.openclaw/sessions/[session-id].json | grep -c '"type":"thinking"' # If output is > 0, thinking blocks are the cause

If you see a count greater than zero from that last command, you have confirmed the thinking block issue. The session JSON contains thinking blocks that the API will reject.

400
HTTP error code returned
#40512
Official GitHub issue
All OS
Affects all platforms

Fix Method 1: Start a Fresh Session (Fastest)

If you don't need to preserve the existing session context, the fastest fix is to simply start a new session. This abandons the corrupted session history entirely and gives you a clean slate.

Quick Reset

# In your chat interface (Telegram/Discord/WhatsApp), send: /reset # Or via CLI: openclaw session reset # Or start a new session without losing memories: /new

Note: /reset clears the session context but does not delete your stored memories. Your agent will remember your name, preferences, and custom rules. Only the conversation history is cleared.

Fix Method 2: Manually Edit the Session File (Context Preserved)

If you need to preserve the session context — for example, you were in the middle of a complex coding project and losing the conversation would mean starting over — you can manually edit the session JSON file to strip out the thinking blocks. This is the surgical approach.

Manual Session Repair Steps

# Step 1: Find your session files ls ~/.openclaw/sessions/ # Sessions are named with timestamps or UUIDs # Step 2: Stop the gateway first openclaw gateway stop # Step 3: Make a backup cp ~/.openclaw/sessions/[session-id].json \ ~/.openclaw/sessions/[session-id].backup.json # Step 4: Use Python to strip thinking blocks python3 <<'EOF' import json, sys session_file = "/Users/YOU/.openclaw/sessions/SESSION_ID.json" with open(session_file, "r") as f: session = json.load(f) # Filter out thinking blocks from all messages def strip_thinking(messages): cleaned = [] for msg in messages: if isinstance(msg.get("content"), list): msg["content"] = [ block for block in msg["content"] if block.get("type") != "thinking" ] if msg["content"]: cleaned.append(msg) elif msg.get("type") != "thinking": cleaned.append(msg) return cleaned session["messages"] = strip_thinking(session.get("messages", [])) with open(session_file, "w") as f: json.dump(session, f, indent=2) print("Done! Thinking blocks removed.") EOF # Step 5: Restart the gateway openclaw gateway start

Important Warning

After stripping thinking blocks, the remaining conversation history may have gaps — places where a question was followed by an answer but the intermediate reasoning is missing. The AI can still work with this, but responses in the next turn may be less coherent. If the task was critical, consider summarizing what was accomplished before /reset-ing instead.

Fix Method 3: Disable Thinking Mode to Prevent Future Breaks

If you restart your gateway regularly — for example, you have automated restarts as part of a maintenance routine, or your system reboots overnight — the safest long-term solution is to configure OpenClaw to either not use extended thinking, or to configure it in a way that thinking blocks are never persisted to session history.

Configuration Options

# Option A: Turn off thinking globally in openclaw.json { "thinking": { "enabled": false } } # Option B: Use a lower thinking level that doesn't persist blocks # In chat: /think minimal # or /think off # Option C: Start isolated sessions for thinking-heavy tasks # (Isolated sessions are not persisted the same way) openclaw run --isolated --think high "Analyze this codebase" # Check current thinking setting /think status

Fix Method 4: Use /compact Before Restarting

The cleanest preventive approach is to run /compact before any planned gateway restart. The compaction process summarizes your session history into a condensed form — and critically, that summary does not contain raw thinking blocks. After compaction, your session is restart-safe.

Pre-Restart Workflow

# Before ANY planned restart, run this sequence: # Step 1: Compact the session /compact save progress on current task before restart # Step 2: Wait for compact to complete (you'll see a summary) # Step 3: THEN restart the gateway openclaw gateway restart # The compacted session will load cleanly — no thinking blocks

Pro tip: Add a note to your HEARTBEAT.md instructing the agent to compact before restart commands. This makes it automatic.

Understanding Session File Structure

For power users who want to understand what's happening under the hood, here's the relevant session JSON structure. A normal session exchange looks like this:

// Normal session structure (no thinking blocks — restart safe)
{ "messages": [ { "role": "user", "content": [{ "type": "text", "text": "Summarize this document" }] }, { "role": "assistant", "content": [{ "type": "text", "text": "Here is the summary..." }] } ] }
// Session WITH thinking blocks (will break on restart)
{ "messages": [ { "role": "user", "content": [{ "type": "text", "text": "Summarize this document" }] }, { "role": "assistant", "content": [ { "type": "thinking", "thinking": "Let me think about this carefully..." // ↑ THIS BLOCK causes the 400 error on restart }, { "type": "text", "text": "Here is the summary..." } ] } ] }

Which Fix Should You Choose?

Use /reset if...

  • • You don't need the old conversation context
  • • The task is complete and you're starting something new
  • • Speed is your priority
  • • You want the cleanest possible result

Edit session file if...

  • • You need to preserve conversation context
  • • You were mid-task on something complex
  • • Losing the history would mean significant rework
  • • You're comfortable with terminal commands

Disable thinking if...

  • • You restart your gateway frequently
  • • Your system reboots overnight automatically
  • • You don't need deep reasoning for your use case

Use /compact if...

  • • You know a restart is coming
  • • You want to be proactive, not reactive
  • • This is the best long-term habit to build

Related Issues You May Also Encounter

If you've resolved the thinking block issue but are still seeing problems, here are other known post-restart issues:

Exec Tool Timeout After Restart

Running openclaw gateway restart via the exec tool (GitHub Issue #32933) causes a timeout because the restart kills the process mid-execution. The tool reports failure even though the restart succeeded. Fix: use openclaw gateway restart --detach or restart from outside the agent.

Device Token Mismatch After Restart

After switching models and restarting (especially with OAuth-backed models like Codex), you may see a 1008 device token mismatch. Run openclaw doctor --fix and then openclaw gateway restart to resync the token state.

Cron Jobs Not Firing After Restart

Scheduled cron jobs sometimes fail to re-register after a gateway restart. Check with openclaw cron list. If jobs appear but don't fire, run openclaw cron reset to re-register all jobs.

Why a Stable Network Makes OpenClaw More Reliable

Many of the session corruption and 400 error issues are made significantly worse by unstable network connections. Here's why: OpenClaw's gateway communicates with the Anthropic API in real time. If your network drops mid-session — especially in the middle of a thinking block being generated — the session state can be left in an inconsistent state. The thinking block may be partially written to session history, creating a malformed JSON entry that neither the client nor the API can handle.

This is why serious OpenClaw users who run the agent for automated, overnight tasks always pair it with a reliable, high-speed VPN connection. The VPN ensures that even when your ISP experiences temporary instability, your connection to the Anthropic API (and other model providers) remains stable and uninterrupted. It also ensures consistent routing — no sudden IP changes mid-session that could cause authentication failures.

Why Network Stability Matters for OpenClaw

✓ Prevents mid-session drops
A stable connection means thinking blocks complete fully before being saved.
✓ Consistent IP address
No auth failures from sudden IP changes during long sessions.
✓ Low latency to AI APIs
Faster responses mean shorter thinking blocks and less data at risk.
✓ Reliable API access
Bypass regional restrictions that throttle or block model API calls.

Full Troubleshooting Checklist

Run openclaw doctor to auto-detect and fix common issues first
Check session file for "type":"thinking" blocks using the grep command above
Choose the appropriate fix: /reset, manual edit, disable thinking, or /compact
For future prevention: always run /compact before any planned restart
Consider setting /think minimal or off if restarts are frequent
Use a stable network connection to prevent partial session writes
If using isolated sessions for heavy tasks, they don't persist thinking blocks the same way

VPN07 — Recommended for OpenClaw Users

Keep your AI agent online with 1000Mbps speeds across 70+ countries

Session corruption from network drops is one of the most preventable OpenClaw problems. VPN07 provides a stable, high-speed 1000Mbps connection that keeps your gateway-to-API link uninterrupted — protecting your sessions from mid-write failures. Running for 10 years with 30-day money-back guarantee.

$1.5/mo
Starting price
1000Mbps
Max bandwidth
70+
Countries
30-day
Money-back

Related Articles

$1.5/mo · 10 Years Trusted
Try VPN07 Free