fix: map stream peek errors upstream - #1987
Conversation
WalkthroughMade the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 adjusts how the gateway classifies immediate streaming peek/read failures so they’re treated as upstream/provider failures (rather than the synthetic stream finish reason), and adds a regression test to lock in the behavior.
Changes:
- Reclassify immediate streaming read/peek exceptions as
upstream_errorwith a synthetic502while preservingstream_read_erroras the error code. - Export
inspectImmediateStreamingProviderErrorfor direct unit testing. - Add a Vitest regression test covering a broken streaming body during the immediate inspection phase.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/gateway/src/chat/chat.ts | Updates immediate streaming inspection error classification and exports the helper for testing. |
| apps/gateway/src/chat/inspect-immediate-streaming-provider-error.spec.ts | Adds regression coverage for immediate stream read failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| async function inspectImmediateStreamingProviderError( | ||
| export async function inspectImmediateStreamingProviderError( |
There was a problem hiding this comment.
inspectImmediateStreamingProviderError is now exported from chat.ts, which makes unit tests import the entire chat route module (large dependency graph + side effects like route/schema initialization). Consider moving this helper into apps/gateway/src/chat/tools/ (and testing that module directly), and keep chat.ts exporting only the route handler to reduce test overhead and coupling.
| export async function inspectImmediateStreamingProviderError( | |
| async function inspectImmediateStreamingProviderError( |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/gateway/src/chat/chat.ts (1)
592-592: Consider extracting this helper instead of exporting fromchat.tsLine 592 exports a route-internal helper mainly for test access. Prefer moving it to a small utility module and importing it from both
chat.tsand the spec to keep this file’s public surface tighter and tests less coupled to route setup.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/gateway/src/chat/chat.ts` at line 592, The helper inspectImmediateStreamingProviderError is being exported from chat.ts solely for tests; extract it into a small utility module (e.g., create a new module exporting inspectImmediateStreamingProviderError) and update chat.ts to import and use that function internally instead of exporting it; then update the test/spec to import the helper from the new utility module; ensure the original function name inspectImmediateStreamingProviderError is preserved and exported only from the new util to keep chat.ts’s public surface minimal.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/gateway/src/chat/chat.ts`:
- Line 592: The helper inspectImmediateStreamingProviderError is being exported
from chat.ts solely for tests; extract it into a small utility module (e.g.,
create a new module exporting inspectImmediateStreamingProviderError) and update
chat.ts to import and use that function internally instead of exporting it; then
update the test/spec to import the helper from the new utility module; ensure
the original function name inspectImmediateStreamingProviderError is preserved
and exported only from the new util to keep chat.ts’s public surface minimal.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b67942cf-f2ea-46bb-b766-5155eadd790c
📒 Files selected for processing (2)
apps/gateway/src/chat/chat.tsapps/gateway/src/chat/inspect-immediate-streaming-provider-error.spec.ts
Summary
streamfinish reasonstream_read_errorcode while mapping the loggable finish reason toupstream_errorVerification
pnpm exec vitest run apps/gateway/src/chat/inspect-immediate-streaming-provider-error.spec.ts --no-file-parallelismpnpm buildpnpm test:unit(fails on unrelated existing suites:apps/api/src/routes/beacon.spec.ts,apps/gateway/src/videos/videos.spec.ts)Summary by CodeRabbit
Bug Fixes
Tests