Skip to content

Run CI's checks before proposing results; allowlist propose's commands - #217

Merged
MaxGhenis merged 12 commits into
mainfrom
results-pr-preflight
Oct 30, 2026
Merged

MaxGhenis merged 12 commits into
mainfrom
results-pr-preflight

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

This closes findings 3 and 2 of the GPT-6.1 Sol review of the results-PR stack (#199, #196, #201, #202). Both were non-blocking gaps. The report, RESULTS_STACK_REVIEW.md, is copied to ~/reviews/scorecard-results-stack-review/. Finding 1, the HF-token fetch order in ci.yml, is a separate task.

1. The results bot runs CI's own checks before it proposes (finding 3)

The App opened results PRs #195, #204 and #206 as ready, and each failed CI's pytest · ruff format job. The builder verified seals, regenerated the replay namespaces and built the database twice. It never ran the suite or the format check.

Now, after every check that stops the run, the build job runs ci.yml's python-job lines on the assembled tree:

  • uvx ruff format --check be nz scorecard_db tests pipeline;
  • uv run --with pytest --with hypothesis --with pypdf --with pyyaml --with numpy --with psutil --with rfc8785==0.1.4 --with jsonschema pytest tests/ -q, with PYTHONPATH=.;
  • the no-drift check after the suite, git status --porcelain.

A test pins both lines, and their environments, to ci.yml word for word.

Permissions and token handling are unchanged. The checks run in build, which has contents: read, unpersisted credentials and no secret. Around them:

  • The script refuses to start the checks if GH_TOKEN or GITHUB_TOKEN is set.
  • The variables that name the step's command files are unset, so a test that writes one by name writes nowhere. That is hygiene, not a sandbox: a process that finds the files on disk can still write them. That is why propose takes every build output as build's word, checked for shape.
  • Workflow commands are paused around the checks' output (::stop-commands:: with a token only the script holds).
  • Everything build outputs about the commit is read before the checks run.

A failure doesn't stop the run. Instead:

  • The builder's preflight subcommand reports each check's exit status, how many things failed, and the first 50 listable names, as one line of JSON. The names are pytest's node ids from the last short test summary, ruff's files in either output format, and git's paths. Listable means printable ASCII, no backtick, no space at either end, at most 200 characters, so three full lists keep the body under GitHub's 65,536-character limit.
  • propose passes the report into the body, where read_preflight refuses any other shape.
  • The PR opens as a draft, and "Validation in the results run" lists the failures in a fenced block.
  • A rerun that should be a draft turns an open ready PR back into a draft (gh pr ready --undo) before the force-push. The builder never marks a PR ready.
  • The build job takes about 12 minutes longer, well within its 45-minute timeout.

2. The detector checks an allowlist, not shell names (finding 2)

runs_pipeline_code's shell-name regex matched text before bash's quote removal, so { …; } | b''ash and | b\ash got past it and ran bash.

The regex is gone. Commands reads the output of shell_residue (#202's lexer, unchanged) and lists every simple command bash would run, in all of these places:

  • the top level;
  • if bodies;
  • { } and ( );
  • $(…), <(…) and >(…);
  • bash 5.3's ${ …; } and ${|…;};
  • function bodies.

Anything it doesn't model is flagged: case, loops, arithmetic, array indices, an array element that splits, brace expansion, a parameter expansion beyond a name with a literal default, and a word after a compound command. propose has no loop, so each declaration in it runs at most once.

disallowed then requires every command word, as written, to be in PROPOSE_RUNS. That set is exactly what propose runs, and a test pins the equality: git, gh, grep, cut, cat, printf, echo, :, [, local, exit, plan, pushgit. It also flags:

  • Variables: assignments to non-local (uppercase) names, command-prefix environments, local with options or declaring a name twice, and printf without a literal non-option format.
  • Tests: [ in any shape but -n or -z and a word, or two words around = or !=. test -v evaluates a subscript, and its operator can sit in a value or an array ([ "$op" "$x" ]), so the operator must be a literal and each operand one word.
  • Words that split: any argument or array element holding an expansion or a glob outside double quotes, because bash turns it into words the text doesn't show. local NAME=$x stays allowed: bash doesn't split a scalar assignment.
  • Arithmetic: anywhere bash evaluates it past a digit or @/* subscript (${a[x]}, ${y:x}, ${!x}, $[x], a[x]=, ([x]=v)). Arithmetic expands a command substitution held in a value (x='a[$(cmd)]').
  • git and gh: subcommands outside the ones propose uses, and git -c other than the credential helper.
  • Options written as words: git options that run a program or write a file (--upload-pack, --receive-pack, --exec, --output), and gh's --editor/--web. This covers arguments, variable values, array elements and defaults, however quoted, escaped (backslash line breaks included), abbreviated (git takes any unambiguous prefix) or bundled (-dw).
  • Writes: anything other than >&2 and >> "$GITHUB_STEP_SUMMARY".
  • Functions: any function definition but pushgit. Its definition is pinned, and it must sit at the top level before its calls.

A function with an allowlisted name would shadow that program. So the test pins that no definition anywhere in the script has one, except plan and pushgit, and that the script contains no eval, source or .. Both pins read every line after quote removal, so quotes, backslashes and line continuations inside a word don't hide it, and neither does a line that only looks like a comment. A redirection touching the word (eval>x y) counts too, as does a case pattern's ) before it. The script holds no $'...' or $"...", and a pin keeps it so, because those can spell any word in escapes ($'\x65val'). It also pins plan and its field helper: the isolated runner's Python, running a fixed program that imports only json and sys.

Both bypasses from the stack review are must-flag cases, as are the inputs the reviews of this PR found (below).

Invariants (each run as a test)

  • Allowlist (property): for any spelling of any command name, in 18 command positions, the command is flagged exactly when the word as written is not an allowed name.
  • Report writer vs reader (differential property): for any exit statuses and log contents, job 1's report is one line, under 100 KB, that job 2's read_preflight accepts unchanged.
  • Summary round trip (property): pytest node ids come back exactly. This holds whatever the messages contain (-, ], extra lines) and when a parametrised id holds - or an unmatched [.
  • Shape: job 2 refuses 26 malformed reports, and a count stays under a billion, at the boundary on both sides.
  • Draft rule (property): a PR is a draft exactly when integrity is incomplete or a check fails.
  • Listing (property): each listed name is a line of its own inside exactly one fence, and any count beyond the list is stated.
  • Size (end to end): with every check failing on 80 names of the longest listable length, the body stays under 65,536 characters.
  • End to end: a stubbed suite and ruff run against a local bare remote, with every command-file variable set as the runner sets them.
    • CI's checks run on the verified commit with no token or command-file variable in their environment, and between the pause and resume tokens. They never see that token, and the resume starts its own line even when the check's output stops mid-line.
    • Each failure mode opens a draft that names it: failed tests, a collection error, unformatted files in both ruff styles, a suite exiting with no summary, and drift.
    • A forged report is refused before the token is minted.
    • A failing rerun turns the PR back into a draft before the push.
    • A passing rerun never marks it ready.

Review

The GPT-6.1 Sol review (lane run 20261021-225349-pr217-review-3; report in ~/reviews/scorecard-results-stack-review/pr217-review-3/) returned CHANGES REQUESTED. It confirmed the production change, the credential boundary, the shape check, the draft rule, the parsers, the size limits and CI-line equality. Fifteen of its 16 mutations were caught by the tests.

It found 14 inputs the detector missed. Each was executed under bash 3.2, 5.2.37 (the CI runner's version) and 5.3. The current propose uses none of them.

  • [ -v 'a[$(cmd)]' ];
  • an array redeclared from a quoted string;
  • process substitution inside ${…};
  • printf {-v,PATH};
  • git and gh options passed through variables, arrays, braces and line continuations;
  • gh option bundles.

The commit after the review applies the reviewer's patch and fixes its other findings:

  • definitions found anywhere in a line, plus the eval/source pin;
  • node ids parsed correctly with unbalanced brackets, and the count bound raised to 10^9;
  • the duplicate-count mutation now caught;
  • every command-file variable set in the end-to-end tests;
  • outputs read before the suite runs;
  • re-drafting before the push;
  • workflow commands paused;
  • git's -u dropped (in git 2.55 it is --set-upstream, not a program);
  • the duplicated cases trimmed.

The re-review at f936b49c (lane run 20261022-043621-pr217-rereview; report in ~/reviews/scorecard-results-stack-review/pr217-rereview/) returned CHANGES REQUESTED and confirmed the earlier fixes. It had one production finding: the runner reads a workflow command only at the start of a line, so a suite that stopped mid-line left commands paused. The pause and resume now each start a line of their own.

The rest were detector inputs, none of which propose uses. 9078c449 closes them by refusing what the detector can't see:

  • a [ operator held in a value or an array, which the fixed [ grammar closes;
  • a declaration a loop repeats, which leaving loops out of the model closes;
  • --web from a word that splits or from a default, which the rule on split words closes (the same rule covers globs);
  • a definition behind a line continuation, and a quoted or escaped eval, source or ., which quote removal before the pins closes.

It also adds the count-boundary and nonce tests its mutation run asked for, and states the summary-header limit. The review's 71 executed inputs and these new ones are all flagged. d3770d66 then removes a check that a mutation run showed could not fail, and routes the script-wide pin through one helper its cases exercise.

The review of d3770d66 (lane run 20261030-105117-pr217-rereview-3; report in ~/reviews/scorecard-results-stack-review/pr217-rereview-2.md) returned MERGE-SAFE WITH NITS. It confirmed every earlier finding closed, and that its four surviving mutants now die. It found two more detector inputs, neither used by propose, and both executed under all three bash versions:

  • an array element that splits or globs (local a=($opt)), which reached gh as --web;
  • a builtin touching a redirection (eval>x y), or spelled in a locale quote ($"eval").

25f4c9b2 closes both, and I probed the neighbouring spellings on the same three versions. eval&>x y, $'eval', $'\x65val' and $'\145val' all ran, so the pin refuses $'...' and $"..." outright rather than normalising them.

The review of 25f4c9b2 (lane run 20261030-123210-pr217-rereview-4; report in ~/reviews/scorecard-results-stack-review/pr217-rereview-3.md) returned MERGE-SAFE WITH NITS. It confirmed both fixes, that the merge brought in only main's changes, and that #218 and #219 break no assumption of preflight. It found two more spellings of eval that the pin missed, neither used by propose: one on a line inside a quote that only looks like a comment, and one after a case pattern's ).

ed25ea09 closes both. The pin now sets no line aside, because telling a comment from code needs quote state, and shell_residue, which tracks it, refuses the script's heredoc. The script's comments had two hits, both prose sentences ending in )., and this commit rewords them. It changes nothing else in the script.

The review of ed25ea09 (lane run 20261030-131859-pr217-rereview-5; report in ~/reviews/scorecard-results-stack-review/pr217-rereview-4.md), scoped to that commit, returned MERGE-SAFE WITH NITS. It confirmed both fixes, and that the script's non-comment lines match 25f4c9b2 byte for byte. Its one new input, a backtick substitution, sits under Known limits: this PR stops the detector's rounds here, because each round since the first has found only spellings propose doesn't use.

Known limits

  • The detector reads propose's body and the helpers it calls. It doesn't read the script's top-level lines, which every job runs: variable settings, the request-id check and the dispatch case.
  • An option or a name assembled at run time (u=--w; u+=eb, n=ev; "${n}al") is beyond any rule on words.
  • The script-wide pin on eval, source and . misses one inside a backtick substitution (x=`eval y` ), which all three bash versions run. propose holds no backticks, and the lexer refuses one in its body.
  • Beyond the rules above, the detector doesn't model what an allowed program does with its arguments.
  • The report is job 1's word, checked only for shape, like the verify-sealed and content-hash lines. A package in job 1 could claim the checks passed; CI on the PR reruns them.
  • On CI, pytest prints whole messages over several lines. The parser reads a message line that itself starts with FAILED or ERROR as another node id, and one that is itself a summary header drops the ids before it. This changes only what is listed: a check's exit status, not its list, says whether it failed.
  • A rerun on an unchanged main pushes nothing, so it leaves the body as it was.

Checks run

  • CI: passes on this head, ed25ea09, merged with main at 96dc07bb, which holds Run the UK replay's year workers that fit the runner's memory, and log memory around each event #218 and Run the real replay's variant code in the candidate sandbox #219.
  • Locally:
    • tests/test_uk_replay_results_pr.py and tests/test_ci_gates.py with -n 4, on the merged tree: 153 passed.
    • uvx ruff format --check be nz scorecard_db tests pipeline passes.
    • Mutation run on d3770d66 (~/reviews/scorecard-results-stack-review/pr217-mutation-4/): a named test fails on 17 of 18 mutants, with every baseline passing first. The mutant that drops the resume's leading newline fails the end-to-end case where the suite stops mid-line. The survivor removes the filter that keeps summary headers out of a property's messages; random text doesn't produce one, and test_a_message_line_that_looks_like_a_summary_is_a_stated_limit pins that behaviour directly.
    • Mutation run on 25f4c9b2 (~/reviews/scorecard-results-stack-review/pr217-mutation-5/): with the baseline passing, test_propose_runs_only_the_commands_it_lists fails on all five mutants of its new rules: allowing a split element, dropping either redirection boundary, dropping the $'...' pin, and widening the boundary to ), which would flag the script's own grep -c .).
    • Mutation run on ed25ea09 (same folder): with the baseline passing, the same test fails on all four mutants: dropping the left ), setting comment lines aside again, dropping the $'...' pin, and widening the right boundary.

axiom: n/a: CI and test tooling

🤖 Generated with Claude Code

The results bot verified seals, regenerated the replay namespaces and
built the database twice, but never ran the suite or the format check, so
#195, #204 and #206 opened ready and failed CI. The build job now runs
ci.yml's own ruff and pytest lines (pinned word for word) and its no-drift
check on the assembled tree, with no token and no step command files in
reach. A failure no longer means a red ready PR: the PR opens as a draft
whose body names the failing tests, files or paths, and a failing rebuild
turns an open PR back into a draft. Nothing marks a PR ready.

runs_pipeline_code matched shell names before quote removal, so b''ash and
b\ash ran bash past it. It now lists every command bash would run from
propose (substitutions, groups, compound commands, function bodies) and
requires each command word, as written, to be one propose uses; what the
parser does not model is flagged. Both bypasses are test cases.

Review of 2443472, findings 2 and 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
policyengine-scorecard Ready Ready Preview Oct 30, 2026 5:19pm UTC

Request Review

MaxGhenis and others added 2 commits October 21, 2026 21:35
…ctor

Bash evaluates an array subscript, a substring offset, ${!name}, $[...]
and an array literal's [index] as arithmetic, and arithmetic runs a
command substitution held in a value: with x='a[$(touch m)]', each of
${a[x]}, ${y:x}, ${!x}, a[x]=1, $[x] and a+=([x]=v) ran touch under bash
3.2, past the allowlist. Parameter expansions are now a name with at most
a literal default, alternative or error word, subscripts are @, * or
digits, and indices and $[...] are unmodelled, so flagged.

printf's format must be a literal that is not an option (quoted -v or an
expansion is still -v). git's options that run a program or write a file
are matched after quote removal and as abbreviations, and --output joins
them; gh may not open an editor or browser. The script-level shadowing
check also finds `name () {` and `function name` definitions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three checks listing 100 names of up to 300 characters could reach about
90,000 characters, past the 65,536 GitHub accepts for a pull request body,
and the branch would already be pushed when gh pr create failed. Each
check now lists at most 50 names of at most 200 characters (about 31,000
for all three), and an end-to-end test fails every check with 80 names of
the longest listable length and checks the body still fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The suite runs with $GITHUB_OUTPUT and the other command-file variables
unset, which stops a test that writes one by name. A process that finds
the files on the runner's disk can still write them; job 2 already takes
every build output as build's word, checked for shape. The script comment,
the release doc and a test comment claimed more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of cf8066b (GPT-6.1 Sol, CHANGES REQUESTED on the test-side
detector only) found 14 inputs bash runs that the detector passed, each
executed under bash 3.2, 5.2.37 and 5.3: [ -v 'a[$(cmd)]' ], an array
redeclared from a quoted value, process substitution inside ${...},
brace-expanded printf -v, and git or gh options passed through variables,
arrays, braces, backslash line breaks or short-option bundles. Its patch
is applied as written: options are checked in every word, after a
backslash line break is removed, and brace expansion, [ -v ] and a local
declared twice are flagged. The claim is narrowed to options written as
words; one assembled at run time is beyond any rule on words. git's -u is
dropped from the rule: in git 2.55 it is --set-upstream.

Function definitions now count wherever they start, and the script holds
no eval, source or . to build one. A node id's brackets end at the first
] its message follows, so an unbalanced [ no longer glues the message on;
the report's count bound is 10^9; a duplicate failure counts once.

The build job reads what it outputs about the commit before the suite
runs in its tree, and pauses workflow commands (::stop-commands:: with a
token only it holds) around the checks' output. A rebuild that should be
a draft turns its open pull request back into one before the push, not
after, and every gh pr ready carries --undo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis and others added 2 commits October 30, 2026 10:38
…t words

Sol's re-review of f936b49 asked for changes. The one production finding:
the runner reads a workflow command only at the start of a line, so a suite
that stopped mid-line left `::<token>::` on that line and later commands
paused. The pause and the resume now each start a line of their own.

The rest is the test-side detector, where it now refuses what it could not
see, rather than listing more spellings:

- `[` runs only as -n or -z and a word, or two words around = or !=. An
  operator held in a value or array ([ "$op" "$x" ]) ran test -v.
- An argument with an expansion or a glob outside double quotes is flagged:
  bash turns it into words the text does not show (--web from a value, a
  default or a file name). A default now counts as a word.
- Loops leave the model, so `while` and `until` are commands PROPOSE_RUNS
  does not list, and each declaration runs at most once. propose has none.
- The script-wide pins read text after quote removal, so `c\<newline>at()`,
  e''val, 'source' and \. no longer pass them.

Tests add the count's boundary, the nonce's generation and exposure, and a
suite that stops mid-line, which close the review's surviving mutants. The
docs state the summary-header limit beside the FAILED/ERROR one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mutation run on 9078c44 showed plain_test's check on split words could
not fail, because disallowed already flags them for every command, so it
goes. It also showed that weakening the pin on eval, source and . passed:
the test asserted on the script and on examples through separate code. Both
now go through runs_text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis and others added 2 commits October 30, 2026 12:25
…..' words

The review of d3770d6 found two detector misses. Both are test-side: propose
uses neither.

An array element splits as an argument does, unlike NAME=$x, so
`local o='--web '; local a=($o)` hands gh --web, and `local a=(*)` does the
same from a filename. Commands.array now raises Unlexed on an element that
splits.

A redirection can touch the builtin's word: `eval>x y` runs eval, and so do
'source'<x, \.<x and eval&>x, on bash 3.2, 5.2.37 and 5.3. Other characters
that end the word leave it no arguments, so the boundary stays narrow:
`grep -c .)`, which the script holds, must not match.

$"eval" runs eval, and so do $'eval', $'\x65val' and $'\145val', which no
normalising of quotes would read. The script holds no $'...' or $"...", so the
script-wide pin now refuses both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The review of 25f4c9b found two more spellings of eval that the pin missed,
which propose does not use. Each runs on bash 3.2, 5.2.37 and 5.3:

    : 'x
    # ';eval y

    case x in x)eval y;; esac

The first line of the pair sits inside a quote, so the second is code that
only looks like a comment. Setting comment lines aside needs quote state, and
shell_residue, which tracks it, refuses the script's heredoc. So runs_text now
sets no line aside. That removes code, and a line that looks like a comment
can no longer hide anything. The script's comments had two hits, both prose
sentences ending in ")."; this rewords both and changes nothing else in the
script.

The left boundary now counts ), which also covers `x). y` and `x)source y`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis marked this pull request as ready for review October 30, 2026 17:35
@MaxGhenis
MaxGhenis merged commit 723bc90 into main Oct 30, 2026
14 checks passed
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Merged at the reviewed head ed25ea09c883d0d0d0c46b35fd2047b2cf2fceaa, pinned with --match-head-commit, as 723bc902. The merged tree matches that head's tree exactly, because main did not move after the branch merged it.

Gates at merge

  • gh pr checks exited 0: 13 pass and 1 skip (publish db to supabase storage, which runs on main only). The CI run and the gate-freshness run both concluded success on this head.
  • mergeable read MERGEABLE, the state read CLEAN, and the PR held no CHANGES_REQUESTED review.
  • Nothing here needs Max's judgment: this is CI and test tooling, with no published number, send or data release.

Independent review (GPT-6.1 Sol, five rounds)

Head Lane run Verdict
cf8066bc 20261021-225349-pr217-review-3 CHANGES REQUESTED
f936b49c 20261022-043621-pr217-rereview CHANGES REQUESTED
d3770d66 20261030-105117-pr217-rereview-3 MERGE-SAFE WITH NITS
25f4c9b2 20261030-123210-pr217-rereview-4 MERGE-SAFE WITH NITS
ed25ea09 20261030-131859-pr217-rereview-5 MERGE-SAFE WITH NITS

The last review covered only the final commit, by a stop rule set before it ran. Its one new input, a backtick substitution, sits under Known limits. propose holds no backticks, and the lexer refuses one in its body. The reports sit in ~/reviews/scorecard-results-stack-review/.

@MaxGhenis
MaxGhenis deleted the results-pr-preflight branch October 30, 2026 17:36

This branch was successfully deployed

1 active deployment
Preview — ed25ea09 Deployed Oct 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant