openclaw - ✅(Solved) Fix [Bug]: isRawToolCallBlock misses snake_case tool call types (tool_use, tool_call), causing corrupted session history errors with Anthropic [2 pull requests, 2 comments, 3 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#48915Fetched 2026-04-08 00:51:07
View on GitHub
Comments
2
Participants
3
Timeline
15
Reactions
0
Author
Timeline (top)
referenced ×7cross-referenced ×4commented ×2labeled ×2

The function isRawToolCallBlock in the session history repair logic only recognizes camelCase tool call block types (toolUse, toolCall, functionCall), but does NOT handle the snake_case variants used by Anthropic and some other providers (tool_use, tool_call, function_call).

This causes repairToolCallInputs - which is supposed to sanitize corrupted history before sending to the model - to silently skip over broken tool_use blocks that are missing their input field.

Error Message

The broken tool_use block is skipped during repair, leading to a "field required" error from Anthropic and a "Session history looks corrupted" error in OpenClaw.

Root Cause

In reply-Bm8VrLQh.js, the function:

function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && (type === "toolCall" || type === "toolUse" || type === "functionCall");
}

Fix Action

Fixed

PR fix notes

PR #48921: fix: add snake_case tool call types to isRawToolCallBlock

Description (problem / solution / changelog)

Problem

The function only recognized camelCase tool call block types (, , ) but missed the snake_case variants (, , ) used by Anthropic and some other providers.

This caused — which sanitizes corrupted history before sending to the model — to silently skip over broken blocks missing their field.

Fix

Added the three snake_case variants to the type check condition.

Fixes #48915

Testing

  • All 23 existing tests in pass.

Changed files

  • src/agents/session-transcript-repair.ts (modified, +10/-2)
  • src/cli/tui-cli.ts (modified, +13/-1)

PR #48985: fix(agents): recognize snake_case tool call types in session history repair (#48915)

Description (problem / solution / changelog)

Summary

isRawToolCallBlock only matched camelCase block types (toolCall, toolUse, functionCall), missing the snake_case variants (tool_call, tool_use, function_call) emitted by Anthropic and some other providers. This caused repairToolCallInputs to skip over broken tool_use blocks that were missing their input field, leading to persistent "corrupted session" errors that even /new could not resolve.

Root Cause

When a streamed tool call is interrupted mid-stream (e.g. timeout, abort), a tool_use block without an input field gets persisted in the session transcript. On the next message, the history repair pass calls isRawToolCallBlock to detect these blocks — but because it only checks camelCase types, the snake_case tool_use block is invisible to the repair logic. Anthropic's API then rejects the request with messages.N.content.N.tool_use.input: field required.

Changes

  • src/agents/session-transcript-repair.ts: Add tool_call, tool_use, function_call to the type check in isRawToolCallBlock
  • src/agents/session-transcript-repair.test.ts: Add regression test for snake_case tool_use block without input; update TOOL_CALL_BLOCK_TYPES test helper

Test

All 24 tests pass (23 existing + 1 new regression test):

✓ src/agents/session-transcript-repair.test.ts (24 tests) 9ms

Closes #48915

Changed files

  • src/agents/session-transcript-repair.test.ts (modified, +22/-1)
  • src/agents/session-transcript-repair.ts (modified, +7/-1)

Code Example

function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && (type === "toolCall" || type === "toolUse" || type === "functionCall");
}

---

function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && (
    type === "toolCall" || type === "toolUse" || type === "functionCall" ||
    type === "tool_call" || type === "tool_use" || type === "function_call"
  );
}

---
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Summary

The function isRawToolCallBlock in the session history repair logic only recognizes camelCase tool call block types (toolUse, toolCall, functionCall), but does NOT handle the snake_case variants used by Anthropic and some other providers (tool_use, tool_call, function_call).

This causes repairToolCallInputs - which is supposed to sanitize corrupted history before sending to the model - to silently skip over broken tool_use blocks that are missing their input field.

Root Cause

In reply-Bm8VrLQh.js, the function:

function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && (type === "toolCall" || type === "toolUse" || type === "functionCall");
}

Proposed Fix

function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && (
    type === "toolCall" || type === "toolUse" || type === "functionCall" ||
    type === "tool_call" || type === "tool_use" || type === "function_call"
  );
}

Impact

Users in Feishu groups experience persistent "corrupted session" errors that /new cannot reliably resolve, because the broken block survives the sanitization pass every time.

Steps to reproduce

  1. Use OpenClaw with Anthropic as provider in a Feishu group chat.
    1. A streamed tool call response is interrupted mid-stream (e.g., timeout, abort), leaving a tool_use block persisted in the session transcript without an input field.
    1. On the next message (even after /new), the history is loaded and passed through repairToolCallInputs, but the broken block is not detected because its type "tool_use" doesn't match the check.
    1. Anthropic's API rejects the request with: messages.N.content.N.tool_use.input: field required
    1. OpenClaw surfaces this as: "Session history looks corrupted (tool call input missing). Use /new to start a fresh session."

Expected behavior

The session history should be correctly repaired/sanitized, and Anthropic API should not reject the request due to missing input fields.

Actual behavior

The broken tool_use block is skipped during repair, leading to a "field required" error from Anthropic and a "Session history looks corrupted" error in OpenClaw.

OpenClaw version

2026.3.13

Operating system

macOS

Install method

npm global

Model

anthropic/claude-sonnet-4.5

Provider / routing chain

openclaw -> anthropic

Config file / key location

No response

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

Affected: Feishu group chat users using Anthropic as provider. Severity: High (blocks workflow, persistent "corrupted session" errors). Frequency: Always (reproducible when tool calls are interrupted). Consequence: Agent cannot respond even after /new if broken content is in history.

Additional information

No response

extent analysis

Fix Plan

To fix the issue, update the isRawToolCallBlock function to recognize both camelCase and snake_case variants of tool call block types.

  • Update the isRawToolCallBlock function as follows:
function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && (
    type === "toolCall" || type === "toolUse" || type === "functionCall" ||
    type === "tool_call" || type === "tool_use" || type === "function_call"
  );
}

Alternatively, consider using a more flexible approach with an array of allowed types and the includes() method:

const allowedTypes = [
  "toolCall", "toolUse", "functionCall",
  "tool_call", "tool_use", "function_call"
];

function isRawToolCallBlock(block) {
  if (!block || typeof block !== "object") return false;
  const type = block.type;
  return typeof type === "string" && allowedTypes.includes(type);
}

Verification

To verify the fix, follow these steps:

  • Reproduce the issue using the steps provided in the problem description.
  • Apply the updated isRawToolCallBlock function.
  • Repeat the steps to reproduce the issue and verify that the "corrupted session" error no longer occurs.

Extra Tips

Consider adding unit tests to ensure the isRawToolCallBlock function works correctly for different input types and variants. Additionally, review other parts of the codebase for similar issues with case sensitivity and type checking.

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 session history should be correctly repaired/sanitized, and Anthropic API should not reject the request due to missing input fields.

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]: isRawToolCallBlock misses snake_case tool call types (tool_use, tool_call), causing corrupted session history errors with Anthropic [2 pull requests, 2 comments, 3 participants]