Summary
Five of the upstream workflow templates have an unconditional pre_activation step that fails its scheduled runs with exit code 4 once gh pr list --search returns no matching PRs.
Affected templates
workflows/adhoc-qa.md
workflows/efficiency-improver.md
workflows/glossary-maintainer.md
workflows/perf-improver.md
workflows/test-improver.md
All five use the same pattern (with different title prefixes):
MAX_OPEN_PRS=8
if [[ "$GITHUB_EVENT_NAME" != "schedule" ]]; then exit 0; fi
COUNT=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --search 'in:title "[<id>]"' --json number --jq 'length')
[[ "$COUNT" -lt "$MAX_OPEN_PRS" ]]
Root cause
gh pr list --search exits with code 4 when the search returns no matches (cli/cli "no results" exit code). The step runs under bash -e, so the command-substitution assignment to COUNT aborts the entire script with that same exit code, the pre_activation job is marked failed, and the workflow run is reported as a failure — even though "zero matching open PRs" is precisely the case where we want the agent to run.
This causes the workflows to fail every single scheduled run for repos that have no open PRs from these agents (which is most of the time after PRs get merged/closed).
Reproducer
In any repo where no PR title starts with [efficiency-improver]:
set -e
COUNT=$(gh pr list --state open --search 'in:title "[efficiency-improver]"' --json number --jq 'length')
echo "COUNT=$COUNT" # never reached
The script aborts before printing, with exit code 4.
Examples in the wild
Daily failures in microsoft/testfx, all with Process completed with exit code 4 in the pre_activation Run MAX_OPEN_PRS=8 step:
We're fixing it locally in microsoft/testfx#8676 but the bug originates here so adopters will keep hitting it.
Proposed fix
Fall back to COUNT=0 when gh pr list returns a non-zero exit code:
- COUNT=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --search 'in:title "[efficiency-improver]"' --json number --jq 'length')
+ # gh pr list exits with code 4 when --search returns no matches; fall back to 0 so set -e doesn't kill the script.
+ COUNT=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --search 'in:title "[efficiency-improver]"' --json number --jq 'length' 2>/dev/null || echo 0)
[[ "$COUNT" -lt "$MAX_OPEN_PRS" ]]
This restores the intended semantics — the workflow runs when there are fewer than MAX_OPEN_PRS matching open PRs, and only short-circuits when the cap is actually reached.
Happy to send a PR if useful.
Summary
Five of the upstream workflow templates have an unconditional
pre_activationstep that fails its scheduled runs with exit code 4 oncegh pr list --searchreturns no matching PRs.Affected templates
workflows/adhoc-qa.mdworkflows/efficiency-improver.mdworkflows/glossary-maintainer.mdworkflows/perf-improver.mdworkflows/test-improver.mdAll five use the same pattern (with different title prefixes):
Root cause
gh pr list --searchexits with code 4 when the search returns no matches (cli/cli "no results" exit code). The step runs underbash -e, so the command-substitution assignment toCOUNTaborts the entire script with that same exit code, thepre_activationjob is marked failed, and the workflow run is reported as a failure — even though "zero matching open PRs" is precisely the case where we want the agent to run.This causes the workflows to fail every single scheduled run for repos that have no open PRs from these agents (which is most of the time after PRs get merged/closed).
Reproducer
In any repo where no PR title starts with
[efficiency-improver]:The script aborts before printing, with exit code 4.
Examples in the wild
Daily failures in
microsoft/testfx, all withProcess completed with exit code 4in thepre_activationRun MAX_OPEN_PRS=8step:We're fixing it locally in microsoft/testfx#8676 but the bug originates here so adopters will keep hitting it.
Proposed fix
Fall back to
COUNT=0whengh pr listreturns a non-zero exit code:This restores the intended semantics — the workflow runs when there are fewer than
MAX_OPEN_PRSmatching open PRs, and only short-circuits when the cap is actually reached.Happy to send a PR if useful.