Skip to content

fix(list-recent-runs): fail loud on transient gh errors instead of a false all-clear - #784

Merged
max-sixty merged 2 commits into
mainfrom
hourly/review-29710673739
Jul 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
hourly/review-29710673739

Conversation

@tend-agent

Copy link
Copy Markdown
Collaborator

Problem

list-recent-runs.sh silently returns an empty (or partial) run list when a gh API call fails transiently, causing review-reviewers / review-runs to record a false all-clear and permanently skip that window's runs.

Directly reproduced this run (review-reviewers leg 29710673739) during the active GitHub Actions incident (critical, started 2026-07-19T23:34Z, affecting API Requests / Issues / Actions / Pages). The workflow-discovery fetch hit an HTTP 503:

+ mapfile -t matches < <(gh workflow list -R max-sixty/cargo-affected --json name --jq ...)
could not get workflows: HTTP 503: No server is currently available to service your request.
+ WORKFLOWS+=("${matches[@]}")   # empty
...
+ echo '[]'                      # <- reported zero runs

At that moment three tend-notifications runs (29708109161, 29708916955, 29710166166) existed in the window. Had the leg trusted the script's output, it would have recorded an all-clear and never analyzed them.

Root cause

Two call sites swallow gh failures, both of which escape set -euo pipefail:

  • mapfile -t matches < <(gh workflow list ...) — a process substitution's exit status is invisible to set -e, and mapfile itself succeeds on empty input. A single 503 here zeros out WORKFLOWS → no runs are queried → [].
  • runs=$(gh run list ... || echo "[]") — the || echo "[]" fallback turns a per-workflow fetch error into an empty result, silently dropping that workflow's runs.

Either way the script emits fewer runs than exist with a 0 exit code, and the calling skill treats it as "nothing happened this hour." The failure is invisible: a false all-clear produces no CI failure, and each leg only ever sees its own one-hour window, so a skipped hour is never re-analyzed.

Fix

A small gh_retry helper retries transient failures (3 attempts, linear backoff). Both fetch sites now use it and fail loud (exit 1) if every attempt fails, so the caller errors instead of reporting a bogus empty window. A genuinely empty result (successful fetch, repo has no matching workflows) still returns [] as before — only fetch failures now abort.

Verification

  • bash -n + shellcheck: clean.
  • Failure path (mocked gh that always 503s): exits 1 with refusing to report an empty run list, instead of printing [].
  • Success path (live): returns the two in-window runs (29710166166, 29708916955) rather than [].

Gate assessment

  • Evidence: directly reproduced this run — clearly-wrong outcome (analysis tooling reports zero runs while runs exist → missed detection that never resurfaces).
  • Structural: yes — any transient fetch failure deterministically produces the empty/partial result; not a stochastic model lapse.
  • Invisible failure mode: yes — a false all-clear surfaces no CI failure and the skipped window is never re-analyzed, so it wouldn't be caught next time without this fix.
  • Change type: targeted fix (retry helper + fail-loud at two call sites), proportionate.

Evidence log: https://gist.github.com/8518c95fe85c0e52a3b5f26695187382

…porting a false all-clear

A 503 from 'gh workflow list' (process substitution, invisible to set -e)
or 'gh run list' (|| echo "[]" fallback) silently emitted an empty/partial
run list with exit 0, so review-reviewers/review-runs recorded a bogus
all-clear and permanently skipped that window's runs. Retry transient
failures and fail loud if they persist.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tend-agent tend-agent added the claude-behavior Behavioral issues found by review-reviewers label Jul 20, 2026

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fail-loud approach is right, and the two swallowing sites (the mapfile process-substitution and the || echo "[]" fallback) are exactly the leaks that produced the false all-clear. bash -n and shellcheck are clean and a genuinely empty successful fetch still returns [].

One small thing: gh_retry sleeps even after the final (3rd) attempt fails, delaying the exit 1 by ~9s. Since this PR's whole point is to fail loud and fast during an incident, skipping the trailing sleep tightens exactly that path.

@tend-agent

Copy link
Copy Markdown
Collaborator Author

Good catch — fixed in a519ad1. gh_retry now guards the backoff with [ "$attempt" -lt 3 ], so a total failure returns immediately after the third attempt instead of sleeping ~9s first. bash -n + shellcheck clean; the mocked all-503 path now exits 1 in ~9s (the two inter-attempt backoffs) rather than ~18s.

@max-sixty
max-sixty merged commit bbeb9d2 into main Jul 20, 2026
5 checks passed
@max-sixty
max-sixty deleted the hourly/review-29710673739 branch July 20, 2026 06:24
@max-sixty max-sixty mentioned this pull request Jul 24, 2026
2 of 4 tasks
max-sixty added a commit that referenced this pull request Jul 24, 2026
## Summary

Cuts release 0.1.12. 5 commits since 0.1.11:

- Raise default harness timeout to 5h50m (#790)
- Stop asking upstream maintainers to do verification the bot couldn't
do itself (#789)
- Fail loud on transient `gh` errors in `list-recent-runs.sh` instead of
a false all-clear (#784)
- Bump pinned `claude_version` to 2.1.215 (#782)
- Tolerate transient non-JSON `gh api` responses in notifications (#780)

(`#778`, a routine post-0.1.11 workflow regen, is omitted from the
changelog as non-user-facing.)

## Test plan

- [x] `wt test` — 276 passed
- [x] `pre-commit run --all-files` — passed
- [ ] CI green on this PR
- [ ] Tag `0.1.12` and push after merge to trigger PyPI publish + GitHub
Release

> _This was written by Claude Code on behalf of Maximilian Roos_
max-sixty pushed a commit to max-sixty/worktrunk that referenced this pull request Jul 25, 2026
Automated nightly regeneration of tend's workflow files via `uvx
tend@latest init`, picking up the tend release since the last regen.

**tend version:** 0.1.11 → 0.1.12

**Notable changes:**

- **Notifications workflow tolerates transient `gh api` blips** — the
notifications fetch now retries on non-JSON responses (e.g. an HTML
error page returned with a 200 during an API blip) and skips the cycle
cleanly instead of aborting the step red (max-sixty/tend#780).
- **`review-runs` fails loud on transient `gh` errors** — a failed run
enumeration no longer reports a false all-clear; it surfaces the error
so the run isn't silently treated as clean (max-sixty/tend#784).
- **`running-in-ci` guidance** — the bot no longer asks outside
contributors to do work it can't do itself (max-sixty/tend#789).
- **Harness bumps** — Claude harness version bumped to 2.1.215
(max-sixty/tend#782) and the default harness timeout raised to 5h50m
(max-sixty/tend#790).

Compare: max-sixty/tend@0.1.11...0.1.12

Co-authored-by: worktrunk-bot <[email protected]>
max-sixty pushed a commit that referenced this pull request Aug 12, 2026
… and stop the fetch limit re-truncating it (#838)

`list-recent-runs.sh`'s dropped-tick recovery anchors the window floor
on the previous **completed** run of the analyzing workflow. `completed`
is a status, not a conclusion, so a run that failed before its agent
produced any analysis advances the anchor exactly as if it had covered
its hour. After an outage the next green run therefore resumes one tick
back and reports an all-clear for a window nothing ever looked at — and
the gap is unrecoverable, because the following run's floor advances
past it too.

This is not hypothetical: it just consumed ~15 hours of
`review-reviewers` coverage.

## What happened

Every `review-reviewers` run from
[30897445507](https://github.com/max-sixty/tend/actions/runs/30897445507)
(09:41Z) through
[30959115609](https://github.com/max-sixty/tend/actions/runs/30959115609)
(23:10Z) failed — 16 consecutive runs, all five matrix legs, `claude -p`
exiting 1 after ~4s. The `result` event in every leg's session log is
identical: `is_error: true`, `num_turns: 1`, `result: "You've hit your
weekly limit · resets 12am (UTC)"`, with `token-usage.json` all zeros.
The agent never started, so none of those runs analyzed anything. (The
outage itself is already tracked by #831 and the annotation-legibility
work in #816 / #818 — this PR is only about the window the outage
swallowed.)

The last run that did analyze anything is
[30893072876](https://github.com/max-sixty/tend/actions/runs/30893072876)
at 08:42Z, which is also the last entry in the `numbagg/numbagg`
evidence gist. At this run's tick (23:47Z intended), the recovery query
picked
`{"conclusion":"failure","createdAt":"2026-08-04T23:10:57Z","databaseId":30959115609}`
and floored the window at 22:47Z, so `list-recent-runs.sh` returned
exactly one row: a `tend-notifications` pre-check no-op.

Everything `numbagg-bot` actually did in the swallowed window sat
outside that floor — PRs
[#719](numbagg/numbagg#719) and
[#720](numbagg/numbagg#720), issue
[#721](numbagg/numbagg#721), three reviews and
four inline comments on #719, and comments on #716, #721 and #1. That is
the densest window numbagg has had in days, and per the skill's Step 1
("If empty, record the run as all-clear … then skip to Step 6") it would
have been recorded as a quiet hour. I only found it by diffing the run
list against the gist's last recorded boundary by hand.

## The change

Anchor on the previous **successful** run rather than any completed one,
filtering server-side with `--status success` (the flag takes
conclusions as well as statuses), and when the existing 6h cap clamps
the recovered floor, say so on stderr so the caller records a coverage
gap instead of a false all-clear. A partially-failed matrix run counts
as a failure here, which only ever widens the window — overlap is
re-offered work the caller dedups against its own evidence log, whereas
a gap is silently unanalyzed.

Widening the window then exposed a second truncation one layer down, so
the fetch loop moves with it. It passed `--limit 50` while a recovered
window spans up to 8h, and `gh run list` returns newest-first — so a
workflow over the limit silently drops its *oldest* runs, which are
exactly the ones in the gap the anchor just reached back for. On
`max-sixty/tend`, `tend-mention` alone produces 57 runs in an 8h window.
The limit is now 200, and a workflow returning exactly the limit warns
rather than truncating in silence.

Two smaller pieces: the anchor query routes through `gh_retry` and exits
non-zero instead of `2>/dev/null || true`, so a transient API error can
no longer masquerade as "no successful run" and emit a confident warning
naming a cause that didn't happen; and `review-reviewers/SKILL.md`,
which still said "if empty, record all-clear" with nothing about the
stderr warnings, now treats any `WARNING:` as a coverage gap — without
that, an agent following the skill literally would print the warning and
record an all-clear anyway.

When every tick fires and succeeds the anchor is the previous tick,
`prev_intended == intended - 3600 == COMPLETED_AFTER`, and the
comparison is a no-op — output is byte-identical to today's on the
healthy path.

<details><summary>Verification against live data</summary>

Same tick, same repo, before vs. after:

```
# anchor query — before (--limit 10, no conclusion filter)
{"conclusion":"failure","createdAt":"2026-08-04T23:10:57Z","databaseId":30959115609}

# anchor query — after (--limit 50, conclusion == "success")
{"conclusion":"success","createdAt":"2026-08-04T08:42:12Z","databaseId":30893072876}
```

`TARGET_REPO=numbagg/numbagg ./list-recent-runs.sh` after the change
returns 5 runs instead of 1, preceded by:

```
WARNING: the last successful 'review-reviewers' run started 2026-08-04T08:42:12Z, more than 6h back. Window floored at 2026-08-04T17:47:00Z; runs that completed before it are NOT in this list. Record a coverage gap, not an all-clear.
```

The recovered anchor (08:42:12Z) matches the gist's last recorded
coverage boundary exactly. Also exercised: the no-successful-run branch
(warns, floors at the cap, exits 0) and the unset-`GITHUB_WORKFLOW`
branch (recovery skipped, unchanged). `shellcheck` clean; `bash -n`
clean. Also exercised after the review follow-ups: the fetch-limit
truncation warning (via a copy with `RUN_LIMIT=5`) and the anchor-query
failure path (exits 1 rather than degrading). See [the follow-up
comment](#838 (comment))
for the full branch table.

</details>

## Gates

- **Evidence level**: Critical — a clearly wrong outcome (the analysis
records an all-clear for a window it never examined, and the window is
then unreachable), which acts on 1 occurrence. Occurrences: 1 this run,
0 historical (no prior gist entry records an outage of a length that
would trigger it).
- **Structural, not stochastic**: no decision point. The anchor query is
deterministic; replayed ten times it picks the failed run ten times.
- **Change type**: targeted fix — one predicate, one query limit, two
stderr warnings. Normal evidence bar under Gate 2, met.
- **Dedup**: checked open issues #831, #830, #829, #828, #827, #824,
#822, #817, #816, #801, #799, #750, #624 and open PRs #826, #825, #823,
#821, #819, #818, #809. #816 / #818 / #823 / #809 all concern outage
*reporting* — naming the cause in the annotation, the stranded trigger,
per-run comment dedup — none touch window recovery. Searching issues and
PRs for `list-recent-runs` surfaces only the three merged predecessors
#526, #753 and #784.

Evidence log: https://gist.github.com/19b5ab297bb7ac7e1e9a44d595ccde0f

---------

Co-authored-by: tend-agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-behavior Behavioral issues found by review-reviewers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants