Skip to content

protected-files fallback-to-issue: include Closes #N in pre-filled compare URL so merging auto-closes the issue #32587

@kaovilai

Description

@kaovilai

Problem

When protected-files: { policy: fallback-to-issue } is configured and a PR touches a protected file, gh-aw creates a tracking issue with a compare URL like:

https://github.com/OWNER/REPO/compare/main...branch?expand=1&title=...

The user then manually opens a PR from that link. However, merging the PR does not auto-close the issue because the pre-filled PR body does not contain Closes #N.

The issue stays open and must be manually closed after merge.

Relationship to auto-close-issue

The existing auto-close-issue feature (default: true) on create-pull-request already solves this for issue-triggered workflows — it auto-appends Fixes #N to the PR body when the workflow trigger is an issue. From the docs:

By default, when a workflow is triggered from an issue, the create-pull-request handler automatically appends - Fixes #N to the PR description if no closing keyword is already present.

However, in the fallback-to-issue flow, the issue is created mid-run by the safe-outputs handler itself, not the workflow trigger. So auto-close-issue doesn't apply — there's no triggering issue at the time the compare URL is generated.

Current Flow (no structural change needed)

  1. Agent creates branch + commit
  2. Safe-outputs detects protected files → creates fallback issue (gets issue number)
  3. Compare URL is rendered into the issue body

At step 3, the issue number is already known. The only change needed is appending &body=Closes%20%23<issue_number> to the compare URL that's already being constructed.

Proposed Solution

Include a body query parameter in the compare URL:

https://github.com/OWNER/REPO/compare/main...branch?expand=1&title=...&body=Closes%20%23<issue_number>

When the user clicks the link and creates the PR, the body is pre-filled with Closes #N, and merging auto-closes the tracking issue. No flow restructuring required — just extend the URL that's already being built.

Context

Example issue created by the fallback flow: kaovilai/kaovilai#54

The compare URL has title pre-filled but no body.

Note

Responses generated with Claude

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions