Repository navigation
fix(notifications): tolerate transient non-JSON gh api responses - #780
Conversation
The tend-notifications pre-check ran `gh api notifications --jq 'length'` as its first command under `bash -e`. When GitHub transiently returns an HTML error page (even with a 200) during a brief API blip, gh's internal jq fails to parse it and exits non-zero, aborting the whole step red — a scheduled janitor cycle turned into a red build over a routine upstream blip. Three bare re-fetches in Layers B/C/D were untolerated too. Fetch notifications once with a short retry, validate the JSON, and skip the cycle cleanly (count=0, exit 0) if it still fails — the next scheduled cycle picks up anything missed. Layers B/C reuse that snapshot (marking a thread read is idempotent). Layer D keeps its semantic re-fetch (it must reflect threads marked read in B/C) but falls back to the snapshot on a transient failure rather than aborting. Closes #779
|
I'm skeptical that GH is actually returning incorrect, empty responses. are we such it's not something that we're doing which is turning errors into empty responses? |
Address review skepticism on #780: the blanket count=0/exit-0 skip on any non-JSON response would also swallow a *persistent* failure (a real problem on our side), not just a transient GitHub-edge blip. On the skip path, dump the HTTP status line + body head via 'gh api -i' so a recurring failure stays diagnosable in the Actions log rather than green-forever silent. This also makes the root-cause question empirically answerable next time: the current logs mask the HTTP status behind gh's jq parse error, so we cannot yet prove the HTML came from GitHub's edge vs. anything else.
|
Good question to push on — I'll separate what the logs prove from what I assumed. What's certain: the failing step calls What I over-stated: my commit message said "even with a 200." The logs don't actually show the HTTP status — The flip side of your concern — which I think is the sharper one: the fix's blanket So I pushed Happy to go further if you'd rather not swallow at all — e.g. only skip on a 5xx / empty-body and let anything else fail the step — but I'd lean against re-introducing red builds for what the evidence points to being genuine transient edge errors. |
|
can we keep the same behavior but log more so we can with out what's actually coming back? |
…empt Move the response diagnostic into the retry loop so a transient blip that recovers on retry still leaves the bad response in the log — previously the plain fetch hid it behind 2>/dev/null and only a *persistent* failure (all retries exhausted) logged anything, via a separate re-fetch that could show a recovered response rather than the one that failed. Behavior is unchanged: retry 3x, skip cleanly (count=0, exit 0) on persistent failure. The extra gh api -i call runs only on a failing attempt; the happy path stays one fetch.
|
Done — pushed `b1a51c8`. Same behavior (retry 3×, skip cleanly on persistent failure), but the response diagnostic now fires on every failed attempt inside the retry loop instead of only after all retries are exhausted. The important shift: previously the transient case — the exact one we want to diagnose — retried, recovered, and threw the bad body away behind `2>/dev/null`; only a persistent failure logged anything, and it did so via a separate re-fetch that could show a recovered response rather than the one that actually failed. Now each failing attempt logs the real response via `gh api notifications -i` (HTTP status line + headers + body head), so the next time this fires we see exactly what GitHub returned — status code included — even if the retry succeeds a second later. That should answer your original question empirically. The extra `-i` call only runs on a failing attempt; the happy path is still a single plain fetch. Full suite green (276), notifications regtest snapshots regenerated. |
## 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_
## Summary - Regenerates tend's own `.github/workflows/tend-*.yaml` via `uvx tend@latest init` against the just-released 0.1.12. - Action pins move `0.1.11` → `0.1.12`. - `tend-notifications.yaml` picks up the transient non-JSON `gh api` response tolerance (#780). ## Test plan - [x] `uvx tend@latest init` ran clean, wrote 8 files - [ ] CI green on this PR > _This was written by Claude Code on behalf of Maximilian Roos_
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]>
Problem
The generated
tend-notifications.yamlpre-check ("Check for unread notifications") opened withCOUNT=$(gh api notifications --jq 'length')as its first command, running under the defaultbash -e. When GitHub transiently returns an HTML error page instead of JSON — a routine minutes-long API blip, sometimes even with a 200 status — gh's internal jq fails withinvalid character '<' looking for beginning of value, gh exits non-zero, andset -eaborts the whole step. A scheduled janitor cycle becomes a red build over a transient upstream blip, and that notification-sweep cycle is skipped until the next schedule interval.The three later bare
gh api notificationsre-fetches (Layers B/C/D) were untolerated too.Solution
Fetch notifications once with a short retry, validate the body is JSON, and if it still fails skip the cycle cleanly (
count=0,exit 0) rather than failing red — the next scheduled cycle picks up anything missed. Layers B and C now reuse that single snapshot (marking a thread read is idempotent, so a stale snapshot at worst re-PATCHes an already-read thread). Layer D keeps its re-fetch because that fetch is semantically meaningful — it must reflect threads marked read in B/C so the processable count is accurate — but falls back to the pre-mutation snapshot on a transient failure instead of aborting (an over-count at worst spends one agent run, never fails the build).This is a structural fix to the generated workflow template, so it reaches every tend consumer at the next release.
Testing
Added
test_notifications_precheck_tolerates_transient_non_json, which extracts the rendered pre-check script and runs it underbash -ewith a fakeghthat mimics the transient blip (baregh api notificationsreturns HTML with exit 0; the--jqform fails as gh's internal jq does). It asserts the script exits 0 and writescount=0. The test fails on the old template (exit 4) and passes on the fix. The 4 notifications regtest snapshots were regenerated; full suite (276 tests) green.Closes #779 — automated triage