Skip to content

fix(gateway): handle network_error finish reason - #1588

Merged
steebchen merged 1 commit into
mainfrom
fix-network-error-finish
Feb 4, 2026
Merged

steebchen merged 1 commit into
mainfrom
fix-network-error-finish

Conversation

@steebchen

@steebchen steebchen commented Feb 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Map network_error finish reason to UPSTREAM_ERROR to prevent "Unknown finish reason encountered" errors from providers like zai

Test plan

  • Build passes
  • Verify logs no longer show "Unknown finish reason encountered" for network_error

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for network-related failures to ensure consistent classification and reporting of network errors across the system.

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>
Copilot AI review requested due to automatic review settings February 4, 2026 11:53
@steebchen
steebchen enabled auto-merge February 4, 2026 11:53
@coderabbitai

coderabbitai Bot commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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

Cohort / File(s) Summary
Error Handling Mapping
apps/gateway/src/lib/logs.ts
Added new case for "network_error" finishReason, mapping it to UnifiedFinishReason.UPSTREAM_ERROR.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

🚥 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 clearly and concisely describes the main change: adding handling for the network_error finish reason in the gateway module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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
  • Commit unit tests in branch fix-network-error-finish

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_error finish reason to UPSTREAM_ERROR in the getUnifiedFinishReason function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +52
if (finishReason === "network_error") {
return UnifiedFinishReason.UPSTREAM_ERROR;
}

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@steebchen
steebchen added this pull request to the merge queue Feb 4, 2026
Merged via the queue into main with commit 7222cb9 Feb 4, 2026
19 checks passed
@steebchen
steebchen deleted the fix-network-error-finish branch February 4, 2026 12:07
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