fix(ci): rbe pre-warm survives a failed gh run list under bash -e, and clamps an over-long worker count (#7162) (#7163)

Actions runs the dispatch step as bash -e, so a failing gh run list ended the
step at the assignment and the could-not-read warning never printed. The
assignment now tolerates the failure. A RBE_PREWARM_WORKERS too long for the
shell's integer compare slipped past the max-4 clamp and the loop dispatched
without bound; two or more digits is now decided in the case (all zeros stays
the kill switch). The behaviour test runs the script with bash -e, as Actions
does, under a 30s deadline, and pins the clamp.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Bee 2026-10-06 22:35:02 +00:00 • committed by GitHub
commit 82872a81a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 2 deletions

View file

@ -621,6 +621,16 @@ jobs:
case "$n" in
'') n=1 ;;
*[!0-9]*) n=1 ;;
# Two or more digits is over the cap unless they are all zeros
# (still the kill switch); deciding it here keeps a string too
# long for the shell's integer compare from slipping past the
# -gt below unclamped.
??*)
case "$n" in
*[!0]*) n=4 ;;
*) n=0 ;;
esac
;;
esac
if [ "$n" -gt 4 ]; then
n=4
@ -637,7 +647,7 @@ jobs:
fi
active="$(gh run list -R "$POOL_REPO" --workflow "$POOL_WORKFLOW" --limit 50 \
--json status --jq '[.[] | select(.status != "completed")] | length' 2>/dev/null)"
--json status --jq '[.[] | select(.status != "completed")] | length' 2>/dev/null)" || true
case "$active" in
'' | *[!0-9]*)
echo "::warning title=rbe-west pre-warm::could not read $POOL_REPO/$POOL_WORKFLOW run status; skipping dispatch"

View file

@ -1,12 +1,14 @@
package scripts_test
import (
"context"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
)
// This file exists alongside ci_workflow_test.go's broader structural checks
@ -494,7 +496,14 @@ exit 127
if err := os.WriteFile(callLog, nil, 0o600); err != nil {
t.Fatal(err)
}
cmd := exec.Command("bash", scriptPath)
// Actions runs a run: step with no shell: as "bash -e {0}", so the
// script is run the same way here: a command that fails outside an
// if/||/&& ends the step before any warning below it can print.
// The deadline bounds a regression in the dispatch loop's clamp,
// which would otherwise dispatch (and log) without end.
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "bash", "-e", scriptPath)
// fakeGHDir first so it shadows any real gh on PATH; the rest of the
// inherited PATH stays so the fake gh's own "#!/usr/bin/env bash"
// shebang can still find env and bash.
@ -577,6 +586,22 @@ exit 127
}
})
t.Run("an over-long RBE_PREWARM_WORKERS is clamped to 4", func(t *testing.T) {
// 20 digits overflows the shell's integer compare; the clamp must
// not depend on it.
r := run(t, map[string]string{
"GH_TOKEN": "tok",
"RBE_PREWARM_WORKERS": "99999999999999999999",
"FAKE_GH_RUN_LIST_OUTPUT": "1",
})
if r.code != 0 {
t.Errorf("exit code = %d, want 0\nstdout: %s", r.code, r.stdout)
}
if got := strings.Count(r.calls, "workflow run"); got != 3 {
t.Errorf("gh workflow run calls = %d, want 3 (cap 4, 1 active)\nstdout: %s", got, r.stdout)
}
})
t.Run("gh workflow run failure warns but still exits 0", func(t *testing.T) {
r := run(t, map[string]string{
"GH_TOKEN": "tok",