diff --git a/.github/scripts/regression-alert.sh b/.github/scripts/regression-alert.sh new file mode 100755 index 0000000..1a34048 --- /dev/null +++ b/.github/scripts/regression-alert.sh @@ -0,0 +1,240 @@ +#!/usr/bin/env bash +# Open or update one `regression-alert` issue per failing scenario. +# +# The first version kept a single issue and commented on whichever +# `regression-alert` issue was open. So every failure landed on the same +# thread whatever caused it: a harness `fetch failed` in +# `regression-verification-001-generic-hmac` on 26 October was appended to an +# issue about a rubric in `regression-filtering-001-regex-capability`, and read +# as more of the same. One issue per scenario keeps "this guard keeps failing" +# readable as one problem, and keeps unrelated failures off it. +# +# Only two failures are a verdict on a scenario, and only they are filed per +# scenario: +# +# - the regression check failed: a red check, so the guarded mistake came back +# or the scorer is wrong about a correct answer; +# - the eval step errored: the cell has no verdict, usually the harness, a +# provider or the agent CLI rather than the agent's answer. Filed per +# scenario because it is about that cell, labelled `harness` when no cell of +# the scenario has a red check. +# +# Everything else goes to one run-level issue: a job outside the matrix +# (`prepare`, `publish-results`), a cell that failed at setup (a missing +# secret, a registry outage, which would otherwise open an issue for every +# scenario), a cancelled or timed-out cell, a cell whose job name GitHub cut +# short, and above all a provider refusal. A refusal uploads a +# `provider-refused-*` artifact and cancels the run (#103), so every remaining +# cell arrives cancelled and none has a verdict. +# +# A same-title issue that was closed is reopened rather than duplicated, so a +# guard that regresses again keeps its history in one thread. +# +# If the run cannot be read, the script still alerts: a red job that tells +# nobody is the failure this exists to prevent. +# +# Env: GH_REPO, RUN_ID, RUN_URL; RUN_ATTEMPT (default 1). +# DRY_RUN set to anything but 0 or empty prints instead of writing. +set -euo pipefail + +: "${GH_REPO:?}" "${RUN_ID:?}" "${RUN_URL:?}" +attempt="${RUN_ATTEMPT:-1}" +case "${DRY_RUN:-0}" in + 0 | "") dry_run=0 ;; + *) dry_run=1 ;; +esac + +RUN_LEVEL_TITLE="Weekly regression run is failing" +CHECK_STEP="Check the regression suite passed" +EVAL_STEP="Run evals" + +# GitHub's API answers the odd 502: three turned up in a 40-run sweep of the +# jobs endpoint. Retry each read before deciding the run is unreadable. Each +# attempt's output is captured whole, so a paginated read that fails partway +# does not leave its first pages behind to be repeated by the next attempt. +retry() { + local n out + for n in 1 2 3; do + if out="$("$@")"; then + printf '%s\n' "$out" + return 0 + fi + if [ "$n" -lt 3 ]; then sleep $((n * ${RETRY_DELAY:-5})); fi + done + return 1 +} + +issues="" +issues_read=0 +if issues="$(retry gh issue list --label regression-alert --state all --limit 200 \ + --json number,title,state)"; then + issues_read=1 +fi + +# Comment on the open issue with this exact title; reopen and comment on a +# closed one; otherwise open one. Without the issue list it opens one: a +# duplicate can be closed, a silent failure cannot be noticed. +post() { + local title="$1" body="$2" label="$3" + local match="" number="" state="" + if [ "$issues_read" = 1 ]; then + match="$(jq -r --arg t "$title" ' + [.[] | select(.title == $t)] + | (map(select(.state == "OPEN")) + map(select(.state != "OPEN")))[0] + | if . == null then "" else "\(.number) \(.state)" end' <<<"$issues")" + fi + if [ -n "$match" ]; then + number="${match%% *}" + state="${match#* }" + fi + + if [ "$dry_run" = 1 ]; then + local action="create" + if [ "$state" = "OPEN" ]; then + action="comment on #${number}" + elif [ -n "$number" ]; then + action="reopen #${number} and comment" + fi + echo "=== ${action}: ${title} [${label}]" + echo "$body" + return + fi + + if [ -z "$number" ]; then + gh issue create --title "$title" --label regression-alert --label "$label" \ + --body "$body" + return + fi + if [ "$state" != "OPEN" ]; then + gh issue reopen "$number" + fi + gh issue comment "$number" --body "$body" +} + +if ! jobs="$(retry gh api --paginate \ + "repos/${GH_REPO}/actions/runs/${RUN_ID}/attempts/${attempt}/jobs?per_page=100" \ + --jq '.jobs[]')"; then + post "$RUN_LEVEL_TITLE" "The weekly regression run failed, and its jobs could not be read to say which scenarios: ${RUN_URL} + +GitHub's API did not answer after three attempts. Open the run and read the failed jobs directly." harness + exit 0 +fi +jobs="$(jq -s '.' <<<"$jobs")" + +# Artifacts are listed for the whole run, every attempt included, so on a +# re-run keep only those made since this attempt started: a refusal before a +# credit top-up must not suppress the scenario issues of the re-run after it. +started="1970-01-01T00:00:00Z" +if [ "$attempt" -gt 1 ]; then + started="$(retry gh api "repos/${GH_REPO}/actions/runs/${RUN_ID}/attempts/${attempt}" \ + --jq '.run_started_at // empty')" || started="" + # A null or missing start time is unreadable, not a timestamp: the string + # "null" sorts above every real one, so it would filter out a current refusal. + case "$started" in 20[0-9][0-9]-*) ;; *) started="" ;; esac +fi +refused="" +refusal_unknown=0 +if [ -z "$started" ] || ! refused="$(retry gh api --paginate \ + "repos/${GH_REPO}/actions/runs/${RUN_ID}/artifacts?per_page=100" \ + --jq ".artifacts[] + | select(.created_at >= \"${started}\") + | .name | select(startswith(\"provider-refused-\")) + | ltrimstr(\"provider-refused-\")")"; then + refusal_unknown=1 + refused="" +fi + +# Matrix job names are `run-evals (, , , )`, +# and GitHub cuts them at 100 characters with "...". The current ids leave the +# first two fields intact with room to spare; a cell whose id or experiment was +# cut is not filed under a guessed scenario. +# shellcheck disable=SC2016 # jq variables, not shell ones +defs=' + def is_cell: .name | startswith("run-evals ("); + def fields: .name | ltrimstr("run-evals (") | rtrimstr(")") | split(", "); + def cut_short: (.name | ltrimstr("run-evals (") | split(", ")) as $q + | ($q | length) < 3 or ($q[0] | endswith("...")) or ($q[1] | endswith("...")); + def failed_step: [.steps[]? | select(.conclusion == "failure")][0].name // ""; + def per_scenario($check; $eval): + is_cell and .conclusion == "failure" and (cut_short | not) + and (failed_step as $s | $s == $check or $s == $eval); +' + +# One line per scenario cell: eval_id experiment kind. +cells="" +if [ -z "$refused" ] && [ "$refusal_unknown" = 0 ]; then + cells="$(jq -r --arg check "$CHECK_STEP" --arg eval "$EVAL_STEP" "${defs}"' + .[] + | select(per_scenario($check; $eval)) + | fields as $p + | [$p[0], $p[1], (if failed_step == $check then "check" else "error" end)] + | @tsv' <<<"$jobs")" +fi + +other_failures="$(jq -r --arg check "$CHECK_STEP" --arg eval "$EVAL_STEP" \ + --arg filed "$([ -n "$cells" ] && echo 1 || echo 0)" "${defs}"' + .[] + | select(.name != "regression-alert") + | select(.conclusion == "failure" or .conclusion == "cancelled" or .conclusion == "timed_out") + | select($filed == "0" or (per_scenario($check; $eval) | not)) + | "- `\(.name)`: \(.conclusion)" + + (failed_step as $s | if $s == "" then "" else " at \"\($s)\"" end)' <<<"$jobs")" + +guidance="Regression scenarios guard mistakes we have already seen and fixed, so +every agent passing is the expected state. A cell whose **checks failed** is one +of two things: the guarded mistake came back, or the scorer is wrong about a +correct answer. Read the transcript in the cell's \`raw-results-*\` artifact +before deciding which; the agent's own report is usually the fastest answer. +A cell that **errored** has no verdict: usually the harness, a provider or the +agent CLI, not the agent's answer." + +if [ -n "$cells" ]; then + while IFS= read -r eval_id; do + lines="$(awk -F'\t' -v id="$eval_id" '$1 == id { + if ($3 == "check") what = "checks failed: the scorer recorded a red check" + else what = "errored: no verdict; usually the harness, a provider or the agent CLI, not the agent'"'"'s answer" + printf "- `%s`: %s\n", $2, what + }' <<<"$cells")" + label="harness" + if awk -F'\t' -v id="$eval_id" '$1 == id && $3 == "check" { found = 1 } END { exit !found }' <<<"$cells"; then + label="scenario" + fi + post "Regression failing: ${eval_id}" "The weekly regression run failed \`${eval_id}\`: ${RUN_URL} + +${lines} + +${guidance}" "$label" + done < <(cut -f1 <<<"$cells" | sort -u) +fi + +if [ -n "$refused" ]; then + refusing="$(awk '{ printf "- `%s`\n", $0 }' <<<"$refused")" + post "$RUN_LEVEL_TITLE" "The weekly regression run was cancelled because a provider refused: ${RUN_URL} + +Refused in: +${refusing} + +A refusal is a credit, quota or auth failure, and the run cancels itself so +the remaining cells do not run and bill. No scenario has a verdict from this +run. Fix the provider account, then dispatch the regression suite. + +Jobs that failed, were cancelled or timed out: +${other_failures:-- none recorded}" harness +elif [ "$refusal_unknown" = 1 ]; then + post "$RUN_LEVEL_TITLE" "The weekly regression run failed, and its artifacts could not be read, so a provider refusal cannot be ruled out: ${RUN_URL} + +No scenario issue was opened, because filing a refused run per scenario would +blame every guard for one credit balance. Check the run's artifacts for +\`provider-refused-*\` before reading the cells below as agent results. + +Jobs that failed, were cancelled or timed out: +${other_failures:-- none recorded}" harness +elif [ -n "$other_failures" ] || [ -z "$cells" ]; then + post "$RUN_LEVEL_TITLE" "The weekly regression run failed outside any single scenario verdict: ${RUN_URL} + +${other_failures:-- no failed job recorded; the run was failed or cancelled before any cell finished} + +This is the pipeline rather than an agent's answer: discovery, setup, a +provider preflight, publishing, or a cancelled cell. Read the failed job's log +first." harness +fi diff --git a/.github/workflows/eval-refresh.yml b/.github/workflows/eval-refresh.yml index f692063..41fabf8 100644 --- a/.github/workflows/eval-refresh.yml +++ b/.github/workflows/eval-refresh.yml @@ -898,54 +898,31 @@ jobs: # clone that could not rebase, and a re-run against a moved branch (#74). if: ${{ (failure() || cancelled()) && github.event_name == 'schedule' }} runs-on: ubuntu-latest + # Narrower than the workflow's: this job reads the run and writes issues, + # and nothing else. + permissions: + contents: read + actions: read + issues: write steps: - - name: Open or update the alert issue + # A sparse checkout of the alert script alone: the logic lives in a file + # so it can be run against a past run with DRY_RUN=1 before it is + # trusted, which an inline block cannot. + - name: Checkout + uses: actions/checkout@9f698171ed81b15d1823a05fc7211befd50c8ae0 # v6.0.3 + with: + sparse-checkout: .github/scripts + sparse-checkout-cone-mode: false + + - name: Open or update the alert issues env: GH_TOKEN: ${{ github.token }} - # This job has no checkout, so `gh` has no git remote to infer the - # repository from — and it does not fall back to `GITHUB_REPOSITORY`. - # Without this the alert step fails and notifies nobody, which is the - # failure it exists to prevent. + # Explicit even with a checkout: the first version of this job had + # none, `gh` could not infer the repository, and the alert step + # failed and notified nobody. GH_REPO: ${{ github.repository }} + RUN_ID: ${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} shell: bash - run: | - set -euo pipefail - - # One issue, reopened and commented rather than a new one each week. - # A suite that breaks and stays broken should read as one problem - # getting worse, not as four identical issues nobody closes. - existing="$(gh issue list --label regression-alert --state open \ - --json number --jq '.[0].number // empty')" - - # Indented for the YAML block scalar, then de-indented for GitHub: - # four or more leading spaces after a blank line is a markdown code - # block, so the first version of this rendered the whole alert as - # monospace with literal `**` and `1.` in it. - body="$(sed 's/^ //' <`, and each +failing cell is labelled by the step that failed: a red check is the agent or the +scorer, and an errored eval step means the cell has no verdict, usually the harness, a +provider or the agent CLI rather than the agent's answer. A provider refusal, a cell +that failed at setup, a cancelled or timed-out cell, or a failure outside the matrix +goes to one run-level issue instead, because none of them is a verdict on a scenario. A +closed issue with the same title is reopened, so a guard that regresses again keeps its +history. Until November there was one issue for everything, and a harness `fetch +failed` landed on a rubric thread and read as more of the same. The logic is +`.github/scripts/regression-alert.sh`; run it with +`DRY_RUN=1 GH_REPO=hookdeck/evals RUN_ID= RUN_URL=` against a past run before +changing it. **Measured on the first run**, 1 October 2026 ([run 36869979661](https://github.com/hookdeck/evals/actions/runs/36869979661)): eighteen cells, **seventeen passed**, fifty minutes of wall clock. The cells run one at a time