Skip to content

fix: skip reasoning parts from different models to prevent Anthropic signature errors#17

Open
lgarceau768 wants to merge 3 commits intoflexfrom
fix/model-change-mid-convo
Open

fix: skip reasoning parts from different models to prevent Anthropic signature errors#17
lgarceau768 wants to merge 3 commits intoflexfrom
fix/model-change-mid-convo

Conversation

@lgarceau768
Copy link
Copy Markdown
Collaborator

Summary

  • When switching models mid-conversation, Anthropic reasoning (thinking) blocks carry a cryptographic signature bound to the model that generated them
  • Replaying those parts to a different model causes a 400 error: thinking.signature: Field required

Changes

  • message-v2.ts: Skip reasoning parts entirely when the historical message came from a different model (differentModel flag already computed upstream)
  • transform.ts: Defence-in-depth guard that strips unsigned reasoning parts before they reach the Anthropic/Bedrock SDK, preventing the 400 even if message-v2 reconstruction is bypassed

Testing

Reproduce by:

  1. Start a conversation with an Anthropic extended thinking model (e.g. claude-sonnet-4-5 with thinking enabled)
  2. Switch to any other model mid-conversation
  3. Continue the conversation — previously this would 400; now it recovers cleanly

…signature errors

When switching models mid-conversation, Anthropic reasoning (thinking) blocks
carry a cryptographic signature bound to the model that generated them. Replaying
those parts to a different model causes a 400 error: 'thinking.signature: Field required'.

- message-v2.ts: skip reasoning parts entirely when the historical message came
  from a different model (differentModel flag already computed upstream)
- transform.ts: defence-in-depth guard that strips unsigned reasoning parts
  before they reach the Anthropic/Bedrock SDK, preventing the 400 even if
  message-v2 reconstruction is bypassed
@github-actions
Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

…text parts

DeepSeek R1 (deepseek-reasoner) does not honour the tools parameter on the
standard api.deepseek.com endpoint despite models.dev reporting tool_call: true.
When tools are sent, R1 ignores them and writes the invocation as markdown text,
causing tool calls to appear as plain text instead of being executed.

- llm.ts: disable canTool for deepseek-reasoner so tools are never sent to it,
  avoiding the markdown-text fallback entirely
- processor.ts: strip <think>...</think> blocks from text parts for reasoning
  models that emit chain-of-thought inline rather than as dedicated reasoning
  events, preventing raw thinking tokens from appearing in the UI
…field

The previous guard checked providerID === 'deepseek' and api.id containing
'reasoner', which only matched the direct DeepSeek API. Bedrock-hosted R1 has
providerID 'amazon-bedrock' and api.id 'deepseek.r1-v1:0' — neither condition
fired, so tools were still being sent to Bedrock R1.

Broaden the guard to use the provider-agnostic family field ('deepseek-thinking')
which is set for all DeepSeek reasoning variants regardless of hosting provider.
Fall back to api.id substring matching ('deepseek.r1') as an additional safety net
for cases where family may be absent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant