Skip to content

Make AI review and agent rules follow the maintainers' review values; route PRs to area experts - #5667

Merged
tianyu-l merged 5 commits into
mainfrom
ai-review-workflow
Oct 29, 2026
Merged

tianyu-l merged 5 commits into
mainfrom
ai-review-workflow

Conversation

@tianyu-l

@tianyu-l tianyu-l commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

PR volume has outgrown review capacity. Of the 1,429 PRs merged since April, one maintainer approved 1,066 (75%), and October alone had 351 merged PRs. Many PRs are agent-generated, and the agents (and @claude) follow .claude/CLAUDE.md, which in several places contradicts how PRs are actually reviewed:

  • Principle 5 says to flag BC breakage. The maintainers deliberately don't promise BC.
  • config.md says "emit a warning" when config is silently skipped. Review comments almost always say "just error out".
  • PR expectations say "new features need CPU unit tests at minimum". In ~1,000 reviews the maintainer almost never asked for a new unit test, and often asked for tests to be removed or folded into existing ones.

The result: across 130 PRs, the current @claude cited CLAUDE.md at least 38 times, mostly to escalate. That produced 16+ BC concerns, 9+ "add a warning" suggestions and 23+ test requests. It also missed the most common real review question: should this change exist in this form at all?

This PR rewrites the rules from what reviewers actually say. The source data:

  • 3,391 inline comments, 289 review bodies and 383 PR comments from Jul-Oct 2026.
  • 48 refactor PRs, used to extract structural preferences.
  • A comparison of 196 @claude runs against the human review on the same PRs.

It then adds a torchtitan review skill, builds on PyTorch's pr-review skill, and routes PRs to area experts without making them blocking owners.

Example: one past PR, as reviewed by the new skill (#5546, at the commit that was originally reviewed; blind, with no access to the real comments):

Verdict: Request changes -- The problem is real, but the fix swaps a hard error for a
warn-and-continue fallback to FA2 ... It also adds a head-dim hook to 9 call sites,
7 of which can never fire.
Must fix
1. torchtitan/tools/utils.py:95-104 -- a missing wheel on Hopper/Blackwell now means a
   warning plus a silent switch to a slower kernel with different numerics ...
   Smallest fix (~15 lines): ... raise a clear error that names the module to install.

The human review of that PR: "450 LoC PR for a safety check sounds insane" and "can we error out -- we don't want people to implicitly get bad perf".

What changed

1. Rules (.claude/CLAUDE.md, .claude/rules/):

  • Core principles rewritten:
    • start from the problem, not the patch;
    • minimal by default;
    • PyTorch-native and upstream first;
    • reuse, but don't bend shared code for one consumer;
    • keep core oblivious to features;
    • no BC promises, but protect numerics, HF loading, metric keys and main-path perf;
    • raise instead of warn;
    • hardware-agnostic.
  • Naming additions: overloaded terms, one name per concept, _private.
  • PR expectations: descriptions must convince a human; tests must earn their cost; one concern per PR.
  • config.md rewritten:
    • each component owns its X.Config;
    • select implementations by config type;
    • X.Config | None instead of enable_*;
    • no post-hoc config mutation;
    • few knobs;
    • validate in __post_init__.
  • distributed.md: spmd_types first, parallelism combinations, hidden D2H syncs, hardware.
  • New rules files:
    • design.md: structural rules distilled from past refactors.
    • tests.md: when to add tests, preferring extensions of existing coverage, placement, golden files.
    • direction.md: current migrations. This needs maintainers to keep it current.

2. pr-review skill (.claude/skills/pr-review/):

Step What it does
Context Applicable rules, maintainer comments addressed or not, earlier bot findings, overlapping open PRs.
Necessity/design gate Is the problem real on main? Root cause vs symptom? Right layer, or upstream? Should torchtitan own this? Superseded? Smallest alternative? Value evidence?
Deep review A quick sweep of every hunk (scope, placement, new knobs and tests), then the checklist, split by lens for large PRs.
Consolidate and fact-check Dedupe by root cause and fix; drop BC, "add a warning", generic "add tests", lint and praise; verify must-fix items.
Output Verdict first, plain-words summary, a concrete before/after example, at most a few must-fix items, details collapsed, unverified claims labeled.
Modes Full review, "review again" (only the delta), "review my review", or answer a specific question first.
Posting Line-anchored findings as inline comments (with suggestion blocks for small fixes, at most ~10, posted only by the main agent after fact-check), then one formal review via gh pr review (--approve / --request-changes / --comment) with the verdict and one-line pointers.

3. PR descriptions:

  • pr-description skill and .github/pull_request_template.md: Why (with a simple example) -> What changed -> user-facing before/after -> numerics -> testing.
  • CONTRIBUTING.md updated to match.

4. @claude workflow (claude-code.yml):

  • Always uses the skill.
  • Allows read-only gh issue view / gh pr view / gh pr diff / gh pr list, plus gh pr review and the action's inline-comment tool (it cannot approve). gh api stays blocked.
  • effort=low|max and fable comment keywords; default effort high.
  • 55-minute timeout.

5. Review routing:

  • CODEOWNERS:
    • *: tianyu-l fegin wwwjn shuhuayu acisseJZhong felipemello1.
    • graph_trainer paths: core plus SherlockNoMad aditvenk sanketpurandare.
    • torchft paths: core plus d4l3k.
    • Every path has an owner, so a bot approval can never satisfy branch protection on its own.
  • .github/area_reviewers.yml and workflows/area_reviewers.yml request at most 3 area experts as non-blocking reviewers, based on which areas the changed files touch. The workflow runs on pull_request_target, reads only the file list through the API, and never checks out PR code.

Alternatives considered

  • Copy PyTorch's skill as-is. Its "missing tests -> Request Changes" and BC section are exactly what produced noise here.
  • PyTorch-style per-directory REVIEW.md files. The existing glob-scoped .claude/rules/ already do this, without more .md sprawl.
  • Deterministic lint hooks for torch.cuda.*, isinstance(.., DTensor) and enable_* fields. Every pattern already has hits on main (12, 15 and 7 files), so they would need allowlists. The skill checks them on the diff instead.
  • Making area experts code owners. That makes them blocking; auto-requesting reviews routes PRs without adding gates.

Testing

Backtest. The new skill reviewed 7 past PRs blind, each at the commit that was originally reviewed, and the output was compared with the real human review. The skill was then fixed for the misses, and the affected cases were re-run.

PR Human review's main point New skill
#5546 too big for a safety check; error out Hit both
#5153 does this happen on main? don't violate the nn.Module contract Hit; proposed the fix that eventually landed
#4754 workaround, not a fix; move the test Hit the root cause (the same fix the author later proposed); missed the test move, now covered by the sweep
#5463 motivation first; LocalCompileConfig design Hit the design and unused kwargs; motivation is a must-fix after the re-run
#5183 NCCL-specific knob in core; TODO; <0 semantics Hit
#4474 approve; DSv4 should fix the model/loss Approve; partly raised the model point
#4421 approve; "how much e2e?" Originally requested changes; approves with items after the re-run

None of the 10 reviews raised BC or asked for a warning.

Other checks:

  • Reviewer routing: the area-reviewer logic was replayed on 1,429 merged PRs. Peak load is about 50 requests/month per person (graph trainer, PP, MoE).
  • Workflow script: dry-run with mocked GitHub objects on a real PR's file list. The author is excluded, existing reviewers are skipped, and a non-collaborator failure doesn't fail the run.
  • YAML and lint: all YAML parses, the inline JS passes node --check, and pre-commit passes.

Known issues / follow-ups

  • Comment-triggered workflows run from main, so claude-code.yml and the skill only take effect after merge. Try @claude review on a real PR right after.
  • Not verified: whether the Claude GitHub App has write access. If it does, its approvals count toward the 1 required approval (but never as a code-owner approval), and its REQUEST_CHANGES blocks merging until it re-approves or someone dismisses it. If it doesn't, its reviews are advisory. The first real review will show which.
  • direction.md and area_reviewers.yml are only useful if they are kept current.
  • Not included:
    • PyTorch's time-budget hook (reviews that hit the 55-minute limit are lost);
    • auto-review on every push, which needs the PyTorch CI owners' hardened setup.

Rewrite CLAUDE.md core principles and the config/distributed rules to match how
PRs are actually reviewed: start from the problem, minimal by default, upstream
first, no BC promises but protect numerics, raise instead of warn, tests must
earn their CI cost, hardware-agnostic. Add design.md (structural rules),
tests.md, and direction.md (current migrations).
pr-review adapts PyTorch's review skill to torchtitan: a necessity/design gate
before line review, a quick sweep of every hunk, consolidation and fact-check,
verdict-first output with a concrete example, re-review and review-my-review
modes, and formal posting via gh pr review.
Allow read-only gh commands plus gh pr review, add effort= and fable keywords,
and set a 55 minute timeout.
Core owners own every path; graph_trainer and torchft add their own owners.
Other area experts are requested as non-blocking reviewers from
.github/area_reviewers.yml by a pull_request_target workflow that never checks
out PR code.
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 29, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 29, 2026
@tianyu-l
tianyu-l requested a review from drisspg October 29, 2026 04:11
@acisseJZhong

Copy link
Copy Markdown
Contributor

I wonder what's our guideline for adding tests? a lot of times I noticed when people fix sth trivial, agent would just add test for that particular path. I feel this is too much and we should probably cleanup our tests?

Allow claude-code-action's inline-comment tool (it cannot approve). The skill
posts fact-checked, line-anchored findings inline with confirmed=true, keeps
one-line pointers in the formal review body, caps them at ~10, and forbids
sub-agents from posting.

@felipemello1 felipemello1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't review it in detail, but i like the checklist. I am ok with approving it since you did the testing and had a good hit rate! As we use it, we can find bad patterns and update the skill.

In torch, its pretty nice that, once you use claude, it will keep replying to new pushes until it marks it as ready for the code owner. It seems that for now we will have to manually trigger claude, but that should be fine.

thanks for working on it!

@tianyu-l

Copy link
Copy Markdown
Contributor Author

I wonder what's our guideline for adding tests? a lot of times I noticed when people fix sth trivial, agent would just add test for that particular path. I feel this is too much and we should probably cleanup our tests?

I agree. In this PR I have a test.md under claude folder, but it can be improved. Could you help improve it later, and clean existing tests in another PR?

@acisseJZhong

Copy link
Copy Markdown
Contributor

sounds like a perfect item for the pytorch BE week!

@tianyu-l
tianyu-l merged commit f00a4ee into main Oct 29, 2026
18 checks passed
@tianyu-l
tianyu-l deleted the ai-review-workflow branch October 29, 2026 05:30
tianyu-l added a commit that referenced this pull request Nov 26, 2026
…er override; agent self-review; rl/transport (#6407)

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->

## Why

Since #5667, `@claude review` has reviewed 459 PRs. Of the 380 PRs it
approved,
30 then got a formal "request changes" from a maintainer, and about 20
more got
substantive inline asks. In nearly all of them the bot either saw the
problem
and approved anyway, or never asked the questions maintainers ask most
("does
the repo already do this?", "who should own this?"). The opposite
failure, the
bot blocking something a maintainer was fine with, is rare: in the PRs
we
sampled, 2 of its 81 must-fix items were wrong and about a third were
minor
(the empty human-written summary was the biggest source).

**Example** (#6112, controller sizes the rollout worker pool):

```
before: bot approved 10 times; tianyu-l then blocked: "the controller reads
        rollouter.rollouts_per_worker to compute a count it hands back to the
        Rollouter -- violates encapsulation"
after:  same commit, new skill -> Request changes, must-fix #1:
        "controller.py:589 -- wrong owner for the worker count ..."
```

There was also no way for a code owner to overrule the bot except
dismissing
its review in the GitHub UI, and a later `@claude review again` would
block
again.

## What changed

**Review skill** (`.claude/skills/pr-review/`, `review-checklist.md`):
- Verdict rules: Approve only when every remaining item is an edit the
bot
could write itself. Anything the author still owes (a design change, an
unexplained golden change, evidence the PR rests on) is Request changes;
anything only a maintainer can decide is Needs discussion. A hedge like
"a
  maintainer should decide" can't come with Approve.
- Always must-fix: a violated written rule, a silent wrong result, a
second
  definition of an existing concept, a gate finding.
- Design gate: new questions for the existing counterpart, in-repo
ownership,
and the design behind a bug; "ban only what doesn't work on main"; read
the
numbers behind a claim. The overlapping-PR search is mandatory and
reported.
- Re-review covers every commit since the last full review, including
code
taken from the bot's own suggestions. A scoped question gets a
`COMMENT`, not
  a whole-PR verdict.
- The bot fact-checks its own proposed fixes, and cites a source for
claims
  about external tools or marks them unverified (never must-fix).
- An empty "Summary (human-written)" is a one-line "Before merge" note
that
  never affects the verdict.
- Checklist: config ownership direction, general shared wrappers, dead
code the
PR creates, model variants as flavors, a mechanical pass over every new
or
  changed function.

**Code owner override** (`SKILL.md`, `claude-code.yml`,
`CONTRIBUTING.md`): a
code owner comments `@claude override` (optionally `@claude override
2,3:
<reason>`); the bot approves if nothing else is open and doesn't
re-raise the
overridden items. A code owner's GitHub approval or "LGTM" is not an
override,
so a teammate can approve without the bot dropping its findings.
Dismissing the
bot's review still unblocks the PR, but isn't an override: the bot can't
tell
who dismissed it.

**Agent self-review** (`CLAUDE.md`, `pr-description`): an agent
preparing a PR
runs `pr-review` in branch mode first and records unaddressed items in
an
optional "Self-review" section. PRs written without an agent are
unaffected; a
missing section is never a finding.

Where each new rule comes from (maintainer asks the bot missed):

| Change | PRs |
| --- | --- |
| No Approve with open design/evidence items or a "maintainer should
decide" hedge | #6007, #5837, #5997, #5712, #5511, #5996 |
| Author waiver can't clear a must-fix | #6201, #6202, #6203 |
| Existing counterpart; one source of truth | #5228, #6169, #5881,
#5823, #5824, #6059, #5812 |
| Responsibility owner; config ownership direction | #6112, #6332,
#5802, #5803, #6325 |
| Fix the design behind the bug; a TODO doesn't justify a workaround |
#5572, #5689, #5657 |
| Fact-check the bot's own suggested fixes | #5740, #5802, #5511, #4819,
#5543 |
| Re-review covers all new commits; scoped asks don't approve | #5824,
#5842 |
| Mandatory overlap search | #5885, #6248 |
| Ban only what doesn't work on main | #5543 |
| Summary placeholder no longer a must-fix | #6119, #6174, #6112, #5868
|

**Rules**: `design.md` gets the one-general-wrapper rule (moved from
`models.md`, whose glob skipped `torchtitan/rl`), thin adapters, and the
consumer owning its values; `config.md` gets ownership direction and "a
Config
doesn't read runtime state"; `direction.md` calls all-to-all the MoE
reference
implementation, so a new vendor-specific dispatch path (e.g. #6242)
needs a
reason the existing backends can't serve.

**Area reviewers**: `.ci/` -> huydhn, wwwjn; `torchtitan/rl/transport/`
-> d4l3k.

**Mechanical, skim**: `torchtitan/rl/transport/` holds data movement
between RL
actors.
- `rl/model_state_dict_transport.py` ->
`rl/transport/model_state_dict.py`
- `rl/MODEL_STATE_DICT_TRANSPORT.md` ->
`rl/transport/MODEL_STATE_DICT_TRANSPORT.md`
- `rl/trainer/rdma_microbatch.py` -> `rl/transport/rdma_microbatch.py`
- tests:
`tests/rl/unit_tests/cpu/test_{model_state_dict_transport,rdma_microbatch}.py`
->
`tests/rl/unit_tests/cpu/transport/test_{model_state_dict,rdma_microbatch}.py`
- imports, READMEs and `scripts/install_rl_env.sh` updated; no code
changes.

## User-facing changes

| Before | After |
| --- | --- |
| Overrule the bot: dismiss its review in the UI, and it blocks again on
the next run | `@claude override [items]: <reason>`; the bot approves
and doesn't re-raise them |
| Empty human-written summary: bot must-fix | One "Before merge" line,
no effect on the verdict |
| `from torchtitan.rl.model_state_dict_transport import ...` | `from
torchtitan.rl.transport.model_state_dict import ...` |
| `from torchtitan.rl.trainer.rdma_microbatch import ...` | `from
torchtitan.rl.transport.rdma_microbatch import ...` |

## Testing

Backtest: the new skill run locally (nothing posted) on each PR at the
commit
and thread state the bot originally saw.

| PR | Bot then | New skill | What the maintainer asked |
| --- | --- | --- | --- |
| #6112 | Approve | Request changes | worker-count ownership (caught) |
| #5837 | Approve | Request changes | apply to `dp_shard` too (caught) |
| #5572 | Approve | Request changes | delete the injection design
(caught) |
| #6201 | Approve after author waived pins | Request changes, waiver
ignored | pins broke GPU tests after merge (caught) |
| #6007 | Approve | Request changes | fold K3.1 into K3 (caught) |
| #5543 | Request changes: "ban it" | Request changes: keep main's path
| don't break gpt-oss + DeepEP (fixed) |
| #6144, #5905 (controls) | Approve | Approve | -- |
| #6137 (control) | Approve | Needs discussion | -- (merge gate on an
upstream API) |

Code owner override, simulated on #6201: override by a code owner lifts
the
named item; `@claude override` from the author changes nothing; a code
owner's
"LGTM" approval followed by "review again" keeps Request changes.

Transport move: 83 RL CPU unit tests pass locally
(`transport/test_model_state_dict.py`, `test_trainer.py`,
`test_engine_loop.py`). `transport/test_rdma_microbatch.py`,
`test_generator.py` and
`test_batcher_actor.py` fail to collect in my env on `origin/main` too
(stale
attention-gym / Monarch), so CI is the check for those.

## Known issues / follow-ups
- Open PRs that edit the moved files rebase cleanly (git follows the
renames),
but new imports of the old module paths will break: #6309 (adds a delta
transport that should live in `rl/transport/`), #6237, #6176, #6177,
#5862,
  and drafts #6127, #6393, #6163, #5764.
- The Actions bot can't read dependency source (e.g. SGLang); follow-up
for the
  workflow.

## Self-review
pr-review (branch mode) at ad905a5: Needs discussion. Fixed: branch
mode diffs
against `origin/main` and skips description findings before a
description
exists; the "Config doesn't read runtime state" rule no longer
contradicts
hardware validation; dismissal dropped as an override form (the bot
can't tell
who dismissed); `test_rdma_microbatch.py` added to the transport area.
Not
addressed:
- One concern per PR -- the five changes ship together at the
maintainer's
  request.
- Open PRs touching the moved files -- listed above; the maintainer will
  coordinate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants