Skip to content

Conversation

@Pratham-Mishra04
Copy link
Collaborator

Summary

Fixed critical input validation logic in Bifrost's speech, transcription, and embedding requests by correcting conditional checks and updating pointer types in request structures.

Changes

  • Fixed incorrect input validation conditions in SpeechRequest, SpeechStreamRequest, TranscriptionRequest, and TranscriptionStreamRequest methods by changing req.Input != nil || req.Input.X == "" to req.Input == nil || req.Input.X == ""
  • Updated embedding request validation in Gemini and Vertex providers to properly check for nil input
  • Changed input fields in request structs from value types to pointer types in test scenarios
  • Fixed content block type mapping in ToResponsesMessages() to ensure proper content type assignment
  • Removed unused JSON parsing code in Bedrock provider's processEventBuffer function

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (Next.js)
  • Docs

How to test

Run the test suite to verify the fixed input validation logic:

# Core/Transports
go version
go test ./...

Specifically test speech, transcription, and embedding requests to ensure proper input validation.

Breaking changes

  • Yes
  • No

Security considerations

This PR fixes input validation logic that could have led to unexpected behavior or potential crashes when processing requests with missing or invalid inputs.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@Pratham-Mishra04 Pratham-Mishra04 marked this pull request as ready for review October 6, 2025 09:32
Copy link
Collaborator Author

Pratham-Mishra04 commented Oct 6, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@akshaydeo akshaydeo merged commit 35d0e86 into v1.3.0 Oct 6, 2025
2 of 3 checks passed
@akshaydeo akshaydeo deleted the 10-06-fix_minor_fixes branch October 6, 2025 09:33
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Prevented rare crashes by safely handling missing inputs across speech, transcription, and embedding requests.
    • Correctly maps content blocks by role and type (text, image, file, audio) for more reliable message rendering.
    • Improved stability by removing fragile incremental JSON parsing in a provider.
  • Refactor
    • Internal validations streamlined for safer nil checks without changing expected outcomes.
  • Style
    • Minor formatting cleanup for readability.

No changes to public APIs beyond safer input handling; existing functionality remains compatible.

Walkthrough

Updated nil-checks and pointer usage to avoid nil dereferences in request validators and embedding builders; removed local JSON parsing for a Bedrock tool input delta; remapped message content block types based on role/type; updated tests and fixtures to use pointer-typed inputs/configs.

Changes

Cohort / File(s) Summary
Core request validation nil-guards
core/bifrost.go
Inverted/expanded nil-checks for Input in speech/transcription (including streaming) validators to return errors when Input is nil or empty and avoid dereferencing nil.
Bedrock tool input handling
core/providers/bedrock.go
Removed local JSON unmarshal and related error fallback for toolUseDelta.Input; tool call creation now proceeds without pre-parsing.
Message content block remapping
core/schemas/mux.go
Added dynamic mapping of content block types by block.Type and role (assistant vs non-assistant) when converting to ResponsesMessage; minor formatting fix.
Embedding request nil-guards
core/schemas/providers/gemini/embedding.go, core/schemas/providers/vertex/embedding.go
Added checks for bifrostReq.Input == nil before accessing nested fields; unchanged early-return behavior when input absent.
Tests & scenarios: pointer-based inputs/configs
tests/core-providers/custom_test.go, tests/core-providers/scenarios/embedding.go, tests/core-providers/scenarios/speech_synthesis.go, tests/core-providers/scenarios/speech_synthesis_stream.go, tests/core-providers/scenarios/transcription.go, tests/core-providers/scenarios/transcription_stream.go, tests/core-providers/scenarios/text_completion.go, tests/core-providers/scenarios/utils.go, tests/core-providers/scenarios/test_retry_framework.go
Converted many value-typed Input, VoiceConfig, and an Error field usages to pointer types; updated test constructors and helpers to allocate and pass pointers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Mux as Mux Converter
  participant Resp as ResponsesMessage

  Caller->>Mux: Convert(message with blocks, role)
  loop for each block
    alt block.Type == Text
      alt role == assistant
        Mux->>Resp: map -> ResponsesOutputMessageContentTypeText
      else
        Mux->>Resp: map -> ResponsesInputMessageContentBlockTypeText
      end
    else block.Type == Image
      Mux->>Resp: map -> ResponsesInputMessageContentBlockTypeImage
    else block.Type == File
      Mux->>Resp: map -> ResponsesInputMessageContentBlockTypeFile
    else block.Type == InputAudio
      Mux->>Resp: map -> ResponsesInputMessageContentBlockTypeAudio
    else
      Mux->>Resp: keep original block.Type
    end
  end
  note right of Mux: Block type determined from content and role before constructing ResponsesMessage
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit taps keys with a gentle thrum,
Nil checks flipped—no crashes to come.
Blocks find their roles, text hops in line,
Pointers now nest, behaving just fine.
Bedrock sheds parsing; the code feels light—🥕🐇

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 10-06-fix_minor_fixes

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d40cfce and 7c76172.

📒 Files selected for processing (14)
  • core/bifrost.go (4 hunks)
  • core/providers/bedrock.go (0 hunks)
  • core/schemas/mux.go (2 hunks)
  • core/schemas/providers/gemini/embedding.go (1 hunks)
  • core/schemas/providers/vertex/embedding.go (1 hunks)
  • tests/core-providers/custom_test.go (1 hunks)
  • tests/core-providers/scenarios/embedding.go (1 hunks)
  • tests/core-providers/scenarios/speech_synthesis.go (3 hunks)
  • tests/core-providers/scenarios/speech_synthesis_stream.go (3 hunks)
  • tests/core-providers/scenarios/test_retry_framework.go (1 hunks)
  • tests/core-providers/scenarios/text_completion.go (1 hunks)
  • tests/core-providers/scenarios/transcription.go (6 hunks)
  • tests/core-providers/scenarios/transcription_stream.go (5 hunks)
  • tests/core-providers/scenarios/utils.go (3 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

3 participants