Skip to content

review-pr: publish the card as a PR review with findings anchored inline - #7303

Merged
zufayu merged 17 commits into
mainfrom
feat/review-bot-inline-anchors
Nov 4, 2026
Merged

zufayu merged 17 commits into
mainfrom
feat/review-bot-inline-anchors

Conversation

@zufayu

@zufayu zufayu commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Today _publish.py posts card.md as one top-level issue comment. This changes it to post a PR review — POST /repos/{owner}/{repo}/pulls/{pr}/reviews with event: "COMMENT", never APPROVE or REQUEST_CHANGES — with the findings that can be anchored attached to the lines they are about, and everything else left in the review body.

The mechanism is ported from ROCm/ATOM's feat/atom-review-bot. ATOM's bot has never posted successfully (its machine account is flagged), so this code has never run against live GitHub. aiter's bot is live, which is why this is a draft — see "What is not verified" below.

Why

Across the 61 real cards this bot has already published on this repo, there are 229 findings. 120 (52%) cite a file:line, and 65 of those lines are inside the PR's own diff. Those are findings a reader would rather meet next to the code than half-way down a wall of prose.

Measured on ten of those real cards, replayed against the diffs they were written for:

PR findings anchored left in summary card chars (today) summary chars (after) change
#5742 2 1 1 1878 1340 −538
#5767 3 0 3 2701 2341 −360
#5776 3 0 3 3249 2866 −383
#6184 5 3 2 4928 2908 −2020
#6188 5 0 5 4108 3752 −356
#6343 3 0 3 3094 2804 −290
#6364 1 1 0 1382 535 −847
#6442 5 2 3 3909 2632 −1277
#6756 4 3 1 3110 1635 −1475
#6815 5 1 4 4666 3360 −1306
total 36 11 25 33025 24173 −8852 (27%)

Every card gets shorter. But read the rows honestly: where nothing anchors (#5767, #6188, #6343, #5776) the card only loses ~300–400 characters, and that is the bold one-sentence PR summary the review body omits — not the mechanism working. The real win is the four rows with ≥2 anchors. On aiter, only 28% of findings anchor (65/229), against the ~50% ATOM measured, because aiter findings more often cite a line of context code the PR did not touch, or carry no file:line at all. 35 of 61 cards would get at least one inline comment; 26 would be unchanged in substance.

The index is not decoration

The review body ends with a one-line index of every finding that went inline:

**3 finding(s) posted inline, on the lines they are about:**
- `aiter/ops/shuffle.py:23` — imports `_FLYDSL_USE_HERD` without pinning it

Without it, a reader of the summary alone cannot tell whether three findings exist elsewhere or none do — and an invisible finding reads exactly like a finding that was never made.

Anchoring is a privilege a finding earns

check_citations.py comes across from ATOM and is wired in as run_one.sh step 3c. It writes citations.txt, _lib.py collects it into the report dir, and _publish.py refuses to anchor any finding carrying a citation the checker flagged — even if another citation in the same sentence would resolve. A top-level card that cites a wrong line is a flaw the reader works around; an inline comment on a wrong line lands in the author's working view and is visibly wrong, and a reviewer who gets burned once stops reading the rest.

With no citations.txt at all, nothing anchors and the whole card stays in the summary — i.e. exactly what this bot posts today. That is the intended degradation.

The checker never gates the run (|| true, not in _gates.py). It ran 1-for-2 on real cards; a 50%-precision heuristic that withholds correct reviews costs more than the defect it catches. It did earn its keep here: on #5776 it flagged aiter/mla.py:2693, and that finding correctly lost its inline slot.

Degrade-to-summary

A review is all-or-nothing: one comments[] entry naming a line GitHub will not accept fails the whole call, summary included — strictly worse than the issue comment this replaces. So a refusal retries the same endpoint with the anchors folded back into the body and says [ANCHORS REFUSED -- folded into summary]. A review that silently sheds half its findings reads exactly like a review that only had the other half. Two tests pin this.

Adapted, not transcribed

Where aiter differs from ATOM and what changed as a result:

  • Card shape. aiter's SKILL.md writes Review (advisory):, not ATOM's Review:, and adds a Perf (advisory|deterministic): line ATOM has no counterpart for. ATOM's literal "Review:" / "Validation" prefixes would have dropped all three status lines, leaving a summary with no verdict in it. The summary now matches on the bare word and keeps every one, in card order. Pinned by a test.
  • Dedup. aiter's BOT is overridable via AITER_BOT_NAME; the dedup marker is deliberately not derived from it, or a box with that var set would repost over every review the real bot already published. And already_posted() now searches both the issues-comments and the reviews endpoints — aiter's markers are sitting in live issue comments right now, and a check that only read reviews would repost on top of all of them. Both pinned by tests.
  • Env names. AITER_BOT_TOKEN(_FILE), AITER_BOT_REPO, repo default ROCm/aiter, status file .aiter-review-status, annotation title aiter-bot — all kept as aiter had them. _api_raw() (the .diff media type) is new; aiter had no caller for it.
  • check_citations.py provenance. Its measurements are ATOM's and have not been rerun on aiter's cards; the docstring now says so instead of presenting them as local facts. Its "ambiguous bare basename" comment was recounted against this tree (aiter has 8 utils.py, 7 quant.py).
  • _lib.py. citations.txt joins OPTIONAL, not REQUIRED: a run whose worker died before writing a card has no citations to check, and absence is not a defect.
  • No divergence was flattened. aiter's _publish.py was ATOM's minus the anchoring work, plus the env-overridable REPO/BOT; both overrides are kept.
  • Untouched: .github/scripts/pr_self_review.py is a separate system that PATCHes its own comment in place. It is not this skill and nothing here goes near it. The workflow YAML is also untouched.

Guards

check_prompts.py gains three checks:

  • check_publish_review_is_advisory — the event stays COMMENT, APPROVE/REQUEST_CHANGES appear nowhere in the file, and there is exactly one POST call site, pulls/{pr}/reviews.
  • check_publish_needs_post_flag — _publish.py falls back to ~/.git-credentials on the self-hosted box, a human PAT with write access, so GITHUB_TOKEN scoping does not stop it posting at all; the missing --post flag is the only closure. If the workflow ever grants issues: write or pull-requests: write, the invocation must pass --post explicitly.
  • check_anchoring_has_a_citation_check — run_one.sh → citations.txt → _lib.py → _publish.py cannot be half-removed in silence, because that degradation looks identical to a card whose findings simply cite nothing.

selftest.sh now runs _publish_test.py (37 cases: the --post closure, the anchoring rule, dedup, the degrade-to-summary fallback), and says out loud when pytest is absent rather than passing over it — a check that did not run is not a check that passed.

Verification, verbatim, on a clean tree built with git archive HEAD

$ bash .claude/skills/review-pr/selftest.sh | tail -1
=== 98 green / 0 red ===

$ python3 .claude/skills/review-pr/check_prompts.py | tail -1
OK: 0 drift(s)

$ python3 -m pytest .claude/skills/review-pr/_publish_test.py -q
.................                                                        [100%]
37 passed in 0.19s

(Baseline on origin/main was 93 green / 0 red and OK: 0 drift(s); the extra green is the new pytest block.)

preflight.sh on the same tree: 20 green / 1 red. The red is pre-existing and environmental — the self-hosted runner is not installed as a systemd service — and is untouched by this change.

What is verified live, and what still is not

A real review was posted by this code on 2026-11-03 —
pullrequestreview-5749640123,
this PR reviewing itself at 72d8c7c3baa9. What GitHub actually stored, read back
through the API:

state=COMMENTED  user=zufayu  commit=72d8c7c3baa9
.claude/skills/review-pr/_publish.py
  start_line=211  line=248  side=RIGHT  start_side=RIGHT  position=191   (not outdated)

That settles the three things the anchor rules were only reasoned about: the API
accepts the payload as built, a range anchor resolves to the span rather than its
first line, and event: "COMMENT" lands as COMMENTED — the bot cannot approve or
request changes. citations.txt was produced by a real run_one.sh in the same run
(CITATIONS: every cited file:line resolves (1 proximity note(s))), and the run
closed 7 gates green with 3 findings, all 3 surviving independent refutation.

Still not verified:

  • The degrade-to-summary fallback has never fired against the real API. The anchors
    were accepted, so the refusal path stayed on the stub that rejects any payload
    carrying comments[]. It is untested where it matters most, and a review is
    all-or-nothing, so this is the residual risk this PR carries.

  • AITER_BOT_TOKEN's scope is unconfirmed by use. The live post was made with a
    classic PAT carrying repo (zufayu), not with the bot's token. The token holder
    says the scope is sufficient; what is on record is that aiter-bot has read on this
    repo and has created zero reviews across the PRs checked, while posting an issue
    comment on each — equally consistent with "the scope is fine and it has never tried"
    and with "the scope is missing". Creating a review needs Pull requests: write where
    an issue comment needs only Issues: write, and the anchor fallback cannot cover this
    case: it handles a bad anchor, not a token that cannot create reviews at all.

    Rather than argue the point, being wrong about it is now cheap: a refused post exits
    non-zero, so the first run under the bot's own token either works or turns one step
    red with the API's own words. Previously it would have printed a failure line and
    exited 0, losing a card per run under a green step.

  • The ten-card replay used each PR's head as it stands now, and only PRs whose head
    still matches the SHA in the card's marker, so those diffs are the ones the findings
    were written against. The 61-card population figures used current diffs, so for PRs
    that have moved since review they are an approximation.

  • A review is attached to the commit it read. Pushing between the review and the publish
    leaves the comment on the older commit — observed here, where the finding posted was
    already fixed at head. In production the window is one job; by hand it is as long as
    you take.

Landed checks

Done, in this order: _publish.py <pr> --payload on this PR and read the JSON, then
--post for real. Both outputs are quoted above. The remaining step for whoever merges
this is the first run under AITER_BOT_TOKEN rather than a personal PAT.

🤖 Generated with Claude Code


PR Self-Review

Reviewed revision

1d33254bb341

Behavior and intent

_publish.py posted the review card as one top-level issue comment. On ten real
aiter-bot cards that comment averages 3300 characters of dense prose, and a single
finding averages ~900 — a paragraph each, in a wall nobody reads to the end. Half the
findings cite a file:line, so some of them can be attached to the code they are about
instead.

It now posts POST /pulls/{n}/reviews with event: "COMMENT" — never APPROVE or
REQUEST_CHANGES; this bot does not gate merges — anchoring the findings whose cited
line is inside the diff, and keeping the rest, plus a one-line index of the anchored
ones, in the review body. The index matters: without it a reader of the summary cannot
tell whether findings exist elsewhere or none do, and an invisible finding reads exactly
like one that was never made.

Anchoring is gated on check_citations.py, ported here from ATOM along with the
run_one.sh step and _lib.OPTIONAL entry that produce and collect citations.txt.
A finding whose citation the checker could not resolve is not anchored: an inline
comment on the wrong line lands in the author's working view and is visibly wrong, and
a reviewer burned once stops reading the rest.

Three further changes landed here because this PR's own review found them, and each is
the same defect wearing a different hat — a check that does not run looks exactly like
a check that passes
:

  • Rejected validation evidence used to abort the run under errexit, producing no card
    at all. One missing optional import took the whole review down, which reads to the
    person waiting on it like the bot being offline. The integrity checks stay fail-closed
    — evidence that does not match this PR's head, base or patch is still never used — but
    rejecting it now degrades the review and records why, instead of deleting it.
  • A dead fetch said nothing. errexit killed run_one.sh inside the fetch pipeline
    before the classification could run, and the exit trap wrote a status file while
    printing nothing, so the log ended mid-sentence. The traps now speak, and a spent
    GitHub quota is told apart from a token fault and from an account GitHub has
    restricted (60 core calls with GraphQL at 0), because only one of those is fixed by
    waiting.
  • flagged_citations() read a crashed checker as a clean verdict. check_citations.py
    raised NameError on every call, run_one.sh's || true swallowed it, and the
    traceback in citations.txt returned an empty flagged-set — "every citation checks
    out" — so findings anchored with no checking at all, which is precisely what the
    checker exists to prevent. Absence of a CITATIONS verdict line now means the checker
    did not run, matching the contract this module's own docstring already stated.

Validation and unverified scope

Validated from inside a clean tree built with git archive HEAD — not merely exported and then run from the working copy. Running it the second way is what found check_prompts.py resolving SKILL.md through git rev-parse --show-toplevel, which returns an empty string outside a checkout and silently makes the path relative to the caller's cwd:

bash .claude/skills/review-pr/selftest.sh | tail -1   → === 98 green / 0 red ===
python3 .claude/skills/review-pr/check_prompts.py     → OK: 0 drift(s)
python3 -m pytest .claude/skills/review-pr/_publish_test.py -q → 37 passed
ruff check . (skills tree)                            → 0 findings

Baseline on origin/main before the change: 93 green / 0 red, 0 drift;
_publish_test.py does not exist there, so all 37 cases are new. Measured on ten real
published cards replayed against the diffs they were written for: 36 findings, 11
anchored, summary 33025 → 24173 characters (−27%). The win is concentrated in the four
cards with ≥2 anchors; cards where nothing anchors barely shrink.

Validated against the live API, on this PR, 2026-11-03, hardware irrelevant (one
gh api call from a CPU box):

python3 _publish.py 7303 --payload   → event=COMMENT, body 1398 chars, 1 inline
python3 _publish.py 7303 --post      → ✅ pullrequestreview-5749640123
gh api .../pulls/7303/comments       → start_line=211 line=248 side=RIGHT
                                        start_side=RIGHT position=191 (not outdated)

The run that produced that card was a real run_one.sh against this repo: 7 gates
green, citations.txt a genuine verdict (every cited file:line resolves, 1 proximity
note), 3 findings, 3 surviving independent refutation.

Unverified, and listed above in full: the degrade-to-summary fallback has never fired
against the real API, because the anchors were accepted; AITER_BOT_TOKEN's scope is
still unconfirmed by use, since the live post used a personal PAT with repo; and the
61-card population figures use current diffs, so for PRs that moved after review they
are an approximation.

One honesty note on method: three of the defects fixed in this PR were found by this
bot reviewing this PR, and two of those were in code written the same day — including a
test suite that passed only because it ran the extracted shell region under bare
set -e while the real script runs set -euo pipefail, so every classification it
claimed to cover was unreachable in production.

PR-specific question

The boundary this introduces: a review is all-or-nothing. GitHub rejects the entire
call — summary included — if any single comments[] entry names a line it will not
accept. The old single comment either posted or did not; after this change, one bad
anchor could lose a whole review, findings and all. That is a strictly worse failure
than the one it replaces, so it is covered three ways:

  1. Anchors are computed from the diff's own hunk headers rather than guessed, and a
    finding only earns one if check_citations.py resolved its citation. A citation the
    checker could not vouch for — including one it never checked, because it crashed —
    forfeits the slot.
  2. On refusal, do_post retries the same endpoint with the anchors folded back into the
    body and says [ANCHORS REFUSED -- folded into summary]. Two tests pin that path,
    including that the folded body still carries the anchored finding's full text. A
    review that silently sheds half its findings reads exactly like one that only ever
    had the other half.
  3. The summary carries a one-line index of every anchored finding, so a reader of the
    summary alone can tell that findings exist elsewhere rather than inferring there are
    none.

The evidence is uneven, and the gap is in the most important place. Paths 1 and 3
are now covered by a live call: a range anchor was accepted and stored on the span
(start_line=211 line=248). Path 2 — the refusal — has only ever run against a stub
that rejects any payload with comments[], because the real API accepted ours. The
fallback is the thing standing between one bad anchor and a lost review, and it is the
one piece still unproven against the API it exists to survive.

Changed op tests

None — no op_tests/ file is touched. The change is confined to
.claude/skills/review-pr/.


Update — anchors point at the section, and what cannot be anchored gets a link

The anchoring above attaches a finding to one line. Two follow-on changes, both measured
on this bot's own archived cards.

1. Range anchors

25 of 221 archived findings cite a line range — layernorm.py:1002-1012 — and every
one was anchored to line 1002 alone, so the reader saw a comment pinned to one line of a
block the finding is about, which reads as a claim about that line. GitHub spells a span
as start_line + line with a start_side/side for each end; a cited range is now
anchored as one.

Both endpoints and every line between must be commentable. That is exactly "inside one
hunk" — commentable() holds one contiguous run per hunk — and checking the two endpoints
alone would accept a span across the gap between hunks, which is a malformed range, which
fails the whole review. When only part of the span is in the diff, the end that is takes
a single-line anchor rather than the finding being dropped.

The span pattern is deliberately tight — ASCII hyphen, no surrounding whitespace. A loose
one reads the real card sentence flash_kda.py:381 — 6 published tuning candidates as the
backwards span 381..6. Over 221 findings the tight form matched 25 spans and no false
positive; the loose form added that one sentence and nothing true.

2. Permalinks for what cannot be anchored

A citation whose line the diff does not reach cannot be anchored — GitHub is right to
refuse it — and used to sit in the summary as bare moe.py:5220 text the reader had to go
and find. It now also gets a blob permalink pinned to the head SHA, alone on its own
line, which is the only place GitHub expands one into the code it names. Pinned and not a
branch: a link that drifts off the code it was written about is a wrong anchor arriving
late. The finding's own path:line text is untouched — the link is in addition.

Neither is invented

Both run through the gate anchoring already had. A citation check_citations.py flagged,
or a card it never ran on, gets no anchor and no link. A path that does not resolve to
a file this PR touched gets no link either: a blob URL built from an unresolved basename is
a guess, and a link to the wrong code is worse than no link, for the same reason a wrong
anchor is.

Measured

Replaying eight real cards against the diffs they were written for — 37 findings:

count
span anchor 11
single-line anchor 16
permalink only 2
nothing 8

Auditing every span citation in the 57-card corpus: 23 of 35 span-anchor cleanly, 1
falls back to an endpoint (part of the span is outside the diff), and 11 resolve to no file
in the diff — a vLLM path, an ambiguous basename matching two changed files, context code
the PR does not touch — and so are correctly left alone. None was too wide for MAX_SPAN.

Replaying also found a defect this change introduced: when a span collapses to one endpoint
the summary index stripped path:563 and left the line opening with a bare -569. Fixed,
and pinned by a test.

The all-or-nothing boundary, again

A malformed span is a new way to fail the whole call. The degrade-to-summary fallback
covers it like any other refusal, and a test now pins that a refused range review degrades
with the span finding's text intact and folded as path:101-104, not as a bare line.

_publish_test.py is new in this PR and carries 37 cases. check_prompts.py gains two drift checks that
build a review over a synthetic two-hunk diff and assert the shape GitHub will take —
start_line < line, matching sides, span inside one hunk, permalinks gated — rather than
the source that produced it.

Verified against the real API

A range anchor was posted and read back: start_line=211 line=248 side=RIGHT start_side=RIGHT, stored on the span, not collapsed to its first line. The
hunk-containment rule held on a real diff. What remains untested is the refusal path —
the anchors were accepted, so the degrade-to-summary fallback has still only ever run
against a stub.

Today the bot posts card.md as one top-level issue comment. Across the 61
real cards it has published on this repo, those carry 229 findings; 120 of
them (52%) cite a `file:line`, and 65 of those lines are inside the PR's own
diff. Those are findings a reader would rather meet next to the code than
half-way down a wall of prose.

_publish.py now POSTs `/pulls/{pr}/reviews` with `event: "COMMENT"` -- never
APPROVE or REQUEST_CHANGES, this bot stays advisory and gates nothing. The
findings whose citation checks out and lands in the diff go up as `comments[]`
on their lines; everything else stays in the review body, together with a
one-line index of the ones that went inline. The index is not decoration:
without it a reader of the summary cannot tell whether findings exist
elsewhere or none do, and an invisible finding reads exactly like a finding
that was never made.

Anchoring is a privilege a finding earns. check_citations.py (ported from
ATOM, where it was built) is now wired in as run_one.sh step 3c: it writes
citations.txt, _lib.py collects it, and _publish.py refuses to anchor any
finding carrying a citation the checker flagged -- a top-level card that
cites a wrong line is a flaw the reader works around, but an inline comment
on a wrong line lands in the author's working view and is visibly wrong. With
no citations.txt at all nothing anchors and the whole card stays in the
summary, which is exactly what this bot posts today. The checker never gates
the run: it ran 1-for-2 on real cards, and a heuristic that withholds correct
reviews costs more than the defect it catches.

A review is all-or-nothing -- one anchor GitHub will not take fails the whole
call, summary included, which is worse than the comment this replaces. So a
refusal retries the same endpoint with the anchors folded back into the body
and says so. A review that silently sheds half its findings reads exactly
like a review that only had the other half.

Measured on ten of those real cards, replayed against the diffs they were
written for: the summary a reader meets first drops from 33,025 to 24,173
characters, 27% shorter, with 11 findings moved onto their lines.

Adapted from ATOM rather than copied: aiter's card writes `Review (advisory):`
where ATOM's writes `Review:` and adds a `Perf` line ATOM has no counterpart
for, so the summary matches on the bare word and keeps all three; the dedup
marker stays a literal `aiter-bot` instead of being derived from the
overridable AITER_BOT_NAME, and still searches issue comments as well as
reviews, so the markers already sitting on live PRs are not reposted over.

check_prompts.py gains three guards: the event stays COMMENT with exactly one
POST call site, the --post closure stays matched to the workflow's
permissions, and the anchoring wiring (run_one -> citations.txt -> _lib ->
_publish) cannot be half-removed in silence. selftest.sh now runs
_publish_test.py, and says out loud when pytest is absent rather than
passing over it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7303 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision a94cab7aa30f · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

zufayu and others added 9 commits November 2, 2026 08:11
… be anchored

Inline anchoring attached a finding to a single line. Two things that costs, both
measured on this bot's own archived cards:

Spans. 25 of 221 archived findings cite a line *range* -- `layernorm.py:1002-1012` --
and every one was anchored to line 1002 alone, so the reader saw a comment pinned to
one line of a block the finding is about, which reads as a claim about that line.
GitHub takes a span as start_line..line with a side for each end; cite a range and it
is now anchored as one. Both endpoints and everything between must be commentable,
which is exactly "inside one hunk" -- checking the ends alone would accept a span
across the gap between two hunks, and one malformed entry fails the whole review,
summary and all other comments with it. When only part of the span is in the diff the
end that is gets a single-line anchor, rather than the finding being dropped.

The span pattern is deliberately tight: an ASCII hyphen with no whitespace. A loose one
reads the real card sentence "flash_kda.py:381 - 6 published tuning candidates" as the
backwards span 381..6. Over 221 findings the tight form matched 25 spans and no false
positive; the loose form added that one sentence and nothing true.

Permalinks. A citation whose line the diff does not reach cannot be anchored -- GitHub
is right to refuse it -- and used to sit in the summary as bare `moe.py:5220` text the
reader had to go and find. It now also gets a blob permalink pinned to the head SHA,
alone on its own line, which is the only place GitHub expands one into the code it
names. Pinned and not a branch: a link that drifts off the code it was written about is
a wrong anchor arriving late. The finding's own text is untouched -- the link is in
addition, never instead.

Neither is invented. Both run through the same gate anchoring already had: a citation
check_citations.py flagged, or a card it never ran on, gets no anchor and no link, and
a path that does not resolve to a file this PR touched gets no link either. A blob URL
built from an unresolved basename is a guess, and a link to the wrong code is worse
than no link for the same reason a wrong anchor is.

Verified by replaying eight real cards against the diffs they were written for: of 37
findings, 11 now take a span anchor, 16 a single line, 2 a permalink only, 8 nothing.
Auditing every span citation in the 57-card corpus, 23 of 35 span-anchor cleanly, 1
falls back to an endpoint, and 11 resolve to no file in the diff and so are left alone.

Replaying also turned up a defect in the index line this change introduced: when a span
collapses to one endpoint the index strips `path:563` and leaves the opening "-569". Fixed
and pinned by a test.

_publish_test.py gains 16 cases (spans, the hunk gap, the prose false positive, the
permalink gates, and a refused *range* review degrading with its text intact);
check_prompts.py gains two drift checks that build a review over a synthetic two-hunk
diff and assert the shape GitHub will take rather than the source that produced it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Found by running the reviewer on this PR, on box 8, end to end. Seven gates green, 33
unit tests passing, and the payload it produced carried zero inline comments. Either
bug alone is enough to erase the feature; both were present.

**Citations resolved against the wrong tree.** check_citations.py picked one tree for
every citation and preferred merge-target, which fetch.sh checks out at BASE_SHA -- the
code before the PR. Citations into lines this PR added could never resolve there:
`_publish.py:221 -- file has 171 lines`, 171 being the length on base. All six were
hard-failed. head/ holds the PR's version of each changed file, merge-target/ the
pre-PR tree for everything else, so neither alone is right; resolution now tries them
in order per file. The reviewer found this one itself and graded it 🔴.

**A 50%-precision heuristic vetoed the feature.** flagged_citations() counted both
halves of the checker's output, so a proximity note disqualified a finding exactly as a
hard failure did. They are not the same claim: a hard failure means the citation
resolves to nothing, while a note says a quoted symbol is not within five lines of the
cited one -- a quality hint the checker's own docstring puts at ~50% precision. Only
hard failures disqualify now. A heuristic that silently switches off what it guards is
the worse failure: a wrong anchor is visible and correctable, an absent one looks
exactly like a review with nothing to say.

Verified on the real card from that run, with the trees rebuilt from the PR's own head
and base: **0 anchors and a 4163-character summary before, 5 anchors and 990 after**.
Three tests pinned the old veto rule and failed, which is what they are for; the veto
test's fixture now uses a hard failure, and a new test pins that a note leaves the
anchor in place.

Still unverified: whether GitHub accepts these payloads. No code here has made a live
review call.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…f deleting it

Ported from ATOM, where this failed for real. The first live auto-validation
run got as far as invoking the validator, then died: the consumer that checks
a validation report runs under errexit, and `import jsonschema` failed on the
runner. No card was produced at all.

aiter's consumer has the same shape -- 33 fail-closed checks, any one of which
aborts fetch.sh -- so it has the same failure available to it. A review that
vanishes reads, to the human waiting on it, exactly like a bot that is down,
and a missing optional dependency is not evidence that anything about the PR
is wrong.

The integrity checks stay fail-closed: evidence that does not match this PR's
head, base or patch is still never consumed. What changes is the consequence
of rejecting it -- the rejection is captured, its reason recorded in
auto_validation_outcome.txt, and the review falls through to the no-evidence
branch, so the card says validation did not run and names why.

_degrade_test.sh extracts the real consumer region out of fetch.sh by its line
markers and drives those bytes with a report for the wrong head, asserting all
four things the live failure got wrong. Collapsing `set +e` back reproduces
that failure exactly -- verified in both repos before committing.

Not ported: ATOM also had to make its validator print why a non-PASS verdict
happened, because it printed the verdict alone and the report evaporated with
the scratch dir. aiter's validator already names its output file, so that is a
different situation and is left alone rather than changed on spec.

selftest: 85 green / 0 red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…t it

Ported from ATOM, where this happened twice in a row on a live run. The log
ended mid-sentence and said nothing further:

    [run_one #2889] fetch...
    GraphQL: API rate limit already exceeded for user ID 349247671.

Two defects, both present here in the same shape. errexit aborts run_one
inside the fetch pipeline, before the line that classifies a failed fetch can
run; the status is then written by the EXIT trap, which wrote the file and
printed nothing -- so the one place the reader already was said the least.
The traps now say their piece out loud, and the fetch status is taken as a
value and classified.

The classification it would have reached was also wrong for this cause:
"check gh auth/token, network, git and disk" sends someone hunting a broken
credential when the credential is fine and a quota is empty. A quota resets on
GitHub's own clock and the only correct response is to wait and re-run, so it
is named separately, quoting the refusal, and it states that nothing about the
PR was examined -- a run that looked at nothing must not be mistaken for a
review that found nothing.

_fetchfail_test.sh drives that classification with a fetch that fails two
ways, asserting the quota is named, the non-examination stated, and that a
non-quota failure still falls through to the generic cause.

selftest: 86 green / 0 red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
"The quota resets on GitHub's own clock (an hour at most)" is not something
anyone can plan around -- it means the same thing one minute before the refill
and fifty-nine minutes before it. GitHub's /rate_limit endpoint does not count
against the quota, so the exact refill time is readable even while the quota
is spent. The line now names it:

  GitHub's API quota for this bot is spent (the token is fine) -- it refills
  at 06:26 UTC, in about 25 min; re-comment then. Nothing about this PR was
  examined.

What is wrong, how long, what to do, and that nothing was looked at. The vague
wording survives as the fallback for when the reset time cannot be read -- a
wrong number would be worse than no number.

The test caught a real defect while being extended for this: the reset lookup
ends in a grep, which returns non-zero when it matches nothing, and under
errexit that killed the run outright -- so the fallback line could never be
reached. Fixed, and both paths are now asserted, along with a non-quota
failure keeping its own cause.

ATOM 97 green / 0 red, aiter 86 green / 0 red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Measured on the bot's own token today: rocm-atom-bot reports core 58/60 and
graphql 0/0. An authenticated account gets 5000/5000 -- 60 with GraphQL at
zero is the profile GitHub leaves on an account it has restricted. That is
what has been failing every run, and it is not a quota that refills.

I had this wrong twice in a row, and told a person to wait an hour for it. The
message shipped an hour ago would have said the same: it reads the reset
timestamp and promises a refill. For a restricted account that promise sends
someone to wait for something that never arrives, which is worse than the
vague wording it replaced.

So the two are now distinguished by what only one of them looks like -- a
60-call cap with GraphQL disabled -- and the restricted case says plainly that
waiting will not clear it, and that the account needs unflagging or the bot
needs a different one. Both still say that nothing about the PR was examined.

Test covers all four paths now: refill time readable, refill time unreadable,
restricted account, and a non-quota failure keeping its own cause. Removing
the restricted branch makes it fail on both of its assertions.

ATOM 97 green / 0 red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… did used the wrong flags

Found by this bot reviewing its own PR. All three findings held up under my
own verification; two of them are about code committed today.

1. check_citations.py's main() called tree_for(); only trees_for() exists, and
   it then passed a `trees` it never assigned. Every invocation raised
   NameError. run_one.sh's `|| true` swallowed the crash, citations.txt
   carried a Python traceback, and _publish.py's flagged_citations() read that
   traceback as "nothing flagged" -- so findings were anchored inline with
   zero citation checking, which is the exact failure this checker was added
   to prevent. The proof is this PR's own run: reports/PR-7303/citations.txt
   is a traceback, and the gate was green.

   The 34 pytest cases all exercise check(). Nothing called main(). A
   function no test calls is a function that does not work yet, so
   _citations_test.sh now runs it end to end on a resolvable and an
   unresolvable citation; restoring the NameError fails all four assertions.

2. Every fetch-failure classification added today was unreachable in
   production. run_one.sh runs `set -euo pipefail`, and
   W="$(grep ... | tail | cut)" is a fatal assignment when grep matches
   nothing -- the script died there, before any classification. The region
   tests passed only because they ran the extracted bytes under bare `set -e`.
   Measured both ways: `set -e` writes the status file and names the cause;
   `set -euo pipefail` exits 1 silently with no status at all.

   That is the defect this project exists to catch, sitting in my own test. All
   region tests now run under the flags the scripts actually use, and removing
   the guard fails eight assertions instead of passing.

3. The same unguarded shape in fetch.sh's rejection handler (also
   `set -euo pipefail`), which would kill the handler whose whole purpose is
   to keep the review alive. Guarded in both repos.

ATOM 98 green / 0 red, aiter 87 green / 0 red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The bot's review of this PR reported that the diff no longer applies to the
merge target: main gained e10bd0a (#6865), whose [derive] selftest block
lands exactly where this branch adds its own test lines. Verified -- that one
file is the only conflict, and every other changed file's base blob still
matches main.

Both sides are kept: #6865's [derive]/[mapping] cases and this branch's
degrade, fetch-failure and citation tests are unrelated checks in the same
file. selftest is 97 green / 0 red on the merged tree, ruff clean, 34 pytest
cases passing.

Merged rather than rebased so the published branch only ever moves forward.

# Conflicts:
#	.claude/skills/review-pr/selftest.sh
Found by this bot reviewing this PR, and it is the half of its own earlier
finding that I fixed badly. That finding asked for two things: stop
check_citations.py crashing, and stop flagged_citations() reading a crash as
"nothing was flagged". I did the first and left the second, so the crash was
gone but the defence against the next one was never built.

The module docstring already promised this behaviour -- "when citations.txt is
missing or the checker could not run, nothing is anchored" -- while the code
did the opposite for the one case that actually happened: a file with content
but no CITATIONS verdict line returned an empty set, which means "every
citation checks out", so every finding anchored with no checking at all.

Absence of a verdict line is now treated as "the checker did not run",
however the file got that way. The test feeds the real traceback this PR
produced two revisions ago; removing the guard fails it.

aiter 35 pytest cases, ATOM 33.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@zufayu zufayu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ROCm/aiter PR #7303 — review-pr: publish the card as a PR review with findings anchored inline

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): N/A — no runtime surface changed
Perf (advisory): N/A — no runtime surface changed

📝 [verified] The PR body's verification counts trail the head it will merge at: the Update section says _publish_test.py "goes from 17 cases to 33" while the file at head has 34 (selftest prints "34 passed"), and the Verification block's "84 green / 0 red" selftest snapshot is 97 / 0 at head — a body whose whole argument is measured, checkable claims should not ship stale ones. Reviewer should ask the author to refresh the counts before marking ready.

📝 [verified] No live GitHub review call has ever been made by this code (the PR's own "What is not verified"), so the exact payload shape — start_line/start_side as built, the hunk-containment rule as modelled — is untested against the real API, with only the degrade-to-summary fallback standing behind it. Reviewer should ask the author to attach the _publish.py <pr> --payload dry-run JSON on one real PR (the body's own suggested landing step) before marking ready.

1 finding(s) posted inline, on the lines they are about:

  • .claude/skills/review-pr/_publish.py:211-248 — _publish.py:211-248

Comment thread .claude/skills/review-pr/_publish.py Resolved
b841de1 staged `.claude/skills/review-pr/` as a directory, which picked up
the eleven files a review run had just written to reports/PR-7303/. They are
not part of this change: they are one run's output, about one commit, and
`run_one.sh` regenerates them. A tracked card is also wrong the moment the PR
moves -- the one committed here reports a finding that is already fixed at
head, and it cites a crashed citations.txt as evidence.

A .gitignore in the skill directory stops the next one, because the mistake
is `git add <dir>` and that will happen again.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu marked this pull request as ready for review November 3, 2026 09:58
@zufayu
zufayu requested review from a team and yzhou103 November 3, 2026 09:58
main() returned 0 whether the review went up or was refused. It printed
"❌ failed to post" and then told the caller everything was fine -- so a
refusal would be invisible to the workflow step, on every run, while each card
was quietly lost.

That matters most for the one refusal the degrade path cannot cover. The
anchored-then-summary fallback handles a bad anchor; it cannot handle a token
that may post issue comments but not create reviews at all (`Issues: write`
without `Pull requests: write` on a fine-grained PAT). Both attempts fail, and
until now the step stayed green.

This is not hypothetical here: aiter-bot has `read` on this repo and has
created zero reviews across the PRs checked, where it has posted an issue
comment on each. That is equally consistent with "the scope is fine and it has
never tried" and with "the scope is missing" -- the two are indistinguishable
from the outside, which is the whole shape this pipeline exists to break. The
holder says the scope is sufficient; this makes being wrong about that cost
one red step instead of every card.

The test pins the refusal the API actually sends and asserts its words reach
the operator. Writing it caught a second defect in itself: stubbing every API
call made the gate skip on PR metadata, so the test passed without reaching
the code it names. It now refuses only the review POST.

aiter 36 cases / 97 green, ATOM 34 cases / 98 green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread .claude/skills/review-pr/_publish.py Resolved
Both defects found by @zoe-cop in review; both verified before changing
anything, and both hold.

The basename fallback searched trees[0], which is head/ -- a sparse tree
holding only the files the PR changed. A citation of real context code by
bare basename (moe.py:5220 in a file this PR never touched) therefore matched
nothing and was reported as "no such file in the tree", i.e. an invented path,
rather than the ambiguity note it was meant to get. _unflagged_cites then
forfeits the whole finding's anchor AND permalink on any single hard failure,
including a correct, fully-qualified, in-diff citation in the same sentence.
So citing context code switched anchoring off silently -- the failure this
checker was added to prevent, produced by the checker.

It now searches merge-target/, the full tree at BASE_SHA. Fixing that exposed
a second half: hits[0] could come from the diff (present in head/) or from the
basename search (present in merge-target/), while resolution assumed one tree,
so a single hit landed on "is in the diff but not the tree". Resolution now
follows whichever tree actually holds the file. Verified on all three verdicts:
a lone context file resolves, several of the same name give a note, an
invented path still fails.

Second: the summary-only retry appended the folded findings to a body still
carrying build_review's "N finding(s) posted inline, on the lines they are
about" index. True of the attempt GitHub refused, false of the one being sent,
where comments[] is empty -- so the degraded review pointed the reader at
lines carrying nothing and then listed the same findings again. That is the
inverse of the silence this fallback exists to prevent. The index is now
stripped before folding.

@zoe-cop also diagnosed why the existing test could not catch it: it asserts a
retry happened and that comments[] emptied, never what the body says, so it
passes on the stale index alone. The new test asserts the anchored body
carries the index and the degraded body does not.

selftest 97 green / 0 red, 37 pytest cases.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zufayu and others added 4 commits November 4, 2026 08:48
Found by running this PR's own verification the way its description tells a
reviewer to: on a clean `git archive HEAD` export, not the working tree.

    $ python3 check_prompts.py
    FileNotFoundError: '.claude/skills/review-pr/SKILL.md'

_skill_md asked git for the repo root. `git rev-parse --show-toplevel` prints
an empty string when there is no repo, and Path("", ".claude", ...) is then a
RELATIVE path resolved against the caller's cwd -- so the check that exists to
catch prompt drift could not run at all in the one place a reviewer would run
it. It passed every time it was tried because every trial was inside a
checkout, including a "fresh /tmp worktree", which is still a git tree.

SKILL.md sits next to check_prompts.py. It reads it from there and asks git
nothing.

The guard reproduces a real export -- `git archive HEAD | tar -x` of the
tracked tree, no .git -- and asserts exit 0 from a cwd outside it. Writing it
the obvious way first (copy the skill directory alone) asserted something the
project does not promise and failed on an unrelated missing workflow file; a
guard has to test the thing that was promised, which here is the export.

Restoring the git-root lookup turns it red in both repos.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The guard added a moment ago built its fixture with `git archive HEAD`. Run
from a working tree that passes; run the suite from a clean export -- which is
what this PR's description tells a reviewer to do -- and there is no repo to
archive from, so the guard failed and the suite went red for a reason that had
nothing to do with the code under test.

A guard that only works inside a checkout cannot test leaving one. It now
builds the fixture directly: the skill tree at its repo depth plus the workflow
file the check reads, in a directory with no .git. No git involved, so it
behaves the same inside a checkout and outside one.

This also closes the loop the previous commit opened. The whole suite now runs
green from inside a clean export in both repos -- aiter 98/0, ATOM 99/0, drift
clean, pytest passing -- which is the state the verification instructions have
been describing all along and that nothing had ever checked.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…efuter

Hit while re-reviewing ATOM#2762, whose diff grew past the 40-minute worker
budget after main was merged in. Raising AGENT_TIMEOUT is the obvious response
and the timeout message names that exact knob -- but a review runs two agents
in series, and the gate that starts each one refuses to begin an attempt that
cannot finish inside RUN_BUDGET. So with AGENT_TIMEOUT=5400 against the
default RUN_BUDGET=7200, the worker runs, the refuter cannot start, the
`independent` gate reds, and the review is withheld after an hour of work --
reported as a timeout whose named fix makes it worse the next time.

The constraint is AGENT_TIMEOUT x 2 <= RUN_BUDGET, and nothing enforced it.
It is checked now before any work is spent, with an error that names both
numbers and both ways out. Exit 2, distinct from the review's own failures.

Verified on three pairs: 5400/7200 refused, 5400/14400 accepted, and the
shipped defaults (2400/7200 here, 2400/6000 on aiter) unaffected. Removing the
check turns the selftest red.

ATOM 100 green / 0 red, aiter 99 green / 0 red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
CI's "Lint the skill for real errors" step runs ruff with --select F,E9 --
the rules that catch actual mistakes rather than style -- and it went red on
F401: `import subprocess` became dead when _skill_md stopped shelling out to
`git rev-parse` in 058dfd0.

My own ruff run used the repo's default rule set, which does not include F401,
so the check I ran and the check CI runs were not the same check. ATOM is
unaffected: its check_prompts still calls subprocess elsewhere.

selftest 99 green / 0 red, ruff --select F,E9 clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu merged commit d7fad35 into main Nov 4, 2026
@zufayu
zufayu deleted the feat/review-bot-inline-anchors branch November 4, 2026 13:10
@zufayu
zufayu restored the feat/review-bot-inline-anchors branch November 4, 2026 13:31
gyohuangxin added a commit that referenced this pull request Dec 3, 2026
…direct (#7525)

Co-authored-by: Cursor <[email protected]>

#7303 moved the gate's heredoc opener to `<<'PY' 2>"$WORK/validation_rejected.txt"`. run_review_gate extracts the block with a pattern that wants a newline right after `<<'PY'`, so it found no block and the three identity-gate tests failed. The opener may now carry text after the delimiter.

Co-authored-by: Xin Huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants