safe_outputs and detection still run when the agent job fails; no supported way for a gate to block publication
Problem
When the agent job fails, detection and safe_outputs still run on whatever output was staged, and there is no supported way for a deterministic gate to stop publication. In the compiled lock (v1.2.0, the same in v1.2.2):
detection:
needs: [activation, agent]
if: always() && needs.agent.result != 'skipped'
safe_outputs:
needs: [activation, agent, detection]
if: (!cancelled()) && needs.agent.result != 'skipped' && needs.detection.result == 'success'
So a step in the agent job that finds something that must not post and fails the job (for example a post-steps check for a credential-shaped value, or a command that would trigger other automation when posted as a comment) does not prevent safe_outputs from posting the staged agent_output.json. The failure only shows on the agent job. The condition needs.agent.result != 'skipped' is true for a failed job.
Why we hit it
We run a deterministic gate after the agent that scans the staged output for content that must never be posted. When it finds something it has to empty the staged files itself, because failing the step does not stop safe_outputs. If emptying fails (for example the agent made a directory read-only), the content could still be posted. We fixed that case in our own scripts, but the root issue is that "this output must not be published" cannot be expressed to gh-aw.
The docs point to safe-outputs.jobs for custom processing and say not to read safe-output files from post-steps. That does not help for the built-in handlers (add-comment, update-issue, submit-pull-request-review, ...), which is where the content goes.
Proposal
An opt-in way to make safe_outputs require a healthy agent job, or an explicit block signal. Any of these would do:
safe-outputs.require-agent-success: true, which makessafe_outputs(anddetection, if wanted) requireneeds.agent.result == 'success'. Opt-in, because some workflows rely on safe outputs running after an agent failure (failure reports).- A supported gate step list, for example
safe-outputs.gate-steps:, run in the agent job after the agent and before output upload, whose failure marks the staged output as blocked so no safe-output job processes it. - An agent job output, set by a documented step output name (for example
block_safe_outputs=true), that the generatedif:ofdetectionandsafe_outputschecks.
Option 1 is the smallest. Happy to test on our workflows.