Repository navigation
fix(ci-gate): two reads per evaluation, coalesce per head SHA, pending (never failure) on an unavailable API - #148
hyperpolymath wants to merge 28 commits into
Conversation
…ontrols Adds a swappable interim `CI/gate`: a reusable workflow (workflow_call, job id gate, no actions, no secrets) that publishes one commit status for the head commit of a completed workflow_run; a pure bash+jq verdict script; a profile validator; per-repository required-check profiles for resource-algebra, mathesis and rsr-template-repo; a caller template; tests/ci-gate.sh wired into the code-hygiene self-test; and docs/CI-GATE.adoc with the workflow acceptance contract. Fail closed: a required check that never reported is a failure, skipped and neutral are not passes, only github-actions check runs count, and a missing or invalid profile is a failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…success validate.jq: parenthesise the forbidden-name binding in check_name. An unparenthesised `... and . as $c | ...` binds the whole `and` chain on jq 1.8, so every negative passed. Audited every other `as` in validate.jq, the validator script and the verdict. Verdict source: jobs (filter=latest) of the kept workflow runs, not check runs. Runs of the gate itself are dropped, the newest run per (workflow_id, event) is kept, and EVERY job of a required name must succeed. Rule order: a non-success required job fails at once; else any active run is pending (timeout fails); else a name with no job fails; else success. The kept runs go to jq by file, not argv (real runs overflow the argument list). Caller template triggers on completed and in_progress so a rerun replaces a stale success with pending. Profiles: add the renamed in-workflow aggregators `Proofs verdict` (resource-algebra#41) and `Proven suite verdict` (mathesis#101); they exist once the consumer rename PRs merge. Tests: 204 checks, fixtures moved to the jobs shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…run is pending
Profiles are schema_version 2: each required check is {job, workflow}, the job display name
and the workflow file that produces it. A display name made by two workflows (the
Empty-linter gate) is two entries, so a second producer that never ran is a failure
("never reported: <file>:<job>"). The validator rejects schema 1, bad or traversing
workflow paths, missing or extra members, duplicate pairs and unsorted entries. The three
shipped profiles are migrated from the real run paths read at the two commits each.
Rule (b): any workflow run of the commit but the gate's own, kept or superseded, that is
active makes the verdict pending, so a rerun of an older run is watched. The timeout clock
uses the oldest kept or active run. Job verdicts still come only from kept runs' latest
attempt jobs. Run paths are read from the runs, jobs carry the run tag.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…oncurrency
scripts/ci-gate-publish.sh now owns reading, evaluating and publishing (gh on PATH only, so
a stub drives it). On an in_progress event it first writes pending ("re-run started: ...").
It fingerprints the runs of the SHA (id, status, conclusion, run_attempt, updated_at, gate's
own excluded), evaluates, re-reads the runs just before the POST and re-evaluates if they
moved (5 rounds, then pending "runs still changing", never success). This covers every
state, so a late evaluator cannot leave a stale pending or failure either. API errors post a
failure status.
The caller template loses its concurrency block (serialising per SHA delayed the in_progress
caller behind a running evaluation that then wrote a stale success). Docs state the residual
window between the last check and the POST and why the status still converges.
Tests: a stub gh with canned runs per call, canned jobs and a POST log; 283 checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
The code-hygiene gate treats the whole word STUB as an untracked debt marker. The publish controls used $STUB for the fake `gh` directory, which failed the gate on 25dfaa9. Rename the variable; no behaviour changes. tests/ci-gate.sh: 283 passed under jq 1.7.1 and 1.8.1, and actions/code-hygiene-check/check.sh passes locally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
The workflow's first step after input validation writes `pending` ("re-run started: ...")
for an in_progress event, before any suite file is fetched. The publisher no longer writes
that itself. After each status POST it re-fetches the runs and recomputes the fingerprint;
if the runs moved it re-evaluates and writes again, within the same bound of 5 rounds, and
the last write of an unsettled gate is pending "runs still changing".
Docs state the residual limit plainly: commit statuses are last-writer-wins with no
compare-and-swap, so a delayed evaluator can briefly publish a stale state, success
included. The bound is the next evaluator, normally seconds; full elimination needs a
compare-and-swap the statuses API lacks and is deferred to the A3 estate-gate.
Tests: a deterministic pause control (a newer pending lands just before the evaluator's
POST, then verification corrects it), the verification bound, and a static step-order
check. 290 checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
Commit statuses are last-writer-wins. A delayed evaluator can leave a stale success (fail-open, until some later evaluator writes) or a stale pending (fail-closed, until a workflow on the commit is re-run). The previous text claimed eventual correctness "normally within seconds", which the design does not guarantee. Documentation only; the reusable, the scripts and the tests are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…e" claims Three statements contradicted the residual limit: docs/CI-GATE.adoc said `completed` settles the verdict and that a late evaluator cannot leave a stale pending or failure; the publisher header and the caller template repeated it. Statuses are last-writer-wins, so the guard and the verification narrow the window for a stale write of any state but do not close it. Comments and docs only; the behaviour is unchanged. tests/ci-gate.sh: 290 passed under jq 1.6 and 1.8.1; the hygiene check and actionlint pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…rap note - ci-gate.yml: also runs on schedule and workflow_dispatch. Those events sweep the open pull request heads and the default branch head (scripts/ci-gate-sweep.sh), running the same guarded publisher once per distinct SHA, capped at 100 with a loud warning above it; a failure on one SHA does not stop the others and the job is red at the end if any SHA failed or errored. Needs pull-requests: read. - templates/ci-gate-caller.yml: workflow_run + schedule (7,22,37,52) + workflow_dispatch, pull-requests: read. - The suite gates itself: .github/workflows/ci-gate-caller.yml (local reusable, context "CI / gate") and profiles/ci-gate/hyperpolymath/proven-cicd-and-workflows.json. The lock-scope guard now accepts a local reusable workflow reference only when it is a plain file under .github/workflows that exists and is in the scope inventory, and inspects its own references; three new mutants cover the refusals. - docs/CI-GATE.adoc: Sweep, Residual limit (no guarantee, no bound), Bootstrap. - tests/ci-gate.sh: 353 checks, including the sweep controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
… ref-qualified run paths - Context guard admits single interior spaces (CI / gate), capped at 128 characters; the validation step and the failure fallback carry the identical guard. - post() (die() included) skips a POST that repeats the standing status for the context (same state and description); a failed or malformed read writes anyway. Bounds repetition toward GitHub's 1000-status cap; does not remove it. - Pass each workflow run record to jq through a file (--slurpfile) so a run above 128 KiB cannot overflow one argv string. - Strip an @<ref> suffix after .yml/.yaml from run paths before comparing with a profile entry; the profile side still rejects it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…amper guard The gate can now be called from a pull_request workflow as well as workflow_run: the head SHA is resolved from either; a pull_request run polls (bounded) while the verdict only means not finished (pending, never reported, never completed) and then gives the unchanged verdict; on timeout it fails naming what is missing. Adds the gate tamper guard (pull_request_target, reads the API only) that fails a pull request touching gate files unless the owner applied gate-change-approved after the newest commit. Tests: ci-gate.sh 446 -> 472, ci-gate-tamper-guard.sh 70. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDj7XpKyxE4WbsgTsTh
…el env (startup failure) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDj7XpKyxE4WbsgTsTh
… and count renamed files once in tamper guard <!-- coderabbit-ai-generated:v1 -->
The label counts only if the actor of its latest labeled event holds admin
(GET repos/{repo}/collaborators/{login}/permission, .permission == "admin").
A write or maintain actor, a missing actor, a malformed login, an API error
or an unexpected answer all fail closed. Tests cover admin, write, maintain,
read, 404, API error, no actor, bad login, and latest-event-decides; the
guard workflows get a no-interpolation-in-run check and a single-default
check for the APPROVAL_LABEL name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…p PR waits, and handle tamper guard edits and dot-prefixed repos <!-- coderabbit-ai-generated:v1 -->
… test the dot-prefixed coordinate, cache and quota paths f6e8548 widened the tamper guard's REPO regex to [A-Za-z0-9_.-]+, which let a/. and a/.. through, and left the same coordinate check unchanged in ci-gate.yml (REPO, WF_REPO), ci-gate-tamper-guard.yml (WF_REPO) and the profile validator, so example/.github was still refused there. - one coordinate rule: owner [A-Za-z0-9][A-Za-z0-9-]*, name [A-Za-z0-9_.-]+, name not "." or "..", in the guard, both workflows, validate.jq, and now the publisher and the sweep (they used the value in a profile path unchecked) - tests: coordinate matrix (a/b/c, /x, a/, a/., a/.., empty, ../x, spaces) against the guard, the workflow validation step (extracted from the YAML), the publisher, the sweep and the validator; example/.github end to end through the profile fetch and the publisher; dotglob so a shipped .github.json profile is checked - tests: quota that resets inside the wait sleeps to the reset and goes on; an unreadable rate limit fails closed; 20 kept runs over 48 polls read each completed run's jobs once Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…r fail on an unavailable API One push on resource-algebra#50 started 22 workflows. Every started and completed workflow evaluated the commit and listed the jobs of every run (N+1 requests, repeated on every poll of a waiting pull request), which exhausted the installation token quota. The gate then published "could not produce a verdict" for a commit whose checks all passed. - Reads: the workflow runs of the head SHA and the latest check runs of the commit (scripts/ci-gate-lib.sh, profiles/ci-gate/join-checks.jq, joined on check suite id) replace the per-run jobs calls and the completed-job cache. Profiles and verdict shape are unchanged. The callers and the reusable now need checks: read. - Coalescing: the reusable's job is in a concurrency group keyed on repository, context and head SHA with cancel-in-progress for workflow_run and pull_request; the sweep has its own group and is never cancelled. The callers trigger on workflow_run completed only, and the early in_progress pending is gone. - gate-pr no longer waits or polls: it writes one deduplicated pending, evaluates once and exits. wait_minutes and poll_seconds are still accepted, documented as deprecated and ignored. - A missing or unfinished required check is pending (failure only past timeout_minutes, or when its run ended unsuccessfully with no job); zero matches is never success. - Every request goes through gate_api: Retry-After, else x-ratelimit-reset, else exponential back-off with jitter, bounded by CI_GATE_BACKOFF_MAX_SECONDS (default 300). A rate limit, 5xx or no answer that outlasts the bound posts pending, never failure (publisher exit 75); a refused pending write exits non-zero without a failure status. A real error (a 403 that is not a rate limit, a 404, an unusable body) still fails closed. The sweep stops at the first unavailable API and ends red. - Every status description goes through one sanitiser (jq): no codepoint above U+FFFF, at most 140 characters, never cutting inside a character. - tests/ci-gate.sh covers the call budget, pagination, the join, coalescing from the YAML, back-off, the sanitiser, and the bootstrap, profile-fetch and fallback steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
…nt-driven pull_request path and pending on an unavailable API Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
main's tree equals #139's head (58c680e), the base of this branch, so the merge keeps this branch's tree unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
…o this branch can be pushed without force Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
…nd back-off CI-GATE.adoc: the 1000-result caps and the incomplete-snapshot rule; the timeout clock starts at the oldest eligible non-gate run (a CI gate run alone does not start it) and is applied by a later evaluation; re-runs write pending at start and first attempts are filtered at no cost; back-off, recheck, sweep and fallback behaviour. profiles README: an unsuccessful required workflow fails at once, and timeout_minutes applies only without a decisive failure. code-hygiene-self-test.yml: reword and rewrap the ci-gate comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
…ccarthy-ly8eue Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
… sweep and snapshot reads - Callers subscribe to workflow_run completed, requested and in_progress; the job if: admits completed always and a start event only for run_attempt > 1. Both start actions take the pending-only path; the second start event of an attempt is a dedupe read only. - gate_api: a 2xx whose body was cut off is transient (GET retried, write rechecked before replay); x-ratelimit-reset is parsed separately with room for 12 digits (ten-digit epochs were truncated); Retry-After accepts RFC 850 (two-digit year rule) and asctime as well as IMF-fixdate, in the C locale. - gate_paginate: snapshot listings need a numeric total_count and are incomplete at 1000 runs or 1000 distinct check suites, whatever total_count says. - publisher: unavailable=true when the post-write read is unavailable, whatever was posted; a pull_request success whose runs moved is replaced by pending before the next round; the pending-write failure reports rejected or unconfirmed. - sweep: "pending not confirmed" unless GitHub rejected the write; the headline counts heads attempted. - tests: every behaviour change, a cut-off answer in the fake gh, ten-digit fake clock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
- Re-runs: which start event GitHub sends is unconfirmed (requested is documented as not emitted for a re-run), so both are subscribed; first attempts are filtered at no API cost; a skipped job still creates a run record. - Document the HTTP-date forms, the epoch reset, cut-off bodies, the snapshot caps and the sweep wording. - Bootstrap recovery: re-run CI gate on the same head; a push starts a new head and is no substitute. - Qualify the self-test comment on a missing required check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
…er replays; classify pending failures - gate_api: a write whose 2xx headers arrived is acknowledged: landed, no recheck, no replay. - gate_status_matches returns "unknown" (not "differs") when its read fails or is malformed; the recheck of an unknown-outcome write then cannot tell, so the write is not replayed and returns 75. The dedupe still writes on doubt. - A sticky GATE_API_UNKNOWN across the retries of one write: a later real error is reported as pending=unconfirmed, never pending=rejected. A local error (no temporary file, unusable description) is pending=local-error, and the sweep says no write was attempted. - docs: wording for these cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
Resolved conflicts so both changes survive: each caller keeps the explicit workflow_run.workflows list from this branch and takes #148's types [completed, requested, in_progress] with the re-run-only `if:`; the docs sentence names both the list and the re-run rule. Tests: ci-gate 868/0 on jq 1.6, 1.8.1 and system jq (including the glob control); ci-gate-tamper-guard 127/0; actionlint clean on both callers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9
|
@coderabbitai approve All findings from the three review rounds are fixed in 57f1b3d..eb67750, and every thread has been answered. The one open item is the live re-run check (behaviour change 4). It can only run once this PR is on Generated by Claude Code |
|
@hyperpolymath The live re-run check remains unverified. Until it passes, do not assume an active re-run sets the gate to pending; a previous success could remain visible. After merge, verify the re-run behaviour on The approval workflow will check eligibility and review readiness. Action performed
|
…e-pin the suite gate to main a0760ce (#56) This PR makes two changes. The second was added on 2026-11-23, following an owner ruling. ## 1. Checker fix (`3b9f658`) `scripts/check-required-contexts.sh` (`localTargetError`) now requires the local reusable to declare `on.workflow_call.inputs.context` with `type: string`. The caller passes `with.context`. GitHub refuses an input that the called workflow does not declare, so a local target without that input could never publish the required status. The tests now cover a missing input, the list form, the string form, no `context` key, a non-string type, and no type. Positive fixtures declare the input. The same fix is in hyperpolymath/rsr-template-repo#451, which is merged, and in hyperpolymath/mathesis#106. ## 2. Re-pin (`384e5c4`) This re-pins the suite gate from `4e9e680` to suite `main` `a0760ce` (hyperpolymath/proven-cicd-and-workflows#164). `4e9e680` reads each run's jobs one API call at a time. When the installation runs out of API quota it fails with "could not read the jobs of run". That failure is what kept this PR's `CI/gate` red. `a0760ce` adds: - retry and back-off on rate limits; - a per-commit concurrency group; - a sweep that stops when it is rate-limited; - the emoji-safe status description, which it keeps. The caller shape is unchanged and no new permissions are needed. Files updated: `ci-gate.yml`, `ci-gate-tamper-guard-caller.yml`, `actions.lock` (SHA swap, `ref` stays `main`), the squabble `SUITE_PIN`, `actions_lock_sha_refs_test.sh`, and the CHANGELOG. `main` was merged in first (`862e044`). ## Proven (local, on the head) - `tests/workflows/squabble_gate_test.sh`: 150 passed, 0 failed. - `tests/workflows/actions_lock_sha_refs_test.sh`: OK. - `scripts/check-lock-sync.sh`: OK. - `scripts/check-required-contexts.sh .`: OK. - `actionlint` on both callers: clean. ## Not proven - Live CI on this head. - The default-branch `workflow_run` gate still runs `main`'s caller, which pins `4e9e680` until this PR merges. It can therefore still post a failure caused by the old code. - The explicit `workflow_run` list, which cuts the number of gate runs per push, is waiting on hyperpolymath/proven-cicd-and-workflows#148 and #151. A second re-pin will follow once they land. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved validation of local reusable workflows, rejecting configurations with missing or invalid `context` inputs. * **Chores** * Updated the reusable CI and tamper-guard workflows to a newer revision. * **Tests** * Expanded coverage for valid and invalid workflow input configurations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <noreply@anthropic.com>
## Why On 2026-11-23 the owner ruled that consumers should re-pin to the suite's `main` now. rsr `main` currently pins `09878f2`, which only exists on the branch of the closed hyperpolymath/proven-cicd-and-workflows#144, a branch that is kept alive only for this pin. `a0760ce` is on suite `main` (hyperpolymath/proven-cicd-and-workflows#164). It carries: - the emoji-safe status description: 4-byte characters are replaced before the 140-character clip, which keeps the CodeRabbit ask from #450; - retry with back-off on API rate limits; - a per-commit concurrency group in the reusable; - a sweep that stops when it is rate-limited. The caller shape is unchanged: the template diff between the old and new pin is comments only, and no new permissions are needed. ## Change `ci-gate.yml`, `ci-gate-tamper-guard-caller.yml` and `actions.lock` swap `09878f2` for `a0760ce`; the lock keeps `ref: 'main'`. The squabble `SUITE_PIN` and the CHANGELOG entry are updated to match. ## Proven (local) - `tests/workflows/squabble_gate_test.sh`: 174 passed, 0 failed - `scripts/check-lock-sync.sh`: OK - `scripts/check-required-contexts.sh .`: OK - `actionlint` on both callers: clean ## Not proven - Live CI on this head. - The explicit `workflow_run` list, which cuts the fan-out. That waits for hyperpolymath/proven-cicd-and-workflows#148, then #151, and a second re-pin follows. --- _Generated by [Claude Code](https://claude.ai/code)_ Co-authored-by: Claude <noreply@anthropic.com>
…lib.sh), pair-rule profile test from #165
|
|
Closing as superseded by main. On the owner's decision, the parts main still lacks are being ported onto main's own REST layer in a new, focused PR. While this PR waited, main merged a parallel rewrite of the same gate:
Merging this PR now would leave two API layers and conflicts in 7 core files. Still missing on
Merge commits 767bd15 and f2872c1 on this branch are unsigned; they were pushed from another session. Generated by Claude Code |
…in; re-run start; sweep outage stop Ports the behaviour of the closed #148 onto main's single REST layer (scripts/ci-gate-api.sh); no second library. 1. Unavailable is not failure. api_request/api_list return 2 for an unavailable answer (429 or a rate-limit 403 past the attempts or the budget, a 5xx, no answer, a truncated transfer) and 1 for a real error. The publisher writes pending ("GitHub API rate-limited or unavailable; re-evaluating later") and exits 75 instead of "could not read the jobs of run N" = failure (run 46407496788, 2026-11-30). If the pending cannot be written either it says "pending not confirmed" or "pending refused" and still writes no failure. The workflow's failure fallback stays silent after unavailable=true (publisher or early step). A permissions 403, a 404, a malformed body and a missing total_count still fail closed. 2. Snapshot by the two-read join: one paginated commits/{sha}/check-runs?filter=latest joined to the runs on check_suite.id == check_suite_id (profiles/ci-gate/join-checks.jq) replaces one jobs read per run (22 workflows: 24 -> 4 billed reads). A snapshot with total_count above the items read, 1000 or more runs, or check runs of 1000 or more suites is incomplete: pending, never a missing-check verdict. checks: read added to the reusable, both callers and the template. 3. Re-run start: the caller job admits workflow_run in_progress only for run_attempt > 1; an admitted in_progress writes ONE deduplicated pending ("a required workflow is re-running; re-evaluating on completion") and evaluates nothing (no list, no check-run read). completed is unchanged. 4. The sweep reads the default branch, its head and the pull request list through the REST layer and stops at once on an unavailable read or a publisher exit 75: it stays red, names the heads not evaluated, and says "pending not confirmed" unless the pending was written or GitHub rejected it. Tests: tests/ci-gate.sh, tests/ci-gate-api.sh, tests/ci-gate-api-budget.sh (census), fake gh with check-runs, 5xx, no-answer and listing endpoints. The mutation helpers of the three ci-gate test files now use perl, not python (estate language policy). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
…in; re-run start; sweep outage stop (#191) Ports the four parts of the closed #148 that `main` still lacked, onto `main`'s own REST layer (`scripts/ci-gate-api.sh`, from #169). There is no second library. The owner chose this route on 2026-11-30. ## Why On 2026-11-30 a scheduled sweep from `main` (run 46407496788, gate at `47616cb`) posted `CI / gate` = **failure**, "ci-gate: could not read the jobs of run 45935619420", on a commit whose required checks had all passed. A read that `main` gave up on went to `die()` and wrote failure. That is the false red from hyperpolymath/resource-algebra#50. ## Change 1. **An unavailable API is pending, never failure.** - `api_request` and `api_list` return 0 (ok), 1 (real error) or 2 (unavailable). - Unavailable means: 429 or a rate-limit 403 past the budget, any 5xx, no answer, or a cut-off 2xx. - The publisher's `unavailable()` posts pending ("GitHub API rate-limited or unavailable; re-evaluating later"), writes `unavailable=true` and exits 75. The workflow's failure fallback skips when either step reports unavailable. - Real errors still fail closed: a permissions 403, a 404, a malformed body, and a missing or non-numeric `total_count`. 2. **A snapshot by two reads.** - One paginated `check-runs?filter=latest` read, joined to the runs on the check suite (new `profiles/ci-gate/join-checks.jq`), replaces the per-run jobs reads. Third-party suites match nothing. - The snapshot is incomplete, and so pending, if `total_count` exceeds the items read, if there are 1000 or more runs, or if the check runs span 1000 or more distinct suites. - `checks: read` is added to the reusable, both callers and the template. 3. **Re-run start.** - The callers keep `types: [completed, in_progress]` and #179's explicit workflow list. The job `if:` admits `in_progress` only when `run_attempt > 1`. - An admitted start writes one deduplicated pending and does not evaluate. `completed` evaluates in full. 4. **The sweep stops on an outage.** - Its own three reads now go through the REST layer. - An unavailable read, or a child exiting 75, stops it at once. It stays red and names the heads it did not evaluate. - It says "pending not confirmed" unless the pending was written or GitHub refused it. ## Census: billed REST requests per gate job (`tests/ci-gate-api-budget.sh`) | Scenario | `main` 47616cb | This PR | |---|---|---| | 4 runs, settled | 6 | 4 | | required run active | 6 | 4 | | 22 workflows, settled | 24 | 4 | | 348 runs on the head | 9 | 7 | ## Tests Run locally on 605103c with Go yq v4.44.3: | Suite | Before (47616cb) | After | |---|---|---| | `tests/ci-gate.sh` | 695 / 0 | **830 / 0** | | `tests/ci-gate-api.sh` | 96 / 0 | **130 / 0** | | `tests/ci-gate-tamper-guard.sh` | 159 / 0 | **159 / 0** | | `tests/ci-gate-caller.sh` | 200 / 0 | **200 / 0** | - The budget bench reports "after <= before in every scenario". - shellcheck 0.10.0 finds nothing new. - actionlint 1.7.7 is clean on `ci-gate.yml`, the suite caller and the template. - Mutation check: with fix 1 reverted, 74 tests fail. - The mutation helpers in three test files used `python3`. They are now Perl, so no Python runs in validation. ## Behaviour changes and limits - A 5xx or no answer is not retried. It gives pending and exit 75 at once, where `main` wrote an immediate false failure. - A first-attempt `in_progress` no longer writes pending, so a standing success on that commit stays until `completed` evaluates. - **Not verified live:** - that `run_attempt` is set on `workflow_run` events; - that `in_progress` is delivered for re-runs; - that the check-run `check_suite.id` matches the run's `check_suite_id`. After merge, re-run one required workflow and check that `CI / gate` turns pending at the re-run's start. - This PR overlaps `claude/ci-gate-fold-guard` (folding the tamper guard into the verdict). It was agreed that whichever merges second merges `main` and resolves the conflicts, and that neither pushes to the other's branch. - Consumer re-pins wait for both PRs and are regenerated with #167's tool. --- _Generated by [Claude Code](https://claude.ai/code)_ Co-authored-by: Claude <noreply@anthropic.com>



Follows #139, which was squash-merged to
mainas4e9e680. This branch mergesmainback in, most recently16546ab(the work-queue profile). Consumers pind2140a5today, a commit from #139.Problem
On hyperpolymath/resource-algebra#50, one push started 22 workflows. Every
workflow_runevent (completedandin_progress), the pollinggate-prjob and the sweep each listed the commit's runs and then read every run's jobs. Together they used up the installation token's quota (API rate limit exceeded for installation (HTTP 403)). The gate then posted "ci-gate could not produce a verdict", a false red, although every required check had passed.Change
actions/runs?head_sha=andcommits/{sha}/check-runs?filter=latest, both paginated.profiles/ci-gate/join-checks.jqjoins them on the check suite id, which rebuilds the existingWorkflow / jobcontexts. Profiles are unchanged.total_count.pending, never a missing-check verdict) whentotal_countexceeds the items collected, when 1000 or more workflow runs were collected, or when the check runs span 1000 or more distinct check suites. Both GitHub listings are capped, and whether the check-runstotal_countcounts suites beyond the cap is undocumented.concurrencygroup,ci-gate-<repo>-<context>-<head SHA>, withcancel-in-progressforworkflow_runandpull_requestevents. The sweep has its own group and is never cancelled.workflow_runtypes are[completed, requested, in_progress].if:admitscompletedalways. It admits a start event (requestedorin_progress) only for a re-run (run_attempt > 1), so first attempts are dropped before any job starts, at no API cost. A skipped job still creates a run record.requestedas not emitted for re-runs and does not guaranteein_progressfor them either; see behaviour change 4.gate-prwrites one deduplicated pending, evaluates once and exits.wait_minutesandpoll_secondsare still accepted but ignored (deprecated).pull_requestsuccess whose snapshot moved after the write is replaced with pending ("runs still changing").gate_apiinscripts/ci-gate-lib.sh.Retry-Afteris honoured in seconds and in all three RFC 9110 HTTP-date forms (C locale, decimal parsing).x-ratelimit-resetis read as a full epoch timestamp and used only when the remaining quota is 0.CI_GATE_BACKOFF_MAX_SECONDS, default 300.pending("ci-gate: GitHub API rate-limited or unavailable; re-evaluating later").unavailable.Tests
bash tests/ci-gate.sh: 861 passed, 0 failed.bash tests/ci-gate-tamper-guard.sh: 127 passed, 0 failed.job.workflow_*and$/actionsnotes.gate-pr / CI gateruns the new code on this PR. GitHub accepted the job-level concurrency group.CI / gatereports "all 11 required checks passed" oneb67750.Behaviour changes for reviewers
timeout_minutesafter the oldest eligible non-gate run, on a later evaluation. A required workflow that ends unsuccessfully before it creates its job fails at once.::warning::(exit 75) and the commit status is pending, so the gate is not silently green. The sweep ends red if the API stays unavailable, and so does the job when the pending write itself is refused.CI gateon the same head once the other checks pass; a push starts a new head and is no substitute.CI / gateturns pending when the re-run starts. If GitHub sent neither start event for a re-run, a standing success would remain until the re-run completes.Consumers to re-pin after merge
hyperpolymath/resource-algebra, hyperpolymath/mathesis and hyperpolymath/rsr-template-repo. Another session owns these re-pins: one PR per consumer, plus a stacked PR that replaces the
"**"workflow glob with an explicit list. Each caller copiestemplates/ci-gate-caller.ymlat this PR's final head:checks: readin the top-levelpermissions; without it, expectstartup_failure;workflow_runtypes to[completed, requested, in_progress], with the re-runif:.🤖 Generated with Claude Code
https://claude.ai/code/session_01J4QvDixLBHyVxqpp8crrsi
Merge with main (27 Nov), decision
Main's #164 added an inline status writer (CI_GATE_STATUS_LIB, post_status) to ci-gate.yml. This PR's scripts/ci-gate-lib.sh already provides the same behaviour (dedupe, 4-byte clip, Retry-After and x-ratelimit-reset back-off, bounded budget, sweep stops when limited) and adds the policy that an unavailable API gives pending and exit 75, never failure. Resolution: ONE status writer, the lib; main's inline writer is dropped, #164's behaviours are kept through the lib and its tests. Main's #165 profile test (pair rule, none-or-both Empty-linter producers) is ported over this branch's older all-profiles assertion. Result: tests/ci-gate.sh 915 passed 0 failed, tests/ci-gate-tamper-guard.sh 127 passed, tests/ci-profiles.sh passed. Not runnable here: tests/workflow-lock-scope.sh (needs yq).
Generated by Claude Code