Skip to content

feat(operator): include check cost in Slack alerts - #2282

Draft
tuusberg wants to merge 2 commits into
HolmesGPT:masterfrom
tuusberg:codex/include-check-costs-in-slack
Draft

feat(operator): include check cost in Slack alerts#2282
tuusberg wants to merge 2 commits into
HolmesGPT:masterfrom
tuusberg:codex/include-check-costs-in-slack

Conversation

@tuusberg

@tuusberg tuusberg commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Preserves aggregate LLM usage from operator-driven health checks and displays it in Slack failure alerts.

  • carries total cost and token counts from the completed check into the alert destination
  • renders a compact Investigation cost and input/output token line in the existing Slack message
  • adds API-handoff and Slack-payload regression tests

Why

Operator health checks can make several LLM calls. The check usage recorder already receives aggregate stats, but the Slack alert path re-created an empty LLMResult, discarding that data before formatting the message.

Validation

  • ruff check for touched source and test files
  • pytest tests/checks/test_checks_api.py tests/plugins/destinations/test_slack.py --no-cov (3 passed)
  • Started pytest tests -m 'not llm' -q; its output was truncated by the local runner after progressing through the suite.

Summary by CodeRabbit

  • New Features

    • Slack investigation messages now include LLM usage details (total cost, input/prompt tokens, and output/completion tokens).
    • Check execution now tracks and carries LLM cost/token accounting through to downstream destinations.
  • Tests

    • Added API test coverage ensuring LLM usage metrics are forwarded to Slack during check execution.
    • Added Slack destination test coverage validating the rendered usage block formatting.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00043246-9d65-468d-b4aa-7cd6cece6916

📥 Commits

Reviewing files that changed from the base of the PR and between f8911c3 and 5932ae6.

📒 Files selected for processing (1)
  • holmes/checks/checks.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • holmes/checks/checks.py

Walkthrough

Changes

LLM usage attribution

Layer / File(s) Summary
Usage fields in check results
holmes/checks/models.py, holmes/checks/checks.py
CheckResult stores cost and token metrics, populated from LLMResult for PASS and FAIL outcomes.
Alert destination usage forwarding
holmes/checks/checks_api.py, tests/checks/test_checks_api.py
Alert execution forwards check usage metrics into destination LLMResult objects, with API coverage for Slack alerts.
Slack usage context
holmes/plugins/destinations/slack/plugin.py, tests/plugins/destinations/test_slack.py
Slack messages append formatted investigation cost and prompt/completion token counts when usage is present.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CheckExecution
  participant AlertAPI
  participant SlackDestination
  CheckExecution->>AlertAPI: produce CheckResult with LLM usage
  AlertAPI->>SlackDestination: pass usage-enriched LLMResult
  SlackDestination->>SlackDestination: append cost and token context
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: propagating check cost into Slack alerts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

@netlify

netlify Bot commented Jul 11, 2026

Copy link
Copy Markdown

Deploy Preview for holmes-docs ready!

Name Link
🔨 Latest commit 5932ae6
🔍 Latest deploy log https://app.netlify.com/projects/holmes-docs/deploys/6a52980f5f96fb000817e236
😎 Deploy Preview https://deploy-preview-2282--holmes-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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

🧹 Nitpick comments (1)
holmes/checks/checks.py (1)

139-164: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider consolidating the PASS/FAIL branches to reduce duplication.

The two CheckResult constructions differ only in status and message; the remaining fields (including the four new usage fields) are identical. Consolidating would prevent future field divergence as more metrics are added.

♻️ Optional refactor to eliminate duplication
-        if check_response.passed:
-            result = CheckResult(
-                check_name=check.name,
-                status=CheckStatus.PASS,
-                message=f"Check passed. {check_response.rationale}",
-                query=check.query,
-                duration=duration,
-                rationale=check_response.rationale,
-                total_cost=response.total_cost,
-                total_tokens=response.total_tokens,
-                prompt_tokens=response.prompt_tokens,
-                completion_tokens=response.completion_tokens,
-            )
-        else:
-            result = CheckResult(
-                check_name=check.name,
-                status=CheckStatus.FAIL,
-                message=f"Check failed. {check_response.rationale}",
-                query=check.query,
-                duration=duration,
-                rationale=check_response.rationale,
-                total_cost=response.total_cost,
-                total_tokens=response.total_tokens,
-                prompt_tokens=response.prompt_tokens,
-                completion_tokens=response.completion_tokens,
-            )
+        status = CheckStatus.PASS if check_response.passed else CheckStatus.FAIL
+        verb = "passed" if check_response.passed else "failed"
+        result = CheckResult(
+            check_name=check.name,
+            status=status,
+            message=f"Check {verb}. {check_response.rationale}",
+            query=check.query,
+            duration=duration,
+            rationale=check_response.rationale,
+            total_cost=response.total_cost,
+            total_tokens=response.total_tokens,
+            prompt_tokens=response.prompt_tokens,
+            completion_tokens=response.completion_tokens,
+        )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@holmes/checks/checks.py` around lines 139 - 164, Consolidate the duplicated
CheckResult construction in the check evaluation flow by selecting status and
the corresponding message from check_response.passed, then instantiate
CheckResult once with the shared fields, including usage metrics. Preserve the
existing PASS/FAIL statuses and message text.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@holmes/checks/checks.py`:
- Around line 139-164: Consolidate the duplicated CheckResult construction in
the check evaluation flow by selecting status and the corresponding message from
check_response.passed, then instantiate CheckResult once with the shared fields,
including usage metrics. Preserve the existing PASS/FAIL statuses and message
text.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa9b0c0f-c513-4aa7-aaaa-a3eec0797ab7

📥 Commits

Reviewing files that changed from the base of the PR and between 423710a and f8911c3.

📒 Files selected for processing (6)
  • holmes/checks/checks.py
  • holmes/checks/checks_api.py
  • holmes/checks/models.py
  • holmes/plugins/destinations/slack/plugin.py
  • tests/checks/test_checks_api.py
  • tests/plugins/destinations/test_slack.py

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.

1 participant