Skip to content

Validate Anthropic extended-thinking request invariants on tool-loop continuation #253

Description

@jpr5

Problem

aimock currently accepts an Anthropic messages.stream request that continues a tool-use loop with extended thinking enabled but omits the original thinking block (and its signature) as the first content block of the prior assistant turn.

The real Anthropic API rejects this with a 400 error (e.g. "expected thinking as the first block / signature required"), and it additionally requires redacted_thinking blocks to be replayed back in subsequent turns.

Because aimock simply replays the next fixture without validating the request shape, a backend that drops, last-only-keeps, or otherwise omits thinking blocks passes green in replay but 400s against the real Anthropic API.

Impact

This masked real bugs in the CopilotKit showcase claude-sdk-python reasoning agents, including:

  • thinking blocks dropped from conversation history on tool-loop continuation
  • only the last thinking block retained instead of all of them
  • redacted_thinking blocks not replayed back

All of these passed under aimock replay while being invalid against the real API.

Ask

When extended thinking is enabled on an Anthropic messages.stream request, aimock should validate the request invariants on the prior assistant turn:

  • the thinking block is present as the first content block
  • the thinking block's signature is present
  • any redacted_thinking blocks are preserved/replayed

When these invariants are violated, aimock should surface a replay error (go red) instead of silently replaying the next fixture — so this class of bug is caught in the harness rather than blowing up against the real provider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions