[q] Fix safe-output jobs running when workflow is cancelled #2891
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
agentjob: skipped (never ran)detectionjob: skipped (never ran)create_issuejob: Started running and failedENOENT: no such file or directory, open '/tmp/gh-aw/safeoutputs/agent_output.json'Root Cause
The condition
if: (!cancelled())evaluates totruewhen dependency jobs are skipped (which happens during workflow cancellation). GitHub Actions treats "skipped" differently from "cancelled".Current Behavior
When a workflow is cancelled:
!cancelled()returnstrue(workflow itself wasn't cancelled, just stopped)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
This ensures:
agentsucceedsagentfails (for error reporting)agentis skipped (workflow cancelled)Changes
Modified Files
pkg/workflow/expressions.go- UpdatedBuildSafeOutputType()to include agent skipped checkpkg/workflow/expressions_cancelled_test.go- Updated test expectationspkg/workflow/safe_outputs_min_condition_test.go- Updated test expectationsCode Changes
Impact
This fix applies to all safe-output jobs:
create_issueadd_commentcreate_pull_requestcreate_pull_request_review_commentupdate_issuecreate_discussioncreate_agent_taskadd_labelspush_to_pull_request_branchupload_assetmissing_toolAfter 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 checkTestSafeOutputConditionWithMin- Verifies condition with min > 0 includes agent skipped checkTestBuildSafeOutputTypeWithMin- Direct function testingTestMinConditionInCompiledWorkflow- End-to-end workflow compilation testRelated
Fixes #2890