Repository navigation
SWF(bug): reject unknown Anthropic message roles - #80
Merged
Merged
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Anthropic Messages requests with a
messages[].roleother than the stringsuserorassistant(e.g.system, or serde's object form{"user":null}) now fail with HTTP 400invalid_request_errorinstead of silently becoming user turns.Root cause:
AnthropicMessage.rolewas a freeString, andto_ir.rsmapped"assistant"to assistant and everything else to user. The field is now a closedAnthropicRolethat deserializes only from those two strings, so invalid roles fail during request deserialization — which both Messages handlers already turn into a 400 — and lowering matches the variants exhaustively. Validuser/assistantrequests are unchanged, and the obsolete test that asserted the collapse is removed.Test plan
Regression tests written and run before/with the fix:
anthropic::tests::convert::rejects_unknown_message_roleproves the wire request is rejected.anthropic::tests::convert::rejects_object_message_roleproves object-shaped roles are rejected.anthropic::handlers::tests::messages_rejects_unknown_role_with_bad_requestprovesPOST /v1/messagesreturns 400invalid_request_error.Failing on main with only the deserialization test added (unknown role deserialized successfully):
The object-role review follow-up also failed before its fix (
{"user": null}deserialized asrole: User):Passing with this change, plus the full spark test binary:
Try it (GPU-free, after
bash scripts/ci_gpu_stubs.sh):ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark messages_rejects_unknown_role_with_bad_requestChecks:
cargo fmt --all -- --check,ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests,bash scripts/check-license-headers.sh, andtyposall exit 0.Notes for reviewers
CLA
Implemented in session Reject invalid Anthropic message roles
Review with Devin · Open in Devin Desktop