Skip to content

Add build failure analysis workflow using binlog-mcp#8326

Merged
Evangelink merged 38 commits into
mainfrom
ykovalova/build-failure-analysis
May 20, 2026
Merged

Add build failure analysis workflow using binlog-mcp#8326
Evangelink merged 38 commits into
mainfrom
ykovalova/build-failure-analysis

Conversation

@YuliiaKovalova
Copy link
Copy Markdown
Contributor

@YuliiaKovalova YuliiaKovalova commented May 18, 2026

Summary

Adds a GitHub Actions workflow that automatically analyzes build failures on PRs using AITools.BinlogMcp and posts diagnostic comments with suggested fixes.

How it works

  1. Build — runs ./build.sh --binaryLog to produce an MSBuild binlog
  2. Extract — uses binlog-mcp via MCP protocol to get structured error data (overview, errors, warnings)
  3. Analyze — calls GitHub Models API (gpt-4o-mini) for AI-powered root cause analysis with source context
  4. Comment — posts a structured analysis comment on the PR with clickable file/line links
  5. Suggest — posts LLM-generated inline fix suggestions as GitHub review comments with "Commit suggestion" buttons

Files

File Purpose
build-failure-analysis.yml Workflow orchestration (181 lines)
scripts/extract-binlog-errors.js MCP client that talks to binlog-mcp
scripts/analyze-errors.js AI analysis, source context reading, fallback formatting
scripts/post-suggestions.js LLM-generated inline fix suggestions
scripts/package.json + lockfile Pinned @modelcontextprotocol/sdk dependency

Features

  • AI analysis with clickable file links in the output
  • Inline fix suggestions with "Commit suggestion" button (LLM-generated)
  • Structured fallback when AI is unavailable (grouped errors, source context, file links)
  • Security: GITHUB_TOKEN cleared during build step, skipped for fork PRs
  • Deterministic: pinned tool version, pinned npm deps with lockfile, pinned Node.js 20

Adds a GitHub Actions workflow that:
- Triggers on PRs to build with binary logging
- On failure, installs binlog-mcp from dotnet-eng feed
- Extracts errors via MCP protocol (JSON-RPC over stdio)
- Uses GitHub Models API for AI-powered root cause analysis
- Posts diagnostic comment on the PR

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 14:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a GitHub Actions workflow to automatically extract MSBuild binlog errors on PR build failures, run an AI-assisted analysis, and post a single up-to-date diagnostic comment on the PR.

Changes:

  • Added PR-triggered workflow to build with --binaryLog, extract binlog errors via binlog-mcp, and comment analysis on failures
  • Added a Node.js MCP stdio (JSON-RPC) client script to query binlog-mcp for overview/errors/warnings
  • Added logic to delete prior analysis comments to avoid PR comment spam

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
.github/workflows/build-failure-analysis.yml New workflow to run build + binlog extraction + AI analysis and post PR comment on failure
.github/workflows/scripts/extract-binlog-errors.js New script implementing MCP Content-Length framing client to extract errors from binlog

Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
ykovalova and others added 2 commits May 18, 2026 16:28
This will be reverted after verifying the workflow.
- set -o pipefail so build failure propagates through tee/tail pipe
- Use file-based approach for passing analysis to comment step
- Fix PR number reference for pull_request events

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 14:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

Comment thread src/Adapter/MSTest.Engine/TimeSheet.cs Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js
YuliiaKovalova and others added 2 commits May 18, 2026 16:47
The repo's NuGet.config has package-source-mapping which blocks
--add-source. Use a temp nuget.config with just dotnet-eng + nuget.org.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add fallback error extraction from build output when MCP fails
- Fix nuget.config for tool install (package source mapping conflict)
- Improve Node.js MCP client with proper request tracking, timeouts
- Don't pre-load binlog at startup to avoid timeout
- Always post PR comment on failure, even without AI analysis
- Verify tool can start before attempting MCP communication

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 14:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

YuliiaKovalova and others added 2 commits May 18, 2026 17:06
The bash sed approach produced invalid JSON with unescaped control
characters from the build log. Use Node.js JSON.stringify instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 15:11
- Replace raw JSON-RPC with @modelcontextprotocol/sdk for reliable
  MCP protocol handling (fixes initialize timeout)
- Try multiple AI endpoints (models.github.ai, models.inference.ai.azure.com)
- Improve fallback: group errors by file with structured markdown
- Remove broken --help check (tool is MCP server, not CLI)
- Re-introduce build error for testing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

