Skip to content

SWF(bug): reject unknown Anthropic message roles - #80

Merged
maplepaladin73 merged 2 commits into
mainfrom
devin/1795398586-anthropic-message-role
Nov 23, 2026
Merged

maplepaladin73 merged 2 commits into
mainfrom
devin/1795398586-anthropic-message-role

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Anthropic Messages requests with a messages[].role other than the strings user or assistant (e.g. system, or serde's object form {"user":null}) now fail with HTTP 400 invalid_request_error instead of silently becoming user turns.

Root cause: AnthropicMessage.role was a free String, and to_ir.rs mapped "assistant" to assistant and everything else to user. The field is now a closed AnthropicRole that 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. Valid user/assistant requests 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_role proves the wire request is rejected.
  • anthropic::tests::convert::rejects_object_message_role proves object-shaped roles are rejected.
  • anthropic::handlers::tests::messages_rejects_unknown_role_with_bad_request proves POST /v1/messages returns 400 invalid_request_error.

Failing on main with only the deserialization test added (unknown role deserialized successfully):

test anthropic::tests::convert::rejects_unknown_message_role ... FAILED

The object-role review follow-up also failed before its fix ({"user": null} deserialized as role: User):

test anthropic::tests::convert::rejects_object_message_role ... FAILED

Passing with this change, plus the full spark test binary:

test anthropic::tests::convert::rejects_unknown_message_role ... ok
test anthropic::tests::convert::rejects_object_message_role ... ok
test anthropic::handlers::tests::messages_rejects_unknown_role_with_bad_request ... ok
test result: ok. 3259 passed; 0 failed; 14 ignored; 0 measured; 0 filtered out; finished in 20.13s

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_request

Checks: cargo fmt --all -- --check, ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests, bash scripts/check-license-headers.sh, and typos all exit 0.

Notes for reviewers

  • Untested: live HTTP request against a running server, Docker, and GPU inference. The 400 path is covered through the Axum handler with a published fixture model; production uses the same handler and existing deserialization-error mapping.

CLA


Software Factory opened this PR for Robert
Implemented in session Reject invalid Anthropic message roles
Review with Devin · Open in Devin Desktop


Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@maplepaladin73
maplepaladin73 merged commit 1094807 into main Nov 23, 2026
1 check 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