Skip to content

fix(bedrock): map response roles explicitly - #1138

Merged
mikehostetler merged 1 commit into
mainfrom
sec/bedrock-role-atom
Oct 22, 2026
Merged

mikehostetler merged 1 commit into
mainfrom
sec/bedrock-role-atom

Conversation

@neilberkman

@neilberkman neilberkman commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

The Bedrock OpenAI-family decoder passed provider-supplied role strings to String.to_existing_atom/1. A string without an existing atom raised ArgumentError in the caller's process.

Replace that conversion with explicit mappings for assistant, user, system, and tool. Unknown values fall back to :assistant, matching the default OpenAI-compatible response builder's response role. The default decoder does not use String.to_existing_atom/1 for response roles.

Extend the existing Bedrock OpenAI unit tests to cover all four supported roles, an unknown string, an unsupported string that already has a VM atom (error), and nil. The unknown-string regression failed against the original decoder and passes with the fix.

Audited conversions left unchanged:

  • amazon_bedrock/cohere.ex: converts provider-response field names, but rescues ArgumentError and preserves unknown names as strings.
  • anthropic.ex: converts caller-supplied tool schema field names during request encoding, and rescues ArgumentError.
  • lmstudio.ex: converts caller-supplied reasoning_effort options after an allowlist check; the corresponding atoms are defined in the module.

Verification:

  • mix format: passed.
  • mix compile --warnings-as-errors: passed.
  • mix credo --strict: passed; 625 source files checked, no issues.
  • mix test test/req_llm/providers/amazon_bedrock/openai_test.exs: 21 passed.
  • mix test: 5,334/5,336 passed, 11 skipped, 240 excluded; two StreamServer synchronization timeouts in metadata_test.exs:147 and error_handling_test.exs:51 (seed 434574).
  • mix test --failed: both previously failing tests passed.
  • ERL_FLAGS='+S 4:4' mix test --max-cases 4: 5,336 passed, 11 skipped, 240 excluded.

The initial timeout cause was not confirmed. No streaming code was changed. Fixture recording was disabled and no fixtures were modified.

🤖 Generated with Codex and Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@mikehostetler
mikehostetler merged commit 38d1d81 into main Oct 22, 2026
21 checks passed
@mikehostetler
mikehostetler deleted the sec/bedrock-role-atom branch October 22, 2026 19:45
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.

2 participants