Skip to content

Commit ac310a4

Browse files
authored
Add triage-ci-failures skill for red PR checks (#15336)
* Add triage-ci-failures skill for red PR checks A dependency bump like Pandoc 3.13 turns a PR red across dozens of bucket x OS jobs, each log several hundred KB. Check-run annotations only name the bucket, and `gh run view --log` silently truncates near 750 KB, so finding which tests failed meant pulling raw logs into context. The script takes a PR number (every failing run on the head commit) or a run id, caches failed-job logs per job id via the jobs/ID/logs endpoint, and prints one row per unique failing test with the OSes it failed on and the verify message. When verify hits a missing output file, the row shows the render error from the OUTPUT tail instead. `##[error]` lines are reported only for jobs with no failing test, since smoke jobs echo each failed bucket there. Jobs whose log shape is not parsed (Playwright, ff-matrix are unverified) are listed with their log path. The skill then has the agent group rows by cause and classify each as dependency output drift or a regression before touching assertions or snapshots. On PR #15320 it reports the 18 failing tests plus the runtime-boundary error in about 6 KB. * Keep diagnostics for more test failure shapes in ci-failures.sh - Capture the assertion message up to the stack trace (max 6 lines). noErrors and noErrorsOrWarnings put the actual errors after a generic first line, which the digest dropped. - Treat "No output created message" and "Path ... doesn't exist" as a failed render, like an OS NotFound, and show the OUTPUT tail. - A FAILED test with no TEST FAILURE block (prereq or teardown-only failure, which test.ts rethrows undecorated) now names the log to grep instead of printing an empty row. - Download logs to a .part file and rename on success, so a failed fetch is retried next run instead of being cached truncated. The PR #15320 digest is unchanged. The new shapes were checked on a log written in the test.ts failure format. * Keep assertion messages across blank lines in ci-failures.sh A Sass failure reaches noErrorsOrWarnings as "Theme file compilation failed:\n\n<diagnostics>" (src/core/dart-sass.ts), and the diagnostics start with "Error:". Stopping the message at a blank line, or at any "Error:" line, dropped the compiler error. The message now ends at the stack trace, recognised as "at" frames or as "<ErrorName>: <first message line>", the line JS stacks begin with. Blank lines are skipped. XPath and layout verifiers append the whole document after "... follows:", so capture ends at that line; the blank line had been doing that job before. The PR #15320 digest only gains the "Path:" line of the NotFound message. * Read the OS label from suffixed smoke job names in ci-failures.sh test-smokes.yml names jobs "Run smoke (<os>)" plus an optional " with timed file" or " - with some extra R packages". Requiring the parenthesis at the end of the name made those rows show the full job name instead of the OS. * Keep CI digest excerpts traceable across OSes A merged test row can contain failures with different causes. Identify the representative excerpt's OS and job and list all contributing logs so those differences can be checked before grouping failures by cause. Clarify that missing output and failures limited to one OS require investigation before assigning a cause. Verified on PR #15320: 18 unique failing tests and the runtime-boundary error, with the render diagnostics preserved in an 8.5 KB digest. Shell syntax and diff checks pass.
1 parent f6626b1 commit ac310a4

2 files changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: triage-ci-failures
3+
description: Use when a quarto-cli PR has red CI checks or a workflow run failed, to find which tests failed on which OSes and why, without loading raw job logs into context. Covers dependency-bump PRs (Pandoc, Typst, Deno) where many assertions break at once.
4+
---
5+
6+
# Triage CI Failures
7+
8+
A red PR on quarto-cli fans out into dozens of failed jobs (test buckets × OSes), each log several hundred KB. Check-run annotations only name the bucket, and `gh run view --log` silently truncates near 750 KB. The script below downloads the failed-job logs to a cache directory and prints a compact digest: one row per unique failing test, the OSes it failed on, and the assertion that broke.
9+
10+
## Step 1: Digest the failures
11+
12+
```bash
13+
bash .claude/skills/triage-ci-failures/scripts/ci-failures.sh <pr-number>
14+
bash .claude/skills/triage-ci-failures/scripts/ci-failures.sh --run <run-id> # one run, e.g. a scheduled run on main
15+
```
16+
17+
The PR form takes every failing run on the PR's head commit. Logs are cached per job id under `$CI_FAILURES_DIR` (default `${TMPDIR:-/tmp}/quarto-ci-failures`), so re-running after a new push only fetches the new jobs.
18+
19+
The output has up to three sections:
20+
21+
- **unique failing tests**: `[OSes] <test>`, then one representative `[verify]` check and its message (up to 6 lines, including `noErrors` diagnostics). The excerpt identifies its OS and job; the row lists every contributing log in the cache directory. Missing output (`No output created message`, a missing path) may indicate a render failure, so the row includes the captured render output from the test's `OUTPUT:` tail. A row with no excerpt may have failed during prereq or teardown and names the log to grep.
22+
- **step errors**: `##[error]` lines from failed jobs that had no failing test (runtime-boundary, lint, setup).
23+
- **failed jobs with no recognised failure**: a log shape the script does not parse (Playwright and feature-format-matrix jobs are unverified). Grep the printed log path for the cause (`grep -n -E 'Error|FAIL' <log> | head`) rather than reading the log whole.
24+
25+
Step 1 is done when every failed job is accounted for by a test row, a step error, or a cause found by grep in its log.
26+
27+
## Step 2: Group rows by cause
28+
29+
Several rows may share one cause, such as a Pandoc change affecting several docx crossref tests. Compare diagnostics in the listed logs before grouping failures across OSes; the representative excerpt may not describe every failure. Investigate failures limited to one OS for platform differences or intermittent behavior; see `dev-docs/debugging-flaky-tests.md`.
30+
31+
## Step 3: Classify each cause before changing any test
32+
33+
For each cause, decide **drift** or **regression** before touching an assertion or snapshot:
34+
35+
- **Drift**: the dependency changed its output in a way that is correct or neutral for users (reordered attributes, hashed bookmark names, new whitespace). Update the assertion or snapshot, and say in the commit which upstream change caused it.
36+
- **Regression**: the rendered result is now wrong for users (missing content, broken cross-reference, a document that no longer renders). Fix Quarto or report upstream; the test stays as it is.
37+
38+
Decide from the rendered output, not the assertion text: render the test document with the dev build and inspect it (`.claude/rules/testing/smoke-all-tests.md` covers how smoke-all tests declare their checks). For a dependency bump, the dependency's changelog usually names the change.
39+
40+
Step 3 is done when every cause carries a drift-or-regression verdict with the evidence behind it. Track one work item per cause, so each verdict and fix can be reviewed on its own.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env bash
2+
# Summarise the failing CI jobs of a PR (or of one workflow run) without
3+
# loading raw logs: one row per unique failing test, deduplicated across OSes.
4+
#
5+
# Usage: ci-failures.sh <pr-number> [repo]
6+
# ci-failures.sh --run <run-id> [repo]
7+
#
8+
# Logs are cached per job id under $CI_FAILURES_DIR
9+
# (default: ${TMPDIR:-/tmp}/quarto-ci-failures).
10+
set -euo pipefail
11+
12+
if [ "${1:-}" = "--run" ]; then
13+
RUNS="${2:?run id required}"; REPO="${3:-quarto-dev/quarto-cli}"
14+
echo "Run $RUNS"
15+
else
16+
PR="${1:?usage: ci-failures.sh <pr-number> | --run <run-id> [repo]}"
17+
REPO="${2:-quarto-dev/quarto-cli}"
18+
SHA="$(gh pr view "$PR" --repo "$REPO" --json headRefOid --jq .headRefOid)"
19+
RUNS="$(gh run list --repo "$REPO" --commit "$SHA" --limit 100 \
20+
--json databaseId,conclusion --jq '.[] | select(.conclusion=="failure") | .databaseId')"
21+
echo "PR #$PR head ${SHA:0:9}: failing runs: $(echo $RUNS)"
22+
[ -n "$RUNS" ] || { echo "No failing runs."; exit 0; }
23+
fi
24+
25+
D="${CI_FAILURES_DIR:-${TMPDIR:-/tmp}/quarto-ci-failures}"; mkdir -p "$D"
26+
JOBS="$D/jobs-$$.tsv"; : > "$JOBS"
27+
trap 'rm -f "$JOBS"' EXIT
28+
29+
for RUN in $RUNS; do
30+
gh api "repos/$REPO/actions/runs/$RUN/jobs?per_page=100&filter=latest" --paginate \
31+
--jq '.jobs[] | select(.conclusion=="failure") | [.id, .name] | @tsv' >> "$JOBS"
32+
done
33+
# Linux jobs first, so excerpts show forward-slash paths.
34+
awk -F'\t' '{print ($2 ~ /ubuntu|linux/ ? 0 : 1) "\t" $0}' "$JOBS" \
35+
| sort -s -k1,1 | cut -f2- > "$JOBS.sorted" && mv "$JOBS.sorted" "$JOBS"
36+
echo "Failed jobs: $(wc -l < "$JOBS" | tr -d ' ') Logs: $D"
37+
38+
# Download job logs directly to avoid truncation.
39+
while IFS=$'\t' read -r id name; do
40+
f="$D/$id.log"
41+
[ -s "$f" ] && continue
42+
# Publish only a complete download, so a failed fetch is retried next run.
43+
gh api --allow-escape-sequences "repos/$REPO/actions/jobs/$id/logs" \
44+
| sed -e 's/\x1b\[[0-9;]*m//g' -e 's/^[0-9T:.-]*Z //' > "$f.part" && mv "$f.part" "$f"
45+
done < "$JOBS"
46+
47+
# Pass 1: one record per (failure, job): kind \t key \t os \t job-id \t excerpt (lines joined by \037)
48+
while IFS=$'\t' read -r id name; do
49+
# "Run smoke (<os>)" may carry a suffix such as " with timed file" (test-smokes.yml).
50+
os="$(printf '%s' "$name" | sed -nE 's/.*\(([^)]*)\).*/\1/p')"; os="${os:-$name}"
51+
group="$(printf '%s' "$name" | sed -E 's/ *\([^)]*\)//')"
52+
awk -v os="$os" -v id="$id" -v group="$group" '
53+
function norm(s) { sub(/^\[smoke\] > /, "", s); gsub(/\\/, "/", s); return s }
54+
function flush( i, n, out, seen, start) {
55+
if (title == "") return
56+
out = verify msg
57+
if (notfound && nout > 0) {
58+
# Missing output: include the captured render output.
59+
out = out "\037render output (OUTPUT tail):"
60+
n = 0; start = nout
61+
for (i = nout; i >= 1 && n < 6; i--) if (!(outl[i] in seen)) { seen[outl[i]] = 1; n++; start = i }
62+
delete seen
63+
for (i = start; i <= nout; i++) if (!(outl[i] in seen)) { seen[outl[i]] = 1; out = out "\037 " outl[i] }
64+
}
65+
print "T\t" norm(title) "\t" os "\t" id "\t" out
66+
title = ""; verify = ""; msg = ""; m1 = ""; nmsg = 0; inmsg = 0; notfound = 0; nout = 0; inout = 0; hdr = 0
67+
}
68+
/ \.\.\. FAILED \(/ { t = $0; sub(/ \.\.\. FAILED.*/, "", t); print "T\t" norm(t) "\t" os "\t" id "\t"; next }
69+
/━━━ TEST FAILURE: / { flush(); title = substr($0, index($0, "TEST FAILURE: ") + 14); next }
70+
title != "" {
71+
if ($0 ~ /^\[verify\] > /) { verify = substr($0, 1, 200); inmsg = 1; next }
72+
# The assertion message runs from [verify] to the stack trace, whose first line is
73+
# "<ErrorName>: <first message line>". noErrors-style messages carry the real
74+
# diagnostics on later lines, possibly after blank lines.
75+
if (inmsg) {
76+
if ($0 ~ /^[ \t]*$/) next
77+
if ($0 ~ /^OUTPUT:/) inmsg = 0
78+
else if ($0 ~ /^[ \t]+at / || (m1 != "" && $0 ~ /^[A-Za-z]+: / && substr($0, index($0, ": ") + 2) == m1)) { inmsg = 0; next }
79+
}
80+
if (inmsg) {
81+
if (m1 == "") m1 = $0
82+
if (nmsg < 6) { msg = msg "\037" substr($0, 1, 240); nmsg++ }
83+
# XPath and layout verifiers end with "... follows:" and then dump the whole document.
84+
if ($0 ~ /follows:[ \t]*$/) inmsg = 0
85+
# Missing output: include the captured render output.
86+
if ($0 ~ /NotFound|os error 2|cannot find the file|No output created message|^Path .* doesn.t exist/) notfound = 1
87+
next
88+
}
89+
if ($0 ~ /^OUTPUT:/) { inout = 1; next }
90+
if ($0 ~ /Stack trace:|throw new AssertionError/) { inout = 0; next }
91+
if (inout) {
92+
l = $0; sub(/^[ \t]+/, "", l); sub(/[ \t]+$/, "", l)
93+
# Skip the echoed "pandoc" options and "metadata" blocks; each ends at a blank line.
94+
if (l == "pandoc" || l == "metadata") { hdr = 1; next }
95+
if (l == "") { hdr = 0; next }
96+
if (!hdr && l !~ /^[0-9]* *\|/ && l != "^") outl[++nout] = substr(l, 1, 240)
97+
}
98+
}
99+
/^##\[error\]/ && !/Process completed with exit code/ {
100+
print "E\t" substr($0, 10, 300) "\t" os "\t" id "\t" group
101+
}
102+
END { flush() }
103+
' "$D/$id.log"
104+
done < "$JOBS" > "$D/records-$$.tsv"
105+
106+
# Pass 2: aggregate into one row per test (and per step error), listing the OSes that failed it.
107+
awk -F'\t' -v jobs="$JOBS" -v dir="$D" '
108+
function addos(list, os) { return index(", " list ", ", ", " os ", ") ? list : (list == "" ? os : list ", " os) }
109+
BEGIN { while ((getline l < jobs) > 0) { split(l, a, "\t"); jname[a[1]] = a[2]; jorder[++nj] = a[1] } }
110+
{ seenjob[$4] = 1 }
111+
$1 == "T" {
112+
testjob[$4] = 1
113+
if (!($2 in tos)) order[++nt] = $2
114+
tos[$2] = addos(tos[$2], $3)
115+
if (ex[$2] == "" && $5 != "") { ex[$2] = $5; exos[$2] = $3; exjob[$2] = $4 }
116+
if (!($2 in tjob)) tjob[$2] = $4
117+
if (!logseen[$2, $4]) {
118+
logseen[$2, $4] = 1
119+
tlogs[$2] = tlogs[$2] (tlogs[$2] == "" ? "" : "; ") "[" $3 "] " $4 ".log"
120+
}
121+
}
122+
$1 == "E" { ejob[++nr] = $4; ekey[nr] = $5 "\t" $2; eosr[nr] = $3 }
123+
END {
124+
printf "\n== %d unique failing tests\n", nt
125+
for (i = 1; i <= nt; i++) {
126+
t = order[i]; printf "\n[%s] %s\n", tos[t], t
127+
if (ex[t] != "") printf " representative excerpt (%s, job %s):\n", exos[t], exjob[t]
128+
n = split(ex[t], lines, "\037"); for (j = 1; j <= n; j++) if (lines[j] != "") print " " lines[j]
129+
printf " logs: %s\n", tlogs[t]
130+
# prereq and teardown-only failures print no TEST FAILURE block.
131+
if (ex[t] == "") printf " no TEST FAILURE block (prereq or teardown failure?); grep %s/%s.log\n", dir, tjob[t]
132+
}
133+
# Hide step annotations when this job already has test rows.
134+
for (r = 1; r <= nr; r++) if (!(ejob[r] in testjob)) {
135+
k = ekey[r]; if (!(k in eos)) eorder[++ne] = k
136+
eos[k] = addos(eos[k], eosr[r])
137+
}
138+
if (ne) printf "\n== %d step errors\n", ne
139+
for (i = 1; i <= ne; i++) { split(eorder[i], p, "\t"); printf "\n[%s] %s\n %s\n", eos[eorder[i]], p[1], p[2] }
140+
m = 0
141+
for (i = 1; i <= nj; i++) if (!(jorder[i] in seenjob)) {
142+
if (!m++) print "\n== Failed jobs with no recognised failure (grep their log for the cause)"
143+
printf "%s\n %s/%s.log\n", jname[jorder[i]], dir, jorder[i]
144+
}
145+
}
146+
' "$D/records-$$.tsv"
147+
rm -f "$D/records-$$.tsv"

0 commit comments

Comments
 (0)