Skip to content

adds nil bodystream check#1310

Merged
akshaydeo merged 1 commit intov1.4.0from
01-12-adds_nil_bodystream_check
Jan 12, 2026
Merged

adds nil bodystream check#1310
akshaydeo merged 1 commit intov1.4.0from
01-12-adds_nil_bodystream_check

Conversation

@akshaydeo
Copy link
Copy Markdown
Contributor

@akshaydeo akshaydeo commented Jan 12, 2026

Summary

Added error handling for empty response streams in the Gemini provider to prevent potential nil pointer dereferences.

Changes

  • Added a check to verify if the response body stream is nil before attempting to scan it
  • If the stream is nil, the code now creates a Bifrost operation error, sets the stream end indicator, and sends the error through the response channel
  • This prevents the application from crashing when Gemini returns an empty response

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

Test the Gemini provider with a scenario that would result in an empty response:

# Core/Transports
go version
go test ./core/providers/gemini/...

# Create a test that mocks an empty response from Gemini API

Breaking changes

  • Yes
  • No

Related issues

Fixes potential nil pointer dereference when Gemini returns empty responses

Security considerations

Prevents potential application crashes that could be triggered by empty responses from the Gemini API.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 12, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling for empty streaming responses to ensure proper error reporting and prevent processing interruptions.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Added nil checks for empty streaming response bodies in Gemini's chat completion and response streaming handlers. When a streaming response body is empty, the handlers now create an operation error, mark stream completion in context, transmit the error through the post-hook channel, and return early.

Changes

Cohort / File(s) Summary
Gemini Streaming Error Handling
core/providers/gemini/gemini.go
Added guard clauses in HandleGeminiChatCompletionStream and HandleGeminiResponsesStream to detect empty streaming response bodies; on detection, creates a Bifrost operation error, sets stream end indicator in context, forwards error to post-hook channel, and returns early (+11 lines)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A stream runs dry, now caught in time,
The rabbit checks what's mine or thine—
If empty flows shall try to play,
We catch the error right away! 🐰✨

✨ 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 01-12-adds_nil_bodystream_check

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 613dfe3 and c1e5ff7.

📒 Files selected for processing (1)
  • core/providers/gemini/gemini.go

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

Copy link
Copy Markdown
Contributor Author

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

@akshaydeo akshaydeo marked this pull request as ready for review January 12, 2026 09:17
@akshaydeo akshaydeo merged commit 22c5159 into v1.4.0 Jan 12, 2026
3 of 4 checks passed
@akshaydeo akshaydeo deleted the 01-12-adds_nil_bodystream_check branch January 12, 2026 09:17
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