Skip to content

fix(chat): forward and log streaming errors with details - #521

Merged
steebchen merged 6 commits into
mainfrom
cursor/forward-and-log-streaming-errors-with-details-841d
Jul 28, 2025
Merged

steebchen merged 6 commits into
mainfrom
cursor/forward-and-log-streaming-errors-with-details-841d

Conversation

@steebchen

@steebchen steebchen commented Jul 25, 2025 •

Copy link
Copy Markdown
Member

Forward streaming errors to clients via SSE and log them with detailed error information.

Previously, streaming errors were only logged to the console, making them invisible to clients and difficult to track in logs. This change ensures errors are properly communicated to the client and recorded for debugging and monitoring.


Open in Web • Open in Cursor

Learn more about Background Agents

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for streaming responses in chat, ensuring users are notified if a streaming error occurs during chat completions.
    • Enhanced test validations to confirm absence of error details in successful chat requests.

- Add streaming error tracking variable to monitor errors during stream processing
- Forward streaming errors to clients via SSE with detailed error information
- Mark logs as errored when streaming errors occur with comprehensive error details
- Include error status code (500), status text, and actual error message in logs
- Ensure graceful error handling even if SSE forwarding fails
- Maintain consistent error format across the system
@coderabbitai

coderabbitai Bot commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The streaming handler in the chat completions endpoint was updated to explicitly track and report streaming errors. A new variable captures streaming errors, sends structured SSE error events to the client, and logs error details. The control flow for cancellation and normal completion remains unchanged. Additionally, an end-to-end test was enhanced to assert that no error details are present in successful logs.

Changes

Cohort / File(s) Change Summary
Chat streaming handler
apps/gateway/src/chat/chat.ts
Enhanced streaming handler to track/report streaming errors, send SSE error events, and log detailed error info.
End-to-end test validation
apps/gateway/src/api.e2e.ts
Added assertion to validate that errorDetails is null in logs for successful requests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2dba822 and 0b0669e.

📒 Files selected for processing (2)
  • apps/gateway/src/api.e2e.ts (1 hunks)
  • apps/gateway/src/chat/chat.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/gateway/src/chat/chat.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Use localStorage instead of cookies for client-side data persistence

Files:

  • apps/gateway/src/api.e2e.ts
**/*.{js,ts}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.{js,ts}: Use drizzle with the latest object syntax for database operations
For read queries, always use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/api.e2e.ts
{apps/api,apps/gateway,packages/db}/**/*.ts

📄 CodeRabbit Inference Engine (CLAUDE.md)

{apps/api,apps/gateway,packages/db}/**/*.ts: Use Drizzle ORM with latest object syntax for database operations
For reads, use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/api.e2e.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use as any or : any in TypeScript files.

Files:

  • apps/gateway/src/api.e2e.ts
🧬 Code Graph Analysis (1)
apps/gateway/src/api.e2e.ts (1)
packages/db/src/schema.ts (1)
  • log (240-297)
⏰ 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). (3)
  • GitHub Check: build / run
  • GitHub Check: e2e / run
  • GitHub Check: autofix
🔇 Additional comments (1)
apps/gateway/src/api.e2e.ts (1)

248-248: LGTM! Correctly validates successful request behavior.

The assertion ensures that errorDetails is null for successful requests, which aligns perfectly with the PR objective of improving streaming error handling. This validates that the error tracking functionality only populates errorDetails when actual errors occur, not for successful completions.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/forward-and-log-streaming-errors-with-details-841d

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@steebchen steebchen changed the title Forward and log streaming errors with details fix(chat): forward and log streaming errors with details Jul 25, 2025
@steebchen
steebchen marked this pull request as ready for review July 25, 2025 16:36
@steebchen
steebchen marked this pull request as draft July 27, 2025 20:28
@steebchen
steebchen marked this pull request as ready for review July 27, 2025 20:28
Added proper assignment of parsing errors to `streamingError` in chat
logic. This helps in identifying and debugging JSON parsing issues in
streaming responses.
@steebchen
steebchen merged commit d8e08f0 into main Jul 28, 2025
@steebchen
steebchen deleted the cursor/forward-and-log-streaming-errors-with-details-841d branch July 28, 2025 14:49
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