fix(ci): watch-ci.sh inspects only runs for the current head commit#3747
Conversation
`gh run list --branch <branch>` returns runs for EVERY commit ever pushed to the branch, so after a branch is fixed and re-pushed, watch-ci kept reporting the OLD commit's failed run forever — even though the new tip's runs all passed. This produced false "CI FAILED" verdicts (observed monitoring PR #3733, where the fix commit was green but the watcher reported the pre-fix failure). Resolve the target's current head SHA each poll cycle (PR → headRefOid, fork-safe; plain branch → commits API) and filter the run list to that SHA in jq. Re-resolving each cycle also means a push mid-watch is tracked automatically, and "no runs for this SHA yet" cleanly covers the window between a push and its runs being created. On a transient SHA-resolution failure, fall back to the last known tip rather than crashing. Also fix the failure hint, which suggested the invalid `gh run view --log-failed --branch <branch>` (run view takes a run id, not --branch), and surface the short SHA in the pass/fail summary lines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011JEaCGwY9Wz8jeV4e22GW4
|
Claude finished @Yeraze's task —— View job PR Review
SummaryThis is a well-targeted fix for a real operational problem. The script is clean, defensive, and well-commented. Below are a few observations: Positive Observations
Issues / Suggestions1. jq inline string interpolation (potential injection risk, line 118) -q ".[] | select(.headSha == \"$HEAD_SHA\") | ..."
-q --arg sha "$HEAD_SHA" '.[] | select(.headSha == $sha) | "\(.name)|\(.status)|\(.conclusion)"'This also avoids the nested quote escaping, improving readability. 2. Early exit on first failure may miss concurrent failures (line 162–169) The "fail fast" logic exits as soon as 3.
4. The guard correctly exits only when 5. The VerdictApproved with minor suggestions. The fix directly addresses the reported problem (stale failed-run reporting), is safe, well-commented, and doesn't break the existing |
Problem
scripts/watch-ci.shpollsgh run list --branch <branch>, which returns runs for every commit ever pushed to the branch. After a branch is fixed and re-pushed, the watcher kept surfacing the old commit's failed run indefinitely — reporting✗ CI FAILEDeven though the new tip's runs all passed.Observed live while monitoring PR #3733: the fix commit (
077552dd) was green, but the watcher repeatedly reported the pre-fix commit'sPR Testsfailure, because that stale completed run outranked the still-queuedruns on the new tip.Fix
gh run listhas no commit filter):headRefOid(fork-safe).repos/{owner}/{repo}/commits/{branch}via the API.gh run view --log-failed --branch <branch>(run viewtakes a run id, not--branch), and added the short SHA to the pass/fail summary lines.Verification
bash -nclean.watch-ci.sh -q 3733(the case the old script wrongly failed) →✓ CI PASSED — all checks green on claude/great-dijkstra-ueptaa @ 077552dd.watch-ci.sh maincorrectly resolves the tip and waits only on that commit's genuinely in-progress runs.🤖 Generated with Claude Code