Skip to content

Re-target a review when HEAD moves, instead of discarding it - #1082

Merged
max-sixty merged 4 commits into
mainfrom
agent-ad8aaffcadcf26b0c
Aug 29, 2026
Merged

max-sixty merged 4 commits into
mainfrom
agent-ad8aaffcadcf26b0c

Conversation

@max-sixty

@max-sixty max-sixty commented Aug 29, 2026 •

Copy link
Copy Markdown
Owner

A review session that found HEAD had moved exited without posting, and the queued synchronize run reviewed the PR from scratch. Over a week across three repos that discarded 128 runs and $482 — more per run than a session that posts, because a superseded session has done the whole review by the time it checks.

Re-targeting

The session now requires the commit it reviewed to be an ancestor of the live head, reads the delta, re-judges its findings against it, and posts anchored at the new head. Findings the delta left alone stand; ones it fixed drop out, and if that empties the review the session approves the new head. It finishes without posting only when it cannot judge the delta — a rewrite, or a review's worth of new code in its own right — and the queued run then covers that head in full, the same path that covers a session dying mid-review.

Three commands read the delta, because no one of them can show it:

  • git log -p --no-merges ... --not "$BASE_SHA" — the author's own new code. A plain two-dot git diff between the heads presents everything a base merge dragged in as the author's; on a branch where they clicked "Update branch", three of main's files alongside the one commit they wrote.
  • git log --format='base merge: %h %s' --merges — base merges, which the scoped log cannot show at all. Labelled, or it reads as one more commit at the end of the patch stream.
  • git show --cc <merge sha> — what a conflicted merge itself changed, which the author commits inside the merge where neither log reaches it.

Re-verification of inline comments against the new gh pr diff is unconditional whenever a base merge appears: a clean merge that only shifts lines prints nothing in any of the three, and --cc shows only hunks differing from every parent, so a resolution taking the base side prints nothing either. --cc tells you what a merge changed, never that a merge changed nothing.

suggestion blocks are re-composed against the new head — one carried over unchanged reverts the author's newest edit on one click.

Pinning

Every posted review now sets commit_id. Unpinned, GitHub anchors the review at whatever is live when the POST lands, so it claims code the session never read. Pinned, the anchor is what bot-review-state.sh reports as LAST_REVIEW_SHA, so the queued run finds that head reviewed and finishes without a second review of the same code.

The sha travels through a file because it cannot travel any other way: the agent composes the review body between reading the head and posting it, and shell state does not survive a tool call. Every recipe reads it into a variable and bails if it is absent — inlined as $(cat ...) a missing file substitutes the empty string and the request still goes out, which is the unpinned review the pin exists to prevent.

weekly needed the same pin — its approvals land on dependency PRs, the population nightly rewrites on purpose. Its file is per-PR and cleared before the guard, since step 2 loops over every dependency PR.

Before an APPROVE the session now requires the pinned commit to still be live. The rollup it reads is the live head's, so once the two differ the red-check gate is reading a different commit than the approval pins.

Tests

test_notification_queue_contract.py becomes test_cross_file_contracts.py — it now pins skill-to-skill contracts as well as the notification queue's. All three delta commands and all three posting recipes are asserted there.

Not in this change

A pre-boot workflow gate that would skip the queued run before it boots an agent. It is a compute-only mechanism and is proposed separately.

This was written by Claude Code on behalf of max-sixty

A review session that found HEAD had moved exited without posting, and
the queued `synchronize` run reviewed the PR from scratch. Over a week
across three repos that discarded 128 runs and $482 — more per run than
a session that posts, because a superseded session has done the whole
review by the time it checks.

## Re-targeting

The session now requires the commit it reviewed to be an ancestor of the
live head, reads the delta, re-judges its findings against it, and posts
anchored at the new head. Findings the delta left alone stand; ones it
fixed drop out, and if that empties the review the session approves the
new head. It finishes without posting only when it cannot judge the
delta — a rewrite, or a review's worth of new code in its own right —
and the queued run then covers that head in full, the same path that
covers a session dying mid-review.

The delta is scoped off base churn with `git log -p --not "$BASE_SHA"`,
as step 1 scopes its own incremental. A plain two-dot `git diff` between
the two heads presents everything a base merge dragged in as the
author's new code: on a branch where the author clicked "Update branch",
it reports three of main's files alongside the one commit they wrote.

Inline comments and `suggestion` blocks are re-verified against the new
head — a suggestion carried over unchanged reverts the author's newest
edit on one click.

## Pinning

Every posted review now sets `commit_id`. Unpinned, GitHub anchors the
review at whatever is live when the POST lands, so it claims code the
session never read. Pinned, the anchor is what `bot-review-state.sh`
reports as `LAST_REVIEW_SHA`, so the queued run finds that head reviewed
and finishes without a second review of the same code.

The sha travels through `/tmp/reviewed-head` because it cannot travel
any other way: the agent composes the review body between reading the
head and posting it, and shell state does not survive a tool call.

`weekly` needed the same pin. Its approvals land on dependency PRs — the
population `nightly` rewrites on purpose — so an unpinned approval there
lands on a commit nothing checked.

Before an APPROVE the session now requires the pinned commit to still be
live. The rollup it reads is the live head's, so once the two differ the
red-check gate is reading a different commit than the approval pins.

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

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two things in the new flow don't hold up, both in code the diff adds.

The larger one is that weekly's already-approved guard no longer stops anything. Previously the gh pr review --approve lived inside the else; now the else only records the sha and the POST recipe sits below the block as unconditional prose, so the "Already approved on this commit; skipping" branch falls straight through into composing a body and approving. Since Step 2 iterates over every dependency PR, /tmp/checked-head is also whatever the previous PR wrote — so the skip path either re-approves a commit it just decided not to, or pins the approval to another PR's sha (and on the first PR of the run, to nothing at all, since the file doesn't exist yet).

The other is that the re-target delta can't show the case its own bullet asks about. --no-merges drops the merge commit and --not "$BASE_SHA" drops everything the merge dragged in, so on a pure "Update branch" push the command prints nothing — indistinguishable from "no new commits". I confirmed it on a scratch repo: the three-commit range (merge + two base commits) produces empty output. That's exactly the push the bullet below warns about — "A base merge re-scopes every file's hunks, so verify every comment when the delta contains one" — and the session has no way to know the delta contained one, so it carries every inline comment over onto hunks that moved.

One smaller observation, no change requested here: the Posting-mechanics block is now ~32 lines with real edge-case handling (rewrite detection, two fetch fallbacks, base-churn scoping). running-in-ci § "Scripts over prose recipes" draws the line at "needs edge-case handling or grows past a couple of dozen lines" — and the base-merge blind spot above is the kind of thing shellcheck-and-tested code in plugins/tend-ci-runner/scripts/ surfaces and a prose recipe doesn't, since every session re-derives it.

The pinning half reads correct throughout — commit_id is set on all three posting recipes, bot-review-state.sh's at_head/fresh_approval_sha get sharper with it, and the full Python suite passes (760) with no stale references to the renamed test module.

…blind spot

`weekly`'s already-approved guard stopped stopping anything when the POST
moved out of the `else` into prose below the block. The skip branch fell
through into composing a body and approving, and `/tmp/checked-head` was
shared across step 2's loop, so it carried the previous PR's sha. The
file is now per-PR and removed up front, and the prose says plainly that
`skipping` ends this PR.

The scoped delta could not show a base merge: `--no-merges` drops the
merge commit and `--not "$BASE_SHA"` drops everything it brought in, so a
pure "Update branch" push printed nothing — indistinguishable from no new
commits, and it is the one delta shape that re-scopes every inline
comment's hunks. A second `git log --merges` reports them, and the bullet
now reads the two outputs as a pair.

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

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both fixes hold. I re-ran the scratch-repo check on the base-merge case: with a git merge of the base tip between the two heads, the scoped log prints nothing and git log --merges prints the merge commit, so the pair does distinguish an "Update branch" click from an empty delta. Weekly's skip path now stops at the guard, and the per-PR filename removes the cross-PR contamination. Full Python suite green (760).

One thing the pair can't do as written, plus a gap in what the test pins — both inline.

…e content

Inlined as `$(cat ...)`, a missing sha file substitutes the empty string
and the request still goes out — the unpinned approval the pin exists to
prevent. All three posting recipes now read the sha into a variable first
and exit if it isn't there.

A conflicted base merge carries the author's resolution inside the merge
commit, where neither log reaches it: the scoped log excludes merges, and
the merges log reports that one happened, not what it changed. Verified
on a scratch repo — a reviewed line went `AUTHOR_BUG` → `RESOLVED_BY_AUTHOR`
inside the merge with both logs silent, while `git show --cc` printed the
resolution hunk exactly. Re-anchoring alone would post a finding the
resolution already fixed.

The merges log is labelled `base merge:` so it can't read as one more
commit at the end of the scoped log's patch stream.

The merges recipe was the one command here nothing pinned — the earlier
assertion never landed, because ruff-format had rewritten the quotes it
matched on and the replace silently no-op'd. All three delta commands are
pinned now.

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

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The --cc bullet lands, but the same commit deleted the sentence that made re-anchoring happen after a base merge, so the clean-merge case now has no instruction at all.

Previously the pair bullet ended: "A base merge re-scopes every file's hunks, so when the second output is non-empty, re-verify every comment even if the first printed nothing." That clause is gone in b28cfbc, and nothing replaced it — the new bullet's own title ("not just re-anchoring") presupposes re-anchoring, but the only re-anchoring rule left is the shortcut two bullets up: "On a file the delta didn't touch, the line is unchanged and the comment stands." After a base merge the scoped log cannot show the touched file, so that shortcut now fires on exactly the delta shape it was overridden for.

Concretely: bot comments on foo.py:6, author clicks "Update branch", main had added two lines above. Scoped log empty, base merge: line present, git show --cc prints the commit header and no hunks, and the flagged line is at 8. The session reads "the delta didn't touch it" and posts at 6.

--cc can't cover this on its own even when the merge conflicted. It shows only hunks differing from all parents, so a resolution that takes the base side prints nothing — I re-ran the earlier repro with RESOLVED_BY_AUTHOR swapped for main's own line and --cc emitted no hunks while the reviewed line was gone. Restoring the clause covers both; --cc still earns its place for judging what a conflicted merge changed.

Inline suggestion below. The rest of the increment holds: all three posting recipes read the sha into a variable and bail before the POST, the label makes the merges log unmistakable, and the module's assertions pin all three delta commands (uv run pytest generator/tests/test_cross_file_contracts.py green, 9).

Repro — clean base merge
git init -q -b main . && printf 'a\nb\nc\nd\ne\n' > foo.py && git add . && git commit -qm base
git checkout -qb feature && printf 'a\nb\nc\nd\ne\nFLAGGED\n' > foo.py && git commit -qam "author work"
H1=$(git rev-parse HEAD)
git checkout -q main && printf 'NEW1\nNEW2\na\nb\nc\nd\ne\n' > foo.py && git commit -qam "main adds lines above"
NEWBASE=$(git rev-parse HEAD)
git checkout -q feature && git merge --no-edit main    # clean
H2=$(git rev-parse HEAD)

git log -p --no-merges --format='%h %s' "$H1..$H2" --not "$NEWBASE"   # nothing
git log --format='base merge: %h %s' --merges "$H1..$H2"             # one line
git show --cc "$H2"                                                  # header only, no hunks
git show "$H1":foo.py | grep -n FLAGGED   # 6
git show "$H2":foo.py | grep -n FLAGGED   # 8

The `--cc` bullet replaced the clause that made re-anchoring happen at
all after a base merge, so the clean-merge case was left with no rule and
fell through to the shortcut two bullets up — "on a file the delta didn't
touch, the line is unchanged and the comment stands" — which is wrong on
exactly that delta shape.

Reproduced both halves. A clean "Update branch" where main added two
lines above a flagged line: scoped log empty, `--cc` empty, and the line
moved 6 → 8, so the shortcut posts at 6. And `--cc` shows only hunks
differing from every parent, so a resolution that took the base side
prints nothing even though the reviewed line is gone.

So re-verification against the new `gh pr diff` is unconditional whenever
a `base merge:` line appears, and `--cc` sits beside it for judging what a
conflicted merge changed rather than in place of it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 6faba62 into main Aug 29, 2026
13 checks passed
@max-sixty
max-sixty deleted the agent-ad8aaffcadcf26b0c branch August 29, 2026 23:07
max-sixty added a commit that referenced this pull request Aug 30, 2026
Version bump, lockfile, and the 0.1.21 CHANGELOG section, which the
release workflow publishes verbatim as the GitHub Release notes.

11 commits since 0.1.20. The headline is
[#1082](#1082): a review session
whose PR gains a commit mid-run now re-targets its findings onto the new
head and posts there, instead of discarding the whole review for the
queued run to redo. Over a week across three repos that discard cost 128
runs and $482.

Not in this release: the `tend-ci-fix` concurrency key, and the
`token-report.sh` download-failure fix.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
max-sixty pushed a commit to max-sixty/worktrunk that referenced this pull request Aug 30, 2026
Automated nightly regeneration of tend's workflow files.

**tend version:** 0.1.20 → 0.1.22

## Notable changes

- **Notifications now run off a recovery queue** (max-sixty/tend#1074).
The pre-check drops the old layered inbox sweep (shadowed-run and
closed-bot-PR marking) in favour of a single paginated snapshot taken
before a 10-minute cutoff, passes that cutoff through to the agent, and
keeps repository watching enabled with an idempotent `PUT
.../subscription` on every cycle. The job also gains a serial
`tend-notifications` concurrency group.
- **`tend-review` re-targets instead of skipping**
(max-sixty/tend#1082). The "skip when the live HEAD is already examined"
gate step and its `if:` guards are gone; a live session now re-targets
when HEAD moves. The concurrency group adds `queue: max` so a push can't
evict a pending `ready_for_review` run.
- **Skills check the default branch for a landed fix before opening a
PR** (max-sixty/tend#1070), and `review-runs` gains the run census as a
second stranded-trigger drain input (max-sixty/tend#1073).
- **Poll/rerun script fixes** (max-sixty/tend#1053,
max-sixty/tend#1055): `tend-review` no longer gates the CI poll, and an
unresolvable commit fails fast rather than passing silently.
- **Generator fixes**: `watched_workflows` and `branches` are validated
as string lists (max-sixty/tend#1076), and block prompts no longer get
padded blank lines (max-sixty/tend#1090).

Full upstream diff:
max-sixty/tend@0.1.20...0.1.22

Co-authored-by: worktrunk-bot <[email protected]>
max-sixty pushed a commit to max-sixty/leaf that referenced this pull request Aug 30, 2026
Automated nightly regeneration of tend's workflow files.

**tend version:** 0.1.20 → 0.1.22

**Notable changes**

- Notifications recover work missed while the unread queue was stale,
and the job now runs under its own `tend-notifications` concurrency
group so overlapping schedules serialize instead of racing
(max-sixty/tend#1074).
- Skills check the default branch for a landed fix before opening a PR,
cutting duplicate PRs for work that already merged
(max-sixty/tend#1070).
- `review-runs` gains the run census as a second stranded-trigger drain
input (max-sixty/tend#1073), and reviews re-target when HEAD moves
rather than being discarded (max-sixty/tend#1082).
- The CI poll no longer lets `tend-review` gate it, and the
commit-resolution script fails fast instead of proceeding on an
unresolved SHA (max-sixty/tend#1053, max-sixty/tend#1055).
- The generator validates `watched_workflows` and `branches` as string
lists, and stops padding blank lines inside block prompts
(max-sixty/tend#1076, max-sixty/tend#1090).

max-sixty/tend@0.1.20...0.1.22


**Beyond the regeneration:** 0.1.22's `tend-review.yaml` sets
`concurrency.queue: max`, which GitHub accepts but the pinned
`actionlint` hook rejects, so this PR also adds a scoped `-ignore` for
that one schema message to `.pre-commit-config.yaml` — otherwise `lint`
is red and the PR can't merge on its own CI. Tracked upstream as
max-sixty/tend#1094.

---------

Co-authored-by: leaf-agent <[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.

2 participants