Comment thread .github/workflows/build-failure-analysis.yml
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
YuliiaKovalova and others added 2 commits May 18, 2026 17:21
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The binlog-mcp tool returns errors as JSON array with file, line,
code, message fields. Parse this properly and format as grouped
markdown with emojis, deduplication, and collapsible warnings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 15:27
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.

Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
YuliiaKovalova and others added 2 commits May 18, 2026 17:37
- Extract source context from binlog via binlog_files MCP tool
- Generate fix suggestions based on error code (CS0246, CS0234, etc.)
- Show source context with expandable details block
- Include source context in AI prompt for better AI-generated fixes
- Re-introduce build error for testing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Binlogs don't embed .cs source files. Read them directly from the
checked-out workspace to provide source context for fix suggestions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 15:44
YuliiaKovalova and others added 2 commits May 19, 2026 13:48
- Commit package.json + lockfile, use npm ci for deterministic installs
- Move tool version to env var (BINLOG_MCP_VERSION) for easy updates
- Fix basename collision in link post-processing (escape all regex metacharacters)
- Skip workflow entirely for fork PRs (read-only token cannot post comments)
- Unify toRelPath implementations (both now handle Windows + Linux paths)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 11:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • .github/workflows/scripts/package-lock.json: Language not supported

Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/scripts/extract-binlog-errors.js
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/build-failure-analysis.yml Outdated
Comment thread .github/workflows/scripts/package.json Outdated
YuliiaKovalova and others added 2 commits May 19, 2026 14:27
- Move dynamic imports inside try/catch in extract script
- Only post review suggestions on lines in the PR diff (avoids 422)
- Clean up package.json (remove failing test script, add private flag)
- Guard client.close() against null client

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AITools.BinlogMcp is only on the dotnet-eng feed and the package
name is not prefix-reserved on nuget.org. Including nuget.org as
a source creates a dependency confusion attack vector.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 12:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • .github/workflows/scripts/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)

.github/workflows/build-failure-analysis.yml:156

  • Analyze errors with AI assumes /tmp/binlog-analysis.json is always valid JSON (JSON.parse(fs.readFileSync(...))) and will throw if the file is missing or malformed, which would skip posting any diagnostic comment even though the build failed. Wrapping this parse in a try/catch and falling back to a minimal message (or reusing /tmp/build-output.log) would make the workflow more resilient.
            const fs = require('fs');
            const path = require('path');
            const data = JSON.parse(fs.readFileSync(process.env.BINLOG_DATA, 'utf8'));
            const workspace = process.env.GITHUB_WORKSPACE_PATH;
            const headSha = process.env.PR_HEAD_SHA;

Comment thread .github/workflows/scripts/package-lock.json
Comment thread .github/workflows/build-failure-analysis.yml
Comment thread .github/workflows/build-failure-analysis.yml Outdated
YuliiaKovalova and others added 2 commits May 19, 2026 15:00
- Regenerate package-lock.json to match renamed package.json
- Validate MCP output is valid JSON before marking as extracted
- Fallback now outputs errors as JSON array (matching MCP format)
  so source context and inline suggestions work in fallback path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Instead of a switch/case on error codes, ask the LLM to generate
exact replacement lines for each error. The LLM sees the source
context and error details, and returns a JSON array of fixes that
are posted as GitHub suggestion blocks with one-click commit.

Also handles declaration-side fixes: when callers break due to a
signature change in the PR, the LLM suggests fixes on the
declaration line (e.g., making new params optional).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 13:21
Simplify the workflow from 820 lines to 181 by extracting logic:
- analyze-errors.js: AI analysis, source context, fallback formatting
- post-suggestions.js: LLM-generated inline fix suggestions
- extract-binlog-errors.js: MCP client (unchanged)

The workflow YAML is now pure orchestration — no inline JavaScript.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • .github/workflows/scripts/package-lock.json: Language not supported

Comment thread .github/workflows/build-failure-analysis.yml
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 13:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • .github/workflows/scripts/package-lock.json: Language not supported

Comment thread src/Adapter/MSTest.Engine/TimeSheet.cs Outdated
Comment thread .github/workflows/build-failure-analysis.yml
Comment thread .github/workflows/scripts/extract-binlog-errors.js
Comment thread .github/workflows/build-failure-analysis.yml Outdated
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Build Failure Analysis

1. Summary of Failure

The build failed due to multiple instances of the same error: a required argument for the TimeSheet.RecordStart(string) method is not provided.

2. Root Causes

  • Missing Required Parameter: The RecordStart method call is missing the testDisplayName parameter.

3. Concrete Code Fix

To resolve the missing parameter issue, update the method call in ThreadPoolTestNodeRunner.cs by passing the required argument.

--- Engine/ThreadPoolTestNodeRunner.cs
+++ Engine/ThreadPoolTestNodeRunner.cs
@@ -204,7 +204,7 @@
         timesheet.RecordStart();
 
         // Replace with the actual test display name variable
-        timesheet.RecordStart();
+        timesheet.RecordStart(testNode.DisplayName); // Assuming testNode has a DisplayName property
 
         PlatformTestNode platformTestNode = testNode.ToPlatformTestNode();

Make sure to replace testNode.DisplayName with the appropriate variable used in your context that corresponds to the test display name.


🤖 Generated using binlog-mcp · commit f44116a · workflow run

- Only delete comments from github-actions[bot] (not human comments)
- Ensure extract script always outputs valid JSON array for errors
- Revert test error

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review May 19, 2026 14:26
Copilot AI review requested due to automatic review settings May 19, 2026 14:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Evangelink Evangelink enabled auto-merge (squash) May 20, 2026 07:58
@Evangelink Evangelink merged commit f6b73f8 into main May 20, 2026
15 checks passed
@Evangelink Evangelink deleted the ykovalova/build-failure-analysis branch May 20, 2026 07:58
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.

4 participants