Skip to content

Conversation

@adityathebe
Copy link
Member

@adityathebe adityathebe commented Feb 11, 2026

Adds a Diagnose Failure button to the playbook run detail page when a run has failed.

resolves: flanksource/mission-control#2744

@vercel
Copy link

vercel bot commented Feb 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aws-preview Ready Ready Preview Feb 12, 2026 9:17am
flanksource-ui Ready Ready Preview Feb 12, 2026 9:17am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

Walkthrough

This change introduces AI-powered diagnostic capabilities for failed playbook runs. It includes a new DiagnosePlaybookFailureButton component with feature-flag gating, renaming PlaybookRunsActions to PlaybookRunDetailView, and enhancing the AI chat infrastructure to support initial prompts that auto-send on open.

Changes

Cohort / File(s) Summary
AI Chat Infrastructure
src/components/ai/AiChat.tsx, src/components/ai/AiChatPopover.tsx
Added support for initial prompt auto-send in AIChat component. Enhanced AiChatPopoverContextValue with initialPrompt state and setInitialPrompt updater. Popover now forwards initialPrompt to AIChat and clears it on close.
Playbook Run Diagnostic Feature
src/components/Playbooks/Runs/Actions/PlaybookRunsActions.tsx, src/components/Playbooks/Runs/DiagnosePlaybookFailureButton.tsx
Renamed exported component from PlaybookRunsActions to PlaybookRunDetailView. Introduced lazy-loaded DiagnosePlaybookFailureButton with feature-flag gating. Button aggregates playbook run data (name, status, error, duration, parameters, spec, per-action details), formats as diagnostic message, and launches AI chat with "Why did this playbook fail?" initial prompt.
Test Updates
src/components/Playbooks/Runs/Actions/__tests__/PlaybookRunsAction.unit.test.tsx
Updated test imports and references to use renamed export PlaybookRunDetailView instead of PlaybookRunsActions.
Page Integration
src/pages/playbooks/PlaybookRunsDetails.tsx
Updated component import alias from PlaybookRunsActions to PlaybookRunDetailView with corresponding JSX usage change.
API Route Formatting
app/api/chat/route.ts
Reformatted multi-line Response object literal in catch block from single-line to multi-line format (no functional change).

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant DFB as DiagnosePlaybookFailureButton
    participant ACP as AiChatPopover Context
    participant AChat as AIChat Component
    participant API as AI API

    User->>DFB: Click "Diagnose Failure"
    DFB->>DFB: Aggregate playbook run data<br/>(status, error, duration, etc.)
    DFB->>DFB: Format diagnostic message<br/>with truncation
    DFB->>ACP: setInitialPrompt("Why did this<br/>playbook fail?")
    DFB->>ACP: Push diagnostic message to chat
    DFB->>ACP: Open popover
    ACP->>AChat: Provide initialPrompt & chat context
    AChat->>AChat: useEffect detects ready status<br/>with initialPrompt
    AChat->>API: Auto-send initial prompt<br/>(once per open)
    API-->>AChat: Response
    AChat-->>User: Display diagnostic result
Loading

Suggested reviewers

  • moshloop
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main feature being added: an AI diagnose failure button for failed playbook runs, which is demonstrated across multiple file changes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/diagnose-playbook-failure-ai

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 and usage tips.

Copy link

@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: 1

🤖 Fix all issues with AI agents
In
`@src/components/Playbooks/Runs/Actions/__tests__/PlaybookRunsAction.unit.test.tsx`:
- Around line 183-189: The failing test throws "useAiFeatureLoader must be used
within AiFeatureLoaderProvider" because PlaybookRunDetailView (rendered in
PlaybookRunsAction.unit.test.tsx) triggers the AiFeatureRequest →
useAiFeatureLoader() path; fix by either wrapping the rendered component with
AiFeatureLoaderProvider (and FeatureFlagsContextProvider) in the test's render
tree or by mocking the feature-flag hook so AI is disabled; specifically update
the test to provide AiFeatureLoaderProvider/FeatureFlagsContextProvider around
<PlaybookRunDetailView data={mockData} /> or mock useAiFeatureLoader /
feature-flags to return isAiDisabled: true to avoid invoking AiFeatureRequest.

@moshloop
Copy link
Member

@adityathebe make the button size consistent with rerun playbook

Add a 'Diagnose Failure' button that opens the navbar AI chat popover
pre-populated with playbook run context (spec, actions, errors) for
interactive failure diagnosis.

- New DiagnosePlaybookFailureButton component with client-side context
- Lazy-loaded behind AI feature flag, only rendered for failed runs
- Rename PlaybookRunsActions to PlaybookRunDetailView
Add ref guard to AIChat's initialPrompt effect so it fires exactly once
instead of re-triggering every time status cycles back to 'ready'.

Update DiagnosePlaybookFailureButton to use setInitialPrompt for
auto-sending 'Why did this playbook fail?' and change quick prompts
to follow-up questions only.
… JSON context

- Pass entire PlaybookRunWithActions JSON to LLM instead of selective formatting
- Add detailed system prompt explaining playbooks, actions, and diagnosis approach
- Remove complex manual formatting and truncation logic
- Simplify code by passing raw JSON data
@adityathebe adityathebe force-pushed the feat/diagnose-playbook-failure-ai branch from 55f8f52 to 6fb33bb Compare February 12, 2026 09:11
@adityathebe adityathebe requested a review from moshloop February 12, 2026 09:12
@moshloop moshloop merged commit a581b0b into main Feb 13, 2026
16 of 19 checks passed
@moshloop moshloop deleted the feat/diagnose-playbook-failure-ai branch February 13, 2026 06:35
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.

Ask AI to fix failed playbook run

2 participants