Skip to content

fix(agents): recover thinking errors from provider body - #98411

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-98308
Jul 1, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-98308

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Claude native-thinking sessions could stay stuck after Anthropic rejected a replayed thinking block signature. The recovery wrapper already knows how to retry without thinking blocks, but the production ProviderHttpError shape kept the provider detail in errorBody, which the detector did not inspect.

Fixes #98308

Why This Change Was Made

The recovery detector now includes the existing ProviderHttpError.errorBody carrier in its error graph traversal. The result shape, retry count, and existing recovery behavior are unchanged.

User Impact

Users on affected Claude native-thinking models can recover from this provider rejection path without destructive manual session compaction.

Evidence

node scripts/run-vitest.mjs src/agents/embedded-agent-runner/thinking.test.ts

Test Files  1 passed (1)
Tests       47 passed (47)
[test] passed 1 Vitest shard in 3.55s

node scripts/run-vitest.mjs src/agents/embedded-agent-runner/thinking.test.ts src/agents/embedded-agent-runner/thinking-replay-repair.test.ts

Test Files  1 passed (1)
Tests       4 passed (4)
Test Files  1 passed (1)
Tests       47 passed (47)
[test] passed 2 Vitest shards in 6.16s

pnpm exec oxfmt --check --threads=1 src/agents/embedded-agent-runner/thinking.ts src/agents/embedded-agent-runner/thinking.test.ts

Checking formatting...
All matched files use the correct format.
Finished in 6ms on 2 files using 1 threads.

node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.scripts.json src/agents/embedded-agent-runner/thinking.ts src/agents/embedded-agent-runner/thinking.test.ts

oxlint_exit=0

node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo

exit=0

git diff --check

exit=0

Live proof: a local runtime script constructed a real ProviderHttpError with generic .message and matching Anthropic JSON in .errorBody, then passed it through wrapAnthropicStreamWithRecovery.

[agent/embedded] [session-recovery] Anthropic thinking request rejected; retrying once without thinking blocks: sessionId=proof-session
{
  "errorName": "ProviderHttpError",
  "errorBodyCarriesDetail": true,
  "calls": 2,
  "resultContent": [
    {
      "type": "text",
      "text": "recovered"
    }
  ],
  "retryContent": [
    {
      "type": "text",
      "text": "visible answer"
    }
  ],
  "recovered": true,
  "recoveredCleanedContent": [
    {
      "type": "text",
      "text": "visible answer"
    }
  ]
}

No secrets or external services were used.

AI-assisted: built with Codex

@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

Codex review: needs maintainer review before merge. Reviewed July 1, 2026, 1:01 AM ET / 05:01 UTC.

Summary
The PR adds ProviderHttpError.errorBody to the Anthropic thinking-recovery error candidate traversal and adds a regression test for that carrier.

PR surface: Source +1, Tests +12. Total +13 across 2 files.

Reproducibility: yes. Current main's detector does not traverse errorBody, while ProviderHttpError stores bounded provider response body text there and the wrapper uses that detector for request and stream recovery.

Review metrics: 1 noteworthy metric.

  • Recovery carriers: 1 added. The detector newly treats ProviderHttpError.errorBody as a recovery trigger, so maintainer review should focus on that carrier and duplicate-branch selection.

Stored data model
Persistent data-model change detected: serialized state: src/agents/embedded-agent-runner/thinking.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #98308
Summary: This PR is a candidate fix for the canonical ProviderHttpError.errorBody Anthropic thinking-recovery issue; the older open duplicate targets the same carrier but has weaker proof.

Members:

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

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] A second open PR applies the same narrow errorBody fix, so maintainers should land only one branch and close the duplicate after merge.
  • [P1] No live Anthropic API stale-signature rejection was exercised in this review; confidence rests on current source, focused regression shape, CI, and the PR body's ProviderHttpError-shaped runtime proof.

Maintainer options:

  1. Decide the mitigation before merge
    Land one narrow ProviderHttpError.errorBody recovery fix with the adjacent wrapper regression test, then close the linked issue and duplicate candidate PRs after merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No code repair is needed; maintainers should choose this current-base, proof-sufficient branch or the overlapping older branch as the single landing candidate.

Security
Cleared: The diff only reads an existing provider error-body field in the recovery predicate and adds a test; it adds no dependencies, logging, network calls, secrets handling, or supply-chain surface.

Review details

Best possible solution:

Land one narrow ProviderHttpError.errorBody recovery fix with the adjacent wrapper regression test, then close the linked issue and duplicate candidate PRs after merge.

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

Yes. Current main's detector does not traverse errorBody, while ProviderHttpError stores bounded provider response body text there and the wrapper uses that detector for request and stream recovery.

Is this the best way to solve the issue?

Yes. Adding the existing ProviderHttpError.errorBody carrier to the existing detector and table test is the narrowest maintainable fix; broader carrier support is already separated into a follow-up issue.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d68ba5edc598.

Label changes

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The linked issue describes affected Claude native-thinking sessions becoming stuck on repeated provider rejections until destructive manual recovery.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix local runtime proof using a ProviderHttpError-shaped error through the recovery wrapper and reports the retry and recovered-message result.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix local runtime proof using a ProviderHttpError-shaped error through the recovery wrapper and reports the retry and recovered-message result.
Evidence reviewed

PR surface:

Source +1, Tests +12. Total +13 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 1 12 0 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 13 0 +13

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-runner/thinking.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-runner/thinking.test.ts src/agents/embedded-agent-runner/thinking-replay-repair.test.ts.
  • [P1] node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.scripts.json src/agents/embedded-agent-runner/thinking.ts src/agents/embedded-agent-runner/thinking.test.ts.
  • [P1] node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo.

What I checked:

Likely related people:

  • mmyzwl: Commit fbc3fa3 added the genericized Anthropic thinking recovery carrier traversal and adjacent tests that this PR extends. (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: Commit 652e616 added the durable rejected-thinking replay repair and attempt wiring that are invoked after successful recovery. (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 commits touched thinking recovery cleanup and provider error body reader behavior near this carrier boundary. (role: recent area contributor; confidence: medium; commits: ba779d836736, e802fb8a9fbb; files: src/agents/embedded-agent-runner/thinking.ts, src/agents/provider-http-errors.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 1, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 1, 2026
@vincentkoc
vincentkoc merged commit 95aced1 into openclaw:main Jul 1, 2026
154 of 164 checks passed
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 2, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic thinking-block recovery does not fire for opus-4.x because ProviderHttpError.errorBody is not inspected

2 participants