fix(chat): guard empty tokens - #1263
Conversation
Add checks for calculatedReasoningTokens alongside calculatedCompletionTokens in conditions that determine empty or no-result completions. This prevents false negatives when reasoning tokens are non-zero, improving accuracy of content filtering and streaming logic. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
WalkthroughThe change modifies empty-response detection in the chat service by requiring reasoning tokens to be absent before treating a response as empty. The new conditional requirement is applied to two finish-condition checks in both streaming and non-streaming paths, affecting downstream logging and error handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (6)**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
apps/{gateway,api}/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
apps/{gateway,api}/src/**/*.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
🔇 Additional comments (1)
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. Comment |
Summary
Changes
Core Functionality
apps/gateway/src/chat/chat.ts(inchat.openapi) to also require(!calculatedReasoningTokens || calculatedReasoningTokens === 0)when determining end-of-stream conditions.Rationale
Tests
calculatedReasoningTokens.Test plan
calculatedCompletionTokensandcalculatedReasoningTokens.🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://www.terragonlabs.com/task/127559f9-e3d5-4176-a52d-9a84e206a6a0
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.