From f9ded0ba4764514eefc1d12f017174c659bc55f2 Mon Sep 17 00:00:00 2001 From: Jean-Paul van Ravensberg <14926452+DevSecNinja@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:47:52 +0100 Subject: [PATCH 1/2] fix(state): retry news-state persist on transient release lookup errors gh reports any failed published-release lookup as 'release not found', so a transient API error lost a fully generated briefing. Look the release up via gh api so only a real 404 creates it, and retry the lookup and asset uploads with backoff. Closes #361 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- Taskfile.yml | 53 +++++++++++++++++++++++++++++++++++------- docs/github-actions.md | 2 ++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 40e7a72a..9b2af40c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -117,20 +117,55 @@ tasks: cp public/data/transparency/latest.md .state/{{.TRANSPARENCY_REPORT_ASSET}} fi - if gh release view {{.STATE_RELEASE}} --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then - gh release upload {{.STATE_RELEASE}} .state/{{.STATE_ASSET}} --clobber --repo "${GITHUB_REPOSITORY}" - if [[ -f .state/{{.TRANSPARENCY_REPORT_ASSET}} ]]; then - gh release upload {{.STATE_RELEASE}} .state/{{.TRANSPARENCY_REPORT_ASSET}} --clobber --repo "${GITHUB_REPOSITORY}" + # gh reports any failed release lookup (5xx, abuse limits, network + # errors) as "release not found", so query the REST API directly to + # tell a real 404 apart from a transient failure, and retry transient + # failures instead of losing a whole generated briefing. + release_endpoint="repos/${GITHUB_REPOSITORY}/releases/tags/{{.STATE_RELEASE}}" + max_attempts="${STATE_PERSIST_ATTEMPTS:-4}" + retry_delay="${STATE_PERSIST_RETRY_DELAY:-5}" + + release_state="" + for (( attempt = 1; attempt <= max_attempts; attempt++ )); do + if lookup="$(gh api "${release_endpoint}" --jq .id 2>&1)"; then + release_state=exists + break + elif [[ "${lookup}" == *"HTTP 404"* ]]; then + release_state=missing + break fi - else - gh release create {{.STATE_RELEASE}} .state/{{.STATE_ASSET}} \ + echo "::warning::Release lookup attempt ${attempt}/${max_attempts} failed: ${lookup}" + if (( attempt < max_attempts )); then sleep $(( retry_delay * attempt )); fi + done + if [[ -z "${release_state}" ]]; then + echo "::error::Could not look up the {{.STATE_RELEASE}} release after ${max_attempts} attempts." + exit 1 + fi + + upload_asset() { + local asset="$1" + for (( attempt = 1; attempt <= max_attempts; attempt++ )); do + if gh release upload {{.STATE_RELEASE}} "${asset}" --clobber --repo "${GITHUB_REPOSITORY}"; then + return 0 + fi + echo "::warning::Upload attempt ${attempt}/${max_attempts} for ${asset} failed; API lookup: $(gh api "${release_endpoint}" --jq '.tag_name' 2>&1 || true)" + if (( attempt < max_attempts )); then sleep $(( retry_delay * attempt )); fi + done + echo "::error::Failed to upload ${asset} to the {{.STATE_RELEASE}} release after ${max_attempts} attempts." + return 1 + } + + if [[ "${release_state}" == "missing" ]]; then + gh release create {{.STATE_RELEASE}} \ --title "Wazzup retained news state" \ --notes "Rolling generated YAML state and JSON mirrors for the Wazzup GitHub Pages deployment." \ --prerelease \ --repo "${GITHUB_REPOSITORY}" - if [[ -f .state/{{.TRANSPARENCY_REPORT_ASSET}} ]]; then - gh release upload {{.STATE_RELEASE}} .state/{{.TRANSPARENCY_REPORT_ASSET}} --clobber --repo "${GITHUB_REPOSITORY}" - fi + fi + + upload_asset .state/{{.STATE_ASSET}} + if [[ -f .state/{{.TRANSPARENCY_REPORT_ASSET}} ]]; then + upload_asset .state/{{.TRANSPARENCY_REPORT_ASSET}} fi news:generate: diff --git a/docs/github-actions.md b/docs/github-actions.md index 409b26e5..926bc0ee 100644 --- a/docs/github-actions.md +++ b/docs/github-actions.md @@ -165,6 +165,8 @@ Operational learning: the site served stale data after manual and watchdog-trigg Operational learning: the site went stale for most of a day because GitHub schedule jitter routinely shifts the hourly `News` cron across hour boundaries. The cadence gate evaluates the local hour at execution time, so a run intended for an odd local hour (07:00, 09:00, …) frequently lands on an even or overnight hour and skips all real work. The original `news-watchdog` could not recover from this: it only checked whether _any_ `News` run existed in the current UTC hour, and since the hourly cron always fires (even when it gate-skips in seconds), it always saw a run and never dispatched a catch-up. The watchdog now runs every hour inside the active local window (07:00–21:59, no odd-hour parity gate so jitter cannot disable it) and decides purely on freshness: it inspects recent `News` runs, treats only a successful `Generate and persist retained news state` step as an effective generation, and dispatches a `workflow_dispatch` catch-up when the newest effective generation is older than the two-hour cadence interval and no `News` run is currently queued or in progress. This keeps the two-hour spacing while making missed scheduled runs self-healing. +Operational learning: a fully generated briefing was lost because `gh release upload news-state` failed with `release not found` although the release existed. `gh` races a published-release REST lookup against a draft-release GraphQL lookup and reports _any_ failure of the REST lookup (a 5xx, abuse limit, or network error) as "release not found" once the draft lookup returns nothing, so a transient API error was indistinguishable from a missing release. `task state:persist` now looks the release up through `gh api` so only a real HTTP 404 creates it, and retries both the lookup and each asset upload with linear backoff (`STATE_PERSIST_ATTEMPTS`, default 4; `STATE_PERSIST_RETRY_DELAY`, default 5 seconds), logging the underlying API response on each failed attempt. + ### Shared model policy Both local Python providers and Actions fetch **data only** from [DevSecNinja/.github/copilot-models.json](https://raw.githubusercontent.com/DevSecNinja/.github/refs/heads/main/copilot-models.json). There are no production model defaults in Wazzup's Python, workflow environment, or agent frontmatter. From 6f7092f2b9806ff93f9e0f4bb3f2200d98bbb5ef Mon Sep 17 00:00:00 2001 From: Jean-Paul van Ravensberg <14926452+DevSecNinja@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:57:08 +0100 Subject: [PATCH 2/2] fix(state): log the failed upload's own error with a release status probe Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- Taskfile.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 9b2af40c..4756392b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -145,10 +145,15 @@ tasks: upload_asset() { local asset="$1" for (( attempt = 1; attempt <= max_attempts; attempt++ )); do - if gh release upload {{.STATE_RELEASE}} "${asset}" --clobber --repo "${GITHUB_REPOSITORY}"; then + if upload_output="$(gh release upload {{.STATE_RELEASE}} "${asset}" --clobber --repo "${GITHUB_REPOSITORY}" 2>&1)"; then return 0 fi - echo "::warning::Upload attempt ${attempt}/${max_attempts} for ${asset} failed; API lookup: $(gh api "${release_endpoint}" --jq '.tag_name' 2>&1 || true)" + # gh hides the failed request's HTTP status behind "release not + # found", so pair its message with an immediate status probe that + # shows whether the release really disappeared or the error was + # transient. + probe_status="$(gh api --include "${release_endpoint}" 2>&1 | head -n 1 || true)" + echo "::warning::Upload attempt ${attempt}/${max_attempts} for ${asset} failed: ${upload_output} (release probe: ${probe_status})" if (( attempt < max_attempts )); then sleep $(( retry_delay * attempt )); fi done echo "::error::Failed to upload ${asset} to the {{.STATE_RELEASE}} release after ${max_attempts} attempts."