Skip to content

Replace Claude Code issue triage with the pi harness - #199555

Closed
drisspg wants to merge 28 commits into
gh/drisspg/434/basefrom
gh/drisspg/434/head
Closed

drisspg wants to merge 28 commits into
gh/drisspg/434/basefrom
gh/drisspg/434/head

Conversation

@drisspg

@drisspg drisspg commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human Note

Agent Notes

Move issue triage from Claude Code to pi while keeping Sonnet 5 as the default, at medium
thinking. Sol remains a manual option. The main change is the trust boundary: the model reads
issues and submits a structured plan; a separate job with no model or AWS credentials applies it.
The model never holds the GitHub write token.

The apply step filters labels, supplies required comment templates, and adds completion labels
for complete classifications. Reproduction requests redact download links using a fixed policy
and the current issue body, not a model-written replacement. Transfers go to human review;
automatic closes are limited to usage questions and expected numerical behavior. Reports show
the comments that will actually be posted, including automatic templates and deduplication.

Manual replay and dry-run support batches; apply accepts exactly one issue. The reusable
read-only Bedrock workflow has blocked egress and short-lived credentials; #199588 reuses it for
distributed triage. Model execution artifacts and usage metrics retain their existing formats. Job summaries remain
readable Markdown; log copies are JSON-encoded to prevent workflow-command interpretation.

For review, start with issue-triage-pi.yml and pi-triage-plan.yml, then apply_plan.py and
its tests. add_bot_triaged.py is removed here. The two validation hooks remain for the old
distributed workflow until #199588 removes their last users. The model still makes triage
judgments; these controls limit its effects rather than making those judgments infallible.

Validation

  • 20-issue Sonnet replay: oncall
    routing matched the historical Claude bot on 20/20 issues. This is agreement, not ground truth.
  • Live ciforge testing exercised issue-opened triage, comments, restricted closing, and the
    distributed handoff. The handoff testing exposed a subqueue-routing gap, now covered by tests.
  • Effective-template reporting was checked with deterministic tests for automatic, unknown,
    and already-posted templates; no new live model run was needed for that reporting-only change.

Linked issue or supporting maintainer

BC-breaking?

No.

Summary (human written only)

Agent details (if applicable)

Implementation and validation are described in Agent Notes above.

cc @albanD

[ghstack-poisoned]
@drisspg
drisspg requested a review from a team as a code owner October 2, 2026 20:17
@pytorch-bot

pytorch-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

🟡 AUTOMATED REVIEW - OUTDATED (earlier commit) - Changes requested:

This PR moves first-pass issue triage from Claude Code with GitHub MCP to pi: a
read-only model job submits a plan, and a separate `issues: write` job with no
AWS access filters and applies it. Recommendation: Request Changes. The apply
step still accepts a `triaged` label requested by the model, which the skill
forbids, and the close/label writes and the tool extension's replay logic have
no tests.

Findings (8):

[major] scripts/issue_triage_pi/apply_plan.py:233
The apply step still applies a `triaged` label requested by the model, where
SKILL.md says it must not. `triaged` is in `labels.json`, so it passes the
filter for every decision. It is only removed for `request_reproduction` or when
`triage review` is present. The checks in the automatic block at line 254
(non-PT2 redirect, pending `request_more_info`, `needs reproduction`) only
govern the label the apply step adds itself. So `request_info` with
`["triaged"]`, or `redirect_oncall` with `["oncall: jit", "triaged"]`, marks an
issue complete that SKILL.md Steps 3 and 7 say must stay open. The author has
reproduced this and deferred it, but the fix is one line: drop `triaged` from
`requested` next to `BOT_TRIAGED`/`PTD_TRIAGED` (line ~194), so the automatic
block is the only place it comes from.
`test_label_plan_adds_labels_and_bot_marker` and
`test_labels_already_present_are_not_re_added` currently encode the wrong
behavior as intended and would need updating. Deferring means shipping a guard
the description says exists but that has a known gap.

[major] scripts/issue_triage_pi/apply_plan.py:350
The writes with the largest effect have no tests.
`test_apply_redacts_current_body_not_planning_snapshot` asserts only the body
`PATCH` and the number of comment `POST`s. Nothing checks that labels go through
`POST /labels` (append) and never replace existing labels (line 350), or that
`close_question`/`close_expected_behavior` send exactly one
`state=closed`/`state_reason=not_planned` `PATCH`, after the comment (line 359).
A regression in either would remove reporters' labels or close bug reports.

[major] .github/pi/extensions/github-issue-tools.ts:55
`github-issue-tools.ts` has no tests. Its replay logic is untested: the
`preTriage` cutoff, dropping bot comments and comments after the cutoff,
removing the replayed issue from `search_issues`, and forcing `state: "open"`.
`labels_before_triage` reimplements the same cutoff in Python, so if one copy
drifts, the replay agreement numbers in the description are skewed. The author
says this coverage is out of scope, but under this repo's review rules new logic
without tests still blocks.

