anthropics / anthropics/claude-agent-sdk-python

MessageParseError: missing signature in thinking block with claude-agent-sdk 0.1.79 and Anthropic-compatible backend

Abierto
#949 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
8.1k
Forks
1.3k
Merge medio
2 d 31 min
PR fusionados (30 d)
1

Descripción

## Summary

claude-agent-sdk crashes with:

```
claude_agent_sdk._errors.MessageParseError:
Missing required field in assistant message: 'signature'
```

This is similar to #339, but I can still reproduce it with `claude-agent-sdk==0.1.79`.

The issue appears when the model/backend emits a `thinking` content block without a `signature` field. The SDK parser currently assumes every thinking block has `signature`.

## Environment

- OS: Linux / Docker
- Python: 3.11
- claude-agent-sdk: 0.1.79
- Runtime: Docker container
- Model: `gpt-5.4` via Anthropic-compatible backend
- SDK entrypoint: `claude_agent_sdk.query(...)`
- `ClaudeAgentOptions` includes:
- `model="gpt-5.4"`
- `allowed_tools=[...]`
- `permission_mode="dontAsk"`
- `skills=[...]`
- `resume=` sometimes true

SDK inspection output:

```
sdk_version = 0.1.79
parser_file = /usr/local/lib/python3.11/site-packages/claude_agent_sdk/_internal/message_parser.py
100: case "thinking":
103: thinking=block["thinking"],
104: signature=block["signature"]
```

## Reproduction

This is reproducible in our bot when the user sends a repository URL, for example:

- `https://github.com/anthropics/claude-agent-sdk-python`
- or a GitLab repository URL

The request runs for ~30 seconds, then fails before any final assistant result is returned.

## Actual behavior

The SDK raises `MessageParseError` while parsing an assistant message:

```
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/claude_agent_sdk/_internal/message_parser.py", line 137, in parse_message
signature=block["signature"],
KeyError: 'signature'

The above exception was the direct cause of the following exception:

claude_agent_sdk._errors.MessageParseError:
Missing required field in assistant message: 'signature'
```

Service logs:

```
claude sdk event type=SystemMessage resume=True
...
MessageParseError: Missing required field in assistant message: 'signature'
```

## Expected behavior

The SDK should not crash the whole query when a thinking block is missing `signature`.

Possible acceptable behaviors:

1. If `signature` is required only for Anthropic native thinking blocks, **document** that non-Anthropic-compatible backends must disable thinking.
2. Provide a **clearer error message** explaining that the backend emitted an invalid/incompatible thinking block.
3. Allow `ClaudeAgentOptions(thinking={"type": "disabled"})` to reliably prevent such blocks from being emitted/parsed.
4. Optionally parse unsigned thinking blocks as a **best-effort compatibility mode**, or expose a config flag for strict vs permissive parsing.

## Related

- #339 — closed not planned, but reproducible on the latest version (0.1.79).
- #473 — similar `KeyError: signature` from the CLI side.
- #786 — proposes `block.get("signature", "")`; would silence the crash but produce empty-signature blocks that may still fail on multi-turn round-trips.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.