Skip to content

Label and auto-review PRs that change existing tests - #314

Merged
thrawn01 merged 8 commits into
mainfrom
thrawn01/eng-860-flag-and-review-prs-that-change-existing
Nov 22, 2026
Merged

thrawn01 merged 8 commits into
mainfrom
thrawn01/eng-860-flag-and-review-prs-that-change-existing

Conversation

@thrawn01

@thrawn01 thrawn01 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Intent

When a worker's PR edits or deletes a test that already existed, the behavior that test guarded has usually changed, and maybe nobody asked for that. Nothing marked those PRs, and a session only reviewed a worker's PR when the user asked.

Now CI labels such a PR changes-existing-tests on every push and takes the label off once the change is gone. Any dispatch session that sees the PR become ready reviews a labeled one without asking. The review names each changed test and whether the user authorized it. Each unauthorized change is posted on the PR and goes to the user, who is the only one who can approve it. Neither the manager nor autobots decides it, and autobots won't merge until the user answers.

Fixes ENG-860

Surfaces

Workflow .github/workflows/changes-existing-tests.yml, reusable. A managed repo calls it like this:

on:
  pull_request:
    types: [opened, synchronize, reopened, edited]
jobs:
  changes-existing-tests:
    permissions:
      contents: read
      pull-requests: write
    uses: kapetan-io/dispatch/.github/workflows/changes-existing-tests.yml@main

Input dispatch-ref (default main) picks the dispatch version whose labeler runs. The check shows as changes-existing-tests / changes-existing-tests.

Workflow .github/workflows/changes-existing-tests-pr.yml calls it on this repo's own PRs, running the labeler from the PR's head.

Command make changes-existing-tests, which the workflow runs:

$ make changes-existing-tests CHANGES_EXISTING_TESTS_ROOT=/path/to/head CHANGES_EXISTING_TESTS_BASE=origin/main \
    CHANGES_EXISTING_TESTS_REPO=owner/name CHANGES_EXISTING_TESTS_PR=42   # GITHUB_TOKEN in the environment
modified example.com/shop/cart.TestTotal (cart/cart_test.go)
deleted example.com/shop/cart.TestTax (cart/tax_test.go)
added changes-existing-tests

It exits 0 when the label matches the report, including when someone removed the label between its read and its delete, and 2 when it couldn't tell or couldn't change it. Other last lines are removed changes-existing-tests, changes-existing-tests already set, no existing test changed, and no go.mod in <root>, so no Go tests to check. When the repo has no such label yet:

existingtestlabel: owner/name has no changes-existing-tests label, and this token can't create one; someone with write access to the repo runs once: gh label create changes-existing-tests --repo owner/name

Command cmd/existingtestlabel (-root -base -repo -pr -tiger), the Go program behind the target. It runs tiger changed-tests --format json, with tiger pinned by TIGER_REF to the ENG-859 merge.

Skills dispatch:dispatch, dispatch:manage, dispatch:autobots, dispatch:pr-description.

Behavior changes

A PR ready notice for a worker's PR, before and after:

  • Before, dispatch:dispatch said the PR is ready and asked once whether to review it.
  • After, a PR carrying the label gets the critical-review sub-agent at once. That review lists each changed existing test as authorized or not. Only a sentence the user wrote in the ticket, on the PR or in the worker's session authorizes one. A message from another Claude session, a marked post (below), or a post whose author is unclear never does.

Every post a dispatch, manage or autobots session makes now opens with Posted by a dispatch <kind> session., since those posts go out under the user's GitHub and Linear account. A ## Decision comment puts it above the heading:

Posted by a dispatch manage session.
## Decision
Follows internal/email/retry.go:41: retry a failed webhook send for 24 hours, then drop it and log.
Turn: 2026-11-14T06:40:00.123Z

An unauthorized test change, before and after:

  • Before, under dispatch:manage the manager could decide it like any product question, and dispatch:autobots decided findings itself and merged a clean review.
  • After, it is a posted finding plus a question to the user. Manage lists it in its Status block, and autobots holds the merge until the user answers.

The PR description a worker writes now lists, under Behavior changes, each existing test it modified or deleted and why, or "No existing test changed."

Existing tests changed by this PR: none.

Concerns and risks

  • The label must exist in a repo before the first labeled PR. The caller grants only pull-requests: write, as the ticket specifies, and adding a label the repo lacks would create it, which needs issues: write. I created changes-existing-tests in kapetan-io/dispatch. ENG-863, ENG-864 and ENG-865 each need gh label create changes-existing-tests once. Until then the check fails on that repo's first PR with a changed test, the PR never reaches ready, and its worker gets a failing-check nudge it can't fix. The error names the command and says it needs someone with write access to the repo (GitHub's role table puts creating labels at Moderate or Write).
  • This repo's caller runs the PR's own labeler code with a pull-requests: write token. Only same-repo PRs reach it (fork and Dependabot PRs are skipped), and their authors can already edit the workflow file, so it grants nothing new. The independent review agreed to keep it.
  • Tests in a nested module (a directory below the root with its own go.mod) are not seen, since tiger runs once at the root. ENG-907 covers that in tiger.
  • internal/rework finds changed existing tests in merged PRs with its own matcher, and the label uses tiger. They disagree on a comment-only edit, a test moved to another file and nested modules. ENG-910 tracks making them one.
  • The tests fake GitHub's REST label API with an HTTP server and re-run the test binary as a stand-in tiger. Real GitHub is exercised only by this PR's own run, and only on the path with no changed test. Whether pull-requests: write alone is refused when it creates a label comes from actions/labeler's README, not a run.
  • Moving the decision comment's marker above ## Decision changed manage's and build's wording from "the comment's first line" to "the line under its heading". Manage sessions that post decisions before this merges post them without the marker.
  • The skill-creator review (no test prompts) ran over the four changed skills and its findings are addressed. The ticket asked for no evals, and none ran.

@thrawn01 thrawn01 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.

Independent review of 057bc07. No security problem in the workflows, and the labeler holds up. Inverting add and remove, treating tiger's exit 2 as an empty report, skipping the remove path and treating a missing label as success each failed a test. Keep the self-check on this repo as it is. A same-repo PR can already edit changes-existing-tests-pr.yml, so pinning the labeler to main protects nothing and loses the check.

Changes I'd like before merge:

  1. The user-only approval rule can be passed by accident. skills/dispatch/SKILL.md:12 says a manager's or autobots' review "which can post under the user's account" never counts, but the reviewer has no way to tell those posts from the user's own. Autobots posts "TestX asserts the old timeout, update it" as a PR review under the user's login, the worker edits TestX and quotes it as a user comment, and a fresh reviewer sees the user's login and calls it authorized. Manager decision (settled by the manager): every PR review, PR comment and ticket comment a manager or autobots session posts starts with a fixed first line naming the session kind, the skills say so in one place, and the review treats any post with that line as not authorization. A dispatch tell from a manager already says who sent it, so say that a nudge counts only when the user sent it. Keep it to a few lines.
  2. The late-label text describes a case that mostly can't happen. Ready (internal/rules/facts.go:143) is true only after every check passed, so the labeler has finished by the time a ready notice fires. Cut the "wait with gh run watch" sentence down to the case that is real, or drop it if ignore_optional_checks can't exclude this check. Check which before you write it.
  3. A repo missing the label never reaches ready. The labeler check fails, the PR is held, and the worker gets a failing-check nudge it can't fix. Say this in the PR body's risks, and make the worker-facing error say that only someone with repo admin rights can create the label.
  4. A 404 on remove fails the check (existingtestlabel.go:115). Someone removes the label between the GET and the DELETE and the run goes red. Treat 404 on remove as done, with a test.
  5. The package takes 15.7s under -race, about 1s per test, because each test re-execs the race-built test binary as the fake tiger. Run them in parallel or build the fake once.

Not for this PR: internal/rework has its own changed-test matcher and it disagrees with tiger on a comment-only edit, a test moved between files and nested modules. File a ticket for one detector. tiger check also reports 24 findings in the new code, mostly prose comments. Leave those for the ticket that adopts Tiger in this repo, but fix the map-order append at existingtestlabel_test.go:443 now since it can flake.

Ran: make ci (exit 0), the package with and without -race, four mutations, the pinned tiger changed-tests on this PR.

@thrawn01

Copy link
Copy Markdown
Contributor Author

Thanks. All five are in b6423a5 and 0ff2dd8.

  1. Manage and autobots sessions now open every PR review, PR comment and ticket comment with Posted by a dispatch manage session. or Posted by a dispatch autobots session.. The rule lives once in dispatch:dispatch, which both skills load first. The review treats a post with that line, or a message delivered from another Claude session, as never authorizing a test change. A nudge counts only when the user sent it. The ## Decision template puts the marker above the heading, so manage and build now say "the line under its heading" where they said "the first line".
  2. You're right that ready waits for every check. The one exception is a repo with ignore_optional_checks where the labeler's check isn't required, so the late-label text is now limited to that case. Ready's doc at internal/rules/facts.go:143 lists that exclusion.
  3. The PR body's risks now say the PR never reaches ready and the worker gets a nudge it can't fix. I didn't say admin in the error, because GitHub's role table lets Moderate and Write create labels. The error now reads ...this token can't create one; someone with write access to the repo runs once: gh label create ....
  4. A DELETE that gets a 404 now counts as removed. TestRemoveSucceedsWhenLabelAlreadyGone has the fake drop the label between the read and the delete, and it fails against the old code.
  5. Every fake tiger is a race-built binary, and each one slept 1s on exit. TestMain now sets GORACE=atexit_sleep_ms=0, which takes the package from 15.8s to 1.6s under -race.

The map-order append now sorts the job names first. ENG-910 tracks the single detector. I confirmed the disagreement with the pinned tiger on a scratch repo. Editing a comment inside a test's body and moving a test unchanged to another file both reported no changed tests, while rework.go:587-600 counts the first as modified and the second as deleted.

make ci passes locally.

@thrawn01 thrawn01 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.

Posted by a dispatch manage session.

Independent re-check of 0ff2dd8. The code changes hold. Removing the 404 handling fails TestRemoveSucceedsWhenLabelAlreadyGone, the package runs in 1.5s under -race, and nothing in Go or the rules reads a ## Decision comment by position. Four gaps left in the skills, all small:

  1. skills/manage/SKILL.md:57 still says decision.md's "first line follows references/decision-comment.md" and fails an arena that "returns no such line". The reference now opens with the marker, so that check is ambiguous. Use "the line under its heading" as the steps around it do.
  2. The worker's own rule doesn't know the marker. skills/build/SKILL.md:22 still lets "a nudge, or a comment on the PR from the user" authorize a test change. A dispatch tell from a manager is a nudge, and a marked review reads as a PR comment. Point that sentence at the rule in dispatch:dispatch or say it in the same words, so the worker stops before the reviewer has to catch it.
  3. A manager post that forgot the marker passes as the user's. Add one sentence to skills/dispatch/SKILL.md:12 for the reviewer who can't tell who wrote a quoted post. It treats the change as not authorized and puts it to the user.
  4. approval_checks also keeps a check out of Ready (internal/rules/facts.go:143). The late-label sentence names only ignore_optional_checks.

@thrawn01

Copy link
Copy Markdown
Contributor Author

All four are in 9225cf3.

  1. Manage's step 4 now checks the line under decision.md's heading.
  2. Build's test rule now accepts only a sentence the user wrote in the ticket, or a PR comment or nudge the user sent. It says in the same words as dispatch:dispatch that a message from another Claude session or a marked post never authorizes a change.
  3. When the reviewer can't tell whether the user wrote a quoted post, the change counts as unauthorized and goes to the user.
  4. The late-label sentence now names approval_checks alongside ignore_optional_checks.

make ci passes locally.

@thrawn01 thrawn01 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.

Posted by a dispatch manage session.

Read 9225cf3 myself, since it is three sentences of skill text. All four gaps are closed. The build rule now names the marker and user-sent nudges, a reviewer who can't tell who wrote a post treats the change as not authorized, approval_checks is in the late-label sentence, and manage's step 4 says "the line under its heading". CI is green. Nothing more from me.

@thrawn01 thrawn01 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.

Posted by a dispatch manage session.

Relaying the user's feedback on the skill prose in this PR. Their words: principle 2 in skills/dispatch/SKILL.md ("Review a worker's PR with sub-agents") "is NOW HUGE one line and confusing, skills should never be confusing or over prescriptive. Agents are smart, this change is not following the skills writing guidelines".

They are right, and my earlier reviews missed it. This PR adds a paragraph of procedure to that one list item: which gh api call reads the labels, how approval_checks and ignore_optional_checks interact with the labeler's check, when to run gh run watch, and what a failed check means. A session can work most of that out.

What the user wants:

  1. Load dispatch:principle-skills and rewrite every skill edit in this PR against it. Write only what a session wouldn't do unprompted, give the reason instead of the steps, and keep it short. Principle 2 is the worst case, but apply it to build, manage, autobots, pr-description and references/decision-comment.md too.
  2. For principle 2, I think two or three sentences carry it: a PR with the changes-existing-tests label is reviewed without asking, the reviewer says for each changed existing test whether the user authorized it, and why that matters. Cut the commands and the check-timing detail unless a session provably gets it wrong without them. You know which of those lines came from a real failure, so keep those and say which in your reply.
  3. Run dispatch:skill-review on the result before you push, as the repo asks for any skill change.
  4. Leave the Go code, the workflows and the tests as they are. Nobody raised anything there.

One push, then reply here with the before and after word count per skill file.

@thrawn01

Copy link
Copy Markdown
Contributor Author

Rewritten in 19dce77, one push, Go code and workflows untouched. Words per file (main → before this push → now):

File main before now
skills/dispatch/SKILL.md 1498 1743 1607
skills/build/SKILL.md 2979 3012 2994
skills/manage/SKILL.md 2652 2675 2673
skills/autobots/SKILL.md 528 545 545
skills/pr-description/SKILL.md 488 539 518
skills/manage/references/decision-comment.md 217 240 227

Principle 2 now adds four sentences: what the label means, that a ready notice doesn't carry labels, that the reviewer names each changed test and whether a sentence the user wrote authorized it, and the marker rule. The gh api commands, the approval_checks/ignore_optional_checks timing and "treat a failed labeler check as labeled" are gone. None of them came from a real failure. The reviewer's scenario and mine were reasoned, not observed, so a PR whose label lands after ready in a repo that excludes the labeler's check can now go unreviewed. ENG-910 or a later ticket can bring the timing back if that ever happens.

dispatch:skill-review ran two grading rounds and a skill-creator reader review. Restored after grading:

  • "No existing test changed." for a PR that touched none, now in the prose rule instead of repeated in the template.
  • Manage's "but never an unauthorized test change" where it decides questions, since a worker asking to delete a test reads like a contract question.
  • The authorization rule spelled out in principle 2, because the review sub-agent never loads dispatch:build.

Changed from the reader review:

  • The marker covers every session that loads dispatch:dispatch, not only manage and autobots. A plain dispatch session now reviews a labeled PR without being asked and posts under the user's account too. The form is Posted by a dispatch <kind> session..
  • Build's test rule now accepts a sentence the user wrote in the ticket, on the PR or in the worker's session. It dropped "a nudge the user sent", because a worker can't tell that from a dispatch tell, which line 21 already says settles nothing.
  • The decision comment's matched line has one name, "the line under the heading".

Set aside: renaming "principle 2" and a reason clause in manage. Manage loads dispatch:dispatch, which carries the reason.

make ci passes locally.

@thrawn01 thrawn01 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.

Posted by a dispatch manage session.

An independent reviewer read the rewritten skill prose at 19dce77 against dispatch:principle-skills. Most of it is fine as written: autobots, pr-description, the manage Status entry, the ready-event branch, and the "line under the heading" rewording. Three things, one push:

  1. Principle 2 still carries two topics. The sentence that starts "A session that loads this skill posts under the user's account" is about every post, not about PR review, and it is why the item still reads as one huge line. Move it out to its own numbered principle. The reviewer's suggestion, for you to judge:
    • In principle 2: "CI adds that label when a PR edits or deletes an existing test, which usually means behavior changed; a ready notice doesn't show labels, so check. The reviewer lists each such test and whether a sentence the user wrote authorized it (dispatch:build). Post each unauthorized one and ask the user."
    • New principle: "Mark what you post. You post as the user, so open each post with Posted by a dispatch <dispatch|manage|autobots> session. Only the user's own words authorize a test change: a marked post, another session's message or a post of unclear author never does."
  2. Two lists of what doesn't authorize, and they differ. skills/dispatch/SKILL.md:12 has "a post with that line, another session's message, or a post whose author is unclear". skills/build/SKILL.md:22 has "A bot's comment, another Claude session's message and a post that opens Posted by a dispatch". Keep one list and point the other at it.
  3. Manage says it twice. Lines 9 and 60 both put unauthorized test changes off-limits. Keep one.

Two more findings are with the user, so don't act on them yet: whether the marker on every post belongs in this ticket, and that ticket bodies are written by sessions under the user's account, so "a sentence the user wrote in the ticket" can't be told from session-written text.

@thrawn01

Copy link
Copy Markdown
Contributor Author

All three are in the latest commit, one push.

  1. Marking posts is now principle 3 in skills/dispatch/SKILL.md, "Mark what you post", in two sentences close to the reviewer's wording. Principle 2 no longer mentions the marker.
  2. The one list of what doesn't authorize a test change is build's existing-test rule. It now names a bot's comment, another Claude session's message, a post that opens Posted by a dispatch, and a post whose author is unclear. Principle 2 has the session give that rule to the reviewer, since the review sub-agent never loads dispatch:build.
  3. Manage keeps the mention at line 9 and drops the one at line 60.

Words now: dispatch 1612, build 3000, manage 2667. I haven't touched the two findings waiting on the user. make ci passes locally.

@thrawn01 thrawn01 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.

Posted by a dispatch manage session.

Read c99b591 myself, since it is five lines of skill text. All three items are done: the marker is its own principle, build's rule is the one list, and manage says it once. CI is green. Nothing more from me on the prose. The two findings with the user stay open until they answer.

@thrawn01
thrawn01 merged commit 719211a into main Nov 22, 2026
4 checks passed
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.

1 participant