[minor] scripts/issue_triage_pi/apply_plan.py:294
Redaction has no host exemption, so it rewrites first-party links in the
reporter's body. Every `request_reproduction` plan runs the fixed policy over
the whole current body, code blocks and logs included. torch.hub tracebacks
(`Downloading: "(link removed) and libtorch install reports (`(link removed)
both get replaced with the "external file downloads are not permitted" notice.
Under the old flow the model chose which links to remove. Fix: exempt
`download.pytorch.org` and `github.com/pytorch/` in `replace_url`, and add both
to the kept list in `test_only_download_and_storage_links_are_removed`. This is
small and should land with this PR, since it affects issues filed by real users.

[minor] scripts/issue_triage_pi/apply_plan.py:341
The comment `POST` uses `gh_api`'s default of 3 attempts. A `POST /comments`
that succeeds on the server but returns non-zero (for example a 502 after the
write) is retried and posts the template twice. The dedup snapshot was taken
before the first attempt, so it cannot catch this. The body `PATCH` already sets
`retry=False` for a similar reason. Pass `retry=False` here too. Label `POST`
and close `PATCH` are idempotent and can keep retrying. This is small and should
land with this PR.

(3 more not shown, see the review run)

Reviewed commit: 7b10889 (NOT the current head d325b0d)

Review run

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199555

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit d325b0d with merge base 421855c (image):
💚 Looks good so far! There are no failures yet. 💚
🟡 GreenLight: changes are too big to review

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T20:22:53.733822Z 58f6094 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58f6094203

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/issue-triage-pi.yml Resolved
Comment thread scripts/issue_triage_pi/apply_plan.py Resolved
Comment thread scripts/issue_triage_pi/apply_plan.py Resolved
[ghstack-poisoned]
drisspg added a commit that referenced this pull request Oct 2, 2026
Issue triage moves from Claude Code to pi. Stage 1 is renamed
`issue-triage.yml` ("Issue Triage"); stage 2, `claude-issue-triage-run.yml`,
is replaced by `issue-triage-pi.yml`, which keeps the `triaging-issues` skill
and `global.anthropic.claude-sonnet-5` and splits the work by trust:

- plan (bedrock, `issues: read`): pi reads the issue through three read-only
  `gh` tools fixed to this repository and submits a schema-validated plan. The
  job holds no write token, has no shell, runs under harden-runner with egress
  blocked to Bedrock, STS, GitHub, and npm, and pi's path tools cannot leave the
  checkout.
- apply (`issues: write`, no AWS, no model): `apply_plan.py` filters the plan
  with the skill's label rules (`validate_labels.py`), only adds labels, posts
  only `templates.json` comments the bot has not already posted, closes only
  usage questions and expected numerical behavior, adds `bot-triaged`, and
  fails the job when triage took no action. It then hands the issue to the
  distributed sub-triage, which now runs only for runs that hand one off.

The previous stage 2 gave the model `issues: write` through the GitHub MCP
server with open egress and relied on in-process hooks to filter its writes.
The skill is rewritten for this flow: its Claude hooks, MCP tool table, and
`add_bot_triaged.py` are gone; `validate_labels.py` and
`validate_issue_target.py` stay because the distributed-triage skill's hooks
use them.

`.github/actions/pi-agent` is a self-contained composite action (lockfile-pinned
pi, model allowlist, per-call tool allowlist) shared with pytorch/ciforge, where
this flow has been running. Manual dispatch supports `replay` (an
already-triaged issue as it was before the triage bot acted, compared with the
labels added since), `dry-run`, and `apply`. Not automated: issue transfers
(become `triage review`) and issue-body redaction. Not ported yet: the S3
execution-log and usage-metric uploads.

Test plan:
- `python3 -m unittest discover -s scripts/issue_triage_pi` (plan-to-effects
  rules, replay reconstruction, and a workflow lockdown contract; the workflow
  also runs them before the model starts)
- actionlint, GHA, PYFMT, ruff, and flake8 on the changed files
- Local runs of the action against live issues with a scripted model; replay of
  #199454 shows its creation-time labels and takes the already-routed path
- In pytorch/ciforge: replays of 8 recently triaged pytorch issues matched the
  existing routing on every issue, and a live issue was labeled end-to-end

ghstack-source-id: 9967f43
Pull-Request: #199555
@drisspg
drisspg requested review from albanD and malfet as code owners October 2, 2026 20:36
@drisspg drisspg changed the title Run issue triage stage 2 on the pi harness instead of Claude Code Replace Claude Code issue triage with the pi harness Oct 2, 2026
drisspg added a commit that referenced this pull request Oct 2, 2026
Issue triage moves from Claude Code to pi. Stage 1 is renamed
`issue-triage.yml` ("Issue Triage"); stage 2, `claude-issue-triage-run.yml`,
is replaced by `issue-triage-pi.yml`, which keeps the `triaging-issues` skill
and `global.anthropic.claude-sonnet-5` and splits the work by trust:

- plan (bedrock, `issues: read`): pi reads the issue through three read-only
  `gh` tools fixed to this repository and submits a schema-validated plan. The
  job holds no write token, has no shell, runs under harden-runner with egress
  blocked to Bedrock, STS, GitHub, and npm, and pi's path tools cannot leave the
  checkout.
- apply (`issues: write`, no AWS, no model): `apply_plan.py` filters the plan
  with the skill's label rules (`validate_labels.py`), only adds labels, posts
  only `templates.json` comments the bot has not already posted, closes only
  usage questions and expected numerical behavior, adds `bot-triaged`, and
  fails the job when triage took no action. It then hands the issue to the
  distributed sub-triage, which now runs only for runs that hand one off.

The previous stage 2 gave the model `issues: write` through the GitHub MCP
server with open egress and relied on in-process hooks to filter its writes.
The skill is rewritten for this flow: its Claude hooks, MCP tool table, and
`add_bot_triaged.py` are gone; `validate_labels.py` and
`validate_issue_target.py` stay because the distributed-triage skill's hooks
use them.

`.github/actions/pi-agent` is a self-contained composite action (lockfile-pinned
pi, model allowlist, per-call tool allowlist) shared with pytorch/ciforge, where
this flow has been running. Manual dispatch supports `replay` (an
already-triaged issue as it was before the triage bot acted, compared with the
labels added since), `dry-run`, and `apply`. Not automated: issue transfers
(become `triage review`) and issue-body redaction. Not ported yet: the S3
execution-log and usage-metric uploads.

Test plan:
- `python3 -m unittest discover -s scripts/issue_triage_pi` (plan-to-effects
  rules, replay reconstruction, and a workflow lockdown contract; the workflow
  also runs them before the model starts)
- actionlint, GHA, PYFMT, ruff, and flake8 on the changed files
- Local runs of the action against live issues with a scripted model; replay of
  #199454 shows its creation-time labels and takes the already-routed path
- In pytorch/ciforge: replays of 8 recently triaged pytorch issues matched the
  existing routing on every issue, and a live issue was labeled end-to-end

ghstack-source-id: 9967f43
Pull-Request: #199555
[ghstack-poisoned]
drisspg added a commit that referenced this pull request Oct 2, 2026
Move issue triage from Claude Code to pi while keeping the triaging-issues
skill and global.anthropic.claude-sonnet-5 model. The model now proposes a
read-only plan; a separate, model-free job validates and applies it. This
moves write enforcement out of model-process hooks. Replay routing matched
Claude on 20/20 issues, but live testing found a distributed-routing gap
that still needs an apply-step fix.

## What changes

- Rename stage 1 to issue-triage.yml and replace claude-issue-triage-run.yml
  with issue-triage-pi.yml for stage 2.
- Plan job: Bedrock access, issues: read, read-only gh tools, no shell, and
  harden-runner with egress blocked except for allowed endpoints.
- Apply job: issues: write, no AWS access or model. apply_plan.py enforces
  the skill's label rules, only adds labels, posts only templates.json
  comments, and closes only usage questions or expected numerical behavior.
  It adds bot-triaged and hands off to distributed triage.
- Rewrite the skill for plan/apply; remove Claude hooks, the MCP tool table,
  and add_bot_triaged.py. Keep validate_labels.py and validate_issue_target.py
  because distributed-triage hooks still use them.
- Run the model through .github/actions/pi-agent (added in the previous PR;
  the same action runs triage in pytorch/ciforge). Manual dispatch supports
  replay, dry-run, and apply.

## Why it is safer

| Boundary | Previous stage 2 | New stage 2 |
| --- | --- | --- |
| Model's GitHub access | issues: write through GitHub MCP | issues: read; read-only gh tools |
| Egress | Open | harden-runner blocked, explicit allowlist |
| Write enforcement | In-process hooks | Separate apply_plan.py job, no model or AWS |
| Allowed effects | Hook-filtered model writes | Add-only labels, template comments, restricted closes |

The model still makes triage judgments; this limits its effects rather than
making those judgments reliable by construction.

## Evidence

Replay: 20 previously Claude-triaged issues, reconstructed before the bot's
first label event. Plans were scored through apply_plan.plan_effects;
distributed sub-triage labels were excluded. Cost was about $1.26 total.
Run: https://github.com/pytorch/ciforge/actions/runs/37063139472

| Replay measure | pi | Claude |
| --- | --- | --- |
| Oncall routing | 20/20 | 20/20 |
| Close-decision agreement with Claude | 19/20 | Reference |
| Status agreement (triaged / triage review) | 17/20 | Reference |
| Topic-label precision / recall vs final labels | 86% / 80% | 96% / 87% |

Claude's scores against final labels are inflated: those labels are mostly
Claude's own, not independent ground truth. Of four human-corrected replay
issues, pi was closer on two: #199106 (regression rather than enhancement,
but still added release triage) and #199179 (caught silent correctness,
but used xpu rather than intel and triage review rather than triaged).
Both missed module: pt2-dispatcher on #199259 and added release triage on
#199277, which a human removed. pi also missed module: pt2-dispatcher on
#199258 and module: elastic on #199178 in replay.

Live: 21 pytorch/pytorch issues were re-opened one at a time in the private
pytorch/ciforge test repo through the real issue-opened flow. Comparing the
recorded stage-2 labels and close decisions with Claude on the originals:

- Exact stage-2 label sets matched on 12/21 issues.
- Oncall label sets matched on 20/21, including 7/8 Claude-routed issues.
- Status labels (triaged / triage review) matched on 19/21.
- Close decisions matched on 20/21. pi closed #199337 as expected numerical
  behavior (pytorch/ciforge#657); Claude left it open. In replay, Claude had
  closed its sibling #199338. This is disagreement, not proven correctness.

The live flow labeled the optimizer issue pytorch/ciforge#653 (#199516),
closed the usage question pytorch/ciforge#655 with a forum redirect, and
closed pytorch/ciforge#657 with the numerical-accuracy template. The
handoff on pytorch/ciforge#656 (#199239) reached distributed infra triage.

Known gap: on pytorch/ciforge#659 (#199028), pi applied the sub-queue label
oncall: distributed checkpointing instead of oncall: distributed. The
sub-triage kept it and stopped, so the parent label, triaged, and security
were never added. The stage-2 score excludes that sub-queue label; it does
not mean no label was applied. This is not fixed: the apply step needs to
map distributed sub-queue labels to the parent before handoff.

## Not in this PR / follow-ups

- Fix the distributed sub-queue-to-parent mapping described above.
- Issue transfers are not automated; they become triage review instead.
  Issue-body redaction is also not automated.
- S3 execution-log and usage-metric uploads are not ported; the inspector
  cannot show pi runs yet.

## Test plan

- python3 -m unittest discover -s scripts/issue_triage_pi
  (plan-to-effects rules, replay reconstruction, workflow lockdown contract;
  the workflow also runs these before starting the model).
- actionlint, GHA, PYFMT, ruff, and flake8 on changed files.
- Local action runs with a scripted model; replay #199454 to check
  creation-time labels and the already-routed path.
- Replay and live end-to-end evaluation above; add a regression test for
  pytorch/ciforge#659 when fixing the apply-step mapping.

ghstack-source-id: 7e554a5
Pull-Request: #199555
drisspg added a commit that referenced this pull request Oct 2, 2026
Move issue triage from Claude Code to pi while keeping the triaging-issues
skill and global.anthropic.claude-sonnet-5 model. The model now proposes a
read-only plan; a separate, model-free job validates and applies it. This
moves write enforcement out of model-process hooks. Replay routing matched
Claude on 20/20 issues, but live testing found a distributed-routing gap
that still needs an apply-step fix.

## What changes

- Rename stage 1 to issue-triage.yml and replace claude-issue-triage-run.yml
  with issue-triage-pi.yml for stage 2.
- Plan job: Bedrock access, issues: read, read-only gh tools, no shell, and
  harden-runner with egress blocked except for allowed endpoints.
- Apply job: issues: write, no AWS access or model. apply_plan.py enforces
  the skill's label rules, only adds labels, posts only templates.json
  comments, and closes only usage questions or expected numerical behavior.
  It adds bot-triaged and hands off to distributed triage.
- Rewrite the skill for plan/apply; remove Claude hooks, the MCP tool table,
  and add_bot_triaged.py. Keep validate_labels.py and validate_issue_target.py
  because distributed-triage hooks still use them.
- Run the model through .github/actions/pi-agent (added in the previous PR;
  the same action runs triage in pytorch/ciforge). Manual dispatch supports
  replay, dry-run, and apply.

## Why it is safer

| Boundary | Previous stage 2 | New stage 2 |
| --- | --- | --- |
| Model's GitHub access | issues: write through GitHub MCP | issues: read; read-only gh tools |
| Egress | Open | harden-runner blocked, explicit allowlist |
| Write enforcement | In-process hooks | Separate apply_plan.py job, no model or AWS |
| Allowed effects | Hook-filtered model writes | Add-only labels, template comments, restricted closes |

The model still makes triage judgments; this limits its effects rather than
making those judgments reliable by construction.

## Evidence

Replay: 20 recently Claude-triaged issues, each shown to pi as it was before
the bot's first label event; plans scored through `apply_plan.plan_effects`.
Distributed issues are scored on routing only (their sub-queue, status, and
module labels come from the separate distributed sub-triage), and
`release triage` is not scored. Labels are measured as agreement with what
Claude applied, since final labels are mostly Claude's own.
Run: https://github.com/pytorch/ciforge/actions/runs/37063139472

| 20-issue replay | Sonnet 5 (shipped) | GPT-5.6 Terra | Terra, high thinking |
| --- | --- | --- | --- |
| Oncall routing | 20/20 | 19/20 | 19/20 |
| Status (triaged / triage review) | 17/20 | 15/20 | 16/20 |
| Close decision | 19/20 | 19/20 | 19/20 |
| Labels vs Claude (precision / recall) | 79% / 88% | 65% / 68% | 64% / 64% |
| Cost for 20 issues | $1.26 | $0.97 | $0.95 |

On the four issues humans later corrected, Sonnet 5 matched the final labels
at 73% precision / 85% recall (Claude: 90% / 69%): it added `module:
regression` on #199106 and `module: correctness (silent)` on #199179 where
Claude did not. Misses include `module: pt2-dispatcher` (#199258) and
`module: elastic` (#199178). Terra routed an ONNX issue (#198691) to
`oncall: export` at both thinking levels.

Live: 21 pytorch/pytorch issues were re-opened one at a time in the private
pytorch/ciforge test repo through the real issue-opened flow. Comparing the
recorded stage-2 labels and close decisions with Claude on the originals:

- Exact stage-2 label sets (excluding `release triage`) matched on 12/21.
- Oncall routing matched on 20/21; the miss is the #659 gap below.
- Status (triaged / triage review) matched on 16/18 non-distributed issues.
- Close decisions matched on 20/21. pi closed #199337 as expected numerical
  behavior (pytorch/ciforge#657); Claude left it open. In replay, Claude had
  closed its sibling #199338. This is disagreement, not proven correctness.

The live flow labeled the optimizer issue pytorch/ciforge#653 (#199516),
closed the usage question pytorch/ciforge#655 with a forum redirect, and
closed pytorch/ciforge#657 with the numerical-accuracy template. The
handoff on pytorch/ciforge#656 (#199239) reached distributed infra triage.

Known gap: on pytorch/ciforge#659 (#199028), pi applied the sub-queue label
oncall: distributed checkpointing instead of oncall: distributed. The
sub-triage kept it and stopped, so the parent label, triaged, and security
were never added. The stage-2 score excludes that sub-queue label; it does
not mean no label was applied. This is not fixed: the apply step needs to
map distributed sub-queue labels to the parent before handoff.

## Not in this PR / follow-ups

- Fix the distributed sub-queue-to-parent mapping described above.
- Issue transfers are not automated; they become triage review instead.
  Issue-body redaction is also not automated.
- S3 execution-log and usage-metric uploads are not ported; the inspector
  cannot show pi runs yet.

## Test plan

- python3 -m unittest discover -s scripts/issue_triage_pi
  (plan-to-effects rules, replay reconstruction, workflow lockdown contract;
  the workflow also runs these before starting the model).
- actionlint, GHA, PYFMT, ruff, and flake8 on changed files.
- Local action runs with a scripted model; replay #199454 to check
  creation-time labels and the already-routed path.
- Replay and live end-to-end evaluation above; add a regression test for
  pytorch/ciforge#659 when fixing the apply-step mapping.

ghstack-source-id: 7e554a5
Pull-Request: #199555
[ghstack-poisoned]
drisspg added a commit that referenced this pull request Oct 2, 2026
Move issue triage from Claude Code to pi while keeping the triaging-issues
skill and global.anthropic.claude-sonnet-5 model. The model now proposes a
read-only plan; a separate, model-free job validates and applies it. This
moves write enforcement out of model-process hooks. Replay routing matched
Claude on 20/20 issues, but live testing found a distributed-routing gap
that still needs an apply-step fix.

## What changes

- Usage metrics go to `claude_code_usage` (test-infra's
  `upload-claude-usage`) and, for applied triage, the execution log to
  `s3://ossci-raw-job-status/review-logs/<issue>.json`, as before and in the
  same format; replays and dry runs never overwrite that log.
- Rename stage 1 to issue-triage.yml and replace claude-issue-triage-run.yml
  with issue-triage-pi.yml for stage 2.
- Plan job: Bedrock access, issues: read, read-only gh tools, no shell, and
  harden-runner with egress blocked except for allowed endpoints.
- Apply job: issues: write, no AWS access or model. apply_plan.py enforces
  the skill's label rules, only adds labels, posts only templates.json
  comments, and closes only usage questions or expected numerical behavior.
  It adds bot-triaged and hands off to distributed triage.
- Rewrite the skill for plan/apply; remove Claude hooks, the MCP tool table,
  and add_bot_triaged.py. Keep validate_labels.py and validate_issue_target.py
  because distributed-triage hooks still use them.
- Run the model through .github/actions/pi-agent (added in the previous PR;
  the same action runs triage in pytorch/ciforge). Manual dispatch supports
  replay, dry-run, and apply.

## Why it is safer

| Boundary | Previous stage 2 | New stage 2 |
| --- | --- | --- |
| Model's GitHub access | issues: write through GitHub MCP | issues: read; read-only gh tools |
| Egress | Open | harden-runner blocked, explicit allowlist |
| Write enforcement | In-process hooks | Separate apply_plan.py job, no model or AWS |
| Allowed effects | Hook-filtered model writes | Add-only labels, template comments, restricted closes |

The model still makes triage judgments; this limits its effects rather than
making those judgments reliable by construction.

## Evidence

Replay: 20 previously Claude-triaged issues, reconstructed before the bot's
first label event. Plans were scored through apply_plan.plan_effects;
distributed sub-triage labels were excluded. Cost was about $1.26 total.
Run: https://github.com/pytorch/ciforge/actions/runs/37063139472

| Replay measure | pi | Claude |
| --- | --- | --- |
| Oncall routing | 20/20 | 20/20 |
| Close-decision agreement with Claude | 19/20 | Reference |
| Status agreement (triaged / triage review) | 17/20 | Reference |
| Topic-label precision / recall vs final labels | 86% / 80% | 96% / 87% |

Claude's scores against final labels are inflated: those labels are mostly
Claude's own, not independent ground truth. Of four human-corrected replay
issues, pi was closer on two: #199106 (regression rather than enhancement,
but still added release triage) and #199179 (caught silent correctness,
but used xpu rather than intel and triage review rather than triaged).
Both missed module: pt2-dispatcher on #199259 and added release triage on
#199277, which a human removed. pi also missed module: pt2-dispatcher on
#199258 and module: elastic on #199178 in replay.

Live: 21 pytorch/pytorch issues were re-opened one at a time in the private
pytorch/ciforge test repo through the real issue-opened flow. Comparing the
recorded stage-2 labels and close decisions with Claude on the originals:

- Exact stage-2 label sets matched on 12/21 issues.
- Oncall label sets matched on 20/21, including 7/8 Claude-routed issues.
- Status labels (triaged / triage review) matched on 19/21.
- Close decisions matched on 20/21. pi closed #199337 as expected numerical
  behavior (pytorch/ciforge#657); Claude left it open. In replay, Claude had
  closed its sibling #199338. This is disagreement, not proven correctness.

The live flow labeled the optimizer issue pytorch/ciforge#653 (#199516),
closed the usage question pytorch/ciforge#655 with a forum redirect, and
closed pytorch/ciforge#657 with the numerical-accuracy template. The
handoff on pytorch/ciforge#656 (#199239) reached distributed infra triage.

Known gap: on pytorch/ciforge#659 (#199028), pi applied the sub-queue label
oncall: distributed checkpointing instead of oncall: distributed. The
sub-triage kept it and stopped, so the parent label, triaged, and security
were never added. The stage-2 score excludes that sub-queue label; it does
not mean no label was applied. This is not fixed: the apply step needs to
map distributed sub-queue labels to the parent before handoff.

## Not in this PR / follow-ups

- Fix the distributed sub-queue-to-parent mapping described above.
- Issue transfers are not automated; they become triage review instead.
  Issue-body redaction is also not automated.

## Test plan

- python3 -m unittest discover -s scripts/issue_triage_pi
  (plan-to-effects rules, replay reconstruction, workflow lockdown contract;
  the workflow also runs these before starting the model).
- actionlint, GHA, PYFMT, ruff, and flake8 on changed files.
- Local action runs with a scripted model; replay #199454 to check
  creation-time labels and the already-routed path.
- Replay and live end-to-end evaluation above; add a regression test for
  pytorch/ciforge#659 when fixing the apply-step mapping.

ghstack-source-id: 76252b1
Pull-Request: #199555
[ghstack-poisoned]
drisspg added a commit that referenced this pull request Oct 2, 2026
Move issue triage from Claude Code to pi, keeping the triaging-issues skill
and switching the model to global.openai.gpt-6.1-sol (medium thinking). The model now proposes a
read-only plan; a separate, model-free job validates and applies it. This
moves write enforcement out of model-process hooks. Replay routing matched
Claude on 20/20 issues, but live testing found a distributed-routing gap
that still needs an apply-step fix.

## What changes

- Rename stage 1 to issue-triage.yml and replace claude-issue-triage-run.yml
  with issue-triage-pi.yml for stage 2.
- Plan job: Bedrock access, issues: read, read-only gh tools, no shell, and
  harden-runner with egress blocked except for allowed endpoints.
- Apply job: issues: write, no AWS access or model. apply_plan.py enforces
  the skill's label rules, only adds labels, posts only templates.json
  comments, and closes only usage questions or expected numerical behavior.
  It adds bot-triaged and hands off to distributed triage.
- Rewrite the skill for plan/apply; remove Claude hooks, the MCP tool table,
  and add_bot_triaged.py. Keep validate_labels.py and validate_issue_target.py
  because distributed-triage hooks still use them.
- Run the model through .github/actions/pi-agent (added in the previous PR;
  the same action runs triage in pytorch/ciforge). Manual dispatch supports
  replay, dry-run, and apply.

## Why it is safer

| Boundary | Previous stage 2 | New stage 2 |
| --- | --- | --- |
| Model's GitHub access | issues: write through GitHub MCP | issues: read; read-only gh tools |
| Egress | Open | harden-runner blocked, explicit allowlist |
| Write enforcement | In-process hooks | Separate apply_plan.py job, no model or AWS |
| Allowed effects | Hook-filtered model writes | Add-only labels, template comments, restricted closes |

The model still makes triage judgments; this limits its effects rather than
making those judgments reliable by construction.

## Evidence

Replay: 20 recently Claude-triaged issues, each shown to pi as it was before
the bot's first label event; plans scored through `apply_plan.plan_effects`.
Distributed issues are scored on routing only (their sub-queue, status, and
module labels come from the separate distributed sub-triage), and
`release triage` is not scored. Labels are measured as agreement with what
Claude applied, since final labels are mostly Claude's own.
Run: https://github.com/pytorch/ciforge/actions/runs/37063139472

| 20-issue replay | GPT-6.1 Sol (shipped) | Sonnet 5 | GPT-5.6 Terra |
| --- | --- | --- | --- |
| Oncall routing | 18/20 | 20/20 | 19/20 |
| Status (triaged / triage review) | 15/20 | 17/20 | 15/20 |
| Close decision | 19/20 | 19/20 | 19/20 |
| Labels vs Claude (precision / recall) | 59% / 80% | 79% / 88% | 65% / 68% |
| Cost for 20 issues (Sol approximate) | ~$0.92 | $1.26 | $0.97 |

High thinking did not change either OpenAI model's results. Sol's lower
agreement is mostly extra labels; read against the skill and `labels.json`,
several are better than what Claude applied: it added the `module:
pt2-dispatcher` umbrella on #199258 and #199259 (humans added it on #199259),
and on #199058 it routed to `oncall: pt2` with `module: inductor` as
`SKILL.md` asks, where Claude and Sonnet used the `oncall: cpu inductor`
sub-queue. Weaker calls: it labelled an invalid ONNX export (#198691) silent
correctness, and added `module: autograd` to an MPS performance issue
(#199277).

Sonnet 5 was closer to Claude's existing labels and stays on the allowlist. On
the four issues humans later corrected it matched the final labels at 73%
precision / 85% recall (Claude: 90% / 69%). Terra routed an ONNX issue
(#198691) to `oncall: export`.

The live run below used Sonnet 5.

Live: 21 pytorch/pytorch issues were re-opened one at a time in the private
pytorch/ciforge test repo through the real issue-opened flow. Comparing the
recorded stage-2 labels and close decisions with Claude on the originals:

- Exact stage-2 label sets (excluding `release triage`) matched on 12/21.
- Oncall routing matched on 20/21; the miss is the #659 gap below.
- Status (triaged / triage review) matched on 16/18 non-distributed issues.
- Close decisions matched on 20/21. pi closed #199337 as expected numerical
  behavior (pytorch/ciforge#657); Claude left it open. In replay, Claude had
  closed its sibling #199338. This is disagreement, not proven correctness.

The live flow labeled the optimizer issue pytorch/ciforge#653 (#199516),
closed the usage question pytorch/ciforge#655 with a forum redirect, and
closed pytorch/ciforge#657 with the numerical-accuracy template. The
handoff on pytorch/ciforge#656 (#199239) reached distributed infra triage.

Known gap: on pytorch/ciforge#659 (#199028), pi applied the sub-queue label
oncall: distributed checkpointing instead of oncall: distributed. The
sub-triage kept it and stopped, so the parent label, triaged, and security
were never added. The stage-2 score excludes that sub-queue label; it does
not mean no label was applied. This is not fixed: the apply step needs to
map distributed sub-queue labels to the parent before handoff.

## Not in this PR / follow-ups

- Fix the distributed sub-queue-to-parent mapping described above.
- Issue transfers are not automated; they become triage review instead.
  Issue-body redaction is also not automated.
- S3 execution-log and usage-metric uploads are not ported; the inspector
  cannot show pi runs yet.

## Test plan

- python3 -m unittest discover -s scripts/issue_triage_pi
  (plan-to-effects rules, replay reconstruction, workflow lockdown contract;
  the workflow also runs these before starting the model).
- actionlint, GHA, PYFMT, ruff, and flake8 on changed files.
- Local action runs with a scripted model; replay #199454 to check
  creation-time labels and the already-routed path.
- Replay and live end-to-end evaluation above; add a regression test for
  pytorch/ciforge#659 when fixing the apply-step mapping.

ghstack-source-id: 8230daa
Pull-Request: #199555
[ghstack-poisoned]
drisspg added a commit that referenced this pull request Oct 2, 2026
Move issue triage from Claude Code to pi, keeping the triaging-issues skill
and switching the model to global.openai.gpt-6.1-sol (medium thinking). The model now proposes a
read-only plan; a separate, model-free job validates and applies it. This
moves write enforcement out of model-process hooks. Replay routing matched
Claude on 20/20 issues, but live testing found a distributed-routing gap
that still needs an apply-step fix.

- Rename stage 1 to issue-triage.yml and replace claude-issue-triage-run.yml
  with issue-triage-pi.yml for stage 2.
- Plan job: Bedrock access, issues: read, read-only gh tools, no shell, and
  harden-runner with egress blocked except for allowed endpoints.
- Apply job: issues: write, no AWS access or model. apply_plan.py enforces
  the skill's label rules, only adds labels, posts only templates.json
  comments, and closes only usage questions or expected numerical behavior.
  It adds bot-triaged and hands off to distributed triage.
- Rewrite the skill for plan/apply; remove Claude hooks, the MCP tool table,
  and add_bot_triaged.py. Keep validate_labels.py and validate_issue_target.py
  because distributed-triage hooks still use them. Clarify two routing rules
  the replay exposed: CPU-only Inductor issues go to `oncall: cpu inductor`
  (as the PT2 rubric already said), and a dispatcher-layer label comes with the
  `module: pt2-dispatcher` umbrella.
- Run the model through .github/actions/pi-agent (added in the previous PR;
  the same action runs triage in pytorch/ciforge). Manual dispatch supports
  replay, dry-run, and apply.

| Boundary | Previous stage 2 | New stage 2 |
| --- | --- | --- |
| Model's GitHub access | issues: write through GitHub MCP | issues: read; read-only gh tools |
| Egress | Open | harden-runner blocked, explicit allowlist |
| Write enforcement | In-process hooks | Separate apply_plan.py job, no model or AWS |
| Allowed effects | Hook-filtered model writes | Add-only labels, template comments, restricted closes |

The model still makes triage judgments; this limits its effects rather than
making those judgments reliable by construction.

Replay: 20 recently Claude-triaged issues, each shown to pi as it was before
the bot's first label event; plans scored through `apply_plan.plan_effects`.
Distributed issues are scored on routing only (their sub-queue, status, and
module labels come from the separate distributed sub-triage), and
`release triage` is not scored. Labels are measured as agreement with what
Claude applied, since final labels are mostly Claude's own.
Run: https://github.com/pytorch/ciforge/actions/runs/37063139472

| 20-issue replay | GPT-6.1 Sol (shipped) | Sonnet 5 | GPT-5.6 Terra |
| --- | --- | --- | --- |
| Oncall routing | 18/20 | 20/20 | 19/20 |
| Status (triaged / triage review) | 15/20 | 17/20 | 15/20 |
| Close decision | 19/20 | 19/20 | 19/20 |
| Labels vs Claude (precision / recall) | 59% / 80% | 79% / 88% | 65% / 68% |
| Cost for 20 issues (Sol approximate) | ~$0.92 | $1.26 | $0.97 |

High thinking did not change either OpenAI model's results. Sol's lower
agreement is mostly extra labels; read against the skill and `labels.json`,
some are better than what Claude applied: it added the `module:
pt2-dispatcher` umbrella on #199258 and #199259 (humans added it on #199259).
Weaker calls: it routed the CPU-only Inductor issue #199058 to `oncall: pt2`
instead of `oncall: cpu inductor` (the PT2 rubric's rule; `SKILL.md` said the
opposite, now fixed), labelled an invalid ONNX export (#198691) silent
correctness, and added `module: autograd` to an MPS performance issue
(#199277).

Sonnet 5 was closer to Claude's existing labels and stays on the allowlist. On
the four issues humans later corrected it matched the final labels at 73%
precision / 85% recall (Claude: 90% / 69%). Terra routed an ONNX issue
(#198691) to `oncall: export`.

The live run below used Sonnet 5.

Live: 21 pytorch/pytorch issues were re-opened one at a time in the private
pytorch/ciforge test repo through the real issue-opened flow. Comparing the
recorded stage-2 labels and close decisions with Claude on the originals:

- Exact stage-2 label sets (excluding `release triage`) matched on 12/21.
- Oncall routing matched on 20/21; the miss is the #659 gap below.
- Status (triaged / triage review) matched on 16/18 non-distributed issues.
- Close decisions matched on 20/21. pi closed #199337 as expected numerical
  behavior (pytorch/ciforge#657); Claude left it open. In replay, Claude had
  closed its sibling #199338. This is disagreement, not proven correctness.

The live flow labeled the optimizer issue pytorch/ciforge#653 (#199516),
closed the usage question pytorch/ciforge#655 with a forum redirect, and
closed pytorch/ciforge#657 with the numerical-accuracy template. The
handoff on pytorch/ciforge#656 (#199239) reached distributed infra triage.

Fixed gap: on pytorch/ciforge#659 (#199028), pi applied the sub-queue label
`oncall: distributed checkpointing` instead of `oncall: distributed`. The
distributed sub-triage keeps an existing sub-queue and stops, so the parent
label, `triaged`, and `security` were never added. The apply step now maps
any `oncall: distributed <sub-queue>` to `oncall: distributed` (with a test),
and the skill says to apply only the parent.

- Issue transfers are not automated; they become triage review instead.
  Issue-body redaction is also not automated.
- S3 execution-log and usage-metric uploads are not ported; the inspector
  cannot show pi runs yet.

- python3 -m unittest discover -s scripts/issue_triage_pi
  (plan-to-effects rules, replay reconstruction, workflow lockdown contract;
  the workflow also runs these before starting the model).
- actionlint, GHA, PYFMT, ruff, and flake8 on changed files.
- Local action runs with a scripted model; replay #199454 to check
  creation-time labels and the already-routed path.
- Replay and live end-to-end evaluation above; add a regression test for
  pytorch/ciforge#659 when fixing the apply-step mapping.

ghstack-source-id: 261693d
Pull-Request: #199555
[ghstack-poisoned]
drisspg added a commit that referenced this pull request Oct 2, 2026
Move issue triage from Claude Code to pi, keeping the triaging-issues skill
and switching the model to global.openai.gpt-6.1-sol (medium thinking). The model now proposes a
read-only plan; a separate, model-free job validates and applies it. This
moves write enforcement out of model-process hooks. Replay routing matched
Claude on 20/20 issues, but live testing found a distributed-routing gap
that still needs an apply-step fix.

- Rename stage 1 to issue-triage.yml and replace claude-issue-triage-run.yml
  with issue-triage-pi.yml for stage 2.
- Plan job: Bedrock access, issues: read, read-only gh tools, no shell, and
  harden-runner with egress blocked except for allowed endpoints.
- Apply job: issues: write, no AWS access or model. apply_plan.py enforces
  the skill's label rules, only adds labels, posts only templates.json
  comments, and closes only usage questions or expected numerical behavior.
  It adds bot-triaged and hands off to distributed triage.
- Rewrite the skill for plan/apply; remove Claude hooks, the MCP tool table,
  and add_bot_triaged.py. Keep validate_labels.py and validate_issue_target.py
  because distributed-triage hooks still use them. Clarify two routing rules
  the replay exposed: CPU-only Inductor issues go to `oncall: cpu inductor`
  (as the PT2 rubric already said), and a dispatcher-layer label comes with the
  `module: pt2-dispatcher` umbrella.
- Run the model through .github/actions/pi-agent (added in the previous PR;
  the same action runs triage in pytorch/ciforge). Manual dispatch supports
  replay, dry-run, and apply.

| Boundary | Previous stage 2 | New stage 2 |
| --- | --- | --- |
| Model's GitHub access | issues: write through GitHub MCP | issues: read; read-only gh tools |
| Egress | Open | harden-runner blocked, explicit allowlist |
| Write enforcement | In-process hooks | Separate apply_plan.py job, no model or AWS |
| Allowed effects | Hook-filtered model writes | Add-only labels, template comments, restricted closes |

The model still makes triage judgments; this limits its effects rather than
making those judgments reliable by construction.

Replay: 20 recently Claude-triaged issues, each shown to pi as it was before
the bot's first label event; plans scored through `apply_plan.plan_effects`.
Distributed issues are scored on routing only (their sub-queue, status, and
module labels come from the separate distributed sub-triage), and
`release triage` is not scored. Labels are measured as agreement with what
Claude applied, since final labels are mostly Claude's own.
Run: https://github.com/pytorch/ciforge/actions/runs/37063139472

| 20-issue replay | GPT-6.1 Sol (shipped) | Sonnet 5 | GPT-5.6 Terra |
| --- | --- | --- | --- |
| Oncall routing | 18/20 | 20/20 | 19/20 |
| Status (triaged / triage review) | 15/20 | 17/20 | 15/20 |
| Close decision | 19/20 | 19/20 | 19/20 |
| Labels vs Claude (precision / recall) | 59% / 80% | 79% / 88% | 65% / 68% |
| Cost for 20 issues (Sol approximate) | ~$0.92 | $1.26 | $0.97 |

High thinking did not change either OpenAI model's results. Sol's lower
agreement is mostly extra labels; read against the skill and `labels.json`,
some are better than what Claude applied: it added the `module:
pt2-dispatcher` umbrella on #199258 and #199259 (humans added it on #199259).
Weaker calls: it routed the CPU-only Inductor issue #199058 to `oncall: pt2`
instead of `oncall: cpu inductor` (the PT2 rubric's rule; `SKILL.md` said the
opposite, now fixed), labelled an invalid ONNX export (#198691) silent
correctness, and added `module: autograd` to an MPS performance issue
(#199277).

Sonnet 5 was closer to Claude's existing labels and stays on the allowlist. On
the four issues humans later corrected it matched the final labels at 73%
precision / 85% recall (Claude: 90% / 69%). Terra routed an ONNX issue
(#198691) to `oncall: export`.

The live run below used Sonnet 5.

Live: 21 pytorch/pytorch issues were re-opened one at a time in the private
pytorch/ciforge test repo through the real issue-opened flow. Comparing the
recorded stage-2 labels and close decisions with Claude on the originals:

- Exact stage-2 label sets (excluding `release triage`) matched on 12/21.
- Oncall routing matched on 20/21; the miss is the #659 gap below.
- Status (triaged / triage review) matched on 16/18 non-distributed issues.
- Close decisions matched on 20/21. pi closed #199337 as expected numerical
  behavior (pytorch/ciforge#657); Claude left it open. In replay, Claude had
  closed its sibling #199338. This is disagreement, not proven correctness.

The live flow labeled the optimizer issue pytorch/ciforge#653 (#199516),
closed the usage question pytorch/ciforge#655 with a forum redirect, and
closed pytorch/ciforge#657 with the numerical-accuracy template. The
handoff on pytorch/ciforge#656 (#199239) reached distributed infra triage.

Fixed gap: on pytorch/ciforge#659 (#199028), pi applied the sub-queue label
`oncall: distributed checkpointing` instead of `oncall: distributed`. The
distributed sub-triage keeps an existing sub-queue and stops, so the parent
label, `triaged`, and `security` were never added. The apply step now maps
any `oncall: distributed <sub-queue>` to `oncall: distributed` (with a test),
and the skill says to apply only the parent.

- Issue transfers are not automated; they become triage review instead.
  Issue-body redaction is also not automated.
- S3 execution-log and usage-metric uploads are not ported; the inspector
  cannot show pi runs yet.

- python3 -m unittest discover -s scripts/issue_triage_pi
  (plan-to-effects rules, replay reconstruction, workflow lockdown contract;
  the workflow also runs these before starting the model).
- actionlint, GHA, PYFMT, ruff, and flake8 on changed files.
- Local action runs with a scripted model; replay #199454 to check
  creation-time labels and the already-routed path.
- Replay and live end-to-end evaluation above; add a regression test for
  pytorch/ciforge#659 when fixing the apply-step mapping.

ghstack-source-id: 29a16b9
Pull-Request: #199555
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@drisspg

drisspg commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

bbayeste added a commit that referenced this pull request Oct 29, 2026
…the goalposts

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Everytime the review agent is running, it introduces some new blockers regardless of what has been ficed and what has been asked by the author to ignore.

## Agent details (if applicable)

On a re-review, the pr-review skill re-reviews the whole PR from scratch, and "Everything is a must-fix" turns every new observation into a blocker, so a PR whose author fixes each round's findings can still collect new blockers every round (pytorch/test-infra#9243; on #199555 the production review raised 1, 2, 2, 5, 6, 5, 4, 7, 5, 6, 7, 7, 6, 6, 7, 5 blocking findings over 16 rounds).

This adds "Re-reviews converge" to "Earlier Automated Findings": settle the earlier blocking findings first (report one still present again as a continuing finding, drop one fixed or convincingly answered); review what changed since the last review in full; on code unchanged since then, raise a new blocking finding only for a defect with a concrete failure and say why it was not raised before; keep earlier non-blocking points non-blocking unless the code got worse. It reads `/tmp/pr-interdiff.txt` when present (changes since the commit the last review saw) and otherwise compares the earlier findings' code with HEAD.

Evaluation: local replays of #199555 rounds 9-11 with production's prompts and models, 3 runs each, every round given the previous round's findings from the same run, as production gives them. Blocking findings in rounds 10 and 11, compared with that run's previous review (matched by an LLM judge):

| | Round 10 (author added code) | Round 11 (10 changed lines) |
|---|---|---|
| Today's skill | 7: 2 new, 2 previously non-blocking | 7: 1 new, on unchanged code |
| This change, with an interdiff | 8: 4 new, all on the code added in that round | 8: 0 new, 0 previously non-blocking |

The hardened workflow does not provide `/tmp/pr-interdiff.txt` yet; without it the skill compares the earlier findings' code with HEAD. Providing it is a follow-up. One PR and three runs: a signal, not a measurement.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .agents/skills/pr-review/SKILL.md
```

This PR was authored with the help of an AI assistant (Claude).
ghstack-source-id: 47ebb0d
Pull-Request: #202634
bbayeste added a commit that referenced this pull request Oct 29, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one or when it is the head under review.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty.
- A new `review` step, after the size gate and before any credential, fetches that one commit (depth 1, as for the merge base) and writes `/tmp/pr-interdiff.txt`: the diff between it and HEAD, limited to the PR's files with literal pathspecs. When there is no earlier review, the commit is gone after a force-push, the PR changes no files, or the result is over `MAX_DIFF_BYTES`, the file holds a one-line note instead, so the model's read rule always resolves and the review never fails for it. A rebase in between also shows the new base's changes to those files; the header says so.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule and model `PREVIOUS_REVIEW_SHA` as a plain value, like `MERGE_BASE_SHA`.

Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given this file and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step's script was also run on that PR's real commits: for rounds 10 -> 11 it wrote the 5 files the author changed (9 KB), and it wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/fetch_pr_comments.py scripts/pr_review/test_fetch_pr_comments.py scripts/pr_review/test_workflow_contract.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Thu Oct 29 14:39:25 2026 -0700
#
# On branch pr-review-rereview-converge
# Your branch is ahead of 'origin/main' by 2 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   .github/workflows/hardened-pr-review-run.yml
#	modified:   scripts/pr_review/fetch_pr_comments.py
#	modified:   scripts/pr_review/test_fetch_pr_comments.py
#	modified:   scripts/pr_review/test_workflow_contract.py
#
ghstack-source-id: 60c464a
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Oct 29, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one or when it is the head under review.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, a git failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, the notes, the size cap and pathspec-like file names.

Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Thu Oct 29 14:39:25 2026 -0700
#
# On branch pr-review-rereview-converge
# Your branch is ahead of 'origin/main' by 2 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   .github/workflows/hardened-pr-review-run.yml
#	modified:   scripts/pr_review/fetch_pr_comments.py
#	modified:   scripts/pr_review/test_fetch_pr_comments.py
#	modified:   scripts/pr_review/test_workflow_contract.py
#
ghstack-source-id: de28ed4
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Oct 30, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Thu Oct 29 14:39:25 2026 -0700
#
# On branch pr-review-rereview-converge
# Your branch is ahead of 'origin/main' by 2 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   .github/workflows/hardened-pr-review-run.yml
#	modified:   scripts/pr_review/fetch_pr_comments.py
#	modified:   scripts/pr_review/test_fetch_pr_comments.py
#	modified:   scripts/pr_review/test_workflow_contract.py
#
ghstack-source-id: e758f74
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Oct 30, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Thu Oct 29 14:39:25 2026 -0700
#
# On branch pr-review-rereview-converge
# Your branch is ahead of 'origin/main' by 2 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   .github/workflows/hardened-pr-review-run.yml
#	modified:   scripts/pr_review/fetch_pr_comments.py
#	modified:   scripts/pr_review/test_fetch_pr_comments.py
#	modified:   scripts/pr_review/test_workflow_contract.py
#
ghstack-source-id: a0bde96
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Oct 30, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Thu Oct 29 14:39:25 2026 -0700
#
# On branch pr-review-rereview-converge
# Your branch is ahead of 'origin/main' by 2 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   .github/workflows/hardened-pr-review-run.yml
#	modified:   scripts/pr_review/fetch_pr_comments.py
#	modified:   scripts/pr_review/test_fetch_pr_comments.py
#	modified:   scripts/pr_review/test_workflow_contract.py
#
ghstack-source-id: 20d174d
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Nov 4, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. The files diffed are the PR's current files plus those the earlier version changed, so a file the author reverted shows up. Git reads no attributes from the PR (`--attr-source` is the empty tree), so its `.gitattributes` cannot pick merge or diff drivers. No earlier review, an unavailable commit, no changed files, a rebase with no author change, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it and says to treat the PR's files as changed unless the note says nothing changed. With fan-out the sub-agents get the Offline section, so they are told about the file too.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. Contract tests also run the new shell with stub `gh`, `git` and `python3`: a malformed previous SHA aborts the run, an unusable or failed compare call leaves the merge base empty without failing, no earlier review makes no compare call, a fetch that fails (the commit gone after a force-push) still builds the file, and the step's condition, its position between the size gate and the credentials, its outputs and arguments, and the three spellings of the path are pinned. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides (diffed against the earlier commit, not the replayed tree), the PR's own `.gitattributes` (ignored, so `merge=union` cannot hide a conflict), a file the author reverted (it shows up although the PR no longer changes it), a rebase with no author change, no rebase, a re-run on the same commit (also when the earlier merge base is unknown), `--repo` from another directory, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: the previous PR's numbers are with this interdiff. In that 15-PR replay, half of the re-reviewed rounds (42 of 84) were rebases with no change by the author, and the interdiff said so in one line; the other half got a median of 4.7 KB. The step was also run on #199555's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).
ghstack-source-id: 0b59367
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Nov 4, 2026
…view

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. The files diffed are the PR's current files plus those the earlier version changed, so a file the author reverted shows up. Git reads no attributes from the PR (`--attr-source` is the empty tree), so its `.gitattributes` cannot pick merge or diff drivers. No earlier review, an unavailable commit, no changed files, a rebase with no author change, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it and says to treat the PR's files as changed unless the note says nothing changed. With fan-out the sub-agents get the Offline section, so they are told about the file too.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. Contract tests also run the new shell with stub `gh`, `git` and `python3`: a malformed previous SHA aborts the run, an unusable or failed compare call leaves the merge base empty without failing, no earlier review makes no compare call, a fetch that fails (the commit gone after a force-push) still builds the file, and the step's condition, its position between the size gate and the credentials, its outputs and arguments, and the three spellings of the path are pinned. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides (diffed against the earlier commit, not the replayed tree), the PR's own `.gitattributes` (ignored, so `merge=union` cannot hide a conflict), a file the author reverted (it shows up although the PR no longer changes it), a rebase with no author change, no rebase, a re-run on the same commit (also when the earlier merge base is unknown), `--repo` from another directory, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: the previous PR's numbers are with this interdiff. In that 15-PR replay, half of the re-reviewed rounds (42 of 84) were rebases with no change by the author, and the interdiff said so in one line; the other half got a median of 4.7 KB. The step was also run on #199555's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).
ghstack-source-id: 7a4dd7e
Pull-Request: #202667
bbayeste added a commit that referenced this pull request Nov 4, 2026
…view

Part of pytorch/test-infra#9243

No.

Pass the differences between PR after addressing some previous review feedback

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. The files diffed are the PR's current files plus those the earlier version changed, so a file the author reverted shows up. Git reads no attributes from the PR (`--attr-source` is the empty tree), so its `.gitattributes` cannot pick merge or diff drivers. No earlier review, an unavailable commit, no changed files, a rebase with no author change, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it and says to treat the PR's files as changed unless the note says nothing changed. With fan-out the sub-agents get the Offline section, so they are told about the file too.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. Contract tests also run the new shell with stub `gh`, `git` and `python3`: a malformed previous SHA aborts the run, an unusable or failed compare call leaves the merge base empty without failing, no earlier review makes no compare call, a fetch that fails (the commit gone after a force-push) still builds the file, and the step's condition, its position between the size gate and the credentials, its outputs and arguments, and the three spellings of the path are pinned. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides (diffed against the earlier commit, not the replayed tree), the PR's own `.gitattributes` (ignored, so `merge=union` cannot hide a conflict), a file the author reverted (it shows up although the PR no longer changes it), a rebase with no author change, no rebase, a re-run on the same commit (also when the earlier merge base is unknown), `--repo` from another directory, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: the previous PR's numbers are with this interdiff. In that 15-PR replay, half of the re-reviewed rounds (42 of 84) were rebases with no change by the author, and the interdiff said so in one line; the other half got a median of 4.7 KB. The step was also run on #199555's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).
ghstack-source-id: 0c06940
Pull-Request: #202667
pytorchmergebot pushed a commit that referenced this pull request Nov 5, 2026
…the goalposts (#202634)

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Everytime the review agent is running, it introduces some new blockers regardless of what has been ficed and what has been asked by the author to ignore.

## Agent details (if applicable)

On a re-review, the pr-review skill re-reviews the whole PR from scratch, and "Everything is a must-fix" turns every new observation into a blocker, so a PR whose author fixes each round's findings can still collect new blockers every round (pytorch/test-infra#9243; on #199555 the production review raised 1, 2, 2, 5, 6, 5, 4, 7, 5, 6, 7, 7, 6, 6, 7, 5 blocking findings over 16 rounds).

This adds "Re-reviews converge" to "Earlier Automated Findings": settle the earlier blocking findings first (report one still present again as a continuing finding, drop one fixed or convincingly answered); review what changed since the last review in full; on code the last review covered and that has not changed since, raise a new blocking finding only for a defect with a concrete failure and say why it was not raised before; keep earlier non-blocking points non-blocking unless the code got worse or the concrete failure that rule requires can now be shown.

Supporting changes in the same file:
- The commit the last review saw comes from its body header ("Automated review of <sha>"), which every review has; `/tmp/pr-interdiff.txt` holds the changes since then when present, and modes with git can run `git diff <sha> HEAD`. Code whose change status the reviewer cannot tell is reviewed as changed, so a missing interdiff costs convergence, not recall.
- "Covered" excludes files an earlier review named as not reviewed (early posts under the Time Budget) and code whose earlier findings were left out (`truncated`, or a body that says some findings did not fit); those get a first review, and so does the whole PR when the reviewer cannot tell which code an omitted finding was about.
- An unaddressed maintainer comment still always blocks, whatever code it is on.
- "Everything is a must-fix" now says exceptions are marked where they apply (runner naming and workflow REVIEW.md advisories already are) and names re-reviews among them, and the skill says to write "non-blocking" in such points, keep them out of the Recommendation's justification, and not recommend Request Changes when only non-blocking points remain. Without that, stage B and post_review.py post every finding as blocking under a Request Changes verdict.
- With fan-out (#202952), the four reviewer sub-agents review the full diff and do not apply these rules, so the main agent does: on a re-review each reviewer marks its candidates as on changed or unchanged code, Step 4 applies "Re-reviews converge" to every merged finding before writing it up, and Step 5's fact-check requires rule 3's concrete failure for a new blocking finding on covered code.
- Stage B's prompt says a point the review labels non-blocking is minor, never major, and that a review whose points are all non-blocking gets ready_for_human_review even under Request Changes, so a non-blocking point is never posted as a blocker, whatever the Recommendation.

Evaluation: local replays of #199555 rounds 9-11 with production's prompts and models, 3 runs each, every round given the previous round's findings from the same run, as production gives them. Blocking findings in rounds 10 and 11, compared with that run's previous review (matched by an LLM judge):

| | Round 10 (author added code) | Round 11 (10 changed lines) |
|---|---|---|
| Today's skill | 7: 2 new, 2 previously non-blocking | 7: 1 new, on unchanged code |
| This change, with an interdiff | 8: 4 new, all on the code added in that round | 8: 0 new, 0 previously non-blocking |

The hardened workflow does not provide `/tmp/pr-interdiff.txt` yet; without it the skill compares the earlier findings' code with HEAD. Providing it is a follow-up. One PR and three runs: a signal, not a measurement.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .agents/skills/pr-review/SKILL.md
```

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: #202634
Approved by: https://github.com/izaitsevfb
pytorchmergebot pushed a commit that referenced this pull request Nov 5, 2026
…view (#202667)

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: #202667
Approved by: https://github.com/izaitsevfb
ghstack dependencies: #202634
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
## Human Note

## Agent Notes

Move issue triage from Claude Code to pi while keeping Sonnet 5 as the default, at medium
thinking. Sol remains a manual option. The main change is the trust boundary: the model reads
issues and submits a structured plan; a separate job with no model or AWS credentials applies it.
The model never holds the GitHub write token.

The apply step filters labels, supplies required comment templates, and adds completion labels
for complete classifications. Reproduction requests redact download links using a fixed policy
and the current issue body, not a model-written replacement. Transfers go to human review;
automatic closes are limited to usage questions and expected numerical behavior. Reports show
the comments that will actually be posted, including automatic templates and deduplication.

Manual replay and dry-run support batches; apply accepts exactly one issue. The reusable
read-only Bedrock workflow has blocked egress and short-lived credentials; pytorch#199588 reuses it for
distributed triage. Model execution artifacts and usage metrics retain their existing formats. Job summaries remain
readable Markdown; log copies are JSON-encoded to prevent workflow-command interpretation.

For review, start with `issue-triage-pi.yml` and `pi-triage-plan.yml`, then `apply_plan.py` and
its tests. `add_bot_triaged.py` is removed here. The two validation hooks remain for the old
distributed workflow until pytorch#199588 removes their last users. The model still makes triage
judgments; these controls limit its effects rather than making those judgments infallible.

## Validation

- [20-issue Sonnet replay](https://github.com/pytorch/ciforge/actions/runs/37063139472): oncall
  routing matched the historical Claude bot on 20/20 issues. This is agreement, not ground truth.
- Live ciforge testing exercised issue-opened triage, comments, restricted closing, and the
  distributed handoff. The handoff testing exposed a subqueue-routing gap, now covered by tests.
- Effective-template reporting was checked with deterministic tests for automatic, unknown,
  and already-posted templates; no new live model run was needed for that reporting-only change.

## Linked issue or supporting maintainer

<!-- Author has write access; fill in if an issue or maintainer applies. -->

## BC-breaking?

No.

## Summary (human written only)

## Agent details (if applicable)

Implementation and validation are described in Agent Notes above.

Pull Request resolved: pytorch#199555
Approved by: https://github.com/izaitsevfb
ghstack dependencies: pytorch#199566
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…the goalposts (pytorch#202634)

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Everytime the review agent is running, it introduces some new blockers regardless of what has been ficed and what has been asked by the author to ignore.

## Agent details (if applicable)

On a re-review, the pr-review skill re-reviews the whole PR from scratch, and "Everything is a must-fix" turns every new observation into a blocker, so a PR whose author fixes each round's findings can still collect new blockers every round (pytorch/test-infra#9243; on pytorch#199555 the production review raised 1, 2, 2, 5, 6, 5, 4, 7, 5, 6, 7, 7, 6, 6, 7, 5 blocking findings over 16 rounds).

This adds "Re-reviews converge" to "Earlier Automated Findings": settle the earlier blocking findings first (report one still present again as a continuing finding, drop one fixed or convincingly answered); review what changed since the last review in full; on code the last review covered and that has not changed since, raise a new blocking finding only for a defect with a concrete failure and say why it was not raised before; keep earlier non-blocking points non-blocking unless the code got worse or the concrete failure that rule requires can now be shown.

Supporting changes in the same file:
- The commit the last review saw comes from its body header ("Automated review of <sha>"), which every review has; `/tmp/pr-interdiff.txt` holds the changes since then when present, and modes with git can run `git diff <sha> HEAD`. Code whose change status the reviewer cannot tell is reviewed as changed, so a missing interdiff costs convergence, not recall.
- "Covered" excludes files an earlier review named as not reviewed (early posts under the Time Budget) and code whose earlier findings were left out (`truncated`, or a body that says some findings did not fit); those get a first review, and so does the whole PR when the reviewer cannot tell which code an omitted finding was about.
- An unaddressed maintainer comment still always blocks, whatever code it is on.
- "Everything is a must-fix" now says exceptions are marked where they apply (runner naming and workflow REVIEW.md advisories already are) and names re-reviews among them, and the skill says to write "non-blocking" in such points, keep them out of the Recommendation's justification, and not recommend Request Changes when only non-blocking points remain. Without that, stage B and post_review.py post every finding as blocking under a Request Changes verdict.
- With fan-out (pytorch#202952), the four reviewer sub-agents review the full diff and do not apply these rules, so the main agent does: on a re-review each reviewer marks its candidates as on changed or unchanged code, Step 4 applies "Re-reviews converge" to every merged finding before writing it up, and Step 5's fact-check requires rule 3's concrete failure for a new blocking finding on covered code.
- Stage B's prompt says a point the review labels non-blocking is minor, never major, and that a review whose points are all non-blocking gets ready_for_human_review even under Request Changes, so a non-blocking point is never posted as a blocker, whatever the Recommendation.

Evaluation: local replays of pytorch#199555 rounds 9-11 with production's prompts and models, 3 runs each, every round given the previous round's findings from the same run, as production gives them. Blocking findings in rounds 10 and 11, compared with that run's previous review (matched by an LLM judge):

| | Round 10 (author added code) | Round 11 (10 changed lines) |
|---|---|---|
| Today's skill | 7: 2 new, 2 previously non-blocking | 7: 1 new, on unchanged code |
| This change, with an interdiff | 8: 4 new, all on the code added in that round | 8: 0 new, 0 previously non-blocking |

The hardened workflow does not provide `/tmp/pr-interdiff.txt` yet; without it the skill compares the earlier findings' code with HEAD. Providing it is a follow-up. One PR and three runs: a signal, not a measurement.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .agents/skills/pr-review/SKILL.md
```

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: pytorch#202634
Approved by: https://github.com/izaitsevfb
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…view (pytorch#202667)

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: replaying pytorch#199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: pytorch#202667
Approved by: https://github.com/izaitsevfb
ghstack dependencies: pytorch#202634
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
## Human Note

## Agent Notes

Move issue triage from Claude Code to pi while keeping Sonnet 5 as the default, at medium
thinking. Sol remains a manual option. The main change is the trust boundary: the model reads
issues and submits a structured plan; a separate job with no model or AWS credentials applies it.
The model never holds the GitHub write token.

The apply step filters labels, supplies required comment templates, and adds completion labels
for complete classifications. Reproduction requests redact download links using a fixed policy
and the current issue body, not a model-written replacement. Transfers go to human review;
automatic closes are limited to usage questions and expected numerical behavior. Reports show
the comments that will actually be posted, including automatic templates and deduplication.

Manual replay and dry-run support batches; apply accepts exactly one issue. The reusable
read-only Bedrock workflow has blocked egress and short-lived credentials; pytorch#199588 reuses it for
distributed triage. Model execution artifacts and usage metrics retain their existing formats. Job summaries remain
readable Markdown; log copies are JSON-encoded to prevent workflow-command interpretation.

For review, start with `issue-triage-pi.yml` and `pi-triage-plan.yml`, then `apply_plan.py` and
its tests. `add_bot_triaged.py` is removed here. The two validation hooks remain for the old
distributed workflow until pytorch#199588 removes their last users. The model still makes triage
judgments; these controls limit its effects rather than making those judgments infallible.

## Validation

- [20-issue Sonnet replay](https://github.com/pytorch/ciforge/actions/runs/37063139472): oncall
  routing matched the historical Claude bot on 20/20 issues. This is agreement, not ground truth.
- Live ciforge testing exercised issue-opened triage, comments, restricted closing, and the
  distributed handoff. The handoff testing exposed a subqueue-routing gap, now covered by tests.
- Effective-template reporting was checked with deterministic tests for automatic, unknown,
  and already-posted templates; no new live model run was needed for that reporting-only change.

## Linked issue or supporting maintainer

<!-- Author has write access; fill in if an issue or maintainer applies. -->

## BC-breaking?

No.

## Summary (human written only)

## Agent details (if applicable)

Implementation and validation are described in Agent Notes above.

Pull Request resolved: pytorch#199555
Approved by: https://github.com/izaitsevfb
ghstack dependencies: pytorch#199566
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…the goalposts (pytorch#202634)

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Everytime the review agent is running, it introduces some new blockers regardless of what has been ficed and what has been asked by the author to ignore.

## Agent details (if applicable)

On a re-review, the pr-review skill re-reviews the whole PR from scratch, and "Everything is a must-fix" turns every new observation into a blocker, so a PR whose author fixes each round's findings can still collect new blockers every round (pytorch/test-infra#9243; on pytorch#199555 the production review raised 1, 2, 2, 5, 6, 5, 4, 7, 5, 6, 7, 7, 6, 6, 7, 5 blocking findings over 16 rounds).

This adds "Re-reviews converge" to "Earlier Automated Findings": settle the earlier blocking findings first (report one still present again as a continuing finding, drop one fixed or convincingly answered); review what changed since the last review in full; on code the last review covered and that has not changed since, raise a new blocking finding only for a defect with a concrete failure and say why it was not raised before; keep earlier non-blocking points non-blocking unless the code got worse or the concrete failure that rule requires can now be shown.

Supporting changes in the same file:
- The commit the last review saw comes from its body header ("Automated review of <sha>"), which every review has; `/tmp/pr-interdiff.txt` holds the changes since then when present, and modes with git can run `git diff <sha> HEAD`. Code whose change status the reviewer cannot tell is reviewed as changed, so a missing interdiff costs convergence, not recall.
- "Covered" excludes files an earlier review named as not reviewed (early posts under the Time Budget) and code whose earlier findings were left out (`truncated`, or a body that says some findings did not fit); those get a first review, and so does the whole PR when the reviewer cannot tell which code an omitted finding was about.
- An unaddressed maintainer comment still always blocks, whatever code it is on.
- "Everything is a must-fix" now says exceptions are marked where they apply (runner naming and workflow REVIEW.md advisories already are) and names re-reviews among them, and the skill says to write "non-blocking" in such points, keep them out of the Recommendation's justification, and not recommend Request Changes when only non-blocking points remain. Without that, stage B and post_review.py post every finding as blocking under a Request Changes verdict.
- With fan-out (pytorch#202952), the four reviewer sub-agents review the full diff and do not apply these rules, so the main agent does: on a re-review each reviewer marks its candidates as on changed or unchanged code, Step 4 applies "Re-reviews converge" to every merged finding before writing it up, and Step 5's fact-check requires rule 3's concrete failure for a new blocking finding on covered code.
- Stage B's prompt says a point the review labels non-blocking is minor, never major, and that a review whose points are all non-blocking gets ready_for_human_review even under Request Changes, so a non-blocking point is never posted as a blocker, whatever the Recommendation.

Evaluation: local replays of pytorch#199555 rounds 9-11 with production's prompts and models, 3 runs each, every round given the previous round's findings from the same run, as production gives them. Blocking findings in rounds 10 and 11, compared with that run's previous review (matched by an LLM judge):

| | Round 10 (author added code) | Round 11 (10 changed lines) |
|---|---|---|
| Today's skill | 7: 2 new, 2 previously non-blocking | 7: 1 new, on unchanged code |
| This change, with an interdiff | 8: 4 new, all on the code added in that round | 8: 0 new, 0 previously non-blocking |

The hardened workflow does not provide `/tmp/pr-interdiff.txt` yet; without it the skill compares the earlier findings' code with HEAD. Providing it is a follow-up. One PR and three runs: a signal, not a measurement.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .agents/skills/pr-review/SKILL.md
```

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: pytorch#202634
Approved by: https://github.com/izaitsevfb
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…view (pytorch#202667)

## Linked issue or supporting maintainer

Part of pytorch/test-infra#9243

## BC-breaking?

No.

## Summary (human written only)

Pass the differences between PR after addressing some previous review feedback

## Agent details (if applicable)

The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.

- `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.
- `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).
- A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`.
- Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it.

The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.

Evaluation: replaying pytorch#199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.

Test plan:

```
python3 -m unittest discover -s scripts/pr_review -t .
lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py
```

actionlint was not run locally (its binary could not be downloaded here); CI runs it.

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: pytorch#202667
Approved by: https://github.com/izaitsevfb
ghstack dependencies: pytorch#202634
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes Merged no automated review Request skipping the automated PR review process ready for review Automated review passed, ready for a final review by a maintainer. skip-pr-sanity-checks topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants