Skip to content

fix peer chat streaming#136

Merged
Rajat-Ahuja1997 merged 2 commits into
mainfrom
rajat/fix-peer-chat-streaming
Jun 20, 2025
Merged

fix peer chat streaming#136
Rajat-Ahuja1997 merged 2 commits into
mainfrom
rajat/fix-peer-chat-streaming

Conversation

@Rajat-Ahuja1997

@Rajat-Ahuja1997 Rajat-Ahuja1997 commented Jun 20, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for streaming chat responses, allowing real-time delivery of messages when enabled.
  • Bug Fixes

    • Improved error handling for streaming chat responses, ensuring users receive appropriate error messages in case of failures.

@coderabbitai

coderabbitai Bot commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The chat endpoint in the peers router was updated to support streaming responses. Now, based on the options.stream parameter, it either returns a traditional response or streams text chunks asynchronously using an async generator and FastAPI's StreamingResponse, with error handling for streaming failures.

Changes

File(s) Change Summary
src/routers/peers.py Modified the chat endpoint to add support for streaming responses based on an options flag.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API (chat endpoint)
    participant Agent
    participant StreamManager

    Client->>API (chat endpoint): POST chat request (with options.stream)
    alt options.stream == False
        API->>Agent: agent.chat(...)
        Agent-->>API: response
        API-->>Client: response
    else options.stream == True
        API->>Agent: agent.chat(..., stream=True)
        Agent-->>API: AsyncMessageStreamManager
        loop for each chunk
            API->>StreamManager: text_stream
            StreamManager-->>API: text chunk
            API-->>Client: text chunk (streamed)
        end
        alt error occurs
            API->>API: log error
            API-->>Client: HTTP 500 error
        end
    end
Loading

Poem

A hop, a skip, a streaming chat,
Now words arrive chunk by chunk—imagine that!
If you want it all at once, just say so,
But with streaming on, the messages flow.
Rabbits love to nibble and stream,
This update’s as smooth as a dream! 🐇✨
"""


📜 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 e37b60e and fd1f1bf.

📒 Files selected for processing (1)
  • src/routers/peers.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/routers/peers.py
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@Rajat-Ahuja1997 Rajat-Ahuja1997 marked this pull request as ready for review June 20, 2025 15:54

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/routers/peers.py (1)

154-154: Consider updating the response model for streaming compatibility.

The endpoint declares response_model=schemas.DialecticResponse but returns StreamingResponse when streaming is enabled. This mismatch may cause issues with OpenAPI documentation and client code generation.

Consider using a Union type or removing the response_model declaration:

-    response_model=schemas.DialecticResponse,
+    response_model=None,  # or use Union[schemas.DialecticResponse, StreamingResponse]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3acf8fa and e37b60e.

📒 Files selected for processing (1)
  • src/routers/peers.py (3 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
src/routers/peers.py

[refactor] 178-204: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)

🔇 Additional comments (2)
src/routers/peers.py (2)

4-4: LGTM! Required imports for streaming support.

The added imports are necessary for the streaming functionality implementation.

Also applies to: 13-14


198-200: Review error handling in streaming context.

The current error handling raises HTTPException during streaming, which may cause issues if response headers have already been sent. Consider whether this is the intended behavior or if alternative error handling (like yielding error messages) would be more appropriate.

Could you verify that raising HTTPException during streaming works as expected in your FastAPI setup? In some cases, once streaming has started, HTTP status codes cannot be changed.

Comment thread src/routers/peers.py Outdated

@dr-frmr dr-frmr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Rajat-Ahuja1997 Rajat-Ahuja1997 merged commit e6c2e1c into main Jun 20, 2025
6 checks passed
This was referenced Jun 24, 2025
@Rajat-Ahuja1997 Rajat-Ahuja1997 deleted the rajat/fix-peer-chat-streaming branch September 2, 2025 17:16
@coderabbitai coderabbitai Bot mentioned this pull request Oct 1, 2025
ranc1 pushed a commit to ranc1/honcho that referenced this pull request Apr 16, 2026
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