AI

审查意见回来时,同一份工作区里已经写下了下一单未完成的重试(中英切换)

This post is currently available in Chinese only. The original text follows.Open the Chinese page →

三人、七台电脑。1 到 3 号机跑编码代理,4、5 号机审查,6 号机做 Windows 验证,7 号机负责合入。审查不是瞬时的。4 号机读一张验签 PR 的时候,1 号机上的代理很少闲着——人会说“先做下一单”,代理自己也会去找下一张票。最省事的做法,是留在刚刚推过 PR 的那份检出里,直接改下一份文件。

周一,1 号机的代理交了一张支付 webhook 验签的 PR。main 上的实现先把请求解析成字典,再对 json.dumps(parsed) 做 HMAC,和提供商在原始请求体上的签名对不上。我在本机复现了这件事:main 的起点是 67c271e,用原始字节签出来的合法请求会被拒绝;两条测试里挂 1 条、过 1 条,那条通过的是“篡改后应拒绝”——它通过,是因为坏掉的校验几乎什么都拒。功能分支 feat/webhook-verify 上的 d5c8a27 改成校验原始请求体,测试 2 通过。PR 开出去,等 4 号机。

代理没有换目录。它在同一份检出里开始写下一单:下游账单接口返回 503 时自动重试。retry_downstream 写进了同一份 webhook.py,没有幂等键。这还只是未提交的修改。我跑了原有那两条测试,仍然 2 通过。它们第一次调用下游就成功,根本不会走到重试。预检脚本 task_switch_preflight.py 在干净的 PR 分支上是 ALLOW,写下重试之后变成 REFUSE,脏文件是 M webhook.py。

4 号机的意见很具体:还要拒绝时间戳超过 300 秒的事件。代理就在这份已经脏了的树上加了 event_is_stale,然后 git add -A,提交说明只写了审查修复。提交是 1df303b。测试 3 通过。提交里已经有 retry_downstream。探针里,一次 503 会向账单下游连写两次,返回却是 ok。

如果 7 号机只问测试绿不绿,或只问审查之后有没有新的生产文件,合入脚本都会把 main 从 67c271e 快进到 1df303b。我实测了这两种模式,都是 MERGED。按符号的闸门拒绝了,main 留在 67c271e——但它拒绝的名单里,既有 retry_downstream,也有这次审查真正要的 event_is_stale 和 STALE_AFTER。

这篇要核对的是:审查意见回来时,工作区里是不是只剩这一张票;代理常用的 git add -A、reset --hard、stash pop、switch --force,分别会把下一单怎么样;怎样才不会把未完成的重试交进原来的 PR,同时又不会把下一单毁掉。它和 做到一半的代理任务要换台机器接着干 谈的是跨机器交接,和 审查机点了 Request changes,开这个 PR 的代理会话已经关了 谈的是谁来接下一刀,都不是同一件事。今天只谈同一台机器、同一份检出里,审查等待和下一项任务叠在一起的时候。

审查意见回到同一份脏工作区时,下一单会被一并交进去

实验室怎么搭

我在本机初始化了一个玩具仓库,默认分支 main 的起点是 67c271e。webhook 用 t= 和 v1= 的头做 HMAC-SHA256,签名对象应当是时间戳加原始请求体。main 上的实现却对重新 dumps 出来的字典签名,所以提供商那种紧凑 JSON 的合法请求过不了。功能分支上的 A 是 d5c8a27:改成校验原始字节,测试仍是那两条。审查意见要求加上 300 秒的过期窗口,并补一条回归测试。未提交的下一单 B,是在同一份 webhook.py 里加入 retry_downstream,遇到 DownstreamBusy 就再发,最多三次,没有幂等键。

五种做法各自从同一份种子仓库克隆,互不影响:add_all 就地改审查意见并 git add -A;reset_hard 先硬复位再改;stash 先把 B 藏起来,审查修复提交之后再 stash pop;force_switch 先 git switch -c feat/webhook-retry 写下脏修改,再切回 PR 分支;worktree 把脏修改留在原工作区,另建一个 worktree 做审查修复。merge_if_isolated.sh 先在目标 SHA 的临时 worktree 里跑 pytest,再跑闸门,通过才对 main 快进。每次快进之后我都把 main 复位到 67c271e。探针 probe_billing.py 让第一次下游调用抛 503,看 POST_BILLING 实际被调用几次。

测试和探针都在本机 Linux 上跑。我没有把这个仓库推到 GitHub,也没有在 Actions 里跑工作流,YAML 只检查了结构。后面给出的短哈希都来自这一次运行;重建仓库时哈希会变,字段关系和判定不会变。

git add -A 会把下一单写进审查修复提交

审查回来时,最省事的动作是:还在这棵树上改,测过,全部加入,提交。1df303b 的说明是“address review: reject events older than 300s”,git diff d5c8a27..HEAD --stat 只列出 webhook.py 和 test_webhook.py,看起来完全像一张审查修复。但 git show HEAD:webhook.py 里已经有 retry_downstream。测试 3 通过,因为新增的过期测试和原来的验签测试都不触发 503。探针则是 billing_calls=2,double_post=true,status=ok。

只看测试的合入模式把 main 快进到了 1df303b。按文件的闸门也放行:审查之后没有出现新的生产路径,泄漏写在本来就属于这张 PR 的 webhook.py 里。按符号的闸门拒绝,列出的新符号包括 retry_downstream、DownstreamBusy、MAX_RETRIES,以及这次审查需要的 event_is_stale 和 STALE_AFTER。main 留在 67c271e。

还有一件必须分开说的事:我在提交之前,也在脏工作区里跑过测试。写下 B、还没改审查意见时,是 2 通过;加上过期检查和回归测试、尚未提交时,是 3 通过。代理如果把“我刚跑过、是绿的”当成提交的证据,看到的其实是工作区,不是即将被推出去的那棵树。这次两者碰巧都绿,所以更不容易发觉泄漏。合入脚本后来改在干净 worktree 里跑测试,仍然放行了 1df303b。测试绿挡不住写进同一文件的未完成功能。

reset --hard 和 switch --force 会把下一单毁掉

想给审查修复腾出一块干净的树,代理很自然会 git reset --hard。我这样做了:复位之后工作区是干净的,webhook.py 里没有 retry_downstream,stash 列表是空的。再写过期检查,提交 d9c5e5a,测试 3 通过,探针不再双写。PR 是干净的,下一单却不在工作区、不在 stash、也不在任何提交里。它就是没了。

force_switch 这一路更接近代理会做的“先开一条新分支”。从干净的 d5c8a27 执行 git switch -c feat/webhook-retry,写下未提交的重试,然后切回 feat/webhook-verify。我原先以为 Git 会拒绝这次切换,因为它看到脏文件。实测退出码是 0。两条分支当时指向同一个提交,未提交的修改可以干净地应用过去,于是脏的 webhook.py 被无提示地带回了 PR 分支,状态仍是 M webhook.py。泄漏在切回去的那一刻就已经发生了,还不用 git add。

随后我在已经位于 feat/webhook-verify 的脏工作区上执行了 git switch --force feat/webhook-verify。Git 报告 Already on this branch,工作区被清空,重试消失,stash 仍是空的。再写审查修复,提交是 07c902a,测试 3 通过,PR 里没有重试。下一单同样被毁掉。--force 并不是“确保我在正确的分支上”,它会丢掉这份检出里还没提交的下一单。

stash pop 在同一文件上冲突,三种解法三种后果

把 B 先藏起来再改审查意见,看起来更稳。git stash push -u -m "wip: downstream retry" 之后,我在干净树上写下过期检查,提交 cdd4f0d,测试 3 通过,探针不双写。这一刻 PR 是干净的。紧接着 stash pop 退出码 1:webhook.py 内容冲突,文件里有冲突标记,stash 被保留。

三种解法我都做了。取 stash 那一侧(--theirs)后,工作区里的 retry_downstream 回来了,event_is_stale 没了。审查修复的测试已经在提交里,调用的是 handle(..., now=1000),而 stash 那一版 handle 不接受这个参数,测试 3 失败,错误都是 TypeError: handle() got an unexpected keyword argument 'now'。探针仍然双写。也就是说,取“自己那单”会把刚刚提交的审查修复从工作区里撤掉。取审查修复那一侧(--ours),测试 3 通过,探针不双写,下一单从工作区里消失。两边都留下,再提交一次,得到 664883e:测试 3 通过,retry_in_commit=true,探针 billing_calls=2。下一单再次进入验签 PR。

stash 不是隔离,它只是推迟冲突。冲突发生在审查修复分支上,代理无论怎么解,都还站在这张 PR 的分支里。

新 worktree 能同时保住审查修复和下一单

正确的隔离是:不要在脏工作区里改审查意见。我把未提交的重试留在原来的检出里,再为审查修复另开一个 worktree。直接 git worktree add <path> feat/webhook-verify 失败了,退出码 128,提示这个分支已经在原来的工作区里被占用。这是 Git 的限制,不是脚本写错。改用 --detach 成功了,HEAD 停在 d5c8a27。然后在这个游离检出上切出 feat/webhook-verify-review,只写过期检查,提交 07c902a。测试 3 通过,提交里没有 retry_downstream,探针不双写。

原来的工作区仍在 feat/webhook-verify 上,状态仍是 M webhook.py,里面还有重试,没有过期检查。在这份脏树上跑原来的测试,仍是 2 通过;探针则是双写。这些绿测试仍然只描述脏工作区,不能当作 07c902a 的证据。审查修复的测试是在新 worktree 里、对着那个提交跑的。

force_switch 与 worktree 的审查修复提交哈希同为 07c902a。不是两个仓库共用了一次提交,而是两次提交的作者、说明、父提交、树和提交时间戳都相同(都在 2026-11-16 05:48:24 -0500,即当地 America/Fortaleza 时间 07:48:24)。树哈希都是 393aea2。哈希相同,只说明这两次审查修复的内容一样,不说明两条策略做了同一件事:前者在过程中丢掉了下一单,后者把它留在了原来的工作区。

五种处理审查意见的做法,这次实验室实际得到的结果

机制:工作区不是分支,测试看到的也不是提交

分支是指向提交的指针。工作区是一份可以脏的文件。代理说“我在这张 PR 的分支上”,这句话并不保证工作区里只有这张票的改动。未提交的下一单默认就叠在当前指针下面。git add -A 不会问这些改动属于哪一张票,它只看工作区。两条分支如果还指向同一个提交,git switch 也不会拦住脏文件,它会把下一单带走。

测试同样默认看工作区。本地绿、提交也绿,并不能说明提交里没有另一单的半成品——只要原有测试和审查回归都不触发那条半成品路径,两边就都会绿。这就是 1df303b 的情况。把测试挪到目标 SHA 的干净 worktree 里跑,只能保证你测到的是即将合入的那棵树,不能保证那棵树里没有泄漏。这次 tests-only 和 files 都在干净树上跑过,仍然把带重试的提交快进进了 main。

按文件的闸门比较的是路径。审查之后如果只改了本来就在 PR 里的文件,它看不见新函数。按符号的闸门用 AST 取出生产文件里新建的顶层函数、类和全大写赋值,所以它抓住了 retry_downstream。但也正因为如此,干净的审查修复一样会被拒绝:event_is_stale 和 STALE_AFTER 也是审查基线之后才出现的符号。符号结果更适合作为给 4 号机的提示——“这棵树上多了这些名字,请确认是不是审查要求的”——不适合当作唯一的合入条件。如果重试被内联进已有的 handle、不新增顶层名字,这次的两种闸门按设计都看不见;我没有单独跑内联那一变体,所以这不是一条实测结论,只是闸门范围上的限制,必须写明。

真正挡住泄漏的,不是更聪明的闸门,而是一开始就不要让两单共享一份脏工作区。预检在写下 B 之后拒绝继续在这里开工,就是这个意思。审查修复放到 PR 分支的新 worktree 里做,下一单要么继续留在原来的脏工作区,要么先 WIP 提交到旁路分支,不要 stash pop 回审查分支上接着写。

审查修复要在 PR 分支的新 worktree 里做,不要在脏检出里做

什么时候不该按这套做

如果你们的工具本来就为每一个会话、每一张票建独立 worktree——比如某些云端代理,或默认 worktree 模式的本地工具——再套一层“审查修复另开 worktree”收益很小。这时更值得检查的,是人会不会在同一会话里对代理说“顺手把下一单也做了”。

如果团队的规矩是 A 合进 main 之前绝不开始 B,这份叠票的问题很少出现。三人七机、代理通宵排票的节奏里,这个规矩往往守不住,因为审查队列本身就有等待。

不要把按符号的闸门设成唯一必过项。这次它会拒绝干净的 d9c5e5a、cdd4f0d 和 07c902a。若审查修复常常要加新的辅助函数,这个闸门会变成长期噪声。把它的输出交给审查机看可以,不要让 7 号机只靠它决定能不能快进。

merge_if_isolated.sh 必须明确切到 main 再快进。我第一版写错过:脚本在当时检出的审查分支上执行了 git merge --ff-only,却把 “MERGED” 打印出来,main 其实没有动。以当前检出为准去合主干,是这种脚本里很常见的错法。现在的脚本会先 switch 到 main。我没有在 GitHub 上跑 Merge Queue 或 branch protection。

明天可以抄走的做法

在 1 到 3 号机的 AGENTS.md 里写清楚:PR 还开着的时候,不要在同一份工作区里开始下一张票。开工前跑 python3 tools/task_switch_preflight.py。被拒绝就停,不要 git add -A,不要 reset --hard,不要 switch --force,也不要把 stash 弹回这条审查分支接着写。把未完成的工作 WIP 提交到 wip/<ticket>,或者给下一单新建 worktree:git worktree add -b feat/<ticket> ../repo-<ticket> main。处理审查意见时,给 PR 分支另开 worktree;若同名分支已经被占用,用 --detach 打到审查基线的 SHA,再切出修复分支。

7 号机的合入脚本应当在目标 SHA 的干净 worktree 里跑测试,而不是相信代理当前目录里的测试输出。按文件的闸门可以挡住新生产文件,挡不住同文件泄漏。按符号的闸门可以作为审查提示,不要单独拿来放行。合入前用探针或针对性测试问一下:一次下游 503,账单会不会被写两次。没有幂等键的重试,不应当只靠“测试是绿的”进主干。

脚本、工作流和 AGENTS.md 片段在 review-isolation-kit.tar.gz 里。预检和闸门可以这样调用:

python3 tools/task_switch_preflight.py --repo .
python3 tools/review_scope_gate.py --repo . --base <review-base-sha> --head HEAD --mode files
bash tools/merge_if_isolated.sh <repo> HEAD <review-base-sha> files main

这次的工作流 YAML 只检查了结构,没有在 GitHub Actions 上运行。

今天最小的一步:在还开着的 PR 上,看一眼开发机的 git status。如果工作区是脏的,而且脏文件和审查意见不是同一件事,先不要让代理在这里改审查意见。给这张 PR 单独建一个 worktree,再把下一单从这份脏检出里挪走。

这次实际跑了什么

运行环境:本机 git 2.47.3、Python 3.13.5、pytest 9.1.1。种子仓库 main 67c271e(测试 1 failed, 1 passed),A d5c8a27(2 passed)。add_all 得到 1df303b(3 passed,重试在提交里,探针双写);tests-only 与 files 均快进 main 到 1df303b,随后复位;symbols 拒绝,main 留在 67c271e。reset --hard 得到 d9c5e5a(3 passed,重试已毁)。stash 的审查提交是 cdd4f0d(先是干净的,3 passed);stash pop 在 webhook.py 冲突;取 stash 侧测试 3 failed(now= TypeError),探针仍双写;取审查侧 3 passed,下一单丢失;两边都留再提交 664883e(3 passed,再次双写)。force_switch 中无 --force 的 switch 退出码 0 并带走脏文件,--force 清空工作区,审查提交 07c902a。worktree 同名分支 add 退出码 128,--detach 成功,审查提交同样是 07c902a(3 passed,无重试),原工作区仍脏、仍含重试。预检在干净树上 ALLOW,在脏树上 REFUSE。

未运行:GitHub API、真实的 branch protection 或 ruleset、Merge Queue、第二份 GitHub 账号点合并、GitHub Actions(YAML 只做了结构检查)、任何 Windows 任务或 windows-latest。短哈希来自这一次运行;重建仓库时会变,判定关系不变。

Three people, seven machines. Machines 1–3 run coding agents, 4 and 5 review, 6 is Windows validation, 7 merges. Review is not instant. While machine 4 reads a signature PR, the agent on machine 1 is rarely idle — a person says “start the next ticket,” or the agent finds one itself. The cheapest move is to stay in the checkout that just pushed the PR and edit the next file there.

On Monday, machine 1’s agent opened a PR that verifies payment webhooks. The implementation on main computed an HMAC over json.dumps(parsed), which does not match a provider that signs the raw request body. I reproduced that on this machine: main starts at 67c271e; a legitimate request signed over the raw bytes is rejected; of two tests, 1 failed and 1 passed. The passing test is “a tampered body is rejected,” and it passes because the broken verifier rejects almost everything. Commit d5c8a27 on feat/webhook-verify checks the raw bytes instead. Tests were 2 passed. The PR is waiting on machine 4.

The agent did not change directories. In the same checkout it started the next ticket: retry the downstream billing call when it returns 503. retry_downstream was written into the same webhook.py, with no idempotency key. It was still uncommitted. I ran the original two tests: still 2 passed. They succeed on the first downstream call and never reach the retry. task_switch_preflight.py was ALLOW on the clean PR branch and REFUSE after the retry was written, with dirty file M webhook.py.

Machine 4’s comment was specific: also reject events whose timestamp is older than 300 seconds. The agent added event_is_stale on the already dirty tree, then ran git add -A. The commit message only mentioned the review fix. The commit is 1df303b. Tests were 3 passed. retry_downstream is in that commit. In the probe, one 503 posts billing twice, and the handler still returns ok.

If machine 7 only asks whether the tests are green, or whether any new production path appeared after review, the merge script fast-forwards main from 67c271e to 1df303b. I measured both modes; both were MERGED. The symbols gate refused, and main stayed at 67c271e — but the refused list included both retry_downstream and the helpers the review actually asked for, event_is_stale and STALE_AFTER.

This post asks whether the worktree still holds only this ticket when review comes back; what the agent’s usual git add -A, reset --hard, stash pop, and switch --force do to the next ticket; and how to keep an unfinished retry out of the original PR without destroying it. That is a different problem from handing a mid-task agent job to another machine, and from who picks up a PR after Request changes when the original session is gone. Today is about one machine, one checkout, and the overlap between waiting for review and starting the next ticket.

When review returns to a dirty checkout, the next ticket is committed too

How the lab was built

I initialized a toy repository on this machine. The default branch main starts at 67c271e. The webhook uses a t= / v1= header and HMAC-SHA256; the signed payload should be the timestamp plus the raw body. The implementation on main signs a re-dumped dict instead, so a compact JSON request from a provider does not verify. A on the feature branch is d5c8a27: raw-body verification, still the same two tests. The review asks for a 300-second freshness window and a regression test. Uncommitted ticket B adds retry_downstream to the same webhook.py, resending on DownstreamBusy up to three times, with no idempotency key.

Each of the five approaches was cloned from the same seed and kept separate: add_all addresses review in place and runs git add -A; reset_hard hard-resets first; stash parks B, commits the review fix, then stash pop; force_switch runs git switch -c feat/webhook-retry, writes the dirty retry, then switches back to the PR branch; worktree leaves the dirty retry in the original checkout and uses a second worktree for the review fix. merge_if_isolated.sh runs pytest in a temporary worktree of the target SHA, then the gate, and fast-forwards main only if both pass. After every fast-forward I reset main to 67c271e. The probe probe_billing.py makes the first billing call raise 503 and counts how many times POST_BILLING is actually invoked.

Tests and the probe ran on Linux on this machine. I did not push this repository to GitHub, and I did not run the workflow on Actions; the YAML was checked for structure only. The short SHAs below come from this run. They will change if the repository is rebuilt; the field relationships and the decisions will not.

git add -A writes the next ticket into the review-fix commit

When review comes back, the cheapest move is: edit this tree, run the tests, add everything, commit. The message on 1df303b is “address review: reject events older than 300s”. git diff d5c8a27..HEAD --stat lists only webhook.py and test_webhook.py, which looks exactly like a review fix. git show HEAD:webhook.py already contains retry_downstream. Tests were 3 passed, because neither the new freshness test nor the original signature tests trigger a 503. The probe reports billing_calls=2, double_post=true, status=ok.

The tests-only merge mode fast-forwarded main to 1df303b. The files gate allowed it too: no new production path appeared after review; the leak lives in webhook.py, which already belonged to the PR. The symbols gate refused. The new symbols included retry_downstream, DownstreamBusy, MAX_RETRIES, and also event_is_stale and STALE_AFTER, which the review actually needed. main stayed at 67c271e.

One more thing has to be stated separately. I also ran the tests in the dirty worktree before committing. After writing B and before the review fix, they were 2 passed; after adding the freshness check and its regression, still uncommitted, they were 3 passed. If an agent treats “I just ran the tests, they were green” as evidence for the commit, it is looking at the worktree, not at the tree that will be pushed. In this run both were green, which makes the leak even easier to miss. The merge script later ran the tests in a clean worktree and still allowed 1df303b. Green tests do not catch an unfinished feature written into the same file.

reset --hard and switch --force destroy the next ticket

To make a clean tree for the review fix, an agent will often run git reset --hard. I did that. After the reset the worktree was clean, webhook.py had no retry_downstream, and the stash list was empty. I then wrote the freshness check and committed d9c5e5a. Tests were 3 passed, and the probe no longer double-posted. The PR is clean. Ticket B is not in the worktree, not in the stash, and not in any commit. It is gone.

The force_switch path is closer to what an agent does when it “starts a new branch first.” From clean d5c8a27 I ran git switch -c feat/webhook-retry, wrote the uncommitted retry, then switched back to feat/webhook-verify. I expected Git to refuse the switch because of the dirty file. The exit code was 0. Both branches pointed at the same commit, so the uncommitted change applied cleanly, and the dirty webhook.py was carried back onto the PR branch with no warning, still M webhook.py. The leak happened at the switch, before any git add.

I then ran git switch --force feat/webhook-verify on that already-checked-out, dirty PR branch. Git reported it was already on the branch, the worktree was emptied, the retry was gone, and the stash list was still empty. The review fix committed as 07c902a, tests were 3 passed, and the PR had no retry. The next ticket was destroyed the same way. --force is not “make sure I am on the right branch.” It drops the uncommitted next ticket in this checkout.

stash pop conflicts on the same file, and each resolution ends differently

Parking B in the stash before addressing review looks safer. After git stash push -u -m "wip: downstream retry", I wrote the freshness check on the clean tree and committed cdd4f0d. Tests were 3 passed, and the probe did not double-post. At that moment the PR was clean. stash pop then exited 1: a content conflict in webhook.py, conflict markers in the file, stash kept.

