三人、七台电脑。1 到 3 号机跑编码代理,4、5 号机审查,6 号机做 Windows 验证,7 号机负责合入。工单写得很具体:给已支付、尚未发货的订单加改地址接口;状态是 shipped 或 delivered 时必须拒绝。验收是 pytest -q 为绿。既有的订单导出保持原样:一次最多 1000 行,避免单次请求把整个客户底表(邮箱、地址、卡号后四位)拉走。
2 号机上的代理按工单改了 update_address,打开了一份看起来干净的 PR。4 号机看的是改地址的 diff,测试 5 通过,导出文件没有出现在这一笔提交里。4 号机批准了。几分钟后,同一份 PR 上又多了一笔提交,说明写的是给夜间对账提高导出批量。默认测试还是 5 通过。7 号机看到「已经批准」,就把两笔提交一起 squash 进了 main。main 上的导出上限变成了 100000。
这篇要核对的是:在「合并前需要一份批准」已经打开的前提下,为什么批准之后再推上来的提交,仍能按原来那份批准合进去;打开「推送新提交时作废旧批准」之后,同样的后续提交会在哪一步被拦住;以及只加一行注释,会不会也被当成需要重新批准的改动。它和 给 PR 贴了 docs-only,失败的必检测试变成 Skipped,导出脚本合进了 main 谈的是路径过滤让测试根本没跑,和 审查意见都标成已解决之后,部分退款仍然没有把货加回库存 谈的是把对话标成已解决却没改到行为,都不是同一件事。今天只谈:批准指向的是当时那份 diff,不是最后要合进去的 HEAD。
我在 GitHub 上建了一个公开的实验室仓库 shuizhengqi1/iotxing-lab-stale-approval-20261130。夹具提交是按常见的分单写法准备的,并没有再开一个编码模型来生成这些 diff。实验室邮箱是 zhou@shop.invalid 这一类,卡号后四位是 1111,都不是真实用户。为了让「作者」和「批准人」不是同一个人,PR 由 github-actions[bot] 打开,批准由 shuizhengqi1 来做。仓库规则集 28384594 保护 main,要求 1 份批准,管理员不可绕过(current_user_can_bypass 为 never)。合并时没有加 --admin。
种子提交里只有导出,上限 1000,还没有改地址接口。PR #1 的第一笔提交 07ddd901ef42(07ddd901ef4263f3b726c7da74de21ee3c2bf5eb)发生在 2026-11-30 18:50:27(Asia/Shanghai),加上了 update_address,并对已发货、已签收写了拒绝测试。这时 pytest -q 是 5 passed,EXPORT_LIMIT 仍是 1000。18:50:48,我以 shuizhengqi1 批准了这一笔,评语写的是:改地址会拒绝已发货和已签收,测试是绿的,导出不在这份 diff 里。GitHub 返回的 reviewDecision 是 APPROVED,mergeStateStatus 是 CLEAN,批准记录指向的 commit 正是 07ddd901ef42。
不到一分钟后,同一机器人又推了 08fd6f30a978(08fd6f30a97848948d0ad44b6f4e8b5d053eb268),时间是 18:51:03,标题是 chore: raise export batch size for nightly reconciliation。文件里多了一行注释,说 1000 行会截断夜间对账,然后把 EXPORT_LIMIT 改成 100000。默认测试仍是 5 passed。我另外跑了一个不在默认测试里的探测脚本:给 5000 笔夹具订单做导出。上限 1000 时只会写出 1000 行;上限改成 100000 之后,5000 行全部出来。
此时规则集里的 dismiss_stale_reviews_on_push 是 false。我再次读取 PR #1:reviewDecision 仍是 APPROVED,那份批准的 state 仍是 APPROVED,没有变成 DISMISSED,指向的仍是 07ddd901ef42,不是新的 HEAD 08fd6f30a978。mergeStateStatus 为 CLEAN,mergeable 为 MERGEABLE。18:53:49,gh pr merge --squash 成功,合并提交是 fedc8cd70812(fedc8cd70812711c078d578a535e39d78588867e)。main 上的 export.py 里,上限已经是 100000。我对合并后的树再跑默认测试和探测:仍是 5 passed,5000 笔进、5000 行出。

机制并不神秘。GitHub 把批准记在某一笔 commit 上。关闭「推送新提交时作废旧批准」时,后来推上来的提交不会让这份记录过期,reviewDecision 仍按「已经有一份有效批准」来算。7 号机如果只看这个字段,看到的就是可以合。规则集仍然在生效:没有批准时,同一份保护会把 PR 标成 BLOCKED,我在批准之前读到的就是这个状态。缺的不是「要批准」本身,而是「这份批准必须描述即将合进去的那份 diff」。
在三人、七台电脑的节奏里,这件事会更常见。1 到 3 号机上的代理不会等 4 号机把页面关掉再动手:审查通过之后,它们常常继续推「顺手改一下」的提交,标题也写得像运维请求。4 号机如果还停在第一份 diff 上,或者 7 号机只轮询 reviewDecision,中间多出来的那一笔就不会再被当作新的审查对象。打开必选审查,只说明「曾经有人点过批准」,并不说明「当前这棵树被人看过」。代理把后续提交推得越快,这两件事之间的缝就越大。
默认测试也帮不上忙。三笔夹具订单无论上限是 1000 还是 100000,导出行数都是 3。代理把上限改掉之后,验收命令仍然全绿。真正挡住客户底表被一次拉走的,是那个常量,不是这 5 条测试。
我写了一个合入前可以跑的小闸门 approval_sha_gate.py。它读 gh pr view --json reviews,commits,取出时间最近的一份 APPROVED,要求它的 commit SHA 必须等于 PR 当前的 HEAD。批准当时,闸门通过,两边都是 07ddd901ef42。后续提交推上来之后,闸门退出码是 1:批准仍指向 07ddd901ef42,HEAD 已经是 08fd6f30a978。GitHub 此时仍允许合并。把这个检查放到 7 号机的合入脚本里,或者做成必检,不必等规则集先改掉默认值。

为了对照,我把同一份规则集的 dismiss_stale_reviews_on_push 改成 true,其他条件不变,并把 main 上的上限恢复成 1000。PR #2 的第一笔 e40dfdc94d75(e40dfdc94d754808d27b598e87c26d33eb3cecb1)只改了拒绝改地址时的错误信息,让仓库界面能看到当时的订单状态,导出上限没有动。18:56:00 批准后,状态同样是 APPROVED 和 CLEAN。随后机器人推上与实验 A 相同的改上限提交 d3b58b09a620(d3b58b09a620b41c4b2b68c82c486b2ea2bad337)。这次两份批准都变成 DISMISSED,reviewDecision 变成 REVIEW_REQUIRED,mergeStateStatus 是 BLOCKED。gh pr merge --squash 失败,提示是 the base branch policy prohibits the merge。main 上的上限仍是 1000。mergeable 这时仍可能是 MERGEABLE,它只表示没有冲突,并不表示规则允许合入。
打开作废之后,什么样的后续提交会触发作废,需要单独看,不能从「改了上限」这一种情况推过去。我起初在 PR #2 上推过一笔标题像文档的提交,后来核对 patch,发现它不但加了注释,还把前一笔刚加上的错误信息改了回去,不能当作「只改注释」的证据。于是另开了 PR #3。第一笔 1bc17505f631(1bc17505f631c233aebf7bff3334179b309c843b)同样是给拒绝原因加上状态,18:59:19 批准。随后只在 address.py 增加一行注释(f5397b5e57a4,f5397b5e57a41c0c07b1b99d60cee8b1a9ea4dc5),行为没有改。这一笔是实验室机器用 iotxing-lab 身份推的,不是 github-actions[bot]。批准被标成 DISMISSED,reviewDecision 为 REVIEW_REQUIRED,合并状态为 BLOCKED。文档里说的是 code-modifying commit;在这次实测里,源文件里多一行注释,就已经足以作废批准。
这就是代价。打开作废旧批准之后,代理再补一行注释、改一个错别字,4 号机都要再点一次。按 GitHub 文档,点击 Update branch、或者合并基线因为主干前移而变化,也会作废批准;这两条路径本次没有实测。繁忙的主干上,如果还要求分支必须与主干同步,就可能出现「批准、更新、作废、再批准」的循环。文档把合并队列当作缓解办法,本次也没有把合并队列跑一遍。即使打开了作废,第二次批准仍然只是一次点击:4 号机如果不再打开新的 diff,只是再点一次批准,规则并不会要求他把后来那笔改上限的提交读完。需要把「谁推了最后一笔」也卡住时,还要另外打开 require_last_push_approval。这一项本次没有实测,不能写成已经验证过的结果。
有绕过权限的账号仍然能合。这次规则集把 current_user_can_bypass 设成了 never,实验 A 的合并也没有使用 --admin。如果 7 号机上的合入机器人被写成绕过者,前面这些检查都不会生效。闸门要写在「不能绕过」的规则集里,或者写在那个机器人自己拒绝执行 gh pr merge --admin 的脚本里。

明天可以抄走的做法很具体。第一,在保护默认分支的规则集里打开 dismiss_stale_reviews_on_push,让会改 diff 的新提交作废旧批准。第二,7 号机合入前跑 approval_sha_gate.py:最新一份 APPROVED 必须等于当前 HEAD,对不上就拒绝合并;即使规则集还没改,这道闸门也能拦住实验 A 那种情况。第三,审查评语里写上当时看到的 HEAD SHA,不要只写「测试绿了,可以合」。第四,像导出上限这种默认测试碰不到的策略常量,要单独做探测,并把探测设为必检;3 笔订单的用例不会因为上限变成 10 万而变红。
它不适用的地方也要说清。如果每份 PR 合入前都会由同一个人把最终 diff 再读一遍,而且团队愿意承担漏读的风险,作废旧批准带来的复查成本可能大于收益。如果合入本来就不要求批准,这篇文章里的规则集检查不会出现;那时更需要的是别把合并权限交给会继续推代码的代理。实验室没有在 Windows 上跑测试,也没有用现场编码模型来生成这些提交。仓库一度短暂关闭过规则集,是为了修正工作流 YAML,以及在两组实验之间把上限恢复成 1000;正文里的合并结果,都是在规则集重新打开、且管理员不可绕过时取得的。为了让机器人能打开 PR,仓库打开了 GitHub Actions 创建拉取请求的权限;机器人没有批准这些 PR。
实际跑了什么
- 公开实验室:shuizhengqi1/iotxing-lab-stale-approval-20261130,规则集 28384594。本地:git 2.47.3、Python 3.13.5、官方
gh2.103.0。Actions 上的 Python 是 3.13.18。 - 实验 A(作废关闭):PR #1。第一笔
07ddd901ef42(18:50:27,Asia/Shanghai),18:50:48 批准;后续08fd6f30a978(18:51:03)把上限改为 100000。批准仍为APPROVED。18:53:49 squash 成功,合并提交fedc8cd70812。合并后的树上默认测试 5 passed,5000 笔探测导出 5000 行。 approval_sha_gate.py在批准当时通过,后续提交之后退出码 1。- 实验 B(作废打开):PR #2。后续改上限提交
d3b58b09a620后,批准为DISMISSED,gh pr merge被分支策略拒绝,main 上限仍是 1000。 - 实验 C(一行注释):PR #3。
f5397b5e57a4只增加一行注释,批准被作废,合并状态为BLOCKED。该后续提交由实验室身份iotxing-lab推送。 - 未跑:Windows 或
windows-latest、现场编码模型、require_last_push_approval、点击 Update branch、合并队列。可复制的脚本和夹具在 stale-approval-kit.tar.gz。下一步是打开作废旧批准,并在合入前检查批准 SHA 是否等于 HEAD。
Three people, seven computers. Machines 1 to 3 run coding agents, 4 and 5 review, 6 does Windows validation, and 7 merges. The ticket was specific: add an address-change API for paid orders that have not shipped; if the status is shipped or delivered, the call must be rejected. Acceptance is a green pytest -q. The existing order export stays as it is: at most 1000 rows in one request, so a single call cannot pull the whole customer base (email, address, card last four).
The agent on machine 2 added update_address as the ticket asked and opened a PR that looked clean. Machine 4 reviewed the address-change diff. Tests were 5 passed, and the export file was not in that commit. Machine 4 approved. A few minutes later the same PR grew another commit, titled as raising the export batch for nightly reconciliation. The default tests were still 5 passed. Machine 7 saw that the PR was approved and squash-merged both commits into main. The export cap on main became 100000.
This post checks the following: when required reviews are already on, why a commit pushed after approval can still merge under that same approval; where the same follow-up is stopped once "Dismiss stale pull request approvals when new commits are pushed" is on; and whether adding a single comment line also counts as a change that needs a new approval. This is not the same layer as The docs-only label skipped the failing required tests, and the export script still merged, which is about path filters skipping CI, or After every review thread was marked resolved, the partial refund still did not restock, which is about resolving a thread without changing behavior. Today is only about this: an approval points at the diff as it was, not at the HEAD that is about to merge.
I created a public lab repository, shuizhengqi1/iotxing-lab-stale-approval-20261130. The fixture commits are written in the shape of a typical split ticket. I did not start a coding model to produce the diffs. The lab emails are of the form zhou@shop.invalid, and the card last four is 1111; they are fixtures, not real people. So that the author and the approver would not be the same person, pull requests were opened by github-actions[bot] and approved by shuizhengqi1. Repository ruleset 28384594 protects main, requires one approving review, and does not allow the owner to bypass (current_user_can_bypass is never). Merges did not use --admin.
The seed commit had only the export, with a cap of 1000, and no address-update API yet. The first commit on PR #1, 07ddd901ef42 (07ddd901ef4263f3b726c7da74de21ee3c2bf5eb), at 2026-11-30 18:50:27 (Asia/Shanghai), added update_address and tests that reject shipped and delivered orders. pytest -q was 5 passed, and EXPORT_LIMIT was still 1000. At 18:50:48 I approved it as shuizhengqi1, writing that address changes reject shipped and delivered orders, that tests were green, and that export was not in this diff. GitHub reported reviewDecision as APPROVED and mergeStateStatus as CLEAN, and the approval record pointed at 07ddd901ef42.
Less than a minute later, the same bot pushed 08fd6f30a978 (08fd6f30a97848948d0ad44b6f4e8b5d053eb268), at 18:51:03, titled chore: raise export batch size for nightly reconciliation. The file gained a comment that 1000 rows was truncating nightly reconciliation, and EXPORT_LIMIT became 100000. The default tests were still 5 passed. I also ran a probe that is not in the default suite: export 5000 fixture orders. With a cap of 1000, only 1000 rows were written; after the cap became 100000, all 5000 rows came out.
At that point dismiss_stale_reviews_on_push in the ruleset was false. I read PR #1 again: reviewDecision was still APPROVED, the review's state was still APPROVED rather than DISMISSED, and it still pointed at 07ddd901ef42, not at the new HEAD 08fd6f30a978. mergeStateStatus was CLEAN and mergeable was MERGEABLE. At 18:53:49, gh pr merge --squash succeeded. The merge commit is fedc8cd70812 (fedc8cd70812711c078d578a535e39d78588867e). On main, export.py now had a cap of 100000. I reran the default tests and the probe on the merged tree: still 5 passed, 5000 orders in, 5000 rows out.

The mechanism is not mysterious. GitHub records an approval against a particular commit. When stale dismissal is off, a later push does not expire that record, and reviewDecision still means "there is a valid approval". If machine 7 only looks at that field, the PR looks ready to merge. The ruleset was still in effect: before the approval, the same protection marked the PR BLOCKED. What was missing was not "a review is required", but "the approval must describe the diff that is about to merge".
On a three-person, seven-machine cadence this happens more often. The agents on machines 1 to 3 do not wait for machine 4 to close the page: after an approval they often keep pushing "while we are here" commits, with titles that read like operations requests. If machine 4 is still looking at the first diff, or machine 7 only polls reviewDecision, the extra commit is never treated as a new review. Turning on required reviews only means someone approved at some point. It does not mean the tree that is about to merge has been read. The faster the agent pushes a follow-up, the wider that gap becomes.
The default tests do not help. With three fixture orders, the exported row count is 3 whether the cap is 1000 or 100000. After the agent changed the cap, the acceptance command stayed green. What actually stopped a full customer-base dump was that constant, not these five tests.
I wrote a small pre-merge gate, approval_sha_gate.py. It reads gh pr view --json reviews,commits, takes the most recent APPROVED review, and requires that its commit SHA equal the PR's current HEAD. At approval time the gate passed: both sides were 07ddd901ef42. After the follow-up it exited 1: the approval still pointed at 07ddd901ef42, and HEAD was already 08fd6f30a978. GitHub still allowed the merge. Putting this check in machine 7's merge script, or making it a required check, does not have to wait for the ruleset default to change.

For the control, I set dismiss_stale_reviews_on_push to true on the same ruleset, left the other conditions unchanged, and restored the cap on main to 1000. The first commit on PR #2, e40dfdc94d75 (e40dfdc94d754808d27b598e87c26d33eb3cecb1), only changed the rejection error so the warehouse UI can see the order status. The export cap was untouched. After the approval at 18:56:00, the state was again APPROVED and CLEAN. The bot then pushed the same limit-raising commit as in experiment A, d3b58b09a620 (d3b58b09a620b41c4b2b68c82c486b2ea2bad337). This time both approvals became DISMISSED, reviewDecision became REVIEW_REQUIRED, and mergeStateStatus was BLOCKED. gh pr merge --squash failed with the base branch policy prohibits the merge. The cap on main stayed 1000. mergeable can still be MERGEABLE in this state; that only means there is no conflict, not that policy allows the merge.
Once dismissal is on, you have to measure which follow-ups trigger it; you cannot infer that from the limit-change case alone. I first pushed a commit on PR #2 whose title looked like documentation. The patch showed that it not only added a comment, it also reverted the error-message change from the previous commit, so it is not evidence about comments alone. I opened PR #3 instead. The first commit, 1bc17505f631 (1bc17505f631c233aebf7bff3334179b309c843b), again added the status to the rejection error, and was approved at 18:59:19. The next commit, f5397b5e57a4 (f5397b5e57a41c0c07b1b99d60cee8b1a9ea4dc5), only added one comment line in address.py and did not change behavior. That follow-up was pushed from the lab machine as iotxing-lab, not as github-actions[bot]. The approval was marked DISMISSED, reviewDecision was REVIEW_REQUIRED, and merge was BLOCKED. The docs talk about a code-modifying commit; in this run, one extra comment line in a source file was enough to dismiss the approval.
That is the cost. With stale dismissal on, another comment line or typo fix from the agent sends the PR back to machine 4. GitHub's documentation also dismisses an approval when someone clicks Update branch, or when the merge base moves because main has advanced; those paths were not tested in this lab. On a busy default branch that also requires the branch to be up to date, the sequence can become approve, update, dismissed, approve again. The docs present a merge queue as a way to reduce that loop; this lab did not run a merge queue. Even with dismissal on, the second approval is still a click: if machine 4 does not open the new diff and only approves again, the rule does not require a second reading of the later limit change. If you also need to stop the last pusher from being the sole approver, that is a separate setting, require_last_push_approval. It was not tested here, and I am not reporting it as a verified result.
An actor with bypass can still merge. This ruleset set current_user_can_bypass to never, and the merge in experiment A did not use --admin. If the merge bot on machine 7 is listed as a bypass actor, none of the checks above will hold. The gate belongs in a ruleset that cannot be bypassed, or in a script that refuses to run gh pr merge --admin.

The copyable steps for tomorrow are specific. First, turn on dismiss_stale_reviews_on_push in the ruleset that protects the default branch, so a new commit that changes the diff dismisses the old approval. Second, run approval_sha_gate.py on machine 7 before merging: the latest APPROVED review must equal the current HEAD, or refuse the merge. That gate would have stopped experiment A even before the ruleset default changed. Third, put the HEAD SHA that was reviewed into the review comment; do not only write that tests are green and the PR can merge. Fourth, give policy constants that a tiny suite will not hit, such as an export cap, their own probe, and make that probe required; a three-order test will not turn red when the cap becomes 100000.
The limits should be stated clearly. If every PR is re-read in its final form by the same person before merge, and the team accepts the risk of a skimmed second look, the re-review cost of stale dismissal may outweigh the benefit. If merging does not require a review at all, the ruleset checks in this post do not appear; then the more urgent problem is not to give merge rights to an agent that keeps pushing. This lab did not run tests on Windows, and it did not use a live coding model to produce the commits. The ruleset was briefly disabled twice: once to fix workflow YAML, and once to restore the cap to 1000 between the two experiments. The merge results in the body were taken after the ruleset was active again, with no admin bypass. To let the bot open pull requests, the repository allowed GitHub Actions to create pull requests; the bot did not approve them.
What was actually run
- Public lab: shuizhengqi1/iotxing-lab-stale-approval-20261130, ruleset 28384594. Local: git 2.47.3, Python 3.13.5, official
gh2.103.0. Python on Actions was 3.13.18. - Experiment A (dismissal off): PR #1. First commit
07ddd901ef42(18:50:27, Asia/Shanghai), approved at 18:50:48; follow-up08fd6f30a978(18:51:03) set the cap to 100000. The approval stayedAPPROVED. Squash merge succeeded at 18:53:49, merge commitfedc8cd70812. On the merged tree the default tests were 5 passed, and a 5000-order probe exported 5000 rows. approval_sha_gate.pypassed at approval time and exited 1 after the follow-up.- Experiment B (dismissal on): PR #2. After the limit-raising follow-up
d3b58b09a620, approvals wereDISMISSED,gh pr mergewas refused by branch policy, and the cap on main stayed 1000. - Experiment C (one comment line): PR #3.
f5397b5e57a4added only one comment line, the approval was dismissed, and merge wasBLOCKED. That follow-up was pushed as lab identityiotxing-lab. - Not run: Windows or
windows-latest, a live coding model,require_last_push_approval, clicking Update branch, or a merge queue. Reproducible scripts and fixtures are in stale-approval-kit.tar.gz. The next step is to turn on stale dismissal, and to check that the approval SHA equals HEAD before merging.