Skip to content

ROB-1689 support stream holmes chat function#1886

Merged
moshemorad merged 2 commits intomasterfrom
ROB-1689-holmes-chat-stream
Aug 7, 2025
Merged

ROB-1689 support stream holmes chat function#1886
moshemorad merged 2 commits intomasterfrom
ROB-1689-holmes-chat-stream

Conversation

@RoiGlinik
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 31, 2025

Walkthrough

A new boolean field stream was added to both HolmesChatParams and HolmesChatRequest classes, enabling support for streaming chat responses. The holmes_chat function was updated to handle streaming responses from the Holmes API when the stream parameter is set, sending chunks to the websocket as they arrive.

Changes

Cohort / File(s) Change Summary
Add stream field to params and request models
src/robusta/core/model/base_params.py, src/robusta/core/reporting/holmes.py
Introduced a boolean stream field (default False) to both HolmesChatParams and HolmesChatRequest using Pydantic's Field.
Enable streaming in chat integration
src/robusta/core/playbooks/internal/ai_integration.py
Modified holmes_chat to support streaming: if params.stream is true, sends streaming POST request and relays chunks via websocket.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant holmes_chat
    participant Holmes API
    participant WebSocket

    User->>holmes_chat: Invoke with params (stream=True)
    holmes_chat->>Holmes API: POST /api/chat (stream=True)
    loop For each chunk in response
        Holmes API-->>holmes_chat: Send chunk
        holmes_chat->>WebSocket: ws(data=chunk)
    end
    holmes_chat-->>User: (returns after streaming)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

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

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ROB-1689-holmes-chat-stream

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/robusta/core/playbooks/internal/ai_integration.py (1)

356-369: Streaming implementation looks good with minor suggestions.

The streaming implementation correctly uses a context manager, appropriate headers, and processes chunks as they arrive. The early return prevents duplicate processing.

Consider these improvements for robustness:

                for line in resp.iter_content(
                    chunk_size=None, decode_unicode=True
-               ):  # Avoid streaming chunks from holmes. send them as they arrive.
+               ):  # Send chunks from Holmes as they arrive
                    if line:
+                       # Log chunk size for debugging if needed
+                       logging.debug(f"Streaming chunk size: {len(line)}")
                        event.ws(data=line)

The comment could be clearer about what's happening, and optional debug logging could help with troubleshooting streaming issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e8d9da and e769d23.

📒 Files selected for processing (3)
  • src/robusta/core/model/base_params.py (2 hunks)
  • src/robusta/core/playbooks/internal/ai_integration.py (1 hunks)
  • src/robusta/core/reporting/holmes.py (2 hunks)
🔇 Additional comments (6)
src/robusta/core/model/base_params.py (2)

5-5: LGTM! Necessary import for the new field.

The Field import is required for the stream parameter definition with a default value.


193-193: LGTM! Well-structured field addition.

The stream field is properly defined with a default value of False, ensuring backward compatibility while enabling the new streaming functionality.

src/robusta/core/reporting/holmes.py (2)

3-3: LGTM! Required import addition.

Adding Field to the pydantic import is necessary for the stream field definition.


41-41: LGTM! Consistent field definition.

The stream field definition matches the pattern used in HolmesChatParams, maintaining consistency across the codebase.

src/robusta/core/playbooks/internal/ai_integration.py (2)

354-355: LGTM! Clean parameter passing and URL definition.

Good practice to pass the stream parameter and define the URL once for reuse in both streaming and non-streaming paths.


371-371: LGTM! Preserved backward compatibility.

The non-streaming path remains unchanged, ensuring backward compatibility for existing functionality.

@moshemorad moshemorad merged commit b964c41 into master Aug 7, 2025
11 of 14 checks passed
@moshemorad moshemorad deleted the ROB-1689-holmes-chat-stream branch August 7, 2025 09:09
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