Skip to content

fix: charge local input tokens when Gemini returns empty response - #2848

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/gemini-empty-responses-local-usage
Feb 5, 2026
Merged

fix: charge local input tokens when Gemini returns empty response#2848
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/gemini-empty-responses-local-usage

Conversation

@seefs001

@seefs001 seefs001 commented Feb 5, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved response tracking and usage calculation accuracy when handling streaming responses.
  • Refactor

    • Enhanced concurrency management for better resource utilization and reliability.

@coderabbitai

coderabbitai Bot commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

These changes introduce explicit response counting via a new ReceivedResponseCount field in RelayInfo to track received responses, replacing text-length-based detection. The code integrates goroutine pooling (gopool) for concurrent work management in stream scanning while maintaining existing synchronization semantics.

Changes

Cohort / File(s) Summary
Response Tracking Infrastructure
relay/common/relay_info.go, relay/channel/gemini/relay-gemini.go
Added ReceivedResponseCount field to RelayInfo struct; updated usage recalculation condition to check info.ReceivedResponseCount > 0 instead of len(responseText).
Goroutine Pooling & Response Counting
relay/helper/stream_scanner.go
Replaced direct goroutine launches with gopool.Go calls in three locations (done channel closure, ping data write, data handling); added ReceivedResponseCount increment when non-[DONE] data is processed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 A counter hops through every stream,
Each response now tracked with gopool's gleam,
No more text lengths clouding the way,
Just count the responses, hip-hip-hooray!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: addressing how local input tokens are charged when Gemini returns empty responses, which aligns with the logic changes in relay-gemini.go and the new ReceivedResponseCount tracking.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Calcium-Ion
Calcium-Ion merged commit 7b1451c into QuantumNous:main Feb 5, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…sponses-local-usage

fix: charge local input tokens when Gemini returns empty response
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