Skip to content

Conversation

@github-actions
Copy link
Contributor

Problem

Safe-output jobs (create_issue, add_comment, etc.) were running even when the workflow was cancelled, causing failures due to missing artifacts.

Example

In workflow run #18982474915:

  • Workflow was cancelled via GitHub Actions UI
  • agent job: skipped (never ran)
  • detection job: skipped (never ran)
  • create_issue job: Started running and failed
    • Error: ENOENT: no such file or directory, open '/tmp/gh-aw/safeoutputs/agent_output.json'

Root Cause

The condition if: (!cancelled()) evaluates to true when dependency jobs are skipped (which happens during workflow cancellation). GitHub Actions treats "skipped" differently from "cancelled".

Current Behavior

create_issue:
  needs: [agent, detection]
  if: (!cancelled())  # ⚠️ Returns true when dependencies are skipped!

When a workflow is cancelled:

  1. Dependencies get skipped (not cancelled)
  2. !cancelled() returns true (workflow itself wasn't cancelled, just stopped)
  3. Job starts running even though dependencies never completed
  4. Fails because required artifacts don't exist

Solution

Add a check for needs.agent.result != 'skipped' to prevent safe-output jobs from running when the agent job was skipped due to workflow cancellation.

New Condition

if: (!cancelled()) && (needs.agent.result != 'skipped')

This ensures:

  • ✅ Runs when agent succeeds
  • ✅ Runs when agent fails (for error reporting)
  • ❌ Does NOT run when agent is skipped (workflow cancelled)

Changes

Modified Files

  • pkg/workflow/expressions.go - Updated BuildSafeOutputType() to include agent skipped check
  • pkg/workflow/expressions_cancelled_test.go - Updated test expectations
  • pkg/workflow/safe_outputs_min_condition_test.go - Updated test expectations

Code Changes

// Before
notCancelledFunc := &NotNode{
    Child: BuildFunctionCall("cancelled"),
}

// After  
notCancelledFunc := &NotNode{
    Child: BuildFunctionCall("cancelled"),
}

agentNotSkipped := &ComparisonNode{
    Left:     BuildPropertyAccess("needs.agent.result"),
    Operator: "!=",
    Right:    BuildStringLiteral("skipped"),
}

baseCondition := &AndNode{
    Left:  notCancelledFunc,
    Right: agentNotSkipped,
}

Impact

This fix applies to all safe-output jobs:

  • create_issue
  • add_comment
  • create_pull_request
  • create_pull_request_review_comment
  • update_issue
  • create_discussion
  • create_agent_task
  • add_labels
  • push_to_pull_request_branch
  • upload_asset
  • missing_tool

After this change, these jobs will properly skip when the workflow is cancelled, preventing spurious failures.

Testing

Updated unit tests to expect the new condition pattern:

  • TestBuildSafeOutputTypeWithCancelled - Verifies new condition includes agent skipped check
  • TestSafeOutputConditionWithMin - Verifies condition with min > 0 includes agent skipped check
  • TestBuildSafeOutputTypeWithMin - Direct function testing
  • TestMinConditionInCompiledWorkflow - End-to-end workflow compilation test

Related

Fixes #2890

AI generated by Q

Issue: Safe-output jobs (create_issue, add_comment, etc.) were running even
when the workflow was cancelled, causing failures due to missing artifacts.

Root Cause: The condition 'if: (!cancelled())' evaluates to true when
dependency jobs are skipped (which happens during workflow cancellation).
GitHub Actions treats 'skipped' differently from 'cancelled'.

Solution: Add check for 'needs.agent.result != "skipped"' to prevent
safe-output jobs from running when the agent job was skipped due to
workflow cancellation.

This ensures:
- ✅ Runs when agent succeeds
- ✅ Runs when agent fails (for error reporting)
- ❌ Does NOT run when agent is skipped (workflow cancelled)

Related: #2890
@pelikhan
Copy link
Contributor

@copilot make sure safe output jobs also check that their output type is present in the outputs of the agent

Copy link
Contributor

Copilot AI commented Oct 31, 2025

@pelikhan I've opened a new pull request, #2893, to work on those changes. Once the pull request is ready, I'll request review from you.

@pelikhan pelikhan merged commit 07902a4 into main Oct 31, 2025
10 of 13 checks passed
@pelikhan pelikhan deleted the fix/safe-outputs-skip-on-cancel-9216d19286161389 branch October 31, 2025 19:57
Sign up for free to 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.

2 participants