Repository navigation
check: report an unreadable ruleset bypass list as unknown, not ungated - #825
Conversation
GitHub serves a ruleset's `bypass_actors` only to a repo admin — below that the field is omitted, so `_tags_admin_gated` cannot decide and returns None. `_policy_gate` credited the tag entries only on True, so a credential environment admitting tags failed for the bot's own write-scoped token while passing for a maintainer's admin token, on identical configuration. That breaks the module's stated invariant that the nightly sees the answers a maintainer does, and fires on exactly the release-environment shape tend prescribes. Split the verdict: a gate confirmed absent still fails, a gate the token cannot see reports unknown, the stance check_branch_protection already takes on an unreadable bypass list.
_policy_gate returned on the first entry that did not gate, so an unverifiable tag entry ahead of a branch entry naming an unverified ref downgraded a settled failure to unknown — and which one came first was whatever order the API listed the policy in. Hold the unverifiable gap and return it only when no entry produced a confirmed one.
tend-agent
left a comment
There was a problem hiding this comment.
The unknown-vs-failure split reads right, and the two new tests pin the halves that matter (withheld list → unknown; a settled bad ref outranking it, both orders). Two things below.
The other reason that moved to verified=False — the deployment branch policy the token cannot list — has no test. Dropping verified=False from that return leaves all 329 tests green, so nothing pins the half of the change the PR body calls out as moving for the same cause. Inline suggestion adds one (verified: it fails on that mutation, passes as-is, ruff format clean).
Separately, holding the unverified gap instead of returning it makes the steerable return reachable while a tag entry was unverifiable, and its message opens admits only verified refs — a claim about refs this token could not verify. The verdict is still a genuine failure there (the bot fires the trigger against an already-admitted ref either way), so this is wording, not logic — but that clause now asserts something the path didn't establish.
…make `_tags_admin_gated` returns None for an unlistable `/rulesets` and for a bypass actor naming a team, app, or deploy key, not only for a withheld bypass list — so the message no longer prescribes the admin re-run that settles just one of those. It names the set, as `check_branch_protection` already does on the same field. The `steerable` gap opened `admits only verified refs` while a held unverified entry meant one of them hadn't settled. The ref list is beside the point on that path — the bot picks the ref — so the reason now states the trigger, which holds either way, and stays a verified finding. Tests: the `_branch_policies` → None path (drop its `verified=False` and it fails), and steerable outranking a held unverified tag entry (return `unverified` first and it fails).
|
On the third point from the review body — the The ref list is beside the point on that path — the bot picks the ref, so what the policy admits doesn't decide the verdict — which is why the finding stays verified even with an unsettled entry held. The two inline threads carry the other two fixes. |
tend-agent
left a comment
There was a problem hiding this comment.
One gap left in the enumeration the commit set out to complete. _bypass_actors_above_bot reaches None a fifth way: a User bypass actor whose id can't be compared because _user_id(bot_name) returned None (the if bot_id is None: unresolved = True branch). The likeliest cause isn't a permission wall — it's a bot_name in .config/tend.yaml that doesn't resolve, so gh api users/<name> 404s. On that input the reader gets a message naming three causes, none of which is theirs, and nothing else in tend check says the login is wrong either: check_bot_permission's 404 path reports "Could not check (may require admin access to read)".
The same sentence in check_branch_protection — the Branch '<b>' is protected but could not verify that the bot cannot bypass its rulesets return — has the identical gap, and it's outside this diff. Happy to push a commit covering both if you want them to stay matched.
`_bypass_actors_above_bot` also returns None when a `User` actor's id has nothing to compare against — `_user_id(bot_name)` 404s — so a `bot_name` that isn't a real login lands on a message naming only causes that aren't theirs. `check_bot_permission` doesn't call it out either, so nothing in `tend check` points at the config. Both copies of the sentence get it: `_policy_gate`'s tags reason and `check_branch_protection`'s ruleset reason read the same helper's None, and the point of matching their wording is that they stay matched.
|
Confirmed and fixed in ce7d23e. Took Left alone: |
tend-agent
left a comment
There was a problem hiding this comment.
ce7d23e names the fifth way in both user-facing messages, but two internal enumerations of the same set still list only four — and one of them is the comment that exists to explain the message directly below it, so the two now contradict each other. Suggestion inline.
The other is _bypass_actors_above_bot's own docstring (outside the diff), which is the canonical statement of when that function returns None:
...None when the list is withheld (only ruleset admins see
bypass_actors) or names a principal this can't resolve (a team, app, or deploy key).
Same gap — the unresolvable-bot_name case is a User actor, which that parenthetical excludes. Happy to push both as one commit if hand-applying isn't convenient.
The comment above the tags reason listed four inputs while the string below it named five, and `_bypass_actors_above_bot`'s docstring — the canonical statement of when that helper returns None — excluded the `User` case by naming only teams, apps, and deploy keys.
…oded (#879) `check_credential_environments` read the environment list with `listed.stdout.split()` and interpolated each name straight into the API path. GitHub admits both a space and a `/` in an environment name, and the list endpoint returns one name per line — so an environment called `staging deploy` became two names, `staging` and `deploy`, that exist nowhere, and one called `a/b` addressed `repos/<r>/environments/a/b/secrets`, a path that names no environment either. Both shapes 404. The first 404 is the `secrets is None or secrets.returncode != 0` branch, which returns the **whole check** as skipped: ``` SKIP credential-environments — Could not list secrets in 'staging' (requires admin access) ``` So the check that backs the security model's "a run the bot can cause reaches no credential" claim stops verifying, and the message blames the token rather than naming the real cause. The genuine environment is never examined either — if it holds an ungated credential, nothing reports it. One such environment costs the repo the check entirely, including for its other environments. `splitlines()` fixes the read. `_env_path` — `quote(name, safe="")` — fixes the way back out: `gh api` percent-encodes a space itself but passes a `/` through as a path separator, and it does not re-encode the escapes it is handed, so encoding the whole name as one segment covers both shapes with one rule. ## Verification Confirmed against live GitHub on `tend-agent/tend-integration`, with both probe environments deleted afterwards: ```console $ gh api -X PUT "repos/$R/environments/zz%20probe" --jq '.name' zz probe $ gh api -X PUT "repos/$R/environments/zz%2Fprobe" --jq '.name' zz/probe $ gh api --paginate "repos/$R/environments" --jq '.environments[].name' tend zz probe zz/probe $ gh api "repos/$R/environments/zz/probe/secrets" # raw slash gh: Not Found (HTTP 404) $ gh api "repos/$R/environments/zz%2Fprobe/secrets" --jq '.total_count' 0 $ gh api "repos/$R/environments/zz%2Fprobe" --jq '.name' zz/probe $ gh api "repos/$R/environments/zz%2Fprobe/deployment-branch-policies" {"total_count":0,"branch_policies":[]} ``` The escapes survive the PUT, which is what shows `gh` passes them through rather than re-encoding the `%`. `%2F` then resolves on the detail, secrets, and deployment-branch-policies endpoints alike, where the raw `/` 404s. The last of those was read with `custom_branch_policies` enabled — that endpoint 404s on an environment with a null `deployment_branch_policy` regardless of encoding, which is the case `_policy_gate` returns on before it ever calls `_branch_policies`. ## Tests `test_credential_environments_reads_a_name_containing_a_space` and `test_credential_environments_reads_a_name_containing_a_slash` both fail with the symptom above when the fix is reverted: ``` FAILED ...::test_credential_environments_reads_a_name_containing_a_space AssertionError: Could not list secrets in 'staging' (requires admin access) assert None is False FAILED ...::test_credential_environments_reads_a_name_containing_a_slash AssertionError: Could not list secrets in 'a/b' (requires admin access) assert None is False ``` The shared `_credential_env_gh` fake now matches the percent-encoded segment, as GitHub answers, so a caller that interpolates a name raw stops matching and falls to the same skipped-for-want-of-admin return. Full generator suite: 353 passed. ## Scope Deliberately narrow. The other `.split()` calls in this file are safe on their inputs — `_tags_admin_gated` splits numeric ruleset ids, and secret names are `[A-Z0-9_]` — so they are left alone rather than swept. Every other environment name reaching an API path in this file is the `TEND_ENVIRONMENT` constant. Found by the nightly survey (bucket 8/28, `generator/src/tend/checks.py`). Independent of the other two open `checks.py` PRs (#825, #826), which both concern `_bypass_actors_above_bot`. --------- Co-authored-by: tend-agent <[email protected]>
… 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]>
Automated nightly regeneration of tend's workflow files. **tend version:** 0.1.14 → 0.1.15 **Notable changes** - **Rate-limit handling**: a maintainer can approve past the spike limit (max-sixty/tend#874), and `tend-mention` now skips comments on `tend-rate-limit`-labelled issues as well as `tend-outage` ones — the same self-trigger loop guard, widened to every issue tend files about its own health. - **Review flow**: a push is queued behind an examined-HEAD gate instead of cancelling the in-flight review (max-sixty/tend#903), the review is submitted before a fix is pushed (max-sixty/tend#834), a force-push triggers a re-review rather than trusting the re-anchored SHA (max-sixty/tend#884), and the `/code-review` second pass is unconditional (max-sixty/tend#937). - **CI monitoring**: both the check poll and the `gh run rerun --failed` poll now end terminally when the cap is hit instead of reading as done (max-sixty/tend#876, max-sixty/tend#951), and a failed GitHub-status probe no longer reads as "no incident" (max-sixty/tend#913). - **Nightly**: conflicted bot PRs are test-merged locally instead of filtered on the lazy `mergeable` field (max-sixty/tend#898), and mention runs skip the bot's own review and a third party's content-free approval (max-sixty/tend#916, max-sixty/tend#955). - **`tend check`**: an unreadable ruleset bypass list is reported as unknown rather than ungated (max-sixty/tend#825), environment names are read one per line and addressed encoded (max-sixty/tend#879), and `credential-environments` no longer points at the setting it rejects (max-sixty/tend#900) — this repo currently `SKIP`s that check, so its wording should improve here. Full comparison: max-sixty/tend@0.1.14...0.1.15 Co-authored-by: worktrunk-bot <[email protected]>
Problem
check_credential_environments(added in #815, unreleased) fails on this repo, and its verdict depends on the token's permission level rather than on the repo's configuration:The
releaseenvironment (PyPI trusted publishing,pypi-release.yaml) admits tags, and this repo does carry the all-tags ruleset the check looks for —Tag operations: targettag, active,include: ["~ALL"], rulescreation+update. The gate is there. What the bot cannot see is its bypass list: GitHub omitsbypass_actorsfrom the ruleset response below repo admin, so_bypass_actors_above_bot(None, …)returns None,_tags_admin_gatedreturns None, and_policy_gate— which credited tag entries only onis True— reported the environment ungated.Verified against the API rather than inferred: reading a ruleset with no bypass actors as admin returns
"bypass_actors": []; reading the same field on this repo with the bot's write-scoped token omits the key entirely (all three of this repo's rulesets, including the branch one).That breaks the invariant this module's own docstring states — "Everything read here is readable with the bot's own write-scoped token, so the nightly run sees the same answers a maintainer does" — and it breaks it on the release-environment shape
TODO.mdprescribes. Once this ships, every adopter whose nightly runstend checkunder the bot's token gets a permanent failure on a correctly-gated environment, and--fixcannot clear it; a maintainer running the same command as admin sees it pass.Solution
Split "confirmed absent" from "could not see".
_policy_gatenow returns a_Gap(reason, verified), andcheck_credential_environmentsroutes an unverified gap into the existing unknown result (Could not read the whole credential surface: …) instead of the failure list. A tag entry with no gating ruleset still fails, unchanged. The one other permission-shaped reason — a deployment branch policy the token cannot list — moves with it, same cause.This is the stance
check_branch_protectionalready takes on the same unreadable field: "Ruleset check was inconclusive — don't false-positive" → unknown, not failure.After the change, on this repo:
The two genuine failures this repo has —
claude-authandrepo-secret-allowlist, both #822 — still fail, so the drift report is unaffected.Testing
test_credential_environments_withheld_bypass_list_is_unknownreproduces it: the admin-shaped tag ruleset withbypass_actorsremoved, asserting unknown. It fails before the change (assert False is None) and passes after. Three more tests pin the rest of the split — a confirmed bad ref outranking a withheld list (both entry orders), the unlistable-policy path, and a steerable trigger outranking a held unverified tag entry — each verified to fail on the mutation that removes what it pins. Full generator suite green (331 passed), pinnedruffclean, andtend checkre-run live against this repo for the output above.Found while triaging #822 — it does not fix that issue, which needs a maintainer to move the token.