Skip to content

Pipeline workflows silently mislabel a PR if the guard step itself fails, not just the agent step #231

Closed

Description

@libravault-xyz

What happened

Found by principal-review-agent while reviewing PR #229 (itself a
crash-handling fix for issue 227) — see that PR's review comment for the
full trace. Not a finding against PR #229 itself; a pre-existing gap in
all three pipeline workflows that PR happens to touch one instance of.

The gap

dev-agent.yml, qa-agent.yml, and principal-review.yml each have an
early "guard"/"Resolve target" step that runs under set -euo pipefail
with no continue-on-error: true. Their later "Advance PR based on
..." step is gated with a condition like:

if: steps.guard.outputs.skip != 'true' && !cancelled()

!cancelled() is what lets that step still run when the agent step
crashes (the intended, already-fixed case: issue 227 for
principal-review, and the equivalent pre-existing handling in the other
two files) — but it doesn't distinguish "agent step failed" from "guard
step itself failed" (e.g. a transient gh API error, hitting set -e
before the step writes any $GITHUB_OUTPUT at all).

If the guard step fails instead:

  1. steps.guard.outputs.skip was never written, so it reads as empty —
    '' != 'true' is true, same as a real skip=false.
  2. The agent step itself is correctly skipped (its own if has no
    override function, so it stays subject to the default "skip once the
    job is failing" behavior).
  3. But "Advance PR" does run (its !cancelled() override bypasses that
    same default). steps.agent.outcome reads "skipped", not
    "failure" — so the crash-handling branch (the one issue 227 added)
    doesn't fire.
  4. It falls through to the normal verdict-parsing path, finds no verdict
    file (the agent never ran), and silently defaults to whatever that
    workflow's no-verdict fallback is
    (human-merge for
    principal-review; check the equivalent fallback in the other two)
    with no PR comment explaining why — unlike every other path in
    these files, which all post an explanation.

Net effect: a transient guard-script hiccup silently mislabels a PR as
"reviewed" (or "needs-info"/whatever each file's fallback is) with zero
audit trail — arguably worse than the original stuck-and-silent bug these
crash-handling branches were built to prevent, just relocated to a
different, less-often-hit step.

Scope

Confirmed to exist in the same shape in all three workflows (grep for
!cancelled() next to a step whose only precondition is a guard-step
output) — not unique to principal-review.yml. A fix should cover all
three together so they don't drift.

Suggested fix (not prescriptive — a human/dev-agent should design this)

Options, roughly in order of how much they change existing behavior:

  1. Add continue-on-error: true to the guard step too, and have it
    explicitly write skip=true (or a distinct guard_failed=true
    output) in a trap/|| fallback on its own failure — the later step
    can then tell "guard genuinely said skip" apart from "guard crashed"
    and post its own explanatory comment for the latter.
  2. Give the "Advance PR" step's crash-branch condition an extra check
    for steps.guard.outcome == 'failure', not just
    steps.agent.outcome.
  3. At minimum, change each fallback path (the "no verdict found" default)
    to always post a comment when it fires, even in the currently-silent
    case — cheapest fix, doesn't fully close the gap but removes the
    "zero audit trail" part, which is the most concerning piece.

Activity

  1. added
    bug
    on Aug 17, 2026
  2. added
    status:ready-for-dev
    status:in-progress
    on Aug 17, 2026
  3. github-actions commented on Aug 17, 2026

    @github-actions
    Contributor

    Implementation blocked — not a scoping problem, a credential permission gap

    The fix is scoped and implemented (branch fix/guard-step-crash-mislabel off dev, commit locally), but I can't push it or open a PR: neither credential available to this agent has the workflows permission GitHub requires to push changes to files under .github/workflows/, which is unavoidable here since this issue lives entirely in dev-agent.yml/qa-agent.yml/principal-review.yml.

    Confirmed both fail with the same rejection:

    • Default GITHUB_TOKEN (github-actions[bot]): refusing to allow a GitHub App to create or update workflow .github/workflows/dev-agent.yml without workflows permission
    • Pipeline App token (libravault-pipeline-bot, via APP_GH_TOKEN): same rejection

    Per docs/agent-team-pipeline.md's "Cross-workflow triggering" section, the pipeline App is installed with "read/write on code, issues, and pull requests" — no explicit workflows permission was granted, so it hits the same GitHub-side restriction as GITHUB_TOKEN (this is a distinct restriction from the "Actions can't create/approve PRs" repo setting APP_GH_TOKEN already works around — GitHub gates any push that touches .github/workflows/** behind an explicit workflows scope/permission, regardless of contents: write). A human with a PAT that has the workflow OAuth scope (or by granting the GitHub App the workflows: write permission) can push this in seconds.

    The fix (tested: YAML-parses cleanly, every run: block passes bash -n)

    Root cause confirmed exactly as described in this issue: the "Advance PR"/"Force-classify risk" step in all three workflows runs on !cancelled() so it can still route an agent-step crash (steps.agent.outcome == 'failure') to a human — but that override also lets it run when the earlier guard step itself crashes before writing its skip output, which reads as empty and is indistinguishable from a real skip=false. That falls through to each workflow's silent no-verdict/no-comment default.

    Implemented option 2 from the issue body (add an explicit steps.guard.outcome == 'failure' check, mirroring the existing steps.agent.outcome check) rather than option 1 (restructuring the guard step's own error handling) — it closes the full gap (correct routing and an explanatory comment, not just the comment) with a much smaller diff, and doesn't touch the guard step's own continue-on-error semantics, which downstream steps like "Mint pipeline App token"/"Run dev agent" currently depend on implicitly (verified: those steps use plain if: steps.guard.outputs.skip != 'true' with no status-check-function override, so they already correctly stay skipped on a guard crash via GitHub's implicit success() gating — confirmed this stays true with the change below, since it never adds continue-on-error to the guard step itself).

    Each of the three "Advance PR"-style steps gets the same shape: a new check at the very top of the run: block, before any use of steps.guard.outputs.*, using only raw event context (github.event.pull_request.number / github.event.issue.number / github.event.inputs.*) since guard's own outputs may never have been written:

    if [ "${{ steps.guard.outcome }}" = "failure" ]; then
      PR_NUMBER="${{ github.event.pull_request.number || github.event.inputs.pr_number }}"  # or issue equivalent for dev-agent.yml's triage path
      echo "Guard step crashed while resolving PR #$PR_NUMBER — routing to status:needs-info instead of silently falling through to the ... default." >&2
      gh pr edit "$PR_NUMBER" --remove-label status:<needs-qa|needs-review|in-progress> || true
      gh pr edit "$PR_NUMBER" --add-label status:needs-info   # via APP_GH_TOKEN where the file's existing convention already does so
      gh pr comment "$PR_NUMBER" --body "The guard step ... crashed before it could finish — see the [workflow run](...). Routed to a human instead of silently advancing or falling through to a default."
      exit 0
    fi

    Full diff (104 lines across the three files):

    fix-231.diff
    diff --git a/.github/workflows/dev-agent.yml b/.github/workflows/dev-agent.yml
    index b941049..4908cc0 100644
    --- a/.github/workflows/dev-agent.yml
    +++ b/.github/workflows/dev-agent.yml
    @@ -381,6 +381,32 @@ jobs:
               APP_GH_TOKEN: ${{ steps.app-token.outputs.token }}
             run: |
               set -euo pipefail
    +
    +          # steps.guard.outputs.* are only trustworthy if the guard step
    +          # actually completed. If it crashed instead (e.g. a transient
    +          # `gh` API error hitting set -e before writing any output), this
    +          # step's own `if` above (`skip != 'true'`) can't tell that apart
    +          # from a real skip=false — steps.guard.outputs.skip just reads as
    +          # empty either way. Handle the crash first, using only raw event
    +          # context (never guard's own outputs, which may not have been
    +          # written at all), so this doesn't depend on how far guard got
    +          # before failing. See issue #231.
    +          if [ "${{ steps.guard.outcome }}" = "failure" ]; then
    +            if [ "${{ github.event_name }}" = "pull_request" ]; then
    +              PR_NUMBER="${{ github.event.pull_request.number }}"
    +              echo "Guard step crashed while resolving PR #$PR_NUMBER — routing to status:needs-info instead of silently falling through to the no-PR default." >&2
    +              gh pr edit "$PR_NUMBER" --remove-label status:in-progress || true
    +              gh pr edit "$PR_NUMBER" --add-label status:needs-info
    +              gh pr comment "$PR_NUMBER" --body "The guard step (resolving target/mode, checking status:blocked) crashed before it could finish — see the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). Routed to a human instead of silently advancing this PR or falling through to a default."
    +            else
    +              ISSUE_NUMBER="${{ github.event.issue.number || github.event.inputs.issue_number }}"
    +              echo "Guard step crashed while resolving issue #$ISSUE_NUMBER — routing to status:needs-info instead of silently falling through to the no-PR default." >&2
    +              gh issue edit "$ISSUE_NUMBER" --add-label status:needs-info
    +              gh issue comment "$ISSUE_NUMBER" --body "The guard step (resolving target/mode, checking status:blocked) crashed before it could finish — see the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). Routed to a human instead of silently advancing or falling through to a default."
    +            fi
    +            exit 0
    +          fi
    +
               ISSUE_NUMBER="${{ steps.guard.outputs.issue_number }}"
     
               PR_NUMBER=""
    diff --git a/.github/workflows/principal-review.yml b/.github/workflows/principal-review.yml
    index 1b2dd96..585b641 100644
    --- a/.github/workflows/principal-review.yml
    +++ b/.github/workflows/principal-review.yml
    @@ -224,9 +224,28 @@ jobs:
               GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
             run: |
               set -euo pipefail
    -          PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
               RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
     
    +          # steps.guard.outputs.* are only trustworthy if the guard step
    +          # actually completed. If it crashed instead (e.g. a transient
    +          # `gh` API error hitting set -e before writing any output), this
    +          # step's own `if` above (`skip != 'true'`) can't tell that apart
    +          # from a real skip=false — steps.guard.outputs.pr_number/skip
    +          # just read as empty either way. Handle the crash first, using
    +          # raw event context rather than guard's own (possibly-unwritten)
    +          # outputs. See issue #231.
    +          if [ "${{ steps.guard.outcome }}" = "failure" ]; then
    +            PR_NUMBER="${{ github.event.pull_request.number || github.event.inputs.pr_number }}"
    +            echo "Guard step crashed while resolving PR #$PR_NUMBER — routing to status:needs-info instead of silently falling through to the human-merge default." >&2
    +            gh pr edit "$PR_NUMBER" --remove-label status:needs-review || true
    +            gh pr edit "$PR_NUMBER" --add-label status:needs-info
    +            gh pr comment "$PR_NUMBER" --body "The guard step (checking status:blocked) crashed before it could finish — see the [workflow run]($RUN_URL). Routed to a human instead of silently advancing this PR or falling through to a default verdict."
    +            echo "verdict=guard-crashed" >> "$GITHUB_OUTPUT"
    +            exit 0
    +          fi
    +
    +          PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
    +
               # A genuine crash (max-turns exhausted, tool error) is a pipeline
               # failure, not a review verdict — there's no principal-verdict.txt
               # to trust either way, so route straight to a human instead of
    diff --git a/.github/workflows/qa-agent.yml b/.github/workflows/qa-agent.yml
    index 8e53a89..42ad5ce 100644
    --- a/.github/workflows/qa-agent.yml
    +++ b/.github/workflows/qa-agent.yml
    @@ -228,9 +228,27 @@ jobs:
               APP_GH_TOKEN: ${{ steps.app-token.outputs.token }}
             run: |
               set -euo pipefail
    -          PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
               RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
     
    +          # steps.guard.outputs.* are only trustworthy if the guard step
    +          # actually completed. If it crashed instead (e.g. a transient
    +          # `gh` API error hitting set -e before writing any output), this
    +          # step's own `if` above (`skip != 'true'`) can't tell that apart
    +          # from a real skip=false — steps.guard.outputs.pr_number/skip
    +          # just read as empty either way. Handle the crash first, using
    +          # raw event context rather than guard's own (possibly-unwritten)
    +          # outputs. See issue #231.
    +          if [ "${{ steps.guard.outcome }}" = "failure" ]; then
    +            PR_NUMBER="${{ github.event.pull_request.number || github.event.inputs.pr_number }}"
    +            echo "Guard step crashed while resolving PR #$PR_NUMBER — routing to status:needs-info instead of silently falling through to the no-verdict default." >&2
    +            gh pr edit "$PR_NUMBER" --remove-label status:needs-qa || true
    +            GH_TOKEN="$APP_GH_TOKEN" gh pr edit "$PR_NUMBER" --add-label status:needs-info
    +            gh pr comment "$PR_NUMBER" --body "The guard step (resolving the linked issue, checking status:blocked) crashed before it could finish — see the [workflow run]($RUN_URL). Routed to a human instead of silently advancing this PR or falling through to a default verdict."
    +            exit 0
    +          fi
    +
    +          PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
    +
               # A genuine crash (max-turns exhausted, tool error) is a pipeline
               # failure, not a QA finding — there's nothing for dev-agent's
               # automated retry to act on, so route straight to a human instead

    Recommend: a human applies this patch directly (or re-triggers this issue via workflow_dispatch after the pipeline App is granted workflows: write), then it just needs status:ready-for-dev re-applied to pick back up — no further design work needed, this is implementation-complete.

  4. added
    status:needs-info
    and removed
    status:in-progress
    on Aug 17, 2026
  5. removed
    status:ready-for-dev
    on Aug 17, 2026
  6. libravault-xyz commented on Aug 17, 2026

    @libravault-xyz
    CollaboratorAuthor

    Dev-agent's implementation was correct but blocked on the workflows permission gap (see its comment above). I reviewed the diff against the live files, applied it, and opened #235 to fix this directly, since .github/workflows/** is human-merge-only per agent-policy.yml regardless.

    Also dropping status:ready-for-dev here — it was left applied alongside status:needs-info when dev-agent's crash-handling branch removed status:in-progress but not this one, which is its own small instance of the same 'inconsistent label state on an unusual exit path' family of bug. Filing that as a separate follow-up rather than folding it into #235's scope.

  7. added
    status:blocked
    and removed
    status:needs-info
    on Aug 17, 2026
  8. libravault-xyz commented on Aug 17, 2026

    @libravault-xyz
    CollaboratorAuthor

    Triage (2026-08-17): Fix already exists and is sitting ready — PR #235 (fix/guard-step-crash-mislabel, human-authored) adds steps.guard.outcome == 'failure' checks to the "Advance PR" step in dev-agent.yml, qa-agent.yml, and principal-review.yml, matching the diff dev-agent had already drafted here. All CI checks on #235 are green (JVM Tests ×2 — itself live evidence of #244 — iOS build, Android build all SUCCESS), and it's currently unlabeled/unmerged.

    Switching label from status:needs-info to status:blocked — not on missing info, but on a human merging #235 directly (.github/workflows/** is a sensitive path requiring human merge regardless of author). @libravault-xyz: this one just needs a review + merge to close.

  9. added a commit that references this issue on Aug 18, 2026
    6e130cd
  10. added a commit that references this issue on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstatus:blocked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions