Repository navigation
feat(reuse): accept pinned trusted external-PR sweeps / 复用:允许固定受信任的外部 PR 扫描 - #4494
Conversation
…s / 复用:允许固定受信任的外部 PR 扫描作为复用来源 External PRs run their sweep through trusted-external-sweep.yml, which dispatches e2e-tests.yml on main. The reuse validator only accepted pull_request run-sweep.yml runs, so an external PR's results could never publish via /use. Accept such a run when it is pinned explicitly, is a workflow_dispatch of e2e-tests.yml on main, and carries the 'e2e Test - External PR #N @ <sha12>' title; attribute it to PR #N and reject it if that PR carries a reuse-incompatible modifier label.
|
Generally most InferenceX submissions don't need to add changes to the infx package. On the off chance they do, generally the diff is small. Please prompt your agent to clean your PR to keep your diff to only necessary & minimal changes too. We have an increased code quality bar for changes to the infx package. 中文大多数 InferenceX 提交通常不需要修改 infx 包。即使确实需要,改动通常也很小。请让你的 agent 清理 PR,使改动只包含必要且最小的内容。infx 包的改动有更高的代码质量要求。 |
There was a problem hiding this comment.
Beyond the inline findings, I checked whether the new external-PR branch in run_pr_number lets unpinned reuse requests trust external runs. It doesn't: validate_reusable_run only calls trusted_external_pr when allow_failed (pinned) is set. The two run_pr_number callers, reuse.py:421 and reuse_comment.py:35, only use the PR number for attribution and the warning text, not as a trust gate.
Extended reasoning...
The change touches the fail-closed reuse validation in reuse.py and sweep_runs.py, which decides which sweep results get published at merge. The inline findings already cover the spoofable display_title, the stale label check and the stage_results mismatch. This note only records that the unpinned path and the run_pr_number attribution were checked and are not affected.
Findings marked 🟡 are optional suggestions and need no follow-up push.
| def trusted_external_pr(run: dict[str, Any]) -> int | None: | ||
| """Return the external PR a trusted-external-sweep dispatch tested, if it is one.""" | ||
| if ( | ||
| run.get("event") != "workflow_dispatch" | ||
| or run.get("path") != TRUSTED_EXTERNAL_PATH | ||
| or run.get("head_branch") != "main" | ||
| ): | ||
| return None | ||
| match = TRUSTED_EXTERNAL_TITLE.fullmatch(str(run.get("display_title") or "")) | ||
| return int(match.group(1)) if match else None |
There was a problem hiding this comment.
🔴 A hand-dispatched e2e-tests.yml run can pass as a trusted external sweep, including trimmed or partial smoke runs. Trust rests on display_title, but e2e-tests.yml builds its title from the free-form test-name input. Any manual dispatch on main with test-name set to External PR #N @ <12 hex> matches TRUSTED_EXTERNAL_TITLE. Inputs like trim-conc, eval-limit, duration-override or generate-cli-command are never checked. Fix: also require the run to come from trusted-external-sweep.yml, e.g. actor/triggering_actor login is github-actions[bot], and reject other dispatchers.
Why this was flagged
e2e-tests.yml:2 sets run-name: e2e Test - ${{ inputs.test-name || ... }}, and test-name is a free-form workflow_dispatch input (e2e-tests.yml:20). .github/workflows/README.md:182 documents manual e2e-tests.yml dispatches, for example lowest-concurrency smoke runs with trim-conc. Suppose a write-access user dispatches on main with test-name External PR #900 @ 75745991a66c plus trim-conc: true or a small eval-limit. trusted_external_pr (sweep_runs.py:54-63) then returns 900. validate_reusable_run (reuse.py:178,192) skips both the pull_request event check and the workflow-path check. A maintainer pins it with /use <id>, and resolve_reusable_run only checks PR #900's current labels for evals-only/agentx-fast. The reduced or arbitrary matrix is then published as the official sweep for the merge. On the base branch every workflow_dispatch run is rejected with "is not a pull_request run". The title is the only provenance check. The run's actor (github-actions[bot] for the GITHUB_TOKEN dispatch at trusted-external-sweep.yml:135) is never checked.
Verification: test-name is a free-form string input (e2e-tests.yml:20-23). trusted_external_pr (sweep_runs.py:54-63) never checks that trusted-external-sweep.yml was the dispatcher. In reuse.py, validate_reusable_run then skips both the pull_request event check and the run-sweep.yml path check. The base rejected every non-pull_request run.
| if pinned_run_id is not None and (external_pr := trusted_external_pr(run)) is not None: | ||
| # Dispatch inputs are not on the run, so the modifiers come from the tested PR's labels. | ||
| source = github.api(repo, f"/pulls/{external_pr}", token) | ||
| if modifiers := incompatible_labels.intersection(label_names(source)): | ||
| raise RuntimeError( | ||
| f"External source PR #{external_pr} uses reuse-incompatible label(s): " | ||
| f"{', '.join(sorted(modifiers))}." | ||
| ) |
There was a problem hiding this comment.
🟡 (optional) A pinned external sweep that actually ran with agentx-fast or evals-only can still be reused if the label was later removed from the external PR. The modifier check reads PR #N's labels at merge time. The dispatch inputs were taken from the labels at dispatch time (trusted-external-sweep.yml:144-148). Removing the label afterwards, a common step once a fast run is done, makes the check pass. Fix: tie the check to what the run was dispatched with, e.g. record the modifier inputs in the run (title or an artifact) and verify them, or fail closed when the PR's labeled/unlabeled timeline shows a modifier was present before the run's created_at.
Why this was flagged
trusted-external-sweep.yml:144-148 sets the evals-only and agentx-fast dispatch inputs from the PR's labels when the label event fires. Later, at reuse time, resolve_reusable_run (reuse.py:253-260) fetches /pulls/{external_pr} and intersects its current labels with incompatible_labels. Take an external PR that was swept with agentx-fast (one warmup request, 20-minute profile). If that label is removed afterwards, a maintainer can pin the run with /use <id>, the label check finds nothing, and the fast-feedback results are ingested as a full sweep. The code comment at reuse.py:254 admits dispatch inputs are not on the run, so the current labels stand in for them. That stand-in does not hold once labels change. On the base branch such a run could never be reused at all, because workflow_dispatch runs were rejected at reuse.py:179.
Verification: .github/workflows/trusted-external-sweep.yml:80 takes labels from the PR at dispatch time. At reuse time, reuse.py:253-260 intersects incompatible_labels with the PR's current label_names(source). Nothing ties that check to how the run was actually dispatched. An agentx-fast or evals-only sweep, which produces incomplete results, passes validate_reusable_run and the new label check.
| external_pr = trusted_external_pr(run) if allow_failed else None | ||
| if run.get("event") != "pull_request" and external_pr is None: | ||
| raise RuntimeError(f"Reusable source run {run_id} is not a pull_request run.") |
There was a problem hiding this comment.
🟡 (optional) Maintainers who post /use <external run id> now get the reuse accepted, but the staging that the same comment triggers always fails. This change taught only reuse.py to accept trusted external dispatches. The second consumer of /use, stage_results.resolve_run, still rejects any run that is not a pull_request run of run-sweep.yml. Fix: make every /use consumer agree on external runs, either by accepting sweep_runs.trusted_external_pr runs in stage_results.resolve_run or by having use_command skip staging for them instead of erroring.
Why this was flagged
stage-results.yml fires on any PR comment whose body starts with /use. stage_results.use_command matches /use 40141873883 and passes the run id to resolve_run (stage_results.py:91-95). There, rejection returns "not a pull-request run of run-sweep.yml" for an e2e-tests.yml workflow_dispatch (stage_results.py:65-69), and the Stage PR Results run exits 1. If the recovery PR has no full-sweep label, reject() instead posts a "staging requires a completed run from a PR using one of ..." comment. Meanwhile reuse_comment.py now reacts with a thumbs-up, because validate_reusable_run accepts the pinned external run (reuse.py:178-180, 192). On the base branch both consumers rejected such a run, so the two always agreed. After the merge, the next step the PR description announces (a recovery PR for #4456 pinning /use 40141873883) gets an accepted reuse and a failed or rejected staging from the same comment. Nothing in this diff touches stage_results.py, so no safeguard keeps the two consumers in step.
Verification: pre-existing. Trigger: a maintainer posts /use <trusted external e2e-tests.yml run id>. In rejection (stage_results.py:67-71), any run whose path is not .github/workflows/run-sweep.yml or whose event is not pull_request gets "not a pull-request run of run-sweep.yml". On the base branch, staging an external run through /use failed by the same rejection, so this is not a new regression.
External PRs sweep through
trusted-external-sweep.yml, which dispatchese2e-tests.ymlonmain.validate_reusable_runonly acceptedpull_requestruns ofrun-sweep.yml, so/use <run_id>could never point at an external PR's results. #4456 merged that way, and its Merge Ingest run 40172192776 failed at "Require sweep reuse". A recovery PR pinning its sweep 40141873883 would be rejected for the same reason.Change
sweep_runs.trusted_external_pr(run)identifies a run as a trusted external sweep when it is aworkflow_dispatchof.github/workflows/e2e-tests.ymlonmainwith the exact titlee2e Test - External PR #N @ <sha12>.run_pr_numberreturns thatN, soreuse-source-pr-numberand the outside-PR warning name the external PR, not whatever PR themainSHA maps to.validate_reusable_runaccepts such runs only for pinned requests (/use <id>). Unpinned/reuse-sweep-runstill searchesrun-sweep.ymlpull_requestruns only.resolve_reusable_runrejects the source if PRNcarriesevals-onlyoragentx-fast.Next step after merge: a recovery PR for #4456 that re-appends its changelog entry and pins
/use 40141873883.外部 PR 通过
trusted-external-sweep.yml在main上调度e2e-tests.yml运行扫描,而复用校验只接受run-sweep.yml的pull_request运行,导致外部 PR 的结果无法通过/use发布(如 #4456)。本 PR 允许显式固定的受信任外部扫描(标题为e2e Test - External PR #N @ <sha12>)作为复用来源,并将其归属到 PR #N。若该 PR 带有evals-only或agentx-fast标签,则拒绝复用。未固定的请求行为不变。