Skip to content

[Bug]: Anthropic rejects request when last assistant message has a trailing thinking block #3071

@Alexx999

Description

@Alexx999

Bug Description

On a subsequent turn of a long-running conversation, Forge sends a request to https://api.anthropic.com/v1/messages that Anthropic rejects with 400 Bad Request:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "messages.17: The final block in an assistant message cannot be `thinking`."
  },
}

Once this state is reached the conversation is dead — every retry hits the same 400 because the invalid message is now persisted in the context DB and replayed on every request.

Steps to Reproduce

Sadly, this depends on bad luck to reproduce, you need execute_chat_turn to return a ChatCompletionMessageFull with:

  • content = ""
  • tool_calls.is_empty() == true
  • reasoning_details = Some([{ text: Some, signature: Some }])

Which persist an invalid message into the conversation context

Expected Behavior

The request to Anthropic must never have an assistant message whose final block is thinking.

Actual Behavior

The reasoning-only message is serialized as [Thinking { … }].
Anthropic rejects the full request with a 400, citing messages.N: The final block in an assistant message cannot be 'thinking'.
Because the bad message is already persisted in the conversation DB, every retry reproduces the same 400.

Forge Version

2.11.3

Operating System & Version

Win11

AI Provider

Anthropic

Model

opus-4-7

Installation Method

Other

Configuration

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions