Skip to content

fix(llm): skip legacy thinking block for claude-opus-4-8 - #3440

Closed
juanmichelini wants to merge 1 commit into
mainfrom
fix/opus-4-8-skip-legacy-thinking-block
Closed

juanmichelini wants to merge 1 commit into
mainfrom
fix/opus-4-8-skip-legacy-thinking-block

Conversation

@juanmichelini

@juanmichelini juanmichelini commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Anthropic's API for claude-opus-4-8 no longer accepts the legacy thinking.type=enabled + budget_tokens block that the SDK emits for every model in EXTENDED_THINKING_MODELS. Every call against litellm_proxy/anthropic/claude-opus-4-8 errors with:

invalid_request_error: "thinking.type.enabled" is not supported for this model.
Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.
request_id: req_011CbX18CQeQxYJ99w7nUorj

Observed in production via SWE‑bench eval runs:

Eval run Outcome
26608744731 (smoke) ✅ — old proxy litellm silently dropped the unknown params
26618647016 (smoke, post‑proxy‑upgrade) ❌ — litellm.UnsupportedParamsError upfront
26641824100 (smoke, after reverting OpenHands/benchmarks#729) ❌ — proxy forwards, Anthropic rejects thinking.type.enabled

All instances landed in output_errors.jsonl with patch_len=0, which the eval-monitor dashboard reports as "0% Critic 1 acceptance" — the critic never actually evaluated anything; the LLM call itself failed.

Root cause

claude-opus-4-8 was added to EXTENDED_THINKING_MODELS in #3427 so it would inherit that branch's stripping of temperature / top_p (which Anthropic now rejects for reasoning models). The intended payload was the side effect of being in that list; the unintended side effect was that the same code path also emits:

out["thinking"] = {"type": "enabled", "budget_tokens": N}
out["extra_headers"] = {"anthropic-beta": "interleaved-thinking-2025-05-14", ...}

That block is correct for claude-sonnet-4-5/4-6 and claude-haiku-4-5. It is not correct for claude-opus-4-8, which is a newer reasoning model expecting the adaptive schema (thinking.type=adaptive + output_config.effort).

Fix

Minimal: in chat_options.py, omit the legacy thinking block (and the interleaved‑thinking beta header) for any model in a new small allow‑list:

_MODELS_WITHOUT_LEGACY_THINKING_BLOCK: list[str] = [
    "claude-opus-4-8",
]

The temperature / top_p stripping that follows in the same branch — the original reason opus‑4‑8 was added to EXTENDED_THINKING_MODELS — is preserved. Other extended‑thinking models are untouched.

Future Anthropic reasoning models that ship with the same constraint can be added to that list in one line. When the SDK is updated to build the new adaptive schema, opus‑4‑8 should be moved off this allow‑list and onto that new path.

Tests

  • New test_claude_opus_4_8_skips_legacy_thinking_block:
    • opus‑4‑8 with extended_thinking_budget=4096, max_output_tokens=8192 → no thinking key, no anthropic-beta header, temperature and top_p still stripped.
    • sonnet‑4‑5 with the same inputs → thinking == {"type": "enabled", "budget_tokens": 4096} and anthropic-beta == "interleaved-thinking-2025-05-14", locking in that the opus‑4‑8 skip does not regress other extended‑thinking models.
  • Existing test_claude_opus_4_8_strips_temp_and_top_p and the thinking‑budget‑clamp tests continue to pass (167 passed locally on tests/sdk/llm/test_chat_options.py + tests/sdk/llm/test_model_features.py).

Caveats / follow‑ups

  • This is a stop‑gap. The proper fix is to teach chat_options.py to build Anthropic's new adaptive schema (thinking: {"type": "adaptive"} + output_config: {"effort": llm.reasoning_effort}) for reasoning models, and route opus‑4‑8 through that. Tracking that as a follow‑up rather than expanding this PR's scope.
  • The companion benchmarks revert is OpenHands/benchmarks#729, which restored the proxy‑side litellm pin so the SDK's payload is forwarded to Anthropic unmodified (without that, the proxy itself errors on reasoning_effort / thinking before Anthropic ever sees the request).
  • Eval‑monitor UX (not in this PR): when output.jsonl == 0 and output_errors.jsonl > 0, the dashboard should surface "all completed instances errored" rather than "0% critic acceptance" — the current label sent us down the wrong rabbit hole during this investigation.

This PR was opened by an AI agent (OpenHands) on behalf of @juanmichelini.

@juanmichelini can click here to continue refining the PR


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:828144c-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-828144c-python \
  ghcr.io/openhands/agent-server:828144c-python

All tags pushed for this build

ghcr.io/openhands/agent-server:828144c-golang-amd64
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-golang-amd64
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-golang-amd64
ghcr.io/openhands/agent-server:828144c-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:828144c-golang-arm64
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-golang-arm64
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-golang-arm64
ghcr.io/openhands/agent-server:828144c-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:828144c-java-amd64
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-java-amd64
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-java-amd64
ghcr.io/openhands/agent-server:828144c-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:828144c-java-arm64
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-java-arm64
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-java-arm64
ghcr.io/openhands/agent-server:828144c-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:828144c-python-amd64
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-python-amd64
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-python-amd64
ghcr.io/openhands/agent-server:828144c-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:828144c-python-arm64
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-python-arm64
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-python-arm64
ghcr.io/openhands/agent-server:828144c-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:828144c-golang
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-golang
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-golang
ghcr.io/openhands/agent-server:828144c-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:828144c-java
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-java
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-java
ghcr.io/openhands/agent-server:828144c-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:828144c-python
ghcr.io/openhands/agent-server:828144ca28b57e4b56d05b7f62d9ab735705978d-python
ghcr.io/openhands/agent-server:fix-opus-4-8-skip-legacy-thinking-block-python
ghcr.io/openhands/agent-server:828144c-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 828144c-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 828144c-python-amd64) are also available if needed

Opus 4.8 was added to EXTENDED_THINKING_MODELS in #3427 so it would
inherit that path's stripping of `temperature` / `top_p`, which
Anthropic now rejects for reasoning models. As a side effect, the same
path also emits the legacy

    thinking: {"type": "enabled", "budget_tokens": N}

block (plus the `anthropic-beta: interleaved-thinking-2025-05-14`
header). Anthropic's API for claude-opus-4-8 now refuses that schema:

    invalid_request_error: "thinking.type.enabled" is not supported
    for this model. Use "thinking.type.adaptive" and
    "output_config.effort" to control thinking behavior.

Observed in production via SWE-bench eval runs against
`litellm_proxy/anthropic/claude-opus-4-8`: every conversation
errored with `LLMBadRequestError` after 4 retries, leaving
`output.jsonl` empty and all instances in `output_errors.jsonl`
(e.g. eval run 26641824100, request_id
`req_011CbX18CQeQxYJ99w7nUorj`).

Until the SDK builds the new adaptive schema (`thinking.type=adaptive`
+ `output_config.effort`), the minimal fix is to omit the legacy
block for opus-4-8 while keeping the temp/top_p stripping that's the
real reason it's in EXTENDED_THINKING_MODELS. Other extended-thinking
models (sonnet-4-5/4-6, haiku-4-5) are unaffected and still get the
legacy block, which is what they expect.

The opt-out is expressed as a small allow-list
(`_MODELS_WITHOUT_LEGACY_THINKING_BLOCK`) in chat_options.py so future
Anthropic reasoning models that ship with the same constraint can be
added in one line.

Tests:
- `test_claude_opus_4_8_skips_legacy_thinking_block` pins that
  opus-4-8 omits the thinking block and beta header even when
  `extended_thinking_budget` is set, while sonnet-4-5 in the same
  call still gets both.
- Existing `test_claude_opus_4_8_strips_temp_and_top_p` and the
  thinking-budget clamp tests continue to pass.

Co-authored-by: openhands <openhands@all-hands.dev>
@juanmichelini juanmichelini added bug Something isn't working lm-support labels May 29, 2026 — with OpenHands AI
@github-actions

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

Copy link
Copy Markdown
Collaborator Author

Closing per @juanmichelini — the allow-list approach is more complex than warranted. Replacing with a smaller PR that reverts #3427 and instead drops temperature/top_p via the reasoning-model check that already covers opus-4-7 / opus-4-5.

@juanmichelini
juanmichelini deleted the fix/opus-4-8-skip-legacy-thinking-block branch May 29, 2026 16:48
@github-actions

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/llm/utils
   model_features.py58198%35
TOTAL28668830071% 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lm-support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants