Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 2, 2025

When PR tests fail, automatically trigger Claude to analyze failures and post diagnostic comments with suggested fixes.

Changes

  • New workflow .github/workflows/claude-on-test-failure.yml

    • Triggers on workflow_run: completed for "Run Tests" workflow
    • Runs only when conclusion == 'failure'
    • Waits for all test jobs to complete before analyzing
    • Uses GitHub MCP tools to fetch workflow logs and failure details
    • Posts structured PR comment with root cause and actionable solution
    • Concurrency controls: Only one analysis runs at a time per branch, with older jobs automatically cancelled
    • Loop detection: Claude checks for bot comment loops (e.g., CodeRabbit ↔ Claude cycles) and exits with a warning if detected
  • Documentation updated in AGENTS.md

Workflow Behavior

When tests fail, Claude:

  1. Fetches failed job logs via get_job_logs and summarize_run_log_failures
  2. Analyzes failures against codebase context
  3. Checks PR comments for bot loops before posting
  4. Posts comment with:
    • Failure summary
    • Root cause analysis
    • Specific file changes needed
    • Detailed logs in collapsible sections

Follows existing Claude workflow patterns (same MCP servers, similar prompt structure, consistent tool allowlist).

Safety Features

  • Concurrency management: cancel-in-progress: true ensures efficient resource usage by canceling superseded analysis runs
  • Loop prevention: Explicit instructions for Claude to detect and break bot interaction loops

<issue_title>Add Claude Workflow for failed tests</issue_title>
><issue_description>When a PR check fails, we should trigger Claude automatically to assess the failure and post a comment with what it thinks the solution to the failure is.
>
> Can we have it wait until all checks on the PR report success or failure?
>
></issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
>
><comment_new>@strawgate
> @claude please make a pull request</comment_new>
>
>

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Claude Workflow for failed tests</issue_title>
<issue_description>When a PR check fails, we should trigger Claude automatically to assess the failure and post a comment with what it thinks the solution to the failure is.

Can we have it wait until all checks on the PR report success or failure?

</issue_description>

Comments on the Issue (you are @copilot in this section)

@strawgate @claude please make a pull request

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 2, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/add-claude-workflow-for-tests

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

Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 2, 2025

Please retry analysis of this Pull-Request directly on SonarQube Cloud

Copilot AI and others added 2 commits November 2, 2025 00:51
Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Claude workflow for failed tests Add automated Claude workflow for test failure analysis Nov 2, 2025
@strawgate
Copy link
Owner

@copilot i think we want to set concurrency controls here so that older jobs get cancelled, only one runs at a time, etc. We also should make it very clear in the prompt that if it detects a loop (code rabbit triggers claude triggers code rabbit triggers claude sorta thing) it must exist.

Copilot AI requested a review from strawgate November 2, 2025 00:54
Copilot finished work on behalf of strawgate November 2, 2025 00:54
@strawgate strawgate marked this pull request as ready for review November 2, 2025 00:55
Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot i think we want to set concurrency controls here so that older jobs get cancelled, only one runs at a time, etc. We also should make it very clear in the prompt that if it detects a loop (cod...

Added in commit 914a4de:

  1. Concurrency controls: Added concurrency group with cancel-in-progress: true to ensure only one analysis runs at a time per branch, canceling older jobs automatically.

  2. Loop detection: Added a critical section to the prompt instructing Claude to:

    • Check PR comments for bot comment loops before posting
    • Detect if CodeRabbit/other bots triggered a cycle
    • Exit immediately with a brief warning comment if a loop is detected
    • Not post another full analysis if loops are detected

Copilot finished work on behalf of strawgate November 2, 2025 00:59
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 2, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
3 Security Hotspots

See analysis details on SonarQube Cloud

@strawgate strawgate merged commit cacb180 into main Nov 2, 2025
1 of 2 checks passed
@strawgate strawgate deleted the copilot/add-claude-workflow-for-tests branch November 2, 2025 02:19
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.

Add Claude Workflow for failed tests

2 participants