openclaw - ✅(Solved) Fix [Bug]: Anthropic-messages adapter crashes with "Cannot read properties of undefined (reading 'type')" on MiniMax Anthropic-compatible endpoint` [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#75633Fetched 2026-05-02 05:32:33
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
2
Author
Timeline (top)
cross-referenced ×2commented ×1labeled ×1referenced ×1

Error Message

~26% of cron-triggered sessions today crashed with this error on the very first model call:

  • stopReason: "error"
  1. ~25% of runs crash with the above error.
  • stopReason: "error"

Fix Action

Fix / Workaround

Production impact

Running two cron-driven editorial agents at 30-min cadence. ~26% session loss is significant — multiple cron firings per day produce zero work despite spending tokens on input. Workaround would be either (a) defensive default in the adapter when content has no text block, or (b) a fallback to surface the thinking content as text when no text block is present (not ideal but unblocks downstream consumers).

PR fix notes

PR #75655: fix: guard against undefined content blocks in anthropic-messages adapter

Description (problem / solution / changelog)

Fixes #75633

Root Cause

The anthropic-messages adapter's message reconstruction loops in convertAnthropicMessages and transformTransportMessages access block.type without guarding against block being undefined or null. When a provider like MiniMax returns a response where the content array contains sparse/malformed entries (or session repair preserves them), the loop crashes with:

Cannot read properties of undefined (reading 'type')

This affects ~26% of cron sessions when MiniMax's Anthropic-compatible endpoint returns responses with only thinking blocks or empty content that gets stored with malformed entries.

Fix

Added defensive if (!block) { continue; } guards in both iteration sites:

  • src/agents/transport-message-transform.ts — the shared message transform used by all transports
  • src/agents/anthropic-transport-stream.ts — the Anthropic-specific wire-format reconstruction in convertAnthropicMessages

Files Changed

  • src/agents/transport-message-transform.ts
  • src/agents/anthropic-transport-stream.ts
  • src/agents/transport-message-transform.test.ts (new tests)

Test Coverage

Added tests for:

  • content: [] (empty array) — no crash, message passes through
  • content: [{type:"thinking",...}] (only thinking) — converted to text, no crash
  • content: [undefined, {type:"text",...}] — undefined skipped, text preserved
  • content: [null, {type:"text",...}] — null skipped, text preserved

Changed files

  • src/agents/anthropic-transport-stream.ts (modified, +3/-0)
  • src/agents/transport-message-transform.test.ts (modified, +63/-0)
  • src/agents/transport-message-transform.ts (modified, +3/-0)

PR #75884: fix(anthropic-messages): guard undefined content blocks (Fixes #75633)

Description (problem / solution / changelog)

Summary

Fixes #75633.

When upstream providers (e.g. MiniMax-M2.5) return an Anthropic-Messages-compatible response that contains only a thinking block — or no content array at all — the transform layer crashed with:

Cannot read properties of undefined (reading 'type')

Root cause

transport-message-transform.ts and anthropic-transport-stream.ts both iterate content blocks and dereference block.type without null-checks. If the array contained undefined/null entries (or was missing), it threw.

Fix

Skip nullish blocks defensively before dereferencing type. Added 4 unit tests covering:

  • empty content array
  • content with only thinking block
  • content with mixed valid + null block
  • missing content key

Notes

Original PR #75655 was auto-closed by openclaw-barnacle bot due to "more than 10 active PRs"; reopened here after freeing 2 slots.

Changed files

  • src/agents/anthropic-transport-stream.ts (modified, +3/-0)
  • src/agents/transport-message-transform.test.ts (modified, +63/-0)
  • src/agents/transport-message-transform.ts (modified, +3/-0)

Code Example

Cannot read properties of undefined (reading 'type')

---

"minimax-portal": {
     "baseUrl": "https://api.minimax.io/anthropic",
     "api": "anthropic-messages",
     "apiKey": { "source": "env", "id": "MINIMAX_API_KEY" },
     "models": [{ "id": "MiniMax-M2.5" }]
   }

---

curl -H "x-api-key: $KEY" -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -X POST https://api.minimax.io/anthropic/v1/messages \
  -d '{"model":"MiniMax-M2.5","messages":[{"role":"user","content":"Say OK"}],"max_tokens":50}'
# returns content: [{"thinking": "...", "type": "thinking"}], stop_reason: "max_tokens"

---

Cannot read properties of undefined (reading 'type')

---
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Environment

  • OpenClaw: 2026.4.21 (f788c88)
  • Node: v24.14.1
  • OS: Windows 11
  • Provider config: api: "anthropic-messages", baseUrl: "https://api.minimax.io/anthropic", apiKey from env (sk-cp- Coding Plan key)
  • Model: MiniMax-M2.5 (returned model id: minimax-m2.5-20260211)

Symptom

~26% of cron-triggered sessions today crashed with this error on the very first model call:

Cannot read properties of undefined (reading 'type')

The assistant message recorded in the session jsonl shows:

  • usage.input > 0 (request reached the provider)
  • usage.output: 0
  • content: []
  • responseId populated (provider responded)
  • stopReason: "error"

So the upstream API returned a response, but the OpenClaw anthropic-messages adapter rejected it before producing any usable output. Sessions exit with no work done.

Failure rate

4 of 15 cron sessions on 2026-05-01 (26%). Concentrated on early-no-op sessions where the model's response is likely a single thinking block that hits stop without ever opening a text block.

Suspected cause

MiniMax's Anthropic-compatible endpoint sometimes returns a response with content that contains only a thinking block (no text block) — particularly when reasoning consumes most of the token budget before stop fires. The streaming adapter at dist/anthropic-vertex-stream-CpkZd5Cl.js appears to handle the streaming events with optional chaining (good), but there may be a downstream consumer that assumes content[0]?.type === "text" and dereferences content[0].type directly when content is empty.

Candidate code paths I traced (without the source map I can't pin a line):

  • Lines ~278–306 of the same file iterate msg.content and access block.type without guards while reconstructing wire-format messages for the next call. If the previous turn's content array is empty or sparse, this would explode.
  • Possibly a non-streaming response finalizer that handles empty content arrays without a defensive default.

Steps to reproduce

  1. Configure provider:
    "minimax-portal": {
      "baseUrl": "https://api.minimax.io/anthropic",
      "api": "anthropic-messages",
      "apiKey": { "source": "env", "id": "MINIMAX_API_KEY" },
      "models": [{ "id": "MiniMax-M2.5" }]
    }
  2. Set agent primary to minimax-portal/MiniMax-M2.5.
  3. Trigger a cron run with low max_tokens or a system prompt that elicits reasoning-heavy responses.
  4. ~25% of runs crash with the above error.

A direct curl reproduces the response shape that likely triggers this — at low max_tokens, MiniMax returns content with only a thinking block:

curl -H "x-api-key: $KEY" -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -X POST https://api.minimax.io/anthropic/v1/messages \
  -d '{"model":"MiniMax-M2.5","messages":[{"role":"user","content":"Say OK"}],"max_tokens":50}'
# returns content: [{"thinking": "...", "type": "thinking"}], stop_reason: "max_tokens"

Production impact

Running two cron-driven editorial agents at 30-min cadence. ~26% session loss is significant — multiple cron firings per day produce zero work despite spending tokens on input. Workaround would be either (a) defensive default in the adapter when content has no text block, or (b) a fallback to surface the thinking content as text when no text block is present (not ideal but unblocks downstream consumers).

Expected behavior

Cron-driven sessions invoke the primary provider via the anthropic-messages adapter, receive a valid Anthropic-format response (one or more content blocks of type text, thinking, and/or tool_use), and produce usable output. When the model's response contains only a thinking block with no text block (e.g. when reasoning fills the token budget before a text block opens), the adapter should either (a) surface the thinking content as text, (b) emit an empty-text fallback, or (c) gracefully request a continuation — not throw an unhandled TypeError.

Actual behavior

Actual behavior

~26% of cron sessions on 2026-05-01 (4 of 15 sessions) crash on the very first model call with:

Cannot read properties of undefined (reading 'type')

The assistant message recorded in the session jsonl shows:

  • usage.input > 0 (request reached the provider, e.g. 18,792 input tokens billed)
  • usage.output: 0
  • content: []
  • responseId populated (provider DID respond — e.g. 0643a57dcd08914129019c18df11e3e1)
  • stopReason: "error"

So the upstream returned a response, but the OpenClaw adapter rejected it before producing any usable output. Sessions exit with no work done. Token cost is incurred for input with zero deliverable result.

Suspected cause

MiniMax's Anthropic-compatible endpoint can return content with only a thinking block (no text block) — particularly when reasoning consumes most of the token budget before stop fires. The streaming adapter at dist/anthropic-vertex-stream-CpkZd5Cl.js handles content_block events with optional chaining (good), but there appears to be a downstream consumer that assumes a text block exists and dereferences content[0].type (or similar) directly.

Candidate code paths I traced:

  • Lines ~278–306 of the same file iterate msg.content and access block.type without guards while reconstructing wire-format messages for the next call. If a previous turn's content array is empty or has only thinking, this could trip.
  • A non-streaming response finalizer that may not defensively handle an empty content array.

OpenClaw version

2026.4.21 (f788c88)

Operating system

Windows 11 Pro 26200, Node v24.14.1

Install method

No response

Model

MiniMax-M2.5via OpenClaw provider idminimax-portal(returned model id from upstream:minimax-m2.5-20260211`, build date 2026-02-11)

Provider / routing chain

primary: minimax-portal/MiniMax-M2.5 (Anthropic-compatible endpoint at https://api.minimax.io/anthropic, sk-cp- Coding Plan key, api setting anthropic-messages) - fallback[0]: openrouter/minimax/minimax-m2.5 - fallback[1]: openrouter/minimax/minimax-m2.5:free - fallback[2]: google/gemini-3-flash - (further Gemini family + alternates after)

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The most likely fix is to add a defensive default in the OpenClaw anthropic-messages adapter to handle cases where the model's response contains only a thinking block with no text block.

Guidance

  1. Verify the suspected cause: Confirm that the issue occurs when the model's response contains only a thinking block by analyzing the session jsonl logs and the response from the MiniMax API.
  2. Check the adapter code: Review the code in dist/anthropic-vertex-stream-CpkZd5Cl.js, specifically lines ~278-306, to see if it assumes the existence of a text block and dereferences content[0].type directly.
  3. Add a defensive default: Modify the adapter code to handle cases where the content array is empty or contains only a thinking block, for example by adding a check for content[0] && content[0].type === "text" before accessing content[0].type.
  4. Test the fix: Trigger a cron run with a low max_tokens setting or a system prompt that elicits reasoning-heavy responses to verify that the adapter no longer crashes and produces usable output.

Example

// Example of how to add a defensive default
if (content[0] && content[0].type === "text") {
  // Process the text block
} else {
  // Handle the case where there is no text block or the content array is empty
  // For example, surface the thinking content as text or emit an empty-text fallback
}

Notes

The fix may require additional changes to the adapter code to handle different scenarios, such as when the model's response contains multiple blocks or when the thinking block is not the first block.

Recommendation

Apply a workaround by adding a defensive default in the OpenClaw anthropic-messages adapter to handle cases where the model

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

Cron-driven sessions invoke the primary provider via the anthropic-messages adapter, receive a valid Anthropic-format response (one or more content blocks of type text, thinking, and/or tool_use), and produce usable output. When the model's response contains only a thinking block with no text block (e.g. when reasoning fills the token budget before a text block opens), the adapter should either (a) surface the thinking content as text, (b) emit an empty-text fallback, or (c) gracefully request a continuation — not throw an unhandled TypeError.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING