Skip to content

ai-code-review: failover only covers dispatch failure, not a dispatched agent's runtime failure #362

Description

@dem-extra1

Deferred from review of #357, where ai-code-review.yml was added.

The gap

ai-code-review.yml picks an agent at random and dispatches that agent's review workflow:

if gh workflow run "$agent_wf" --repo "$REPO" "${REF_ARGS[@]}" -f pr_number="$PR_NUMBER"; then
  echo "Dispatched the review to $agent ($agent_wf)."
  exit 0
fi

gh workflow run returns as soon as the run is queued, so a zero exit status
proves only that the dispatch was accepted --- not that the review ran, and not
that it produced a verdict. An agent that dispatches fine and then dies partway
through (quota exhaustion, an SDK error, the stub-review signature gha#185
covers for Claude) is never failed over to the next candidate: the loop has
already exited 0.

So the fallback currently covers exactly the dispatch-time cases:

  • no API key/token secret configured for that agent
  • the agent's review workflow file missing or disabled in the caller repo

Why it was not fixed in #357

Waiting synchronously is not a one-line change, and the obvious form does not
work. gh workflow run reports no run id, so gh run watch has nothing to
attach to; locating the dispatched run means polling
gh run list --workflow "$agent_wf" and matching on a heuristic (recent
created_at, the head SHA, the dispatch inputs), each of which can pick the
wrong run when two dispatches land close together --- which is the normal case
on a PR that gets several pushes.

There is also a real design question underneath, worth settling before
implementing: a synchronous wait turns this from a ~10 second dispatcher into a
job that occupies a runner for the whole length of a review, and the timeout it
would need is the review's timeout plus a margin.

Suggested approach, if picked up

  • Have each per-agent review workflow report its own outcome somewhere
    attributable (a check-run name, or a PR comment marker), and have this
    workflow poll for that rather than for the run itself --- the outcome is what
    the failover actually cares about, and it is not ambiguous between concurrent
    runs the way a run-list heuristic is.
  • Bound the wait explicitly and treat a timeout as "this agent did not deliver",
    falling through to the next candidate.
  • Decide whether a failed-over review should say so on the PR, so a reader can
    tell a second agent's review from a first agent's.

Meanwhile

#357 documents the current scope rather than leaving it implied --- in the
workflow's own header comment, in website/workflows.qmd, and in
website/reference/ai-code-review.qmd --- so the README's summary no longer
reads as though a runtime failure is covered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions