Bug: base-branch does not work because baseRef is not passed in the GraphQL mutation
Context
Issue #17046 requested base-branch support for assign-to-agent. PR #17133 implemented it and was merged. However, the feature does not work — Copilot still opens PRs against main even when base-branch: "develop" is configured.
Root Cause
The GitHub GraphQL API's AgentAssignmentInput has a dedicated baseRef field:
baseRef (String) — The base ref/branch for the repository. Defaults to the default branch if not provided.
— GitHub GraphQL API docs: AgentAssignmentInput
The official documentation shows it being used directly:
agentAssignment: {
targetRepositoryId: "REPOSITORY_ID",
baseRef: "main",
customInstructions: "Fix the reported bug"
}
The REST API equivalent is base_branch in agent_assignment:
{
"assignees": ["copilot-swe-agent[bot]"],
"agent_assignment": {
"target_repo": "OWNER/REPO",
"base_branch": "main",
"custom_instructions": ""
}
}
PR #17133 does not use this field. Instead, it injects a natural language instruction into customInstructions:
IMPORTANT: Create your branch from the 'develop' branch, NOT from 'main'.
This text is prepended to customInstructions and passed as a string to the mutation. The baseRef field in agentAssignment is never set.
Why This Fails
-
Copilot does not reliably follow natural language instructions about which branch to use. It has its own branch resolution logic and the customInstructions text is advisory, not authoritative.
-
The buildBranchInstruction() wording is ambiguous — it says "Create your branch from" but does not say "open the PR targeting." These are different git operations (branching from vs. PR target).
-
The GraphQL API has a formal baseRef parameter specifically for this purpose behind the GraphQL-Features: issues_copilot_assignment_api_support header. This is how the GitHub.com UI specifies the base branch when assigning Copilot.
Current Code (PR #17133)
In actions/setup/js/assign_agent_helpers.cjs, the agentAssignment only passes:
targetRepositoryId
model
customAgent
customInstructions
baseRef is never included in the mutation variables.
Fix
Add baseRef to the agentAssignment fields in assignAgentToIssue(), following the same pattern as other fields:
if (baseBranch) {
agentAssignmentFields.push("baseRef: $baseRef");
agentAssignmentParams.push("$baseRef: String!");
variables.baseRef = baseBranch;
}
Also add the required feature flag header if not already present:
GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection
The buildBranchInstruction() text injection into customInstructions should be removed (or kept as a secondary hint), since baseRef is the authoritative mechanism.
Implementation Plan
1. Update assignAgentToIssue() in actions/setup/js/assign_agent_helpers.cjs
Add baseRef as a parameter and include it in the GraphQL mutation agentAssignment:
if (baseBranch) {
agentAssignmentFields.push("baseRef: $baseRef");
agentAssignmentParams.push("$baseRef: String!");
variables.baseRef = baseBranch;
}
2. Update assign_to_agent.cjs handler
Pass the resolved effectiveBaseBranch to assignAgentToIssue() as a new baseBranch parameter (instead of only using it to build a text instruction).
3. Remove or demote buildBranchInstruction()
Since baseRef is the formal API mechanism, the natural language instruction in customInstructions is redundant. Either:
- Remove
buildBranchInstruction() entirely, or
- Keep it as a soft secondary hint but make
baseRef the primary mechanism
4. Add the feature flag header
Ensure the GraphQL request includes:
GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection
5. Update tests
- Update
assign_agent_helpers.test.cjs to verify baseRef appears in the mutation
- Test that
baseRef is correctly passed when GH_AW_AGENT_BASE_BRANCH is set
- Test backward compatibility when no base branch is configured
6. Follow Guidelines
- Use error message format: "what's wrong. what's expected. example"
- Run
make agent-finish before completing
Reproduction
safe-outputs:
assign-to-agent:
target: "*"
pull-request-repo: "org/code-repo" # default branch: develop
base-branch: "develop"
github-token: ${{ secrets.TOKEN }}
Result: Copilot branches from main and opens PR targeting main, ignoring the base-branch: "develop" configuration.
References
Bug:
base-branchdoes not work becausebaseRefis not passed in the GraphQL mutationContext
Issue #17046 requested
base-branchsupport forassign-to-agent. PR #17133 implemented it and was merged. However, the feature does not work — Copilot still opens PRs againstmaineven whenbase-branch: "develop"is configured.Root Cause
The GitHub GraphQL API's
AgentAssignmentInputhas a dedicatedbaseReffield:The official documentation shows it being used directly:
The REST API equivalent is
base_branchinagent_assignment:{ "assignees": ["copilot-swe-agent[bot]"], "agent_assignment": { "target_repo": "OWNER/REPO", "base_branch": "main", "custom_instructions": "" } }PR #17133 does not use this field. Instead, it injects a natural language instruction into
customInstructions:This text is prepended to
customInstructionsand passed as a string to the mutation. ThebaseReffield inagentAssignmentis never set.Why This Fails
Copilot does not reliably follow natural language instructions about which branch to use. It has its own branch resolution logic and the
customInstructionstext is advisory, not authoritative.The
buildBranchInstruction()wording is ambiguous — it says "Create your branch from" but does not say "open the PR targeting." These are different git operations (branching from vs. PR target).The GraphQL API has a formal
baseRefparameter specifically for this purpose behind theGraphQL-Features: issues_copilot_assignment_api_supportheader. This is how the GitHub.com UI specifies the base branch when assigning Copilot.Current Code (PR #17133)
In
actions/setup/js/assign_agent_helpers.cjs, theagentAssignmentonly passes:targetRepositoryIdmodelcustomAgentcustomInstructionsbaseRefis never included in the mutation variables.Fix
Add
baseRefto theagentAssignmentfields inassignAgentToIssue(), following the same pattern as other fields:Also add the required feature flag header if not already present:
The
buildBranchInstruction()text injection intocustomInstructionsshould be removed (or kept as a secondary hint), sincebaseRefis the authoritative mechanism.Implementation Plan
1. Update
assignAgentToIssue()inactions/setup/js/assign_agent_helpers.cjsAdd
baseRefas a parameter and include it in the GraphQL mutationagentAssignment:2. Update
assign_to_agent.cjshandlerPass the resolved
effectiveBaseBranchtoassignAgentToIssue()as a newbaseBranchparameter (instead of only using it to build a text instruction).3. Remove or demote
buildBranchInstruction()Since
baseRefis the formal API mechanism, the natural language instruction incustomInstructionsis redundant. Either:buildBranchInstruction()entirely, orbaseRefthe primary mechanism4. Add the feature flag header
Ensure the GraphQL request includes:
5. Update tests
assign_agent_helpers.test.cjsto verifybaseRefappears in the mutationbaseRefis correctly passed whenGH_AW_AGENT_BASE_BRANCHis set6. Follow Guidelines
make agent-finishbefore completingReproduction
Result: Copilot branches from
mainand opens PR targetingmain, ignoring thebase-branch: "develop"configuration.References
base-branchsupport toassign-to-agentfor cross-repo PR creation #17133 — Current (broken) implementationbaseReffieldbaseRefusage examples