From 15c47753abe5b84f3397635f763553e7f9cd34ab Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 2 Apr 2026 13:50:50 +0000
Subject: [PATCH 1/2] Initial plan
From e5743f750d0db6ca6576a439c7b3aa8bd4c49871 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 2 Apr 2026 14:12:21 +0000
Subject: [PATCH 2/2] fix: create_pull_request branch guidance, PR-comment tool
selection, shallow clone fallback
- Issue 1: Strengthen branch name guidance in safe_outputs_create_pull_request.md
to make clear the branch parameter must match git branch --show-current exactly
- Issue 2: Add pr_context_push_to_pr_branch_guidance.md with guidance to prefer
push_to_pull_request_branch over create_pull_request when triggered by a PR comment.
Inject it conditionally when push-to-pull-request-branch is configured.
- Issue 3: Fetch base commit before git cat-file -e in create_pull_request.cjs
fallback path to handle shallow clone (fetch-depth: 1) environments.
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/507fdac8-ffba-44f8-9607-afd77e808000
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
---
.github/workflows/craft.lock.yml | 3 +++
.github/workflows/mergefest.lock.yml | 3 +++
.github/workflows/poem-bot.lock.yml | 3 +++
.github/workflows/tidy.lock.yml | 3 +++
actions/setup/js/create_pull_request.cjs | 10 ++++++++++
.../md/pr_context_push_to_pr_branch_guidance.md | 4 ++++
actions/setup/md/safe_outputs_create_pull_request.md | 4 +++-
pkg/workflow/prompt_constants.go | 1 +
pkg/workflow/unified_prompt_step.go | 12 ++++++++++++
9 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 actions/setup/md/pr_context_push_to_pr_branch_guidance.md
diff --git a/.github/workflows/craft.lock.yml b/.github/workflows/craft.lock.yml
index 8b750c1a732..ae1e4710e52 100644
--- a/.github/workflows/craft.lock.yml
+++ b/.github/workflows/craft.lock.yml
@@ -216,6 +216,9 @@ jobs:
if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_prompt.md"
fi
+ if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
+ cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_push_to_pr_branch_guidance.md"
+ fi
cat << 'GH_AW_PROMPT_4438e0d43626c214_EOF'
{{#runtime-import .github/workflows/craft.md}}
diff --git a/.github/workflows/mergefest.lock.yml b/.github/workflows/mergefest.lock.yml
index efd4d090df9..6e30472dcb7 100644
--- a/.github/workflows/mergefest.lock.yml
+++ b/.github/workflows/mergefest.lock.yml
@@ -219,6 +219,9 @@ jobs:
if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_prompt.md"
fi
+ if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
+ cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_push_to_pr_branch_guidance.md"
+ fi
cat << 'GH_AW_PROMPT_c0b73803c180c67c_EOF'
{{#runtime-import .github/workflows/mergefest.md}}
diff --git a/.github/workflows/poem-bot.lock.yml b/.github/workflows/poem-bot.lock.yml
index 5133053e728..4275915c2ca 100644
--- a/.github/workflows/poem-bot.lock.yml
+++ b/.github/workflows/poem-bot.lock.yml
@@ -245,6 +245,9 @@ jobs:
if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_prompt.md"
fi
+ if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
+ cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_push_to_pr_branch_guidance.md"
+ fi
cat << 'GH_AW_PROMPT_5fc315a4df6b25f8_EOF'
{{#runtime-import .github/workflows/shared/reporting.md}}
diff --git a/.github/workflows/tidy.lock.yml b/.github/workflows/tidy.lock.yml
index 0d4da5b4ebb..a28915c0bb7 100644
--- a/.github/workflows/tidy.lock.yml
+++ b/.github/workflows/tidy.lock.yml
@@ -238,6 +238,9 @@ jobs:
if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_prompt.md"
fi
+ if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
+ cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_push_to_pr_branch_guidance.md"
+ fi
cat << 'GH_AW_PROMPT_7566e6fbf25b1c24_EOF'
{{#runtime-import .github/workflows/tidy.md}}
diff --git a/actions/setup/js/create_pull_request.cjs b/actions/setup/js/create_pull_request.cjs
index 07cf883f82f..e606522c3d7 100644
--- a/actions/setup/js/create_pull_request.cjs
+++ b/actions/setup/js/create_pull_request.cjs
@@ -895,6 +895,16 @@ gh pr create --title '${title}' --base ${baseBranch} --head ${branchName} --repo
} else {
core.info(`Original base commit from patch generation: ${originalBaseCommit}`);
+ // In shallow clones (fetch-depth: 1) the base commit may not be locally available.
+ // Attempt to fetch it explicitly before checking whether it exists.
+ try {
+ await exec.exec("git", ["fetch", "origin", originalBaseCommit, "--depth=1"]);
+ } catch (fetchError) {
+ // Non-fatal: the commit may already be available, or the server may not support
+ // fetching individual SHAs (e.g. some GHE configurations). Log for troubleshooting.
+ core.info(`Note: could not fetch base commit ${originalBaseCommit} explicitly (${fetchError instanceof Error ? fetchError.message : String(fetchError)}); will verify local availability next`);
+ }
+
// Verify the base commit is available in this repo (may not exist cross-repo)
await exec.exec("git", ["cat-file", "-e", originalBaseCommit]);
core.info("Original base commit exists locally - proceeding with fallback");
diff --git a/actions/setup/md/pr_context_push_to_pr_branch_guidance.md b/actions/setup/md/pr_context_push_to_pr_branch_guidance.md
new file mode 100644
index 00000000000..a6bd1ba36ae
--- /dev/null
+++ b/actions/setup/md/pr_context_push_to_pr_branch_guidance.md
@@ -0,0 +1,4 @@
+
+
+When triggered by a pull request comment, if you need to push code changes, prefer using `push_to_pull_request_branch` to add commits to the existing pull request branch rather than `create_pull_request` which opens a separate new pull request. Only use `create_pull_request` if the instructions explicitly ask you to create a new, separate pull request.
+
diff --git a/actions/setup/md/safe_outputs_create_pull_request.md b/actions/setup/md/safe_outputs_create_pull_request.md
index 632c252ef50..4f04568f248 100644
--- a/actions/setup/md/safe_outputs_create_pull_request.md
+++ b/actions/setup/md/safe_outputs_create_pull_request.md
@@ -3,7 +3,9 @@
To create a pull request:
1. Make any file changes directly in the working directory.
-2. If you haven't done so already, create a local branch using an appropriate unique name.
+2. If you haven't done so already, create a new local branch using `git checkout -b ` with an appropriate unique name.
3. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Verify you haven't deleted or changed any files you didn't intend to.
4. Do not push your changes. That will be done by the tool.
5. Create the pull request with the create_pull_request tool from safeoutputs.
+
+**Important**: The `branch` parameter in the create_pull_request tool **must exactly match the name of your current local git branch** — the branch you just committed to. You can verify this with `git branch --show-current`. Never invent or guess a branch name; always use the actual branch name from `git branch --show-current`. If you are on an existing branch (e.g. you checked out a PR branch), use that branch name.
diff --git a/pkg/workflow/prompt_constants.go b/pkg/workflow/prompt_constants.go
index a29a759da88..6e56b519eed 100644
--- a/pkg/workflow/prompt_constants.go
+++ b/pkg/workflow/prompt_constants.go
@@ -10,6 +10,7 @@ import (
const (
promptsDir = constants.GhAwRootDirShell + "/prompts"
prContextPromptFile = "pr_context_prompt.md"
+ prContextPushToPRBranchGuidanceFile = "pr_context_push_to_pr_branch_guidance.md"
tempFolderPromptFile = "temp_folder_prompt.md"
playwrightPromptFile = "playwright_prompt.md"
qmdPromptFile = "qmd_prompt.md"
diff --git a/pkg/workflow/unified_prompt_step.go b/pkg/workflow/unified_prompt_step.go
index 60669144fca..3de37295505 100644
--- a/pkg/workflow/unified_prompt_step.go
+++ b/pkg/workflow/unified_prompt_step.go
@@ -272,6 +272,18 @@ func (c *Compiler) collectPromptSections(data *WorkflowData) []PromptSection {
ShellCondition: shellCondition,
EnvVars: envVars,
})
+
+ // When push_to_pull_request_branch is configured, add guidance to prefer it over
+ // create_pull_request when the workflow was triggered by a PR comment.
+ if data.SafeOutputs != nil && data.SafeOutputs.PushToPullRequestBranch != nil {
+ unifiedPromptLog.Print("Adding push-to-PR-branch tool preference guidance for PR comment context")
+ sections = append(sections, PromptSection{
+ Content: prContextPushToPRBranchGuidanceFile,
+ IsFile: true,
+ ShellCondition: shellCondition,
+ EnvVars: envVars,
+ })
+ }
}
return sections