Skip to content

safe_outputs and detection still run when the agent job fails; no supported way for a gate to block publication #77504

Done

Description

@ekbritecore

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:

  1. safe-outputs.require-agent-success: true, which makes safe_outputs (and detection, if wanted) require needs.agent.result == 'success'. Opt-in, because some workflows rely on safe outputs running after an agent failure (failure reports).
  2. 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.
  3. An agent job output, set by a documented step output name (for example block_safe_outputs=true), that the generated if: of detection and safe_outputs checks.

Option 1 is the smallest. Happy to test on our workflows.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions