fix(gateway): handle network_error finish reason - #1588
Conversation
Map network_error finish reason to UPSTREAM_ERROR to prevent "Unknown finish reason encountered" errors from providers like zai. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughAdds handling for a new "network_error" finish reason value in the getUnifiedFinishReason function, mapping it to UnifiedFinishReason.UPSTREAM_ERROR. This provides consistent categorization of network-related errors alongside existing upstream error handling. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Pull request overview
This PR adds handling for the network_error finish reason from providers like zai by mapping it to the unified UPSTREAM_ERROR finish reason, preventing "Unknown finish reason encountered" errors in logs.
Changes:
- Added mapping for
network_errorfinish reason toUPSTREAM_ERRORin thegetUnifiedFinishReasonfunction
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (finishReason === "network_error") { | ||
| return UnifiedFinishReason.UPSTREAM_ERROR; | ||
| } |
There was a problem hiding this comment.
The new network_error finish reason mapping should have test coverage. Looking at the test file (logs.spec.ts), similar error finish reasons like upstream_error, gateway_error, and client_error all have test coverage in the "handles special cases" test block. A test case should be added for network_error to maintain consistency with the existing test pattern.
Summary
network_errorfinish reason toUPSTREAM_ERRORto prevent "Unknown finish reason encountered" errors from providers like zaiTest plan
network_error🤖 Generated with Claude Code
Summary by CodeRabbit