Skip to content

🧵 fix: Strip Unsupported Claude Assistant Prefill#186

Merged
danny-avila merged 3 commits into
mainfrom
danny-avila/fix-claude-prefill
May 21, 2026
Merged

🧵 fix: Strip Unsupported Claude Assistant Prefill#186
danny-avila merged 3 commits into
mainfrom
danny-avila/fix-claude-prefill

Conversation

@danny-avila
Copy link
Copy Markdown
Owner

Summary

I fixed Claude 4.6+ Anthropic dispatch so requests ending with assistant messages no longer fail on models that reject assistant prefill. This addresses the root cause behind danny-avila/LibreChat#13196.

  • Detect Claude Opus, Sonnet, and Haiku 4.6+ model IDs across direct and provider-shaped names.
  • Strip trailing assistant-role messages immediately before Anthropic streaming and non-streaming dispatch for affected models.
  • Preserve existing assistant-prefill behavior for Claude 4.5 and older models.
  • Add regression coverage for affected and unaffected Claude model IDs.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

I validated the fix with targeted unit coverage, package build, and live Vertex AI checks against claude-sonnet-4-6.

Test Configuration:

  • Project: regulated-dev-441020
  • Region: us-east5
  • Model: claude-sonnet-4-6
  • Auth: user ADC via gcloud auth application-default login

Commands and checks:

  • npm test -- --runTestsByPath src/llm/anthropic/llm.spec.ts --runInBand --modulePathIgnorePatterns='<rootDir>/.claude' -t 'Claude assistant prefill compatibility'
  • npm run build
  • git diff --check
  • Live Vertex raw SDK: user-final message succeeded, final assistant prefill failed with This model does not support assistant message prefill. The conversation must end with a user message.
  • Live Vertex non-streaming: base ChatAnthropic failed with the same 400, patched CustomAnthropic succeeded with the same final AIMessage input.
  • Live Vertex streaming: base ChatAnthropic failed with the same 400, patched CustomAnthropic succeeded with the same final AIMessage input.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective
  • Local unit tests pass with my changes

@danny-avila danny-avila marked this pull request as ready for review May 21, 2026 17:20
@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de9147b9cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/llm/anthropic/utils/message_inputs.ts Outdated
@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0f7f42c83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/llm/anthropic/utils/message_inputs.ts Outdated
@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila merged commit 3827a85 into main May 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant