Skip to content

Harden experimental pull request merging - #73922

Merged
pelikhan merged 7 commits into
mainfrom
pelikhan/harden-pr-merging
Nov 2, 2026
Merged

pelikhan merged 7 commits into
mainfrom
pelikhan/harden-pr-merging

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The experimental merge handler evaluated one PR head but merged without an expected-head SHA, and missing GraphQL review data could be interpreted as no blocking reviews. Workflows also had no explicit CI or independent human-approval requirement for eligible unprotected integration branches.

Approach

  • Bind the merge API call to the evaluated head SHA, without retrying the merge after a mismatch. Reject missing, malformed, incomplete, or stale review evidence, including invalid pagination.
  • Add workflow-owned required-checks and required-approvers. Named check runs must succeed on the evaluated revision. Approval requires at least one allowlisted human on that revision, excluding the PR author, bot accounts, and authenticated merge identity.
  • Revalidate mutable policy state before merges and staged previews, and return decision evidence with revisions, gate results, check-run IDs, and approval provenance.
  • Wire compiler configuration, schema validation, permissions, mirrored tool catalogs, and reference/specification documentation.
  • Grant live handlers checks: read for branch-derived requirements even without configured checks; revalidate asynchronous mergeability separately from stable authorization inputs, with bounded read retries.
  • Reject missing/ambiguous check producers and compiler-detected overlap with this workflow's agent-controlled create-check-run name. Review supersession uses validated submission times, not creation IDs, and missing/ambiguous ordering blocks authorization.
  • Mark results/evidence as untrusted data while retaining exact policy values and approval provenance. Minimize redundant label/pattern and raw API-error text in logs; verify empty check requirements cause no check-run reads or returned metadata in live/staged mode.
  • Synchronize compiler threat specification 1.0.81, its changelog, compatibility notes, and implementation/test mappings with the reviewed behavior.

The feature remains experimental. Existing targeting, repository allowlisting, max=1 default, protected/default branch refusal, open upstream PR requirement, and draft/conflict/reviewer/thread gates are preserved.

ADR: ADR-73922: Bind PR Merges to the Evaluated Head with Workflow-Owned Gates

Boundaries

The new CI and affirmative approval policies are opt-in; omitted policies do not imply successful CI or human authorization. Labels remain filters, not authorization. GitHub atomically enforces only the head SHA; other policy state retains a race window after final reads. Documentation explains credential separation, check-producer trust, and why reverting a merge does not undo downstream deployments or external effects.

No expected check producer is authenticated by name matching; ambiguous producers are rejected, but operators must protect CI publishers and workflow definitions. checks: read remains necessary for runtime-discovered requirements; an empty requirement union does not query check runs or imply successful CI.

Privacy-preserving debug records contain fixed events/phases, booleans, and counts, not identities, content, credentials, or raw errors. Label/pattern informational logs report counts; merge failure logs report status or phase while full diagnostics remain in untrusted results. These scoped controls do not establish that all operational logs or decision evidence are private, and data_trust: untrusted is advisory, not prompt-injection isolation or sanitization.

Validation

  • Latest mocked merge-handler and handler-manager suites: 277 passed, 3 skipped.
  • Relevant Go compiler, schema, and permission tests passed; build, typecheck, formatting, and changed-file lints passed. Full JavaScript lint completed with warnings and no errors. Compiler threat-spec mapping tests and the latest change-scoped pre-publication gate also passed.
  • Full workflow compilation succeeded, but the validation gate still reports pre-existing workflow-lock drift on main, including firewall 0.29.0 pins versus the existing 0.29.5 default. Generated lock files were restored and are not included.
  • No production merges or live workflow dispatches were performed.

Bind merges to evaluated head revisions, fail closed on incomplete review evidence, and add workflow-owned CI and independent approval controls with decision evidence and final revalidation.

Co-authored-by: Copilot App <[email protected]>
@pelikhan
pelikhan marked this pull request as ready for review November 2, 2026 01:28
Copilot AI adaptive review requested due to automatic review settings November 2, 2026 01:28
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

Document compiler and runtime evidence boundaries, opt-in CI and approval policies, revision binding, and residual trust risks in specification 1.0.81.

Co-authored-by: Copilot App <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · gpt56 · ~15 AIC · ⌖ ~6 AIC · ⊞ 15.1K · ◷

Generated by Ponytail Reviewer for #73922

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · sonnet50 · ~16 AIC · ⌖ ~16 AIC · ◇ ~8 AIC · ⊞ 12.7K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR adds 131 lines to business logic directories under pkg/ (the threshold is 100), and it doesn't link an Architecture Decision Record (ADR). I found no ADR in the PR body or in docs/adr/ on the branch.

📄 Draft ADR committed: docs/adr/73922-bind-pr-merges-to-evaluated-head-with-workflow-owned-gates.md. I generated it from the diff. Please review and complete it before merging.

The draft describes this decision: every merge_pull_request merge is bound to the head SHA that was evaluated, and the merge isn't retried on a mismatch. Missing or malformed review data blocks the merge. Two new opt-in frontmatter policies, required-checks and required-approvers, are set in the workflow and can't be changed by the agent. The handler rechecks all policy state before merging or producing a staged preview, and it returns decision_evidence.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff and spec changes.

  2. Complete the missing sections. Fill in Deciders (marked [TODO: verify]), refine the rationale, and check that the alternatives match the ones you actually considered. The draft lists three: relying on branch protection or rulesets, adding only SHA binding, and passing policy as tool-call arguments.

  3. Commit the finalized ADR to docs/adr/ on your branch.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-73922: Bind Experimental PR Merges to the Evaluated Head SHA with Workflow-Owned CI and Approval Gates (link unavailable: invalid HTTPS URL)

Once the ADR is linked in the PR body, this gate will run again and check that the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs keep a searchable, permanent record of why the code looks the way it does. Future contributors, including you, can look up the reasoning later.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide, and why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs, positive and negative?

ADRs are stored in docs/adr/ as Markdown files named by PR number (for example, 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: opus55 xhigh · ~50 AIC · ⌖ ~1 AIC · ⊞ 7.7K · ◷
Comment /review to run again

Log only fixed events and phases, counts, and booleans for merge evidence, revalidation, and outcomes. Cover identifier and error exclusion with mocked regression tests and document the debug-only privacy boundary.

Co-authored-by: Copilot App <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-02T01:39:00Z
review_event: REQUEST_CHANGES
top_themes: [checks permission mismatch, mergeability revalidation race]
files_reviewed: [actions/setup/js/merge_pull_request.cjs, actions/setup/js/merge_pull_request.test.cjs, actions/setup/js/safe_outputs_tools.json, docs/src/content/docs/reference/safe-outputs-pull-requests.md, docs/src/content/docs/specs/safe-outputs-specification.md, pkg/parser/schema_merge_pull_request_test.go, pkg/parser/schemas/main_workflow_schema.json, pkg/workflow/compiler_validators.go, pkg/workflow/merge_pull_request.go, pkg/workflow/safe_output_handlers.go, pkg/workflow/safe_outputs_handler_registry_pull_requests.go, pkg/workflow/safe_outputs_validation_merge_pull_request_test.go]
comment_count: 2

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~9 AIC · ⌖ ~1 AIC · ⊞ 1.7K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes

Two correctness issues should be fixed before merging:

Blocking findings
  • Branch-protection-required checks can trigger checks.listForRef without the checks: read permission when workflow-owned required-checks is omitted, causing unexpected 403 failures.
  • Final revalidation treats asynchronous mergeable recomputation as policy mutation, causing flaky false rejections.

Inline comments contain the required remediation and test guidance.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~9 AIC · ⌖ ~1 AIC · ⊞ 1.7K
Comment /review to run again

Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Comment thread actions/setup/js/merge_pull_request.cjs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd. The change is well tested and fails closed. Two notes, neither blocking.

📋 Verification and findings

Verified

  • Go suites pass: TestMainWorkflowSchema_MergePullRequestPolicies (pkg/parser) and TestMergePullRequest|TestValidateSafeOutputsMergePullRequest (pkg/workflow).
  • Check-read failures fail closed: the try around evaluateRequiredChecks catches errors and returns merge_operation_error.
  • Protected branches are refused before check evaluation, so branch-protection-derived checks never reach the checks: read permission path. No gap there.

Notes

  • Check-name collision (see inline comment on merge_pull_request.go). required-checks matches check-run names only. A create-check-run name that matches a required check would satisfy the gate. The agent cannot choose that name, since it comes from workflow config, so this needs a workflow author to configure both. Rejecting the overlap at compile time is a cheap hardening step.
  • Producer identity (see inline comment on merge_pull_request.cjs). Filtering by app.id would make the producer of a check run explicit. The docs already state that check names do not authenticate the producer, so this is optional.

Not verified

  • The JS suite merge_pull_request.test.cjs did not run. The npm registry TLS certificate is untrusted in this environment, so vitest is not installed. The JS behaviour is reviewed by reading only.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routing failed · ~10 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again

Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Comment thread pkg/workflow/merge_pull_request.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Review selection uses creation IDs rather than submission times, allowing a later-submitted change request to be ignored and a stale approval to authorize a merge when reviewDecision is null.

3 open issues
What changed in this PR

Hardens the experimental merge-pull-request safe output across the runtime and compiler while preserving existing repository and branch restrictions.

Changes:

  • Binds merges to the evaluated head SHA and adds fail-closed review reads and final policy revalidation.
  • Introduces optional workflow-owned CI and independent-approver requirements, plus structured decision evidence.
  • Updates configuration, permissions, regression coverage, tool descriptions, and documentation.
File Description
specs/​compiler-threat-detection-spec.md Defines merge authorization boundaries and evidence requirements.
specs/​compiler-threat-detection-changelog.md Records specification revision 1.0.81.
pkg/​workflow/​safe_outputs_validation_merge_pull_request_test.go Tests policy parsing, serialization, validation, and permissions.
pkg/​workflow/​safe_outputs_handler_registry_pull_requests.go Passes workflow-owned policies to the handler.
pkg/​workflow/​safe_output_handlers.go Adds conditional checks: read permission.
pkg/​workflow/​merge_pull_request.go Adds check and approver configuration and validation.
pkg/​workflow/​js/​safe_outputs_tools.json Updates the compiler-side merge tool description.
pkg/​workflow/​compiler_validators.go Integrates policy validation into compilation.
pkg/​parser/​schemas/​main_workflow_schema.json Defines the new frontmatter policy fields.
pkg/​parser/​schema_merge_pull_request_test.go Tests policy field schema constraints.
docs/​src/​content/​docs/​specs/​safe-outputs-specification.md Specifies merge gates, evidence, and operational limits.
docs/​src/​content/​docs/​reference/​safe-outputs-pull-requests.md Documents policy configuration and authorization boundaries.
actions/​setup/​js/​safe_outputs_tools.json Mirrors the updated runtime tool description.
actions/​setup/​js/​merge_pull_request.test.cjs Adds mocked merge-hardening regressions.
actions/​setup/​js/​merge_pull_request.cjs Implements revision binding, approval checks, revalidation, and evidence collection.

Review effort: Max (auto)

Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Grant check-read permissions for branch-derived requirements, separate asynchronous mergeability from stable policy inputs, and record the merge authorization decision.

Co-authored-by: Copilot App <[email protected]>
@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: No code change is needed for this completion notice. The two concrete findings from this review are addressed in their inline threads with focused regression coverage.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: No code change is needed for this status notice, which now reports that the skills review failed. I am not treating it as successful review or validation evidence.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: No code change is requested by this reported_no_action result. I am not treating that result as evidence that validation or publication succeeded.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: No code change is requested by this reported_no_action result. Focused mocked runtime and compiler tests passed rather than relying on this status as test evidence.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: The concrete ADR requirement below is addressed by adding the decision record and linking it in the PR body. This completion notice itself requires no separate code change.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Accepted: added and linked ADR-73922, covering the decision, alternatives, consequences, and remaining trust boundaries. No draft existed on the live branch, so the record was created without inventing named deciders or claiming maintainer approval.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Both recorded findings are addressed in their inline threads: check-read permissions now cover branch-derived requirements, and asynchronous mergeability is revalidated separately from stable authorization inputs. The fixes include focused regressions; this managed memory comment is left unchanged.

Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Reject ambiguous check producers and agent-controlled check overlap, order reviews by validated submission time, and designate returned metadata as untrusted without weakening exact policy comparisons or approval provenance.

Co-authored-by: Copilot App <[email protected]>
Comment thread actions/setup/js/merge_pull_request.cjs Resolved
Comment thread pkg/workflow/safe_output_handlers.go Resolved
Keep exact untrusted decision evidence and runtime check permissions while avoiding redundant metadata/error text in logs. Verify live and staged execution skip check reads when no requirements exist.

Co-authored-by: Copilot App <[email protected]>
@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Completion acknowledged; the concrete findings have separate fixes and regression coverage. No additional change is requested here.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: This review failed and is not successful validation evidence. No source change follows from this status alone.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: The reported_no_action outcome is not validation or publication proof. No additional source change is requested.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: This no-action notice does not establish test success. Focused regression results are separate evidence.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: The ADR exists and is linked in the PR body. This completion notice requires no separate change.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: ADR-73922 now exists with the requested sections and a PR-body link. It remains Draft pending maintainer review; named deciders or approval cannot be invented.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Both recorded findings have fixes and focused regressions on the current branch. The managed memory remains unchanged.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: this completion notice needs no additional change. The two concrete findings have separate inline responses and regressions.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: the failed review is not successful validation evidence. No additional change is needed for this status.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: reported_no_action is not validation or publication proof. No further source change is requested.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: focused regression coverage exists independently of the no-action notice. Validation results are not inferred from that notice.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: the ADR artifact exists and the PR body links it. No separate change is needed for the completion notice.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: the linked ADR covers the requested decision sections. Its status remains Draft with deciders unknown, not finalized or maintainer-approved.

@pelikhan

pelikhan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

In response to this comment: Confirmed: current code covers branch-derived check permissions and separately revalidates mergeability, with regressions. The managed memory remains untouched.

Correct check permission compatibility and map no-check reads, review ordering, check-name collisions, and scoped log minimization to the implemented regressions.

Co-authored-by: Copilot App <[email protected]>
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.0

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.

3 participants