Skip to content
Merged
61 changes: 34 additions & 27 deletions .claude/commands/recover-failed-ingest.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ gh api --paginate "repos/SemiAnalysisAI/InferenceX/actions/runs/$RUN_ID/artifact
| --- | --- |
| `results_bmk/agg_bmk.json` | JSON array; filter the intended model, hardware, topology, scenario, and concurrency. The collector parses JSON but does not validate or deduplicate rows. |
| `eval_results_all/agg_eval_all.json` and `eval_*` | Aggregate rows must match task, concurrency, score, and `n_eff`; retain per-config `meta_env.json`, results, and samples where needed. Collection may keep completed points from failed batches; reuse requires valid coverage. |
| `bmk_agentic_<suffix>` and `agentic_<suffix>` | Pair exact suffixes, including `_concN`; raw `profile_export.jsonl` is required. Preserve dataset identity, request accounting, and relevant `server_logs_*`. |
| `bmk_agentic_<suffix>` and `agentic_<suffix>` | Pair exact suffixes, including `_concN`; raw `profile_export.jsonl` is required. Preserve dataset identity, request accounting, and relevant `server_logs_*`. `num_requests_successful` counts profiled records only, while `num_requests_total` also counts warmup drops, so their ratio is not an error rate. Read `request_accounting.records_error_dropped` and `error_categories` instead. |
| Power audits | Retained diagnostics or `power_valid` alone do not prove successful requests, answer quality, or publishable power. Inspect the outcome and each required window's validity. |

Download only unexpired artifacts into a fresh `mktemp -d` directory. Check shape
Expand Down Expand Up @@ -84,8 +84,11 @@ For PR-number input, use `gh pr view "$ORIGINAL_PR" --json mergeCommit` and
with `-R SemiAnalysisAI/InferenceX`; select the exact target, not the newest unrelated run.

Find completed `pull_request` runs of `run-sweep.yml` on the original PR branch.
Skip no-op reuse-gate runs without results. Require success unless the user explicitly
pinned the exact failed/cancelled source; only its completed, valid points can be recovered.
Skip no-op reuse-gate runs without results (zero artifacts, about 30 seconds long).
Require success unless the user explicitly pinned the exact failed/cancelled source;
only its completed, valid points can be recovered. Do not just take the run cited in
a sign-off. Later commits can change the recipe, so choose the newest run whose
execution inputs match the final PR head.

```bash
SOURCE_JSON=$(gh api "repos/SemiAnalysisAI/InferenceX/actions/runs/$SOURCE_RUN_ID")
Expand All @@ -104,6 +107,15 @@ uv run --project inferencex-e2e --extra workflows python -m infx.workflows.recov
git diff "${ORIGINAL_MERGE_SHA}^" "$ORIGINAL_MERGE_SHA" -- inferencex-e2e/perf-changelog.yaml
```

If the original PR merged `main`, a whole-tree diff mostly shows `main`'s changes.
Restrict the comparison to the files the original merge commit changed:

```bash
git diff --name-only "${ORIGINAL_MERGE_SHA}^" "$ORIGINAL_MERGE_SHA" |
grep -v perf-changelog.yaml | xargs git diff --stat "$SOURCE_HEAD_SHA" \
"refs/remotes/origin/source-pr-$ORIGINAL_PR" --
```

Compare the recovered config and its image, model, recipe, runner, launcher,
arguments, and environment at the source SHA and final original PR head.
Stop if execution semantics changed. Unrelated edits and generator/eval-selection
Expand All @@ -116,9 +128,6 @@ intended entries from the original PR diff or stop on ambiguity.
Create an empty bootstrap branch/commit from current `origin/main`, then open the
PR before changing the changelog. Use a bilingual title/body and the required AI
disclosure; set `BRANCH` and `RECOVERY_PR` to its branch and number.
An authorized `OWNER`, `MEMBER`, or `COLLABORATOR` must pin the source
with `/use <run_id>` (legacy `/reuse-sweep-run <run_id>` is also accepted).
Verify acknowledgement before pushing the changelog change.

Reuse needs no sweep label. If a primary label is present, allow only one.
Never use `evals-only` or `agentx-fast` on the recovery PR, or select a source
Expand All @@ -144,44 +153,42 @@ Commit the append, set `RECOVERY_COMMIT=$(git rev-parse HEAD)`, and validate:
```

Require only the intended recovery scope; current matrix row counts may differ
from the source. With no uncommitted or untracked work, attach source ancestry
without changing the recovery tree:
from the source. Push the append, which starts no GPU jobs while the PR has no
primary sweep label:

```bash
test -z "$(git status --porcelain)" || exit 1
TARGET_PARENT=$(git rev-parse HEAD)
TARGET_TREE=$(git rev-parse HEAD^{tree})
ATTACH_SHA=$(printf 'chore: attach reusable sweep run %s\n' "$SOURCE_RUN_ID" |
git commit-tree "$TARGET_TREE" -p "$TARGET_PARENT" -p "$SOURCE_HEAD_SHA")
git reset --hard "$ATTACH_SHA"
test "$(git rev-parse HEAD^1)" = "$TARGET_PARENT" || exit 1
test "$(git rev-parse HEAD^2)" = "$SOURCE_HEAD_SHA" || exit 1
test "$(git rev-parse HEAD^{tree})" = "$(git rev-parse HEAD^1^{tree})" || exit 1
test "$(git diff --name-only origin/main...HEAD)" = "inferencex-e2e/perf-changelog.yaml" || exit 1
git diff --check origin/main...HEAD || exit 1
git push origin "$BRANCH"
```

Never rebase, locally squash, amend, or force-push after attaching the source.
If `main` advances or conflicts, update from it and recreate the final two-parent
carrier; preserve the verified first-parent tree. Do not silently drop ancestry.
An authorized `OWNER`, `MEMBER`, or `COLLABORATOR` then pins the source with
`/use $SOURCE_RUN_ID` (legacy `/reuse-sweep-run <run_id>` is also accepted). The
source commit belongs to the original PR, not the recovery PR, so expect the bot to
react 👍 and post an outside-PR warning comment. Require the 👍 before merging.
A 👎 explains itself only in the matching `reuse-sweep-comment.yml` run log
(`Reuse rejected / 复用请求未接受: ...`).

## Verify reuse and merge

```bash
gh api --paginate "repos/SemiAnalysisAI/InferenceX/pulls/$RECOVERY_PR/commits" \
--jq '.[].sha' | grep -Fx "$SOURCE_HEAD_SHA"
test "$(gh pr diff "$RECOVERY_PR" -R SemiAnalysisAI/InferenceX --name-only)" = \
"inferencex-e2e/perf-changelog.yaml"
gh pr checks "$RECOVERY_PR" -R SemiAnalysisAI/InferenceX --watch --fail-fast
```

Wait for the `run-sweep.yml` run at `ATTACH_SHA`, not just early comment checks.
Wait for the `run-sweep.yml` run at the PR head, not just early comment checks.
Require passing `check-changelog` and `reuse-sweep-gate`, with `setup` and GPU jobs
skipped. Keep `ATTACH_SHA` as the PR head. Merge only with explicit authorization;
never bypass failed or pending checks. Admin merge is allowed only when passing
checks leave repository policy as the sole blocker. GitHub squash merge is safe
because it does not rewrite the PR branch's recorded ancestry.
skipped. Merge only with explicit authorization; never bypass failed or pending
checks. Admin merge is allowed only when passing checks leave repository policy as
the sole blocker. Do not use `merge_with_reuse` here. It posts its own
`/reuse-sweep-run` chosen from the recovery PR's commits, which supersedes the pinned
source and finds no sweep. Merge directly:

```bash
gh pr merge "$RECOVERY_PR" -R SemiAnalysisAI/InferenceX --squash --admin \
--match-head-commit "$(git rev-parse HEAD)"
```

## Verify the exact publication

Expand Down
12 changes: 6 additions & 6 deletions .github/codeowner-signoff-verify-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ Then decide:
Name the path and its real owners in one line.

## Check 1 — A passing sweep + evals ran on a commit IN this PR
The merge standard (and InferenceX's own reuse gate) requires a green full sweep,
including evals, on a commit that is CURRENTLY part of this PR. A sweep that ran on a
commit later rebased/force-pushed out does NOT count: at merge, `merge_with_reuse.py`
→ `validate_reusable_run` (in `inferencex-e2e/infx/workflows/reuse.py`) rejects any source
whose `head_sha` is not in `GET /pulls/<n>/commits`. So the whole question collapses
to one fact: does a commit still in this PR carry green, executed sweep/eval checks?
The merge standard requires a green full sweep, including evals, on a commit that is
CURRENTLY part of this PR. A sweep that ran on a commit later rebased/force-pushed out
does NOT count. The reuse tooling no longer enforces this: a pinned `/use <run_id>` may
name any run, and the acknowledgement bot only posts a warning comment when its commit is outside the
PR. This check is therefore the enforcement point, and the whole question collapses to
one fact: does a commit still in this PR carry green, executed sweep/eval checks?

The cleanest way to answer is the check-runs attached to each in-PR commit. You do
NOT need to list `run-sweep.yml` runs or parse reuse logs.
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ a primary sweep label on the PR, although staging its results requires one:
```

Keep the command and required run ID on one line. This pins an eligible completed
`run-sweep.yml` PR run whose commit remains in the PR, including failed or cancelled
runs with usable results.
`run-sweep.yml` PR run, including failed or cancelled runs with usable results. The
run may come from any PR; its commit need not be part of this one.

The legacy `/reuse-sweep-run <run_id>` remains equivalent. Bare `/reuse-sweep-run`
selects the latest successful eligible run automatically; bare `/use` is rejected.
Expand All @@ -271,9 +271,10 @@ certify a green full sweep. Verify coverage and pin the run ID when a full sweep
is required by the review process.

The latest matching comment across both names by an `OWNER`, `MEMBER`, or `COLLABORATOR` wins.
The bot reacts with 👍 after validating the request, or 👎 on rejection; details
are in the Actions run summary. Edits replace the bot's old reaction. The reuse
check posts no comment, but `/use <run_id>` also triggers `stage-results.yml`.
The bot reacts with 👍 after validating the request, or 👎 on rejection. When the
pinned run's commit is not part of the PR, it also posts one warning comment for
that request and run; reuse still proceeds. Details are in the Actions run summary.
Edits replace the bot's old reaction. `/use <run_id>` also triggers `stage-results.yml`.
Staging requires a primary sweep label on the PR and a source run created while
one was applied. It posts a staging comment, or a rejection comment when the PR
has no primary label. Comments do not trigger or cancel GPU sweeps. Later commits
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/merge-ingest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
with:
script: |
await core.summary.addTable([
['Source PR', `#${process.env.SOURCE_PR}`],
['Source PR', process.env.SOURCE_PR ? `#${process.env.SOURCE_PR}` : 'unknown'],
['Source run', process.env.SOURCE_RUN_URL],
['Reused benchmark source', process.env.SOURCE_SHA],
]).write();
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ The verdict records only the commit actually assessed; it does not carry approva

A full benchmark sweep is expensive GPU time, and the runners are shared by every open PR, so an approved PR's sweep runs only once, for PR validation. `main` never reruns it after merge; the reuse path publishes that PR sweep instead:

- After your PR has an eligible green full sweep, an authorized maintainer (`OWNER`/`MEMBER`/`COLLABORATOR`) comments `/use <run_id>` on the PR to select that run. Keep the command and run ID on the same line.
- After your PR has an eligible green full sweep, an authorized maintainer (`OWNER`/`MEMBER`/`COLLABORATOR`) comments `/use <run_id>` on the PR to select that run. Keep the command and run ID on the same line. The pinned run may come from any PR; if its commit is not part of this PR, reuse is still accepted but flagged as a warning.
- `/reuse-sweep-run <run_id>` remains supported with identical behavior. Bare `/reuse-sweep-run` selects automatically; bare `/use` is rejected.
- The merge-to-`main` run then validates and ingests the PR sweep's artifacts; `main` never re-runs the sweep itself.
- **Reuse is mandatory.** A green sweep alone is not enough. The reuse command must be on record (the sign-off verification checks for it), otherwise the `main` run fails and the PR's results are never ingested.
- Reuse does not require retaining a primary label, but it is rejected while the PR carries `evals-only` or `agentx-fast`, and `merge_with_reuse` refuses a PR with more than one primary label. The bot reacts to the command with 👍 when accepted or 👎 when rejected, with details in the Actions run summary; source artifacts are revalidated at merge.
- Reuse does not require retaining a primary label, but it is rejected while the PR carries `evals-only` or `agentx-fast`, and `merge_with_reuse` refuses a PR with more than one primary label. The bot reacts to the command with 👍 when accepted or 👎 when rejected, with details in the Actions run summary, and posts a warning comment when the pinned run's commit is outside the PR; source artifacts are revalidated at merge.
- A missing authorized reuse command produces a Check 4 **WARN**, not a rejection. The warning stays visible in the sign-off verdict; posting an authorized command is still required to reuse artifacts.
- From the repository root, `uv run --project inferencex-e2e --extra workflows python -m infx.workflows.merge_with_reuse <pr-number>` is the supported merge path. It posts the command, syncs the branch with `main`, waits for checks, and squash-merges. See the [workflows README](.github/workflows/README.md#reusing-an-approved-pr-full-sweep) for eligibility details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ def make_request_case(monkeypatch) -> dict:
"head_sha": "tested-sha"},
"commits": [{"sha": "tested-sha"}],
"artifacts": [{"name": "results_bmk", "expired": False}],
"reactions": [], "writes": [],
"reactions": [], "writes": [], "posted": [],
}

def api(repo, path, token, params=None, *, method="GET", data=None):
assert repo == "example/project"
assert token == "test-token"
if case.get("fail_path") == path:
raise RuntimeError("GitHub unavailable")
if method == "POST" and path == "/issues/7/comments":
if case.get("fail_warning"):
raise RuntimeError("comment write failed")
posted = {"id": 900 + len(case["posted"]), "body": data["body"],
"user": {"login": "github-actions[bot]"}}
case["posted"].append(posted)
case["comments"].append(posted)
return posted
if method == "POST":
assert path == "/issues/comments/41/reactions"
case["writes"].append(data["content"])
Expand All @@ -59,6 +67,8 @@ def api(repo, path, token, params=None, *, method="GET", data=None):
return case["pr"]
if path == "/pulls/7/commits":
return case["commits"]
if path == "/commits/tested-sha/pulls":
return case.get("source_pulls", [])
if path == "/actions/runs/123":
return case["run"]
if path == "/actions/workflows/run-sweep.yml/runs":
Expand Down Expand Up @@ -111,13 +121,40 @@ def test_explicit_partial_source_keeps_existing_acceptance(request_case, conclus
assert bot_status(request_case) == ["+1"]


def test_source_outside_pr_is_accepted_then_warned_once(request_case, capsys):
request_case["commits"] = [{"sha": "different-sha"}]
request_case["run"]["head_branch"] = "other-branch"
request_case["source_pulls"] = [
{"number": 6, "head": {"ref": "unrelated"}},
{"number": 5, "head": {"ref": "other-branch"}},
]
event = event_for(request_case)
for _ in range(2):
assert acknowledgment.acknowledge("example/project", event, "test-token") == 0
assert bot_status(request_case) == ["+1"]
assert len(request_case["posted"]) == 1
assert "(from PR #5, commit `tested-sha`)" in request_case["posted"][0]["body"]
assert "::warning::Reuse source run 123 head tested-sha is not part of PR #7" in capsys.readouterr().out


def test_warning_comment_failure_keeps_acceptance(request_case):
request_case["commits"] = [{"sha": "different-sha"}]
request_case["fail_warning"] = True
assert acknowledgment.acknowledge("example/project", event_for(request_case), "test-token") == 0
assert bot_status(request_case) == ["+1"]


def test_source_in_pr_posts_no_warning(request_case):
assert acknowledgment.acknowledge("example/project", event_for(request_case), "test-token") == 0
assert request_case["posted"] == []


@pytest.mark.parametrize("problem,reason", [
("unauthorized", "OWNER, MEMBER, or COLLABORATOR"),
("syntax", "Usage:"),
("closed", "not open"),
("workflow", "expected .github/workflows/run-sweep.yml"),
("running", "not completed"),
("orphan", "not in PR #7's commit list"),
("empty", "no benchmark, eval, or agentic result artifact"),
("expired", "no benchmark, eval, or agentic result artifact"),
("modifier", "reuse-incompatible"),
Expand All @@ -136,8 +173,6 @@ def test_rejects_invalid_requests_without_approving(request_case, capsys, proble
case["run"]["path"] = ".github/workflows/other.yml"
elif problem == "running":
case["run"]["status"] = "in_progress"
elif problem == "orphan":
case["commits"] = [{"sha": "different-sha"}]
elif problem == "empty":
case["artifacts"] = [{"name": "run-stats"}]
elif problem == "expired":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def test_validate_reusable_run_rejects_non_success_run_by_default(conclusion) ->
reuse.validate_reusable_run(
"SemiAnalysisAI/InferenceX",
"run-sweep.yml",
1321,
{
"id": 25763404168,
"event": "pull_request",
Expand Down Expand Up @@ -430,6 +429,47 @@ def fake_paginated_github_api(repo, path, token, item_key, params=None):
assert outputs["reuse-source-head-sha"] == "abc123"


def test_main_reports_outside_run_source_pr(monkeypatch, tmp_path) -> None:
run = {
"id": 77, "event": "pull_request", "status": "completed", "conclusion": "success",
"path": ".github/workflows/run-sweep.yml", "pull_requests": [],
"head_sha": "other-sha", "head_branch": "other-branch",
}

def fake_github_api(repo, path, token, params=None):
return {
"/commits/merge-sha/pulls": [{"number": 1321}],
"/pulls/1321": {"merged_at": "2026-05-13T00:01:00Z", "labels": []},
"/actions/runs/77": run,
"/commits/other-sha/pulls": [{"number": 900, "head": {"ref": "other-branch"}}],
}[path]

def fake_paginated_github_api(repo, path, token, item_key, params=None):
return {
"/issues/1321/comments": [{
"created_at": "2026-05-13T00:00:00Z", "author_association": "OWNER",
"body": "/use 77",
}],
"/pulls/1321/commits": [{"sha": "abc123"}],
"/actions/runs/77/artifacts": [{"name": "results_bmk"}],
}[path]

output_path = tmp_path / "outputs"
monkeypatch.setenv("GITHUB_TOKEN", "token")
monkeypatch.setattr(reuse.github, "api", fake_github_api)
monkeypatch.setattr(reuse.github, "paginate", fake_paginated_github_api)
monkeypatch.setattr(reuse.sys, "argv", [
"find_reusable_sweep_run.py", "--repo", "SemiAnalysisAI/InferenceX",
"--commit-sha", "merge-sha", "--event-name", "push", "--ref", "refs/heads/main",
"--github-output", str(output_path),
])

assert reuse.main() == 0
outputs = dict(line.split("=", 1) for line in output_path.read_text().splitlines())
assert outputs["reuse-source-run-id"] == "77"
assert outputs["reuse-source-pr-number"] == "900"


def test_main_enables_explicitly_pinned_failed_run(monkeypatch, tmp_path) -> None:
comments = [
{
Expand Down
Loading
Loading