I tried all three resolutions. Taking the stash side (--theirs) brought retry_downstream back and dropped event_is_stale. The review-fix tests were already in the commit and call handle(..., now=1000), but the stash version of handle does not accept that argument. Tests were 3 failed, all TypeError: handle() got an unexpected keyword argument 'now'. The probe still double-posted. Taking “my next ticket” reverted the review fix in the worktree. Taking the review-fix side (--ours) left tests at 3 passed, no double post, and ticket B gone from the worktree. Keeping both and committing again produced 664883e: 3 passed, retry_in_commit=true, probe billing_calls=2. The next ticket is in the signature PR again.

A stash is not isolation. It postpones the conflict. The conflict happens on the review-fix branch, and whatever resolution the agent chooses, it is still standing on that PR’s branch.

A new worktree can keep the review fix and the next ticket

The isolation that works is: do not address review in the dirty worktree. I left the uncommitted retry in the original checkout and added a second worktree for the review fix. git worktree add <path> feat/webhook-verify failed with exit 128: the branch is already used by the original worktree. That is a Git limitation, not a script typo. --detach succeeded, with HEAD at d5c8a27. From that detached checkout I created feat/webhook-verify-review, wrote only the freshness check, and committed 07c902a. Tests were 3 passed, the commit has no retry_downstream, and the probe did not double-post.

The original worktree was still on feat/webhook-verify, still M webhook.py, still containing the retry and not the freshness check. The original tests on that dirty tree were still 2 passed; the probe double-posted. Those green tests still describe the dirty worktree. They are not evidence about 07c902a. The review-fix tests ran in the new worktree, against that commit.

The review-fix commits from force_switch and worktree share the hash 07c902a. They are not one commit reused across two repositories. The two commits have the same author, message, parent, tree, and timestamp (2026-11-16 05:48:24 -0500, which is 07:48:24 in the local America/Fortaleza zone). Both trees are 393aea2. The shared hash only means the review-fix contents were identical. It does not mean the two strategies did the same thing: the first destroyed the next ticket along the way; the second left it in the original worktree.

What the five ways of addressing review actually did in this lab

The mechanism: a worktree is not a branch, and tests do not see a commit by default

A branch is a pointer to a commit. A worktree is a set of files that can be dirty. When an agent says “I am on this PR’s branch,” that does not mean the worktree holds only that ticket’s edits. An uncommitted next ticket sits under the current pointer by default. git add -A does not ask which ticket the changes belong to; it looks at the worktree. If two branches still point at the same commit, git switch will not stop dirty files either; it will carry the next ticket along.

Tests look at the worktree by default too. Green locally and green in the commit does not mean the commit has no unfinished work from another ticket — not if the existing tests and the review regression never hit that path. That is 1df303b. Moving the tests into a clean worktree of the target SHA only guarantees you tested the tree that is about to merge. It does not guarantee that tree has no leak. In this run, both tests-only and files ran on a clean tree and still fast-forwarded the retry commit onto main.

The files gate compares paths. If the only files touched after review already belonged to the PR, it cannot see a new function. The symbols gate uses the AST to collect new top-level functions, classes, and all-caps assignments in production files, so it caught retry_downstream. For the same reason it also refuses a clean review fix: event_is_stale and STALE_AFTER are new since the review base too. Treat that list as a prompt for machine 4 — “these names appeared on the tree, confirm they are what the review asked for” — not as the only merge condition. If the retry were inlined into the existing handle without a new top-level name, both gates in this lab would miss it by design. I did not run a separate inlined variant, so that is a scope limit, not a measured result, and it should be named as such.

What actually stops the leak is not a smarter gate. It is not letting two tickets share a dirty worktree in the first place. That is what the preflight means when it refuses to start more work here after B has been written. Address review in a new worktree of the PR branch. Leave the next ticket dirty in the original checkout, or WIP-commit it on a side branch. Do not stash pop back onto the review branch and keep typing.

Address review in a new worktree of the PR branch, not in the dirty checkout

When you should not install this

If your tools already create a worktree per session or per ticket — some cloud agents, or local tools that default to worktree mode — another “open a worktree for the review fix” layer adds little. What is still worth checking is whether a person will tell the same session to “do the next ticket while you wait.”

If the team rule is that B does not start until A is on main, this overlap is rare. On a three-person, seven-machine cadence where agents queue tickets overnight, that rule is hard to keep, because the review queue itself is a wait.

Do not make the symbols gate the only required check. In this run it would refuse the clean commits d9c5e5a, cdd4f0d, and 07c902a. If review fixes often add a helper, the gate becomes standing noise. Handing its output to the review machine is fine. Letting machine 7 fast-forward on that verdict alone is not.

merge_if_isolated.sh has to switch to main before it fast-forwards. My first version got this wrong: it ran git merge --ff-only on whichever review branch was checked out, printed “MERGED,” and left main unmoved. Merging into whatever happens to be checked out is a common bug in this kind of script. The current script switches to main first. I did not run a GitHub merge queue or branch protection.

What to copy tomorrow

In AGENTS.md for machines 1–3, say this plainly: while a PR from this checkout is still open, do not start a second ticket in the same worktree. Run python3 tools/task_switch_preflight.py before starting new work. If it refuses, stop. Do not git add -A, do not reset --hard, do not switch --force, and do not pop a stash back onto the review branch and keep writing. WIP-commit unfinished work on wip/<ticket>, or add a worktree for the next ticket: git worktree add -b feat/<ticket> ../repo-<ticket> main. When review comments arrive, add a worktree of the PR branch; if that branch is already checked out, use --detach at the review-base SHA and create a fix branch.

Machine 7’s merge script should run tests in a clean worktree of the target SHA, and should not trust test output from the agent’s current directory. A files gate can catch new production files; it cannot catch a same-file leak. A symbols gate can be a review prompt; it should not be the only allow. Before merge, ask with a probe or a targeted test: if billing returns 503 once, is it posted twice? A retry without an idempotency key should not reach main just because the tests were green.

The scripts, the workflow, and the AGENTS.md snippet are in review-isolation-kit.tar.gz. Call the preflight and the gate like this:

python3 tools/task_switch_preflight.py --repo .
python3 tools/review_scope_gate.py --repo . --base <review-base-sha> --head HEAD --mode files
bash tools/merge_if_isolated.sh <repo> HEAD <review-base-sha> files main

The workflow YAML in this lab was inspected for structure. It was not run on GitHub Actions.

The smallest step today: on an open pull request, look at git status on the development machine. If the worktree is dirty, and the dirty files are not the review comment, do not let the agent address review here. Give that PR its own worktree, and move the next ticket out of this dirty checkout.

What was actually run

Run: git 2.47.3, Python 3.13.5, and pytest 9.1.1 on this machine. Seed main 67c271e (tests 1 failed, 1 passed), A d5c8a27 (2 passed). add_all produced 1df303b (3 passed, retry in the commit, probe double-posted); tests-only and files fast-forwarded main to 1df303b, then a reset; symbols refused, main stayed at 67c271e. reset --hard produced d9c5e5a (3 passed, retry destroyed). The stash review commit is cdd4f0d (clean at that point, 3 passed); stash pop conflicted in webhook.py; taking the stash side was 3 failed (now= TypeError) with the probe still double-posting; taking the review side was 3 passed and ticket B lost; keeping both and committing 664883e was 3 passed and a double post again. In force_switch, switch without --force exited 0 and carried the dirty file; --force emptied the worktree; the review commit is 07c902a. In worktree, adding the same branch exited 128, --detach succeeded, the review commit is also 07c902a (3 passed, no retry), and the original worktree stayed dirty with the retry. Preflight was ALLOW on the clean tree and REFUSE on the dirty tree.

Not run: the GitHub API; a real branch protection rule or ruleset; a merge queue; a second GitHub account to click merge; GitHub Actions (the YAML was checked for structure); any Windows job or windows-latest runner. The short SHAs come from this run. They will change if the repository is rebuilt; the field relationships and the decisions will not.