Skip to content

Treat non-waiting workflow runs as skipped in approve_workflow_run - #54895

Open
pelikhan with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-9919-1036865607-26ec1918-ae7d-4678-939d-b60348abbd40
Open

Treat non-waiting workflow runs as skipped in approve_workflow_run#54895
pelikhan with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-9919-1036865607-26ec1918-ae7d-4678-939d-b60348abbd40

Conversation

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

PR Sous Chef's Process Safe Outputs step has been failing ~8% of runs, generating a steady stream of duplicate [aw] Failed jobs issues. The suspected cause was a whole-batch validation abort, but the logs from run 32543132845 show something narrower.

Root cause

##[error]6 safe output(s) failed:
  - approve_workflow_run: Workflow run 32542848528 is not awaiting approval (status: completed)
  - approve_workflow_run: Workflow run 32542848455 is not awaiting approval (status: completed)
  ... (6 total, all approve_workflow_run)

The per-item loop in safe_output_handler_manager.cjs already degrades gracefully — every item is processed, which is why Upload Safe Outputs Items still succeeds. The bug is item classification, not batch abort.

approve_workflow_run returned a fatal failure whenever the target run was no longer in waiting. On a 15-minute cadence this is a routine race: by the time the safe_outputs job runs, the run has usually already been approved by a human or by an earlier PR Sous Chef run. Nothing is left to do, yet the hard failure fed core.setFailed and failed the step.

Changes

  • actions/setup/js/approve_workflow_run.cjs
    • run.status !== "waiting" now returns a skipped result so the manager's existing result.skipped === true branch reports it in the summary without failing the step.
    • Max-count-reached now uses the same result shape as other handlers (add_comment, create_issue): skipped: true + reasonCode: "MAX_COUNT_REACHED".
  • actions/setup/js/approve_workflow_run.test.cjs — assertions updated for both result shapes.
if (run.status !== "waiting") {
  const reason = `Workflow run ${runId} is not awaiting approval (status: ${run.status || "none"})`;
  core.warning(reason);
  return { success: false, skipped: true, reasonCode: "NOT_AWAITING_APPROVAL", reason, error: reason };
}

Genuine authorization and configuration errors — fork without fork: true, protected file changes, disallowed workflow, unauthorized PR, API errors — remain fatal.

Copilot AI and others added 2 commits August 22, 2026 18:57
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Copilot Request Treat non-waiting workflow runs as skipped in approve_workflow_run Aug 22, 2026
Copilot AI requested a review from pelikhan August 22, 2026 19:01
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot approve workflow run only applies to "action_required" state

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot approve workflow run only applies to "action_required" state

Good catch — the handler was gating on status === "waiting" only, so runs held in the action-required state were never approvable at all.

Fixed in a0d1b9d with an isAwaitingApproval() helper that accepts status: "action_required" (the state the fork-PR approval endpoint applies to), plus status: "waiting" and conclusion: "action_required" for runs GitHub reports as completed while pending the approval decision. Test fixtures now default to action_required, with added cases for the other two shapes. Reference docs, glossary, spec, and the agent-facing tool description in safe_outputs_tools.json were updated to match.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot this is not just for forks, it is also happening for agent-initiated PRs like copilot/* PRs.

Check current PRs and review workflow runs. You should find runs n the action required state.

Extend the safe output to only consider PRs from this repo by default.

Workflows from forks must be explicitely allowed in allowed-repos list. (Defaults to current repo)

Copilot AI and others added 2 commits August 22, 2026 21:21
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot this is not just for forks, it is also happening for agent-initiated PRs like copilot/* PRs.

Check current PRs and review workflow runs. You should find runs n the action required state....

Confirmed from the Actions API: runs in the action-required state include same-repo agent PRs (e.g. copilot/fix-github-actions-job-failure on run 32598809282, conclusion: action_required), not just forks.

Replaced the boolean fork option with an allowed-repos allowlist:

  • The handler now resolves each associated PR's head.repo.full_name instead of the misleading head.repo.fork flag (which is true for same-repo PRs inside a forked repository).
  • The current repository is always allowed, so copilot/* and other in-repo branches are approvable by default.
  • PRs from any other repository (forks) are refused unless their slug matches an allowed-repos entry; wildcards such as org/* are supported. The rejection message names the head repo and points to allowed-repos.
  • fork: is removed from the schema, Go config, handler config, docs (reference, glossary, spec, automation guide), and pr-sous-chef.md; workflows recompiled.

@pelikhan
pelikhan marked this pull request as ready for review August 22, 2026 22:08
Copilot AI balanced review requested due to automatic review settings August 22, 2026 22:08
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts on this branch.

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

@pelikhan Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 87ab1ef2-4dbe-4dea-8da7-644c6ed9b43d

Sorry for the inconvenience!

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.

Pull request overview

Makes workflow-run approval races non-fatal while introducing repository-scoped fork authorization.

Changes:

  • Classifies non-awaiting runs and max-limit cases as skipped.
  • Replaces fork with allowed-repos.
  • Updates tests, schemas, documentation, and generated workflow output.
Show a summary per file
File Description
pkg/workflow/safe_outputs_handler_registry.go Emits allowed repositories.
pkg/workflow/js/safe_outputs_tools.json Updates tool description.
pkg/workflow/approve_workflow_run.go Parses allowed repositories.
pkg/workflow/approve_workflow_run_test.go Updates parser tests.
pkg/workflow/approve_workflow_run_integration_test.go Verifies generated configuration.
pkg/parser/schemas/main_workflow_schema.json Replaces the fork schema option.
docs/src/content/docs/specs/safe-outputs-specification.md Updates approval requirements.
docs/src/content/docs/reference/safe-outputs-pull-requests.md Documents new behavior.
docs/src/content/docs/reference/glossary.md Updates the glossary entry.
docs/src/content/docs/reference/frontmatter-full.md Updates frontmatter reference.
actions/setup/js/safe_outputs_tools.json Updates runtime tool description.
actions/setup/js/approve_workflow_run.test.cjs Covers states and repository allowlists.
actions/setup/js/approve_workflow_run.cjs Implements skipping and repository checks.
.github/workflows/pr-sous-chef.md Removes obsolete fork configuration.
.github/workflows/pr-sous-chef.lock.yml Regenerates compiled workflow output.
.github/skills/agentic-workflows/SKILL.md Removes an unrelated routing entry.
.github/aw/safe-outputs-automation.md Updates automation guidance.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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

Comment on lines +283 to +290
if (!isAwaitingApproval(run)) {
// Benign race: by the time the safe_outputs job runs, the workflow run may have
// already been approved (by a human or an earlier run) and moved past the
// pending-approval state. There is nothing left to do, so report this as a skipped
// no-op instead of a failure that would fail the whole safe outputs step.
const reason = `Workflow run ${runId} is not awaiting approval (status: ${run.status || "none"})`;
core.warning(reason);
return { success: false, skipped: true, reasonCode: "NOT_AWAITING_APPROVAL", reason, error: reason };
Comment on lines +7153 to +7159
"allowed-repos": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"description": "Repositories in format 'owner/repo' whose pull requests may have their workflow runs approved, in addition to the current repository which is always allowed. Use this to allow fork pull requests. Supports wildcard patterns such as 'org/*'."
@@ -103,6 +103,5 @@ After loading the matching workflow prompt or skill, follow it directly:
- Choose workflow architecture and patterns: `.github/aw/patterns.md`
- Optimize token usage and cost: `.github/aw/token-optimization.md`
- Design long-running multi-agent research workflows: `.github/aw/multi-agent-research.md`
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.

[deep-report] PR Sous Chef: safe_outputs step fails whole batch on one invalid item (recurring, prior fix didn't stick)

3 participants