AI

git blame 指到我,但这行是 2 号机隔夜写的(中英切换)

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

三人、七台电脑。1 到 3 号机跑编码代理,4、5 号机审查,6 号机做 Windows 验证,7 号机负责合入。这七台电脑的 git user.name 和 user.email,写的都是各自机主的名字。2 号机的机主在实验室里叫陈浩,邮箱是 chenhao@team.invalid。这是夹具身份,不是真人。

周日夜里,账单服务有一张票:折扣取整有偏差,要修。2 号机的代理改了 apply_discount。周一早上,PR 已经开着,标题是 fix: discount rounding,单元测试 3 通过。7 号机按仓库习惯 squash 合进 main,分支随后删掉。中午,有人发现一笔 29.90 元的订单,用了 5 元券,应付 24.90,实际扣成了 24.00。值班的人在 main 上对那一行做 git blame,指到的是陈浩。陈浩说:我没动过这段,这是 2 号机隔夜跑的。再去翻代理会话,会话已经关了。合入提交的留言是 fix: discount rounding (#88),下面列了三条 subject,没有机器号,也没有会话号。

这篇要核对的是:代理用机主的 git 身份提交时,git blame 会指向谁;Co-authored-by 或 Made with Cursor 这样的产品行,够不够告诉你是哪一台机器、哪一场会话;以及团队若习惯 squash 合入,这些写在提交正文里的行,还能不能出现在 main 上。它和 4 号机刚 Approve,2 号机的代理又 force-push 了一次:合进去的到底是哪一版? 谈的是审查之后 SHA 又动了,和 审查机点了 Request changes,开这个 PR 的代理会话已经关了:谁来改下一刀? 谈的是会话死了之后谁接着改,和 下层折扣 PR 被 squash 进 main 之后,上层结账分支对 main 做普通 rebase,停在已经合过的那条提交上 谈的是 squash 之后上层分支怎么续,都不是同一件事。今天只谈:出了线上问题,blame 指到人,却找不到是哪台机器写的。

我按常见的代理写法准备了这些提交,并没有再开一个编码模型来生成它们。玩具仓库的种子是 f53a1d2:一份用整数分计算应付额的账单函数。GitHub 的 squash 留言是按 GitHub 文档和 2022-08-23 的 changelog 在本地复原的,多提交时「commit list」按历史上常见的格式写成一条 subject 一行。我没有在 GitHub 上点过 squash,也没有调用合入 API。Windows 没有参与这次实验。

测试 3 通过,29.90 的单却少了 90 分

种子提交上,apply_discount(10000, 0)、apply_discount(10000, 1000) 和「优惠不能把应付额打到零以下」这三条测试通过。生产里真正出问题的金额不在测试里。我对种子跑了探针 apply_discount(2990, 500),结果是 2490,也就是 24.90 元,这是正确值。

代理写下的「取整」是先把金额抹成整元,再减去优惠:

rounded = (amount_cents // 100) * 100
return max(0, rounded - discount_cents)

2990 分先变成 2900,再减 500,得到 2400。10000 分这种整元金额,抹完还是 10000,所以三条测试仍然通过。我在后面每一次实验里都跑了同一组单元测试和同一条探针:测试都是 3 通过,探针都是 2400。只看测试,合入闸门看不出这笔少了 90 分的单。

git blame 读的是作者字段,不是正文里的 Machine 行

先看最常见的写法。三条提交的作者都是陈浩,每条留言末尾都有:

Machine: 2
Agent-Session: sess_7f3a
Co-authored-by: machine-2-agent <machine-2-agent@iotxing.invalid>

引入那行 rounded 的提交是 e3edf32,分支头是 f38dbc6。git blame 指向陈浩。git log --format='%(trailers)' 能看见机器号和会话号。也就是说,trailer 已经写在提交上了,它并不会自动出现在 blame 的输出里。要读到这些行,得对那次提交再跑一次 git log 或 git interpret-trailers --parse。值班的人如果只看 blame,看到的仍是机主的名字。

把作者改成 machine-2-agent,把陈浩写进 Co-authored-by,情况反过来。引入该行的提交是 f671e58,blame 指向 machine-2-agent。git shortlog -sn HEAD 是 3 次 machine-2-agent、1 次陈浩(种子)。这时 blame 能告诉你是哪台机器,却不再指向那个你半夜可以喊醒的人。作者字段只能填一个名字。你要么把人放在作者里、把机器放进 trailer,要么反过来。没有第三种字段会同时出现在 git blame 里。

产品行更帮不上忙。我另外做了一组提交,正文里只放了 Co-authored-by: Claude <noreply@anthropic.com> 和结构化的 Made-with: Cursor(提交 ec1cc72)。blame 仍是陈浩。attributed 闸门拒绝,理由是缺 Machine 和 Agent-Session,产品行不够。它对三人七机真正要问的问题——是 2 号机还是 3 号机,会话号是什么——没有给出答案。Claude Code 默认会写 Co-Authored-By: Claude <noreply@anthropic.com>,Cursor 文档写的是可以自动加上 Made with Cursor。这些行命名的是产品,不是你的电脑编号。

我还把两句官方用语写进同一条留言,先是 Claude 的 Co-Authored-By,紧接着是不带冒号的 Made with Cursor。这组提交的头是 604267d。git interpret-trailers --parse 的结果是空的。单独解析 Claude 那两行时,Co-Authored-By 能被读出来;单独解析 Made with Cursor 时,结果也是空的,因为它不是 Key: value。把这句没有结构的话放在已经写好的 trailer 后面,整段末尾不再被当成 trailer 块。这是我在夹具留言上看到的解析行为。我没有打开 Cursor 或 Claude Code 去生成真实提交,不能断言这两个产品会按这个顺序追加页脚。

PR 上的 Machine 行还在,squash 进 main 之后 git blame 只看得见陈浩

默认 squash 把正文丢掉,main 上就只剩下人名

分支上的 trailer 还不是最终会留在 main 上的东西。三人七机这套节奏里,7 号机常常 squash。GitHub 文档对默认 squash 留言的规则是:只有一条提交时,使用该提交的标题和正文;有两条或更多提交时,使用 PR 标题、编号,外加一份 commit list。仓库还可以改成只保留 PR 标题,或保留标题加正文,或保留标题加 commit details。changelog 里把多提交时的「commit details」同样写成 list of commits。这些页面没有给出 list 的逐字节格式。我按 GitHub squash 对话框里常见的样子,把它复原成一条 subject 一个星号行,不带正文。下面的合入提交都是在本地 git merge --squash 生成的,作者身份用的是陈浩,因为 PR 通常是用机主的账号开的。

三条带 Machine trailer 的提交,按默认留言 squash 之后,合入提交是 9217b51。留言是:

fix: discount rounding (#88)

* fix: discount rounding

* test: note that fixtures are whole yuan

* chore: comment that math stays in cents

git interpret-trailers --parse 是空的。blame 指向陈浩。tests_only 闸门放行,因为测试仍是 3 通过。attributed 闸门拒绝:将要落在 main 上的留言里既没有 Machine,也没有 Agent-Session。只保留 PR 标题,或保留标题加 commit details,结果一样,合入提交分别是 09591f8 和 5866ed4。

单提交的 PR 是另一回事。我把同样的代码改动收成一条带完整 trailer 的提交 6e755c6,再按「默认 = 提交标题加正文」squash,合入提交是 66502e2,Machine 和会话号还在,attributed 放行。团队一旦习惯把格式化、补测试拆成第二条、第三条提交,就会掉进多提交那条路径,默认留言不再复制正文。

「保留 PR 标题和描述」也不是自动安全的。把 Machine 和会话号写进 PR 正文再 squash,合入提交 26066ad 留下了这些行,闸门放行。把正文换成普通的说明,末尾是 Tests: 3 passed.,合入提交是 e95e133。git interpret-trailers --parse 读到的是 Tests: 3 passed.。留言里确实出现了 trailer,只是这条 trailer 在说测试过了,没有机器号。闸门仍然拒绝。看起来像元数据的一行,并不等于你要的那一行。

机器作者也逃不过这一步。f671e58 在分支上 blame 指向 machine-2-agent。按默认留言 squash 成 1de4687 之后,blame 指回陈浩,git shortlog -sn HEAD 变成 2 次陈浩,三次机器提交从默认分支的历史上消失了。作者字段在 squash 时被写成了合入所用的身份。不把机器号写进合入留言,main 上就只剩机主的名字。

测试都是 3 通过:差别在合入留言还留不留机器号

7 号机要检查将要落在 main 上的那条留言

机制其实很窄。git blame 标注的是引入这一行的那次提交的作者字段。trailer 是留言正文末尾的 Key: value 块,blame 不读它,git log --format='%s' 也不读它。squash 会新写一条提交。这条新提交的作者是合入时使用的身份,留言是 squash 对话框或 gh pr merge --squash 当时采用的那一段文本。分支上曾经有过的 Machine 行,不会自己长到这条新提交上。

所以闸门不能只看「PR 分支的头有没有 trailer」。它要看将要落在默认分支上的那条留言。我让 7 号机先跑 harvest_trailers.py,从 base..head 收集 Machine、Agent-Session 和 Co-authored-by,写进 squash 留言,再跑 check_attribution.py --mode attributed。对那组带机器号的提交,收获后的合入是 260471b,留言里留下了 Machine: 2 和 sess_7f3a,闸门放行。blame 仍然指向陈浩:收获解决的是「main 上还能不能读到机器号」,不是「blame 的作者栏会不会变成机器」。

第一版闸门在这里翻过一次。收获 machine-2-agent 那组提交时,留言里是 Machine: 2。脚本只在 trailer 的值里搜索单词 machine,值却是数字 2,于是判定 Machine 缺失。我改成「键是 Machine,且值是数字或 machine-N」之后,同一条合入 2bc76da 才放行。闸门本身也会写错。要把这种误拒留在测试里,不要只在文档里写「检查 Machine」。

产品行被收获之后,仍然不够。结构化的 Claude / Cursor trailer 收获进 ef58c97,attributed 继续拒绝。官方用语那组更干脆:因为 Made with Cursor 破坏了 trailer 块,收获脚本对 604267d 这一支什么都没收集到,合入提交 7040876 的留言只剩标题,闸门拒绝。若仓库还开着 vendor_ok 这种较弱的模式,产品行可以通过,但它回答不了「该去哪台机器打开哪场会话」。

tests_only 在上述所有合入提交上都放行,包括丢掉机器号的 9217b51 和 1de4687。三人七机如果只把测试作为合入条件,这篇里的事故在闸门上不会留下任何痕迹。

7 号机要检查将要落在 main 上的那条留言

什么时候不该这样装

不要指望把作者改成机器名,就能同时解决「叫醒谁」和「是哪台机器」这两件事。git blame 只能显示作者。若法务或 DCO 要求提交作者必须是人,就保持人做作者,把 Machine 和 Agent-Session 作为合入条件;不要指望审查的人会记得再跑一次 git log。若你更在乎主分支上的 blame 直接显示机器,就要让作者成为 machine-N-agent,并把人放进 Co-authored-by,同时接受 blame 不再指向可以喊醒的那个人。

不要把产品行当成机器号。Co-Authored-By: Claude 或 Made with Cursor 至多说明用过哪个工具。七台机器可能跑的是同一个产品。关掉这些产品行、或者企业策略统一禁用它们,都不会自动补上机器号;那是另一条要自己写的规则。

不要假设 squash 总能保住正文。单提交 PR 在默认设置下会复制完整留言,这是 66502e2 放行的原因。多提交 PR 的默认路径是标题加 subject 列表,这是 9217b51 被拒绝的原因。把仓库改成「只保留 PR 标题」,连 subject 都不会留下。若坚持 squash,7 号机必须收获 trailer,或者把机器号写进 PR 正文,并且不要用「只保留标题」这种设置。不愿意改 squash 留言的团队,可以用 merge commit 或 rebase and merge 保住原来的提交;那也有代价,main 会更吵,而且 下层被 squash 之后上层 rebase 会重放已经合过的提交 这类问题要另作处理。

不要在 trailer 块后面再追加一句没有 Key: value 结构的产品页脚。我在夹具里看到的结果是:git interpret-trailers --parse 变成空,收获脚本什么都留不下。机器号要写在留言末尾连续的 trailer 块里。

不要把本地 hook 或「代理自己会写 Co-authored-by」当成合入条件。包装脚本可以被跳过,产品行也可以被项目说明关掉。真正起作用的是 7 号机对将要落在 main 上的那条留言做的检查。

一人维护的仓库,或不做 squash、并且每条提交已经用机器身份签署的团队,不必上这套闸门。没有多机并发、出了问题直接问唯一作者就够的团队,也可以不装。闸门回答的是「默认分支上还能不能找到机器和会话」,不是「这行代码对不对」。折扣取整少了 90 分,要靠测试和审查;这篇的闸门不会替你抓住这个算术错误。

明天可以抄走的步骤

在 1 到 3 号机的 AGENTS.md 里写清楚:不要只用这台电脑上的机主 git 身份提交。提交前设置 MACHINE_ID 和 AGENT_SESSION,用 commit_as_machine.sh 或同等包装。需要人做作者时,把人放进 Co-authored-by,并加上 Machine: 和 Agent-Session: 两行。产品页脚不能代替这两行。

7 号机合入前,对将要使用的 squash 留言跑 attributed 闸门,而不是只看分支头:

python3 tools/harvest_trailers.py --repo . --base <default-branch-sha> --head HEAD --title "<pr title> (#<n>)" > /tmp/squash-msg.txt
python3 tools/check_attribution.py --repo . --mode attributed --message-file /tmp/squash-msg.txt

如果仓库允许「只保留 PR 标题」的 squash,把这项检查做成必过,或者改掉默认留言,否则分支上的机器号到不了 main。

脚本、包装命令、AGENTS.md 片段和一份工作流样例在 blame-attribution-kit.tar.gz。工作流 YAML 只做过结构检查,没有在 GitHub Actions 上跑过。

今天最小的一步:对一个即将合入的代理 PR,看一看即将写进 main 的那条留言里有没有机器号和会话号。不要只看 blame 指向谁,也不要只看测试是不是 3 通过。

实际跑了什么

运行环境:本机 git 2.47.3、Python 3.13.5、pytest 9.1.1。提交时间戳固定在 2026-11-19T12:00:00Z 起按秒递增,短哈希在这次重建里是稳定的。种子 f53a1d2:测试 3 通过,探针 apply_discount(2990, 500) 为 2490。所有带该取整错误的提交:测试 3 通过,探针 2400。

陈浩为作者、带 Machine trailer 的分支头 f38dbc6,引入错误行的提交 e3edf32,blame 为陈浩,attributed 放行。无 trailer 的分支头 a588970,引入行 5112463,attributed 拒绝。机器作者分支头 99a9411,引入行 f671e58,blame 为 machine-2-agent,shortlog 为 3 次机器、1 次陈浩。单提交 6e755c6,默认 squash 为 66502e2,trailer 保留,闸门放行。

默认多提交 squash 9217b51、仅标题 09591f8、标题加 commit details 5866ed4:留言无 Machine,tests_only 放行,attributed 拒绝。PR 正文带 trailer 的 26066ad 放行;正文以 Tests: 3 passed. 结尾的 e95e133 会解析出这条测试 trailer,但仍被拒绝。收获后的 260471b 放行,blame 仍为陈浩。机器作者默认 squash 1de4687:blame 回到陈浩,shortlog 为 2 次陈浩。收获后的 2bc76da 在修好 Machine: 2 解析之后放行,blame 仍为陈浩。

git interpret-trailers --parse:Machine: 2 能解析;官方 Made with Cursor 不能;Claude 的 Co-Authored-By 单独可以;把它和后面一句 Made with Cursor 放在同一段末尾时,整段解析为空。官方页脚分支头 604267d 的 %(trailers) 为空,收获后的合入 7040876 被拒绝。

未运行:在 GitHub 网页或 API 上执行 squash;GitHub Actions(YAML 只做过结构检查);分支保护或 ruleset;Windows 或 windows-latest;由 Cursor 或 Claude Code 当场生成的真实提交(产品行按公开文档与公开讨论写成夹具);第二个 GitHub 账号。陈浩、chenhao@team.invalid 和 machine-2-agent@iotxing.invalid 都是实验室夹具。

Three people, seven computers. Machines 1 to 3 run coding agents, 4 and 5 review, 6 does Windows validation, and 7 merges. On all seven computers, git user.name and user.email are the name of the person who owns that machine. In the lab, the owner of machine 2 is Chen Hao, chenhao@team.invalid. That identity is a fixture, not a real person.

On Sunday night there was a ticket to fix discount rounding on the billing service. The agent on machine 2 changed apply_discount. On Monday morning the PR was already open, titled fix: discount rounding, and the unit tests were 3 passed. Machine 7 squash-merged it the way the repository usually does, and the branch was deleted. At noon someone found a 29.90 order with a 5.00 coupon: it should have been 24.90, and it was billed as 24.00. The on-call ran git blame on that line on main. It pointed at Chen Hao. Chen Hao said he had not touched it; machine 2 had run overnight. The agent session was already closed. The landed message was fix: discount rounding (#88) followed by three subjects, with no machine id and no session id.

This post checks what git blame points at when an agent commits with the machine owner's git identity; whether a product line such as Co-authored-by or Made with Cursor is enough to tell you which computer and which session wrote the line; and whether those lines still exist on main if the team squash-merges. It is not the same question as which SHA landed after an approval and a force-push, or who picks up a pull request after the authoring session has already ended, or what happens to a stacked branch after the base was squash-merged. Today is only this: after a production incident, blame points at a person, and you cannot tell which machine wrote the line.

I prepared the commits in the way agents commonly write them. I did not start a coding model to generate them. The toy repository seed is f53a1d2: a payable-amount function in integer cents. GitHub squash messages were recreated locally from GitHub's documentation and the 2022-08-23 changelog. For a multi-commit list I used one bullet per subject, which is the form the squash dialog has historically inserted. I did not click squash on GitHub, and I did not call a merge API. Windows was not part of this run.

The tests were 3 passed; a 29.90 order was 90 cents short

On the seed commit, the three tests pass: no discount, a typical coupon, and a discount that must not push the payable amount below zero. The amount that fails in production is not in the suite. A production probe apply_discount(2990, 500) on the seed returned 2490, which is the correct 24.90.

The agent's "rounding" wipes the amount down to whole yuan before subtracting the coupon:

rounded = (amount_cents // 100) * 100
return max(0, rounded - discount_cents)

2990 becomes 2900, then 2400 after subtracting 500. A whole-yuan fixture such as 10000 is unchanged by that integer division, so the three tests still pass. I ran the same suite and the same probe after every later experiment: the tests were always 3 passed, and the probe was always 2400. A tests-only merge gate cannot see the missing 90 cents.

git blame reads the author field, not a Machine line in the body

Start with the common case. All three commits are authored by Chen Hao, and each message ends with:

Machine: 2
Agent-Session: sess_7f3a
Co-authored-by: machine-2-agent <machine-2-agent@iotxing.invalid>

The commit that introduced the rounded line is e3edf32. The branch head is f38dbc6. git blame points at Chen Hao. git log --format='%(trailers)' shows the machine and the session. The trailers are already on the commit, and they still do not appear in blame. To read them you have to run git log or git interpret-trailers --parse on that commit. If the on-call only looks at blame, they still see the machine owner's name.

Set the author to machine-2-agent and put Chen Hao in Co-authored-by, and the picture flips. The introducing commit is f671e58, and blame points at machine-2-agent. git shortlog -sn HEAD is three commits for machine-2-agent and one for Chen Hao, the seed. Blame can now tell you which machine wrote the line, and it no longer points at the person you can wake at 2 a.m. The author field holds one name. Either the person is the author and the machine lives in a trailer, or the other way around. There is no third field that blame will print.

A vendor line does not help. Another set of commits, introduced at ec1cc72, carries only Co-authored-by: Claude <noreply@anthropic.com> and a structured Made-with: Cursor. Blame is still Chen Hao. The attributed gate refuses: Machine and Agent-Session are missing, and a product line is not enough. It does not answer the question a seven-machine team actually has — machine 2 or machine 3, and which session. Claude Code's default line is Co-Authored-By: Claude <noreply@anthropic.com>. Cursor's documentation says it can append Made with Cursor. Those lines name a product, not a computer number.

I also put both official phrases in one message: the Claude Co-Authored-By line, then the unpunctuated Made with Cursor. The branch head is 604267d. git interpret-trailers --parse returned empty. Parsed alone, the Claude footer yields Co-Authored-By. Parsed alone, Made with Cursor is empty, because it is not Key: value. Place that unstructured sentence after a trailer block, and the whole ending stops being a trailer block. That is what I saw on fixture messages. I did not have Cursor or Claude Code create a live commit, so I am not claiming either product appends footers in that order.

The PR still had Machine trailers; after squash, git blame only sees Chen Hao

A default squash drops the body, and main is left with a person's name

Trailers on the branch are not yet what will exist on main. In this seven-machine cadence, machine 7 often squashes. GitHub's documentation says the default squash message uses the commit title and message when the pull request has one commit, and the pull request title, number, and a list of commits when it has two or more. A repository can also keep only the pull request title, the title plus the description, or the title plus commit details. The changelog describes "commit details" for the multi-commit case as a list of commits as well. Those pages do not define the list byte for byte. I recreated it as one starred subject line per commit, without bodies, which is the form the GitHub squash dialog has historically inserted. Every landed commit below was created with a local git merge --squash. The author identity was Chen Hao, because the pull request is usually opened with the machine owner's account.

After a default-message squash of the three commits that had Machine trailers, the landed commit is 9217b51. The message is:

fix: discount rounding (#88)

* fix: discount rounding

* test: note that fixtures are whole yuan

* chore: comment that math stays in cents

git interpret-trailers --parse is empty. Blame points at Chen Hao. The tests_only gate allows it, because the tests are still 3 passed. The attributed gate refuses: the message that would land on main has neither Machine nor Agent-Session. Keeping only the PR title, or the title plus commit details, is the same: landed commits 09591f8 and 5866ed4.

A single-commit pull request is different. I made the same code change as one commit with a full trailer, 6e755c6, then squashed under the default "commit title and message" rule. The landed commit is 66502e2. The Machine and session lines are still there, and attributed allows it. As soon as a team splits formatting or tests into a second and third commit, they fall onto the multi-commit path, and the default message no longer copies the bodies.

"Title and description" is not automatically safe either. When the PR body already contained the Machine and session lines, the landed commit 26066ad kept them, and the gate allowed it. When the body was an ordinary summary ending in Tests: 3 passed., the landed commit is e95e133. git interpret-trailers --parse yields Tests: 3 passed. There is a trailer in the message, and it is a sentence about tests, not a machine id. The gate still refuses. A line that looks like metadata is not the same as the line you need.

A machine author does not survive this step on its own. On the branch, f671e58 blames machine-2-agent. After a default-message squash to 1de4687, blame points at Chen Hao again, and git shortlog -sn HEAD is two commits for Chen Hao. The three machine commits have disappeared from the default-branch history. The squash author was the identity used to land the commit. If the machine id is not in the landed message, main only has the owner's name.

Every run was 3 passed: the difference is whether the landed message still has a machine id

Machine 7 has to inspect the message that will land on main

The mechanism is narrow. git blame annotates a line with the author of the commit that introduced it. A trailer is a Key: value block at the end of the message body. Blame does not read it, and neither does git log --format='%s'. A squash writes a new commit. The author of that commit is the identity used at merge time, and the message is whatever the squash dialog or gh pr merge --squash used. A Machine line that existed on the branch does not move onto that new commit by itself.

So the gate cannot only ask whether the pull request head still has trailers. It has to ask about the message that will land on the default branch. I had machine 7 run harvest_trailers.py over base..head to collect Machine, Agent-Session, and Co-authored-by, write them into the squash message, and then run check_attribution.py --mode attributed. For the commits that already had a machine id, the harvested landing is 260471b. The message still has Machine: 2 and sess_7f3a, and the gate allows it. Blame still points at Chen Hao: harvesting answers whether main still carries the machine id, not whether the blame author column will turn into a machine name.

The first version of the gate failed here. When harvesting the machine-2-agent commits, the message contained Machine: 2. The script only searched the trailer value for the word machine. The value is the number 2, so it reported Machine as missing. After I accepted a numeric value for that key, the same landing 2bc76da was allowed. The gate can be wrong too. Keep that miss in a test. Do not only write "check Machine" in a document.

A harvested product line is still not enough. Structured Claude / Cursor trailers harvested into ef58c97 are still refused by attributed. The official-wording set is starker: because Made with Cursor broke the trailer block, the harvest script collected nothing from the 604267d branch, the landed commit 7040876 is only the title, and the gate refuses. A weaker vendor_ok mode will accept a product line, and it still cannot tell you which machine to walk to or which session to reopen.

tests_only allowed every one of these landings, including 9217b51 and 1de4687, which had already lost the machine id. If a seven-machine team only requires tests to merge, the incident in this post leaves no mark on the gate.

Machine 7 has to inspect the message that will land on main

When you should not install this

Do not expect a machine-name author to answer both "who do I wake" and "which computer was it." git blame can only show the author. If legal or DCO rules require a human author, keep the person as author and make Machine and Agent-Session a merge requirement; do not rely on a reviewer remembering to run git log. If you want blame on the default branch to show the machine, make machine-N-agent the author and put the person in Co-authored-by, and accept that blame no longer points at someone you can wake.

Do not treat a product line as a machine id. Co-Authored-By: Claude or Made with Cursor can at most tell you which tool ran. All seven machines may be running the same product. Turning those product lines off, or disabling them in an enterprise policy, does not invent a machine id. That rule has to be written separately.

Do not assume squash will keep the body. A single-commit pull request under the default setting copies the full message, which is why 66502e2 was allowed. A multi-commit pull request under the default path is the title plus a list of subjects, which is why 9217b51 was refused. Set the repository to keep only the pull request title, and even the subjects disappear. If you keep squashing, machine 7 has to harvest trailers, or the machine id has to be in the pull request body, and you should not use a title-only default. Teams that do not want to rewrite squash messages can use a merge commit or rebase and merge to keep the original commits. That has a cost: main gets noisier, and problems such as a stacked branch replaying commits that were already squashed have to be handled separately.

Do not append an unstructured product footer after a trailer block. In the fixtures, git interpret-trailers --parse became empty, and the harvest script kept nothing. Put the machine id in a contiguous trailer block at the end of the message.

Do not treat a local hook, or "the agent will write Co-authored-by," as the merge requirement. A wrapper can be skipped, and a product line can be turned off in project settings. What matters is the check machine 7 runs on the message that will land on main.

A solo repository, or a team that does not squash and already signs every commit with a machine identity, does not need this gate. A team with no concurrent machines, where the only author is also the only person you would ask, can skip it too. The gate answers whether the default branch still carries a machine and a session. It does not answer whether the code is right. The missing 90 cents is a test and review problem; this gate will not catch that arithmetic error.

What to copy tomorrow

In AGENTS.md for machines 1 to 3, say this plainly: do not commit with only the machine owner's git identity on that computer. Set MACHINE_ID and AGENT_SESSION before committing, and use commit_as_machine.sh or an equivalent wrapper. If a human must remain the author, add them as Co-authored-by, and add Machine: and Agent-Session:. A vendor footer is not a substitute for those two lines.

Before machine 7 merges, run the attributed gate on the squash message it is about to use, not only on the branch head:

python3 tools/harvest_trailers.py --repo . --base <default-branch-sha> --head HEAD --title "<pr title> (#<n>)" > /tmp/squash-msg.txt
python3 tools/check_attribution.py --repo . --mode attributed --message-file /tmp/squash-msg.txt

If the repository allows a title-only squash, make this check required, or change the default message. Otherwise the machine id on the branch will not reach main.

The scripts, the wrapper, an AGENTS.md snippet, and a sample workflow are in blame-attribution-kit.tar.gz. The workflow YAML was checked for structure. It was not run on GitHub Actions.

The smallest step today: on an agent pull request that is about to merge, look at the message that will be written to main and see whether it still has a machine id and a session id. Do not stop at who blame points at, and do not stop at 3 passed.

What was actually run

Runtime: git 2.47.3, Python 3.13.5, and pytest 9.1.1 on this machine. Commit timestamps were fixed at 2026-11-19T12:00:00Z and incremented by seconds, so the short hashes are stable in this rebuild. Seed f53a1d2: tests 3 passed, probe apply_discount(2990, 500) was 2490. Every commit with the rounding error: tests 3 passed, probe 2400.

The Chen Hao branch with Machine trailers is f38dbc6; the introducing commit is e3edf32; blame is Chen Hao; attributed allows it. The branch with no trailers is a588970; the introducing commit is 5112463; attributed refuses. The machine-author branch head is 99a9411; the introducing commit is f671e58; blame is machine-2-agent; shortlog is 3 machine commits and 1 Chen Hao. The single commit 6e755c6 squash-defaults to 66502e2, keeps the trailers, and is allowed.

The default multi-commit squash 9217b51, the title-only squash 09591f8, and the title-plus-commit-details squash 5866ed4 have no Machine line; tests_only allows them, attributed refuses. 26066ad, with trailers in the PR body, is allowed. e95e133, whose body ends in Tests: 3 passed., parses that tests line as a trailer and is still refused. Harvested 260471b is allowed; blame is still Chen Hao. The machine-author default squash 1de4687 points blame back at Chen Hao, and shortlog is 2 Chen Hao commits. Harvested 2bc76da is allowed after the Machine: 2 parser was fixed; blame is still Chen Hao.

git interpret-trailers --parse: Machine: 2 parses; official Made with Cursor does not; Claude's Co-Authored-By parses on its own; the same line followed by Made with Cursor at the end of the message parses as empty. The official-footer branch head 604267d has empty %(trailers), and the harvested landing 7040876 is refused.

Not run: a squash in the GitHub UI or API; GitHub Actions (the YAML was checked for structure); branch protection or a ruleset; Windows or windows-latest; a live commit produced by Cursor or Claude Code (the product lines were typed as fixtures from public documentation and public discussion); a second GitHub account. Chen Hao, chenhao@team.invalid, and machine-2-agent@iotxing.invalid are lab fixtures.