Commit 863fc2b
committed
fix(gemini): Robust error handling for empty streaming responses
PROBLEMA (Screenshot 2025-11-24 20-07-30):
❌ Error: 'response.text' quick accessor requires valid Part
❌ finish_reason=1 (STOP) but no text returned
❌ Frame budget exceeded: 6255.3ms
CAUSA-RAIZ:
- Gemini retorna chunks sem .text (blocked by safety filters)
- Código tentava acessar chunk.text cegamente
- AttributeError causava crash do streaming
SOLUÇÃO:
1. Verificar hasattr(chunk, 'text') ANTES de acessar
2. Fallback para chunk.parts se .text não existir
3. Try-catch individual por chunk (não quebra todo stream)
4. Log de finish_reason quando detectado
5. Mensagem clara se zero chunks recebidos
Mudanças:
• Wrapped chunk.text access em try-except
• Added hasattr checks
• Fallback: chunk.parts[].text
• Counter: chunks_received
• Fallback message se nenhum chunk válido
Benefícios:
✅ Streaming não crasha mais em respostas vazias
✅ Logs claros de por que falhou
✅ Mensagem informativa ao usuário
✅ Graceful degradation
Constitutional Compliance:
✅ P1 (Completeness): Error handling completo
✅ P3 (Critical Skepticism): Não assume chunk.text existe
✅ P6 (Efficiency): Previne crash = economiza tokens
Issue: #GEMINI-STREAMING-EMPTY-RESPONSE1 parent 9faafa8 commit 863fc2b
1 file changed
+24
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
223 | 224 | | |
224 | | - | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
226 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
227 | 249 | | |
228 | 250 | | |
229 | 251 | | |
| |||
0 commit comments