Skip to content

Default stacked PR runs to top-of-stack with configurable on.pull_request.max-stack - #49420

Merged
pelikhan merged 3 commits into
mainfrom
copilot/update-max-stack-on-pull-request
Aug 1, 2026
Merged

Default stacked PR runs to top-of-stack with configurable on.pull_request.max-stack#49420
pelikhan merged 3 commits into
mainfrom
copilot/update-max-stack-on-pull-request

Conversation

CopilotAI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Agentic workflows currently run on every PR in a stack, which multiplies CI cost. This change adds stack-aware gating so workflows default to running only on the latest stack layer, with an explicit frontmatter override.

  • Frontmatter contract (on.pull_request)

    • Added max-stack to workflow schema.
    • Semantics:
      • default: 1 (run only top/latest PR in a stack)
      • N > 1: run on top N stack layers
      • -1: disable stack protection (run all layers)
  • Compiler behavior

    • Added pull-request stack filter in workflow condition generation.
    • Applied filter only when pull_request trigger is present.
    • Condition allows non-stacked PRs and non-PR events unchanged.
  • Generated workflow readability

    • Updated on: cleanup/commenting to mark max-stack as compiler-applied (like other derived trigger filters), so lock output remains clear about source-of-truth behavior.
  • Coverage updates

    • Added focused tests for default behavior, custom max-stack, disable mode (-1), and trigger-shape handling (on: pull_request vs object form).
on:
pull_request:
types: [opened, synchronize]max-stack: 2# run only on top 2 PRs in a stack; use -1 to disable

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

run: https://github.com/github/gh-aw/actions/runs/30676859249

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.7 AIC · ⊞ 5.7K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title Run stacked PR workflows on latest layer by defaultDefault stacked PR runs to top-of-stack with configurable on.pull_request.max-stackJul 31, 2026
CopilotAI requested a review from pelikhanJuly 31, 2026 22:15
@pelikhan
pelikhan marked this pull request as ready for review August 1, 2026 00:49
CopilotAI review requested due to automatic review settings August 1, 2026 00:49

CopilotAI 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.

Pull request overview

Adds configurable stack-aware gating for pull-request workflows, defaulting execution to the top PR.

Changes:

  • Adds the on.pull_request.max-stack schema and compiler filter.
  • Comments compiler-processed configuration in generated YAML.
  • Adds unit coverage and recompiles affected workflows.
Show a summary per file
FileDescription
pkg/workflow/frontmatter_on_section_cleanup.goComments processed max-stack fields.
pkg/workflow/filters.goImplements stack gating.
pkg/workflow/filters_stack_test.goTests stack-filter configurations.
pkg/workflow/compiler_orchestrator_workflow.goInvokes stack filtering.
pkg/parser/schemas/main_workflow_schema.jsonDefines max-stack.
.github/workflows/visual-regression-checker.lock.ymlAdds generated stack conditions.
.github/workflows/test-quality-sentinel.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-update-cross-repo-pr.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-test-tools.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-temporary-id.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-project.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-pi.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-opencode.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-multi-pr.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-gemini.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-create-cross-repo-pr.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-copilot-arm.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-codex.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-claude.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-ci.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-call-workflow.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-antigravity.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-agent-scoped-approved.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-agent-public-none.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-agent-public-approved.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-agent-all-none.lock.ymlAdds generated stack conditions.
.github/workflows/smoke-agent-all-merged.lock.ymlAdds generated stack conditions.
.github/workflows/refiner.lock.ymlAdds generated stack conditions.
.github/workflows/pr-description-caveman.lock.ymlAdds generated stack conditions.
.github/workflows/pr-code-quality-reviewer.lock.ymlAdds generated stack conditions.
.github/workflows/mattpocock-skills-reviewer.lock.ymlAdds generated stack conditions.
.github/workflows/impeccable-skills-reviewer.lock.ymlAdds generated stack conditions.
.github/workflows/firewall-escape.lock.ymlAdds generated stack conditions.
.github/workflows/design-decision-gate.lock.ymlAdds generated stack conditions.
.github/workflows/changeset.lock.ymlAdds generated stack conditions.
.github/workflows/ai-moderator.lock.ymlAdds generated stack conditions.

Review details

Tip

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

  • Files reviewed: 36/36 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment on lines +948 to +950
"type": "integer",
"minimum": -1,
"description": "Maximum number of top stack layers to run on for stacked pull requests. Default is 1 (only the latest/top pull request in the stack). Set to -1 to disable stack protection and run on every pull request in the stack."

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed. Changed max-stack schema from {"type":"integer","minimum":-1} to an anyOf that accepts only const: -1 or minimum: 1, so 0, -2, and other invalid values are now rejected with a schema validation error. Schema tests covering rejection of 0 and -2 added in pkg/parser/schema_location_test.go.

Comment threadpkg/workflow/filters.go Outdated
}

stackCondition := fmt.Sprintf(
"github.event_name != 'pull_request' || github.event.pull_request.stack == null || github.event.pull_request.stack.position + %d > github.event.pull_request.stack.size",

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed. GitHub Actions expressions don't support arithmetic operators, so the generated if: condition was rewritten:

  • max-stack: 1 (default): Uses github.event.pull_request.stack.position == github.event.pull_request.stack.size (equality only — always a supported operator). All 266 lock files have been recompiled with this corrected expression.
  • max-stack: N > 1: Instead of arithmetic in if:, injects a pre-steps bash step that computes size - position < N via shell arithmetic and exits 1 if the PR is not in the top-N layers. This keeps the job-level if: free of arithmetic.

Integration tests in pkg/workflow/filters_stack_integration_test.go (build-tagged integration) verify that no arithmetic operators appear in the compiled job-level if: conditions.

"max-stack": {
"type": "integer",
"minimum": -1,
"description": "Maximum number of top stack layers to run on for stacked pull requests. Default is 1 (only the latest/top pull request in the stack). Set to -1 to disable stack protection and run on every pull request in the stack."

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Added. A "Stacked PR Filtering (max-stack:)" subsection has been added to docs/src/content/docs/reference/triggers.md in the Pull Request Triggers section. It covers default behavior (run only the top PR), custom N (max-stack: 2), the disable mode (max-stack: -1), and explains why lower stack layers are skipped.

@github-actions

Copy link
Copy Markdown
Contributor

test body

Generated by 🔧 PR Triage Agent · auto · 44.8 AIC · ⌖ 5.88 AIC · ⊞ 7.9K ·

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: feature
  • Risk: medium
  • Priority: 60/100
  • Action: fast_track

Generated by 🔧 PR Triage Agent · auto · 44.8 AIC · ⌖ 5.88 AIC · ⊞ 7.9K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot Please address the outstanding review feedback, refresh the branch, and run the pr-finisher skill before handing back for maintainer review.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.7 AIC · ⊞ 5.7K ·
Comment /souschef to run again

@github-actions

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Hey @pelikhan 👋 — Thanks for implementing stack-aware gating for agentic workflows! This addresses the real cost multiplier from workflows running on every layer of a PR stack. The feature is well-scoped, the schema contract is clear (max-stack: 1 by default, -1 to disable), and the compiler logic is clean.

✅ Tests are in place for default behavior, custom values, and disable mode.
✅ Description is thorough with a concrete YAML example.
✅ Lock files are properly generated (36 workflow artifacts updated).
✅ No new external dependencies.

This looks ready for review and merge.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • patchdiff.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
allowed:
- defaults
- "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by ✅ Contribution Check · auto · 60 AIC · ⊞ 8.7K ·

…ema, add docs
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

CopilotAI commented Aug 1, 2026

Copy link
Copy Markdown
ContributorAuthor

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Addressed all three review items in the latest commit:

  1. Schema — reject max-stack: 0: Changed the max-stack schema definition from {"type": "integer", "minimum": -1} to an anyOf that accepts only const: -1 or minimum: 1, so 0 and negative integers other than -1 are now rejected. Tests added in schema_location_test.go.

  2. Arithmetic operator fix: GitHub Actions expressions don't support +. Fixed by:

    • max-stack: 1 (default) — uses position == size (equality, supported) in the job-level if:. All 266 lock files recompiled with this corrected expression.
    • max-stack: N > 1 — injects a PreStep that uses bash arithmetic via env vars to compute the check. The step exits 1 if the PR is not in the top-N layers, blocking subsequent default-condition steps. Integration tests in filters_stack_integration_test.go verify no arithmetic appears in the job-level if:.
  3. Documentation: Added a "Stacked PR Filtering (max-stack:)" subsection to docs/src/content/docs/reference/triggers.md under Pull Request Triggers, with examples for the default (max-stack: 1), custom N (max-stack: 2), and disable (max-stack: -1) cases.

CopilotAI requested a review from gh-aw-botAugust 1, 2026 01:48
@pelikhan
pelikhan merged commit 184c9d1 into mainAug 1, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/update-max-stack-on-pull-request branch August 1, 2026 01:51
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.2

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@gh-aw-bot@pelikhan