Skip to content

fix(agents): detect thinking-block errors in ProviderHttpError.errorBody (fixes #98308) (AI-assisted) - #98334

Closed
liuhao1024 wants to merge 1 commit into
openclaw:mainfrom
liuhao1024:fix/thinking-recovery-errorbody-detection
Closed

liuhao1024 wants to merge 1 commit into
openclaw:mainfrom
liuhao1024:fix/thinking-recovery-errorbody-detection

Conversation

@liuhao1024

@liuhao1024 liuhao1024 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When Anthropic rejects a replayed thinking block with an invalid signature, the recovery wrapper (wrapAnthropicStreamWithRecovery) should detect the error and retry with stripped thinking blocks. However, ProviderHttpError stores the raw Anthropic response on .errorBody while .message carries a generic user-facing string. The detection predicate only traversed cause, error, rawError, errorMessage, and message — missing errorBody entirely. This means sessions become permanently bricked by stale thinking signatures even though a non-destructive repair path exists.

Why This Change Was Made

The production error shape from ProviderHttpError is:

  • .message → "LLM request failed: provider rejected the request schema or tool payload." (generic)
  • .errorBody → {"error":{"message":"messages.12.content.3: Invalid \signature` in `thinking` block",...}}` (specific)

The THINKING_BLOCK_ERROR_PATTERN regex correctly matches the error text, but errorBody was never fed to it. Adding current.errorBody to the error graph traversal in shouldRecoverAnthropicThinkingError closes this gap.

User Impact

Users on Claude opus-4.x, sonnet-4.x, haiku-4.x, and claude-5+ with native extended thinking enabled will no longer have sessions permanently bricked by stale thinking-block signatures. The recovery path now correctly detects the ProviderHttpError.errorBody shape and fires the non-destructive repair.

  • AI-assisted (Hermes Agent)

Evidence

  • Behavior addressed: Anthropic thinking-block recovery fails to detect errors stored in ProviderHttpError.errorBody
  • Environment tested: macOS 26.4.1, Node 22.22.3, OpenClaw 2026.6.11 (816038e)
  • Steps run after the patch:
    1. Added current.errorBody to the error graph traversal in shouldRecoverAnthropicThinkingError (thinking.ts:549)
    2. Added a parameterized test case for ProviderHttpError.errorBody to the existing wrapAnthropicStreamWithRecovery test suite
    3. Ran the full test suite for the changed module
  • Evidence after fix:
 RUN  v4.1.8
 ✓  agents  src/agents/embedded-agent-runner/thinking.test.ts (47 tests) 65ms
 Test Files  1 passed (1)
      Tests  47 passed (47)
  • Observed result after fix: All 47 pass including the new ProviderHttpError errorBody test case, which verifies that wrapAnthropicStreamWithRecovery now correctly detects thinking-block signature errors stored in .errorBody and retries with stripped thinking blocks
  • What was not tested: Live Anthropic API interaction with real stale thinking signatures (requires specific session state and API timing that cannot be reliably reproduced in a local test environment)

Real behavior proof

  • Behavior addressed: Anthropic thinking-block recovery fails to detect errors stored in ProviderHttpError.errorBody
  • Environment tested: macOS 26.4.1, Node 22.22.3, OpenClaw 2026.6.11 (816038e)
  • Steps run after the patch:
    1. Added current.errorBody to the error graph traversal in shouldRecoverAnthropicThinkingError (thinking.ts:549)
    2. Added a parameterized test case for ProviderHttpError.errorBody to the existing wrapAnthropicStreamWithRecovery test suite
    3. Ran the full test suite for the changed module
  • Evidence after fix:
 RUN  v4.1.8
 ✓  agents  src/agents/embedded-agent-runner/thinking.test.ts (47 tests) 65ms
 Test Files  1 passed (1)
      Tests  47 passed (47)
  • Observed result after fix: All 47 pass including the new ProviderHttpError errorBody test case, which verifies that wrapAnthropicStreamWithRecovery now correctly detects thinking-block signature errors stored in .errorBody and retries with stripped thinking blocks
  • What was not tested: Live Anthropic API interaction with real stale thinking signatures (requires specific session state and API timing that cannot be reliably reproduced in a local test environment)

The recovery predicate in shouldRecoverAnthropicThinkingError only
traversed cause, error, rawError, errorMessage, and message fields.
ProviderHttpError stores the raw Anthropic response on errorBody,
which contains the specific thinking-block signature rejection text,
while .message carries a generic user-facing string.

Adding errorBody to the error graph traversal lets the recovery path
detect the production error shape and fire the non-destructive repair
(repairRejectedThinkingReplayInSessionManager) instead of rethrowing
the HTTP 400 and bricking the session.

Test: added errorBody case to the wrapAnthropicStreamWithRecovery
parameterized test suite.

Fixes openclaw#98308
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: #98411 already merged the same ProviderHttpError errorBody recovery carrier and regression test onto current main, and this PR's current potential merge result would only add a duplicate current.errorBody candidate.

Root-cause cluster
Relationship: superseded
Canonical: #98411
Summary: This PR is superseded by the merged current-main ProviderHttpError.errorBody recovery fix; the remaining open carrier work is a distinct follow-up for additional provider wrapper fields.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Keep #98411 as the canonical landed fix for ProviderHttpError.errorBody; track broader body/detail/responseBody carrier work separately in #98368 and #100193.

So I’m closing this here and keeping the remaining discussion on #98411, #98368, and #100193.

Review details

Best possible solution:

Keep #98411 as the canonical landed fix for ProviderHttpError.errorBody; track broader body/detail/responseBody carrier work separately in #98368 and #100193.

Do we have a high-confidence way to reproduce the issue?

Yes at source level for the pre-fix release: v2026.6.11 lacks the errorBody candidate while ProviderHttpError stores provider response bodies there. Current main no longer reproduces the gap because commit 95aced1 added the carrier and regression case.

Is this the best way to solve the issue?

No for this branch now. The narrow fix shape was correct, but #98411 is already merged on current main and this branch would add duplicate traversal rather than a unique improvement.

Security review:

Security review cleared: The diff only reads an existing provider error-body field in recovery detection and adds a test; it adds no dependency, logging, secret, network, or supply-chain surface.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • sunlit-deng: Authored merged PR fix(agents): recover thinking errors from provider body #98411, which added the current-main errorBody traversal and regression test that supersede this branch. (role: canonical fix author; confidence: high; commits: 95aced10b08a; files: src/agents/embedded-agent-runner/thinking.ts, src/agents/embedded-agent-runner/thinking.test.ts)
  • mmyzwl: Authored the merged genericized Anthropic thinking-error recovery change that introduced the named-carrier traversal and adjacent recovery tests extended by the later errorBody fix. (role: introduced named-carrier recovery behavior; confidence: high; commits: fbc3fa387637; files: src/agents/embedded-agent-runner/thinking.ts, src/agents/embedded-agent-runner/thinking.test.ts)
  • Josh Avant: Authored the durable rejected-thinking replay repair and attempt wiring that runs after this recovery detector fires. (role: adjacent replay-repair contributor; confidence: high; commits: 652e616a297c; files: src/agents/embedded-agent-runner/thinking.ts, src/agents/embedded-agent-runner/thinking-replay-repair.ts, src/agents/embedded-agent-runner/run/attempt.ts)
  • Vincent Koc: Recent history includes thinking recovery cleanup and provider error-body reader work near the carrier boundary reviewed here. (role: recent adjacent provider-error contributor; confidence: medium; commits: ba779d836736, e802fb8a9fbb; files: src/agents/embedded-agent-runner/thinking.ts, src/agents/provider-http-errors.ts)

Codex review notes: model internal, reasoning high; reviewed against 704c58468667; fix evidence: commit 95aced10b08a, main fix timestamp 2026-07-01T08:13:24Z.

@vincentkoc

Copy link
Copy Markdown
Member

Confirmed against current main: provider errorBody is already included in the thinking-error candidate graph, with the matching regression coverage. This landed in #98411 at 95aced1, which is an ancestor of current main. Closing as fixed/superseded. Thanks for the original diagnosis.

@vincentkoc vincentkoc closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants