Skip to content

Rob 1942 holmes return rate limit when happen - #854

Merged
moshemorad merged 5 commits into
masterfrom
ROB-1942-holmes-return-rate-limit-when-happen
Aug 19, 2025
Merged

moshemorad merged 5 commits into
masterfrom
ROB-1942-holmes-return-rate-limit-when-happen

Conversation

@moshemorad

Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai

coderabbitai Bot commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds litellm rate-limit handling: server endpoints now catch litellm.exceptions.RateLimitError and return HTTP 429. Streaming utilities add an SSE "error" event, helpers to format SSE error messages, and catch RateLimitError in stream formatters to emit structured SSE error events instead of aborting.

Changes

Cohort / File(s) Summary
SSE streaming utilities
holmes/utils/stream.py
Added StreamEvents.ERROR = "error"; added create_sse_error_message(description, error_code, msg) and pre-bound create_rate_limit_error_message (error_code=5204, msg="Rate limit exceeded"); create_sse_message now defaults None data to {}; wrapped stream_investigate_formatter and stream_chat_formatter with try/except catching litellm.exceptions.RateLimitError to emit SSE error events.
Server endpoints rate-limit handling
server.py
Imported litellm; added except litellm.exceptions.RateLimitError handlers in five endpoints (/api/investigate, /api/workload_health_check, /api/workload_health_chat, /api/issue_chat, /api/chat) to return HTTP 429 with the error message, placed after AuthenticationError handling and before generic Exception.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server
  participant LiteLLM

  Client->>Server: HTTP POST /api/(investigate|workload_*|issue_chat|chat)
  Server->>LiteLLM: Request completion
  alt Rate limit hit
    LiteLLM-->>Server: RateLimitError
    Server-->>Client: HTTP 429 {error}
  else Normal
    LiteLLM-->>Server: Response
    Server-->>Client: 200 {result}
  end
Loading
sequenceDiagram
  participant Client
  participant Server
  participant StreamFmt as Stream Formatter
  participant LiteLLM

  Client->>Server: GET /api/stream/investigate (SSE)
  Server->>StreamFmt: start stream
  StreamFmt->>LiteLLM: stream tokens
  alt Rate limit hit
    LiteLLM-->>StreamFmt: RateLimitError
    StreamFmt-->>Client: SSE event "error" {success:false, code:5204, msg:"Rate limit exceeded", description}
  else Normal stream
    LiteLLM-->>StreamFmt: tokens
    StreamFmt-->>Client: SSE events (data)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fee951b and 558795e.

📒 Files selected for processing (1)
  • server.py (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: ALWAYS place Python imports at the top of the file, not inside functions or methods
Type hints are required (project is type-checked with mypy)
Use Ruff for formatting and linting (configured in pyproject.toml)

Files:

  • server.py
🪛 Ruff (0.12.2)
server.py

152-152: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


243-243: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


274-274: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


303-303: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


375-375: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ 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: Pre-commit checks
  • GitHub Check: llm_evals
  • GitHub Check: Pre-commit checks
✨ 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-1942-holmes-return-rate-limit-when-happen

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@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 (6)
holmes/utils/stream.py (6)

22-25: Add return type to create_sse_message.

Project requires type hints; add the return type.

Apply this diff:

-def create_sse_message(event_type: str, data: Optional[dict] = None):
+def create_sse_message(event_type: str, data: Optional[dict] = None) -> str:

28-38: Type-hint create_sse_error_message return type.

Minor typing improvement to comply with mypy.

Apply this diff:

-def create_sse_error_message(description: str, error_code: int, msg: str):
+def create_sse_error_message(description: str, error_code: int, msg: str) -> str:

40-45: Optional: narrow exception import to avoid importing the full litellm module.

Catching RateLimitError can be done by importing the class directly (from litellm.exceptions import RateLimitError) and using except RateLimitError here as well, which reduces module-level import surface.

Do you want me to patch this file to import RateLimitError directly and adjust the excepts accordingly?


47-69: Add explicit return type and parameter typing to the formatter.

Yield type is str (SSE lines). Also type runbooks to align with usage.

Apply this diff:

-def stream_investigate_formatter(
-    call_stream: Generator[StreamMessage, None, None], runbooks
-):
+def stream_investigate_formatter(
+    call_stream: Generator[StreamMessage, None, None],
+    runbooks: Optional[List[dict]],
+) -> Generator[str, None, None]:

75-90: Add explicit return type to chat formatter.

Comply with type-hinting guidelines.

Apply this diff:

-def stream_chat_formatter(
-    call_stream: Generator[StreamMessage, None, None],
-    followups: Optional[List[dict]] = None,
-):
+def stream_chat_formatter(
+    call_stream: Generator[StreamMessage, None, None],
+    followups: Optional[List[dict]] = None,
+) -> Generator[str, None, None]:

67-69: Consider logging rate-limit events for observability.

Emitting SSE error is great for clients; a server-side warning log would aid ops visibility and rate-limit diagnostics.

Do you want me to add a logging.warning("Rate limit hit during streaming", exc_info=True) here? I can wire in a safe import logging at the file top.

Also applies to: 88-89

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bcea41f and fee951b.

📒 Files selected for processing (2)
  • holmes/utils/stream.py (2 hunks)
  • server.py (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: ALWAYS place Python imports at the top of the file, not inside functions or methods
Type hints are required (project is type-checked with mypy)
Use Ruff for formatting and linting (configured in pyproject.toml)

Files:

  • server.py
  • holmes/utils/stream.py
🧬 Code Graph Analysis (1)
holmes/utils/stream.py (2)
holmes/core/investigation_structured_output.py (1)
  • process_response_into_sections (225-238)
holmes/core/tool_calling_llm.py (1)
  • call_stream (573-708)
🪛 Ruff (0.12.2)
server.py

152-152: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


242-242: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


273-273: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


302-302: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


374-374: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ 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: Pre-commit checks
  • GitHub Check: llm_evals
  • GitHub Check: Pre-commit checks
🔇 Additional comments (2)
server.py (1)

138-156: Mapping rate-limit errors to HTTP 429 is the right UX.

Catching RateLimitError and returning 429 across these endpoints is consistent and user-friendly. Nice.

Also applies to: 185-246, 248-277, 279-306, 318-377

holmes/utils/stream.py (1)

10-15: SSE ERROR event addition looks good.

The explicit StreamEvents.ERROR = "error" provides a clean, standardized path for structured streaming failures.

Comment thread server.py
@moshemorad
moshemorad enabled auto-merge (squash) August 19, 2025 11:22

@arikalon1 arikalon1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@moshemorad
moshemorad merged commit bd74a6e into master Aug 19, 2025
@moshemorad
moshemorad deleted the ROB-1942-holmes-return-rate-limit-when-happen branch August 19, 2025 12:34
@github-actions

Copy link
Copy Markdown
Contributor

Results of HolmesGPT evals

  • ask_holmes: 32/39 test cases were successful, 2 regressions, 2 skipped, 2 setup failures
Test suite Test case Status
ask 01_how_many_pods ✅
ask 02_what_is_wrong_with_pod ✅
ask 03_what_is_the_command_to_port_forward ✅
ask 04_related_k8s_events ↪️
ask 05_image_version ✅
ask 09_crashpod ✅
ask 10_image_pull_backoff ✅
ask 11_init_containers ✅
ask 14_pending_resources ✅
ask 15_failed_readiness_probe ✅
ask 17_oom_kill ✅
ask 18_crash_looping_v2 ✅
ask 19_detect_missing_app_details ✅
ask 20_long_log_file_search ✅
ask 24_misconfigured_pvc ✅
ask 28_permissions_error 🚧
ask 29_events_from_alert_manager ↪️
ask 39_failed_toolset ✅
ask 41_setup_argo ✅
ask 42_dns_issues_steps_new_tools ⚠️
ask 43_current_datetime_from_prompt ✅
ask 45_fetch_deployment_logs_simple ✅
ask 51_logs_summarize_errors ✅
ask 53_logs_find_term ✅
ask 54_not_truncated_when_getting_pods ✅
ask 59_label_based_counting ✅
ask 60_count_less_than 🚧
ask 61_exact_match_counting ✅
ask 63_fetch_error_logs_no_errors ✅
ask 79_configmap_mount_issue ✅
ask 83_secret_not_found ✅
ask 86_configmap_like_but_secret ❌
ask 93_calling_datadog ✅
ask 93_calling_datadog ✅
ask 93_calling_datadog ✅
ask 97_logs_clarification_needed ❌
ask 110_k8s_events_image_pull ✅
ask 24a_misconfigured_pvc_basic ✅
ask 13a_pending_node_selector_basic ✅

Legend

  • ✅ the test was successful
  • ↪️ the test was skipped
  • ⚠️ the test failed but is known to be flaky or known to fail
  • 🚧 the test had a setup failure (not a code regression)
  • 🔧 the test failed due to mock data issues (not a code regression)
  • ❌ the test failed and should be fixed before merging the PR

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