Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

  • Analyze the workflow failure logs
  • Identify root cause: agent passes wrong branch name in create_pull_request
  • Option 1: Update workflow instructions to not specify branch (auto-detect)
  • Option 2: Update workflow instructions to pass correct branch name
  • Option 3: Make safe-outputs MCP server smarter about branch detection
  • Add tests for branch detection logic
  • Validate all tests pass
  • Address code review feedback: extract getBaseBranch() helper function
  • Manual testing of the fix
Original prompt

This section details on the original issue you should resolve

<issue_title>Unbloat docs broken</issue_title>
<issue_description>/q Investigate why https://github.com/githubnext/gh-aw/actions/runs/19076334499 failed</issue_description>

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

@pelikhan /q the agent claims that a pull request was created but the create pull request job did not find a patch file. Investigate this run https://github.com/githubnext/gh-aw/actions/runs/19077057301/job/54495502914#step:40:1 @pelikhan @copilot apply option 1, 2, 3.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@pelikhan
Copy link
Contributor

pelikhan commented Nov 4, 2025

@copilot continue work

Option 1: Update workflow instructions to not specify branch parameter
- Added explicit instruction to NOT pass branch in create_pull_request
- Or if specified, use the exact branch name created earlier

Option 2: Add branch creation step to workflow instructions
- Added step 7 to create descriptive branch before making changes
- Updated section numbering accordingly

Option 3: Make safe-outputs MCP server smarter about branch detection
- Detect when provided branch equals base branch and use git instead
- Change getCurrentBranch() to prioritize git over environment variables
- Apply same logic to push_to_pull_request_branch handler
- Add debug logging for branch detection scenarios

This fixes the issue where agents would pass "main" as the branch name
when they created a different feature branch, causing empty patch files
and PR creation failures.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot continue work

Applied all three options as requested in commit 92529d6:

Option 1: Updated workflow instructions to explicitly tell the agent NOT to pass a branch parameter in create_pull_request (let it auto-detect), or if specified, use the exact branch name created earlier.

Option 2: Added step 7 to instruct the agent to create a descriptive branch before making changes, with clear examples.

Option 3: Made the safe-outputs MCP server smarter:

  • Detects when provided branch equals base branch and uses git to get the actual working branch
  • Changed getCurrentBranch() to prioritize git command over environment variables
  • Applied same logic to push_to_pull_request_branch handler

This comprehensive fix addresses the root cause where agents would pass "main" as the branch name when they created a different feature branch, causing empty patch files and PR creation failures.

Copilot AI changed the title [WIP] Investigate unbloat docs failure in CI Fix unbloat docs workflow branch detection (3-option solution) Nov 4, 2025
@pelikhan pelikhan added the smoke label Nov 4, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

Agentic Changeset Generator triggered by this pull request.

@pelikhan pelikhan marked this pull request as ready for review November 4, 2025 18:57
Copilot AI review requested due to automatic review settings November 4, 2025 18:57
@pelikhan pelikhan enabled auto-merge (squash) November 4, 2025 18:57
Copy link
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

This pull request improves branch detection logic in GitHub Agentic Workflows to fix a bug where AI agents were incorrectly passing the base branch name instead of the working branch when creating pull requests. The key changes include:

  • Reordering branch detection to prioritize git commands over environment variables for more reliable detection
  • Adding special handling to detect when the provided branch equals the base branch and auto-correct it
  • Updating workflow documentation to guide agents on proper branch usage
  • Adding a test file to document the expected behavior

Reviewed Changes

Copilot reviewed 60 out of 60 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflow/js/safe_outputs_mcp_server.cjs Refactored getCurrentBranch() to prioritize git command over env vars; enhanced PR handlers to detect and correct base branch misuse
pkg/workflow/js/safe_outputs_branch_detection.test.cjs New test file documenting branch detection behavior (placeholder tests)
.github/workflows/unbloat-docs.md Added instructions for creating branches and avoiding base branch in PR creation
.github/workflows/*.lock.yml Regenerated workflow files reflecting the JavaScript changes
.changeset/patch-add-jqschema-utility.md Changeset entry for the patch

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*/
const createPullRequestHandler = args => {
const entry = { ...args, type: "create_pull_request" };
const baseBranch = process.env.GH_AW_BASE_BRANCH || "main";
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The base branch determination is duplicated in both createPullRequestHandler (line 476) and pushToPullRequestBranchHandler (line 509). Consider extracting this into a helper function getBaseBranch() to reduce code duplication and ensure consistency.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted getBaseBranch() helper function in commit 70c902e to eliminate the duplication and ensure consistency between both handlers.

Addresses code review feedback to extract the base branch determination
logic into a dedicated helper function. This eliminates the duplication
between createPullRequestHandler and pushToPullRequestBranchHandler,
ensuring consistency and improving maintainability.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
auto-merge was automatically disabled November 4, 2025 19:10

Head branch was pushed to by a user without write access

@pelikhan pelikhan merged commit fa2b2f5 into main Nov 4, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/investigate-unbloat-docs branch November 4, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbloat docs broken

2 participants