三人、七台电脑。1 到 3 号机跑编码代理,4、5 号机审查,6 号机做 Windows 验证,7 号机负责合入。生产部署的工作流当初是从拉取请求的 CI 里抄过来的,连带抄上了这几行:
concurrency:
group: production-deploy
cancel-in-progress: true
在拉取请求上,这样写是合理的。旧的检查还没跑完,新的提交已经让它过时,取消可以省掉几分钟,而且那次作业通常只读代码、跑测试,不会去改一份大家共用的数据库。同一份设置落到生产部署上,含义就变了。部署作业不只是编译一个制品,它会改共享状态。
这天 7 号机先把 1 号机的 pull request 合进 main。那一趟要给已有订单补上必填的 partner_id,规则是写成 internal。回填按单走,每条停几秒,还要把进度提交到生产状态里,所以这趟部署会跑两到三分钟。四十多秒之后,2 号机的 pull request 也落到了 main 上:剩下的订单、以及新的合作方结账,默认改成 web。GitHub 看到同一组 production-deploy 里又来了一趟,就把还在回填的那一趟取消了。生产库停在半更新:一部分订单已经有 partner_id=internal,其余的还没有;部署锁停在 migrating。随后,第二趟部署在这份脏数据上接着跑。
这正是这次在 GitHub Actions 上看到的事。
我在 GitHub 上建了一个公开的实验室仓库 shuizhengqi1/iotxing-lab-prod-deploy-cancelled-20261205。店铺数据是 chen@shop.invalid、li@shop.invalid 这一类,没有真实顾客资料,也没有真实卡号。夹具提交是按常见的分单写法准备的,并没有再开一个编码模型来生成这些 diff。实验室没有在 Windows 上跑测试,下文也不对 6 号机做任何断言。
所谓「生产库」在这里是一条名叫 lab-prod 的分支,上面只有 prod/orders.json 和 prod/deploy_state.json。部署作业用 GITHUB_TOKEN 去更新这条分支。工作流只在 main 上触发,而且 GITHUB_TOKEN 的推送默认不会再启动一轮新的工作流,所以回填进度提交不会递归引爆部署。这是替身,不是真实商户的生产系统。录完结果之后,线上工作流仍是那份会取消进行中作业的 deploy.yml;推荐的排队和互斥锁放在配套包里,没有被设成这个实验室仓库的必检工作流。

为什么 PR CI 可以取消,生产回填不行
cancel-in-progress: true 的本意,是让同一并发组里只保留「最新那一次」。对拉取请求的检查来说,这几乎总是对的。前一次 pytest 跑到一半,作者又推了一笔,旧结果已经没有决策价值,留着只会占 runner。取消它,等于丢掉一次只读计算。
生产部署一旦开始回填,作业的副作用就已经写进共享状态里了。这次实验室里的 scripts/deploy.py 会先把 deploy_state 写成 migrating 并推到 lab-prod,再按当前仓库里的默认规则,给还没有 partner_id 的订单赋值,每五条提交一次进度,全部完成后才把状态改回 live。它故意写得慢,每条睡五秒,是为了把「进行到一半被取消」这件事暴露出来,而不是为了模拟某家真实商户的耗时。
GitHub 取消一次 in-progress 的作业,并不是礼貌地通知脚本去收尾。日志里最后一行是 The operation was canceled. 回填循环、尚未推送的本地进度、把锁改回 live 的那一步,都不会再执行。已经推上去的进度提交还在。于是数据库停在一个既不是旧版、也不是新版的中间态:锁还是 migrating,一部分行已经变了,一部分还没有。
下一趟部署并不会先问「上一趟是不是还没做完」。它只是再 checkout 一次 main 上的新 SHA,再 fetch 一次 lab-prod,再按自己带来的规则继续填空。若脚本对已有 partner_id 保持幂等——这次就是这样——它会留下上一趟已经写进去的值,只把剩下的行按新规则补上。于是同一张订单表里出现了两种来源不同的 partner_id。看起来像是一次「合作方分配策略」,其实只是两次部署在时间上撞车的残骸。
这和语义冲突、错误的制品 SHA、从功能分支拉热修,不是同一类事故。这里没有合错文件,也没有发错包。被抄错的是并发策略本身:把「可以丢掉的检查」当成了「可以杀掉的迁移」。
实验室里实际看到的
种子提交 950e92d124fa 于 18:43:39(Asia/Shanghai,下同)给出了三十张没有 partner_id 的订单。lab-prod 的种子是 ca87554d28e4,状态为 live。SHA-A 63e02fc64f35be670447e7f94288db60a1545352 于 18:44:29 把回填脚本和那份会取消进行中作业的工作流加进 main,18:44:35 推送。
运行 47510919673 在 18:44:40 创建,18:44:45 打出 DEPLOY_START ref=refs/heads/main sha=63e02fc64f35be670447e7f94288db60a1545352,随即把 lab-prod 标成 migrating。18:45:12 第一次进度提交 3a2c1573ed1d 落地:internal=5 web=0 missing=25。被写成 internal 的是 ord_1001 到 ord_1005,赋值时间从 18:44:51 到 18:45:11,partner_assigned_by_sha 都是 SHA-A。18:45:15,SHA-B 72fdbc44fd96c90737583b81c468c5397cc09ee8 被推上 main。18:45:31,运行 A 的日志出现 The operation was canceled. 结论是 cancelled,没有 DEPLOY_DONE。作业在 18:45:33 结束。
此时 lab-prod 仍是 migrating,五条已回填,二十五条空着。运行 47510976235 在 18:45:18 就已创建,A 还没取消时它处于 pending,作业于 18:45:36 开始。18:45:44 它打出 DEPLOY_START,紧接着是 DEPLOY_FETCHED total=30 partner_internal=5 partner_web=0 missing=25 deploy_status=migrating。第二趟部署看见的就是那份被取消的半成品。它没有退出,也没有回滚,而是按 SHA-B 带来的规则 web,从第一条还缺 partner_id 的订单继续填。ord_1006 到 ord_1030 陆续被写成 web,partner_assigned_by_sha 都是 SHA-B。
18:47:57,最后一次成功推到远程的进度提交是 f102e453a77e5b6e8924ab8eae4b42872003e391:internal=5 web=25 missing=0,状态仍是 migrating,finished_at 仍是空的。脚本在 runner 本地又做了一次「deploy done live」提交,但 18:48:05 推送被远程拒绝:! [remote rejected] HEAD -> lab-prod (failed)。作业因此以 failure 收场,日志里没有 DEPLOY_DONE。远程的 lab-prod 停在 f102e45。GitHub 返回的拒绝原因很短,我没有单独复现这一次推送失败,所以不把它解释成某种确定的钩子策略。需要记住的是已经写进远程的事实:五条来源是 SHA-A 的 internal,二十五条来源是 SHA-B 的 web,部署锁没有回到 live。
第二趟部署并没有给出一个「成功的绿钩、但数据是脏的」——它比那种情况更糟。钩子是红的,数据已经被改完了,锁还卡着。若有人只看 Actions 的红叉,以为生产没动,就会漏掉已经分裂的订单表;若有人只看「二十五条空行被填上了」,又会忽略锁还停在 migrating,下一趟部署会面对一份说自己正在迁移的库。

为了对照修法,我在保留实验 A 证据的前提下,把 lab-prod 强制推回种子 ca87554d28e4(实验 A 的脏尖端仍留在标签 experiment-a-lab-prod-dirty 和分支 lab-prod-after-experiment-a),再把工作流临时改成 cancel-in-progress: false。这次强制推送是实验室操作,下面会写清楚。
SHA-B1 9b2e2ce3765282a62cae89abfb8647fa55bdbfcb 于 18:50:09 推送,规则回到 internal。运行 47511386014 在 18:50:12 创建,18:50:14 进入 in_progress。18:50:16,SHA-B2 d408f6b0870ab72a5f9a557ce9a6354e823871b6 把默认规则再改回 web 并推送。运行 47511396816 随即出现,并且在 B1 整个回填期间一直是 pending;B1 结束后、runner 接手前,还看到过 queued。B1 没有被取消。它在 18:52:58 打出 DEPLOY_DONE ... backfilled=30,三十条订单全部是 internal,状态回到 live。B2 的作业到 18:53:03 才开始,18:53:05 看到的是 DEPLOY_FETCHED total=30 partner_internal=30 missing=0 deploy_status=live,BACKFILL_START rule=web pending=0,18:53:08 DEPLOY_DONE ... backfilled=0。最终订单表仍是三十条 internal,没有一条被改成 web。第二趟部署跑的是更新的 SHA,但它是在上一趟迁移已经结束、数据库一致之后才动的。
排队能避免两趟部署叠在一起写。它不能代替另一道更窄的闸:若因为别的入口、重试或误配,第二趟仍然在 status=migrating 时启动,脚本应当直接非零退出,或者安全地恢复同一趟迁移,而不是按新规则接着填空。这道互斥锁我在本地用同一份 scripts/deploy.py(ENFORCE_DEPLOY_MUTEX=1)演示过:人为留下 internal=10 missing=20 status=migrating 之后,第二次调用打出 DEPLOY_BLOCKED reason=already_migrating,退出码 1,计数和锁都没有变。这不是 GitHub Actions 上的重叠竞态,因为一旦 cancel-in-progress 为 false,第二趟会等第一趟结束,锁在启动时往往已经是 live。互斥锁是防重叠的深一层,不是实验 B 在 Actions 上观察到的那件事。不要把本地结果说成是线上跑出来的。
录完实验 B 之后,为了让实验室仓库的直播头重新停在实验 A 的脏状态、并且不要再触发第五趟部署,我短暂关闭了这个仓库的 Actions,把 main 强制推回 72fdbc44fd96(仍是 cancel-in-progress: true),把 lab-prod 强制推回 f102e45,再打开 Actions。当前运行列表仍然只有上面四次,没有第五趟。实验 B 的提交留在分支 experiment-b 和相应标签上。推荐的闸门因此没有成为这个实验室的线上必检工作流。
钢人:第二笔 SHA 更新,为什么还要把旧部署跑完?
最有力的反对意见是这样的:SHA-B 才是现在的 main,它代表更新的产品决定——剩下的订单应该是 web,而不是 internal。继续把 SHA-A 跑完,等于明知规则已经改了,还要故意把二十五条写成旧值。取消旧部署、让新部署接手,不正是连续交付想要的吗?若回填脚本是幂等的,杀了重来也不该坏。
这个反对意见的前半句是对的。新 SHA 确实更新,产品决定也可以改。错在「接手」两个字被理解成了「从中间接着写」。取消发生时,SHA-A 已经把五条订单写成了 internal。新部署并没有把这五条改成 web,也没有把整张表恢复到「全部缺 partner_id」再按新规则重来。它只填空。于是最终既不是「全部 internal」(旧规则跑完),也不是「全部 web」(新规则贯彻),而是按取消时刻切了一刀。这不是一次经过设计的迁移,是一次由 runner 被杀掉的时刻决定的分配。
如果你的确希望新规则作用于所有已有订单,正确顺序是:先让已经开始的迁移结束,或把它显式回滚到一个一致点;然后再跑一趟针对「已经带有 partner_id 的行」的、写进变更记录的迁移。那是一个新的、可审查的决定,不是第二趟部署在脏数据上顺便完成的副作用。实验 B 给出的是前半段:先让 in-flight 的回填把库带回 live 且三十条一致,再让排在后面的部署在一致的库上运行最新 SHA。因为已有行被幂等地跳过,B2 没有偷偷改写那三十条 internal。若产品这时仍想把它们改成 web,应该另开一趟迁移,而不是指望「取消再来一次」自动得到正确结果。
「脚本是幂等的,所以杀了也没关系」同样经不起这次观察。幂等保证的是「同一条规则再跑一遍不会把已写的值改乱」,并不保证「两条不同规则前后接力会得到一种有意义的分配」。它也保证不了锁会被清掉。实验 A 里,第二趟甚至没能把 live 推上去,migrating 一直留在远程。下一次再有人部署,面对的就是一把没释放的锁和一张已经分裂的表。
还有一种更窄的优化是成立的:如果这一个 SHA 已经不再是最新的 main,并且部署还没有开始改库,那么跳过它、直接去跑最新 SHA,可以少做一趟无效工作。可选的「过期则跳过」必须卡在变异开始之前。一旦 deploy_state 已经写成 migrating,或已经有行被改写,就只能做完或回滚,不能 SIGKILL。
代价,以及这套修法不适用的时候
把 cancel-in-progress 改成 false,意味着较新的 SHA 可能要等一趟已经开始的部署结束。若回填要三分钟,2 号机的合并不会立刻生效。对生产迁移来说,这通常是正确的延迟。若三分钟不可接受,该做的是把迁移做得更短、可重启、可扩展收缩,而不是把进行中的写入杀掉。
这套做法也不该被理解成「永远不要取消任何部署」。如果发布是不可变的、原子的——比如只是把一个已经做好的容器切到线上,旧环境没有被写到一半,取消未完成的 rollout 往往是安全的。预览环境、按 PR 起的临时应用,也可以继续用 cancel-in-progress: true。即便如此,只要同一次作业里还夹着不能向前兼容的模式迁移,仍需要一把部署锁;GitHub 的 concurrency 只锁作业,并不协调数据库迁移。若团队已经有成熟的发布队列(自建的部署协调器,或专门的发布产品),应当用那个队列来串行化变异,而不是指望 GitHub Actions 的并发组充当迁移协调器。即使如此,只要作业本身会改共享状态,也不要把 cancel-in-progress 设成 true。
可重启、可扩展收缩的迁移能减小伤害:重跑时跳过已写的行,向前兼容的加列可以先加后填。它替代不了互斥。取消一次进行中的变异,仍然是错的。实验 A 的脚本已经对已有 partner_id 做了跳过,伤害还是发生了,因为跳过把两种规则并存给固化了。
这次没有验证的事
实验室没有在 Windows 上跑,6 号机不在范围内。lab-prod 不是真实商户库。夹具提交不是现场编码模型生成的,文中也不编造「代理总会如何」的比例。互斥锁只在本地演示,没有在 GitHub 上制造两次作业同时写库的竞态。回滚路径没有写成可执行的 down migration,只论证了「必须先结束或回滚」这个顺序。仓库没有分支保护,也没有给 production 配 GitHub Environment 必批人。第二趟部署最后一次推 live 被远程拒绝,原因信息很少,我没有把它单独做成一条可重复的失败案例。实验 B 为了重置替身库,对 lab-prod 做了强制推送;录完后又短暂关闭 Actions,把 main 和 lab-prod 推回实验 A 的尖端。这些强制推送都只发生在实验室仓库里,并且已经在上文交代。

明天能抄走的做法
不要把拉取请求 CI 上的 cancel-in-progress: true 抄到会改共享状态的生产部署工作流上。生产部署应当排队:cancel-in-progress: false。再补一把更窄的锁:若替身或真实库的部署状态已经是 migrating,新的部署必须非零退出,或安全地恢复同一趟迁移,而不能按另一套规则在脏数据上接着填。迁移应当可重启,尽可能先扩展再收缩,但这不能代替互斥。一旦变异已经开始,就只能做完或回滚;不要在回填中途发 SIGKILL。若某个 SHA 已经不是最新,且还没有开始改库,可以跳过它、去跑最新 SHA;排在后面的部署可以在库重新一致之后再跟到最新 SHA。看钩子不够,还要看部署状态和数据本身:实验 A 的第二趟是红叉,二十五条订单却已经按新规则写完,锁仍停在 migrating。
完整脚本、有缺陷的工作流、推荐的排队工作流、互斥开关、原始日志和 git bundle:prod-deploy-cancelled-kit.tar.gz。
The production deploy was still backfilling partner_id when the next merge cancelled it
Three people, seven computers. Machines 1 to 3 run coding agents, 4 and 5 review, 6 does Windows validation, and 7 merges. The production deploy workflow was copied from pull-request CI, including these lines:
concurrency:
group: production-deploy
cancel-in-progress: true
On a pull request, that setting is reasonable. If an older check is still running when a newer commit lands, the old result is already stale. Cancelling it saves minutes, and that job is usually read-only: it reads code and runs tests, it does not mutate a shared database. The same setting on a production deploy means something else. The job is not only building an artifact. It mutates shared state.
On this day machine 7 first merged machine 1's pull request into main. That deploy had to backfill a required partner_id onto existing orders, with the rule set to internal. The backfill walked the catalog order by order, slept a few seconds per row, and committed progress into the production state, so the deploy would take two to three minutes. Forty-plus seconds later, machine 2's pull request also landed on main: leftover orders, and new partner checkout, should default to web. GitHub saw another run in the same production-deploy group and cancelled the backfill that was still in progress. The production database stopped half-updated: some orders already had partner_id=internal, the rest did not; the deploy lock stayed at migrating. The second deploy then started on that dirty state.
That is what this run showed on GitHub Actions.
I created a public lab repository, shuizhengqi1/iotxing-lab-prod-deploy-cancelled-20261205. Shop records use addresses such as chen@shop.invalid and li@shop.invalid. There is no real customer PII and no real card numbers. The fixture commits were prepared in the ordinary ticket-splitting style; I did not launch a coding model to produce those diffs. The lab did not run tests on Windows, and nothing below makes a claim about machine 6.
"Production" here is a branch named lab-prod, holding only prod/orders.json and prod/deploy_state.json. The deploy job updates that branch with GITHUB_TOKEN. The workflow triggers only on main, and GITHUB_TOKEN pushes do not start a new workflow run, so progress commits do not recursively fire another deploy. This is a stand-in, not a real merchant production system. After the results were recorded, the live workflow is again the deploy.yml that cancels in-progress jobs. The recommended queue and mutex shipped in the kit were not installed as the required workflow on this lab.

Why pull-request CI may cancel, and a production backfill may not
cancel-in-progress: true is meant to keep only the latest run in a concurrency group. For pull-request checks that is almost always right. If pytest is halfway through when the author pushes again, the old result has no decision value and only occupies a runner. Cancelling it throws away a read-only computation.
Once a production deploy has started a backfill, the job's side effects are already in shared state. In this lab, scripts/deploy.py first writes deploy_state as migrating and pushes that to lab-prod, then assigns partner_id on orders that still lack one, using the default rule in the current tree, committing progress every five rows, and only then setting status back to live. It is deliberately slow — five seconds per order — so that a mid-backfill cancel can be observed. It is not an attempt to mimic a particular merchant's latency.
When GitHub cancels an in-progress job, it does not politely ask the script to finish. The last line in the log is The operation was canceled. The backfill loop, any unpushed local progress, and the step that would return the lock to live do not run again. Progress commits that already landed stay landed. The database is left in a state that is neither the old version nor the new one: the lock is still migrating, some rows have changed, some have not.
The next deploy does not first ask whether the previous one finished. It checks out the new SHA on main, fetches lab-prod again, and continues filling blanks under the rule it brought with it. If the script is idempotent about rows that already have a partner_id — and this one is — it leaves the values written by the cancelled run and fills only the remainder under the new rule. The same order table then holds two different sources of partner_id. It looks like a partner-assignment policy. It is the wreckage of two deploys colliding in time.
This is not the same accident as a semantic conflict, a wrong artifact SHA, or a hotfix cut from a feature branch. No file was merged wrongly, and no package was shipped from the wrong tree. What was copied wrongly was the concurrency policy itself: treating a disposable check as a migration you can kill.
What the lab actually showed
Seed commit 950e92d124fa at 18:43:39 (Asia/Shanghai, same below) provided thirty orders with no partner_id. The lab-prod seed was ca87554d28e4, with status live. SHA-A 63e02fc64f35be670447e7f94288db60a1545352 at 18:44:29 added the backfill script and the cancelling workflow to main, and was pushed at 18:44:35.
Run 47510919673 was created at 18:44:40 and printed DEPLOY_START ref=refs/heads/main sha=63e02fc64f35be670447e7f94288db60a1545352 at 18:44:45, then marked lab-prod as migrating. The first progress commit, 3a2c1573ed1d, landed at 18:45:12: internal=5 web=0 missing=25. The rows written as internal were ord_1001 through ord_1005, assigned from 18:44:51 to 18:45:11, all with partner_assigned_by_sha equal to SHA-A. At 18:45:15, SHA-B 72fdbc44fd96c90737583b81c468c5397cc09ee8 was pushed to main. At 18:45:31 the log for run A showed The operation was canceled. The conclusion was cancelled. There was no DEPLOY_DONE. The job finished at 18:45:33.
lab-prod was still migrating, with five rows backfilled and twenty-five empty. Run 47510976235 had already been created at 18:45:18 and sat pending while A was still running; its job started at 18:45:36. At 18:45:44 it printed DEPLOY_START, then DEPLOY_FETCHED total=30 partner_internal=5 partner_web=0 missing=25 deploy_status=migrating. The second deploy saw the half-finished work of the cancelled run. It did not exit, and it did not roll back. It continued from the first order still missing partner_id, under SHA-B's rule web. ord_1006 through ord_1030 were written as web, all with partner_assigned_by_sha equal to SHA-B.
At 18:47:57 the last progress commit that successfully reached the remote was f102e453a77e5b6e8924ab8eae4b42872003e391: internal=5 web=25 missing=0, status still migrating, finished_at still empty. The script created a local "deploy done live" commit on the runner, but the push at 18:48:05 was rejected: ! [remote rejected] HEAD -> lab-prod (failed). The job ended as failure, and the log has no DEPLOY_DONE. Remote lab-prod stayed at f102e45. GitHub's rejection message was sparse; I did not reproduce that push failure in isolation, and I will not treat it as a known hook policy. What matters is what already landed: five rows sourced from SHA-A as internal, twenty-five sourced from SHA-B as web, and a deploy lock that never returned to live.
The second deploy did not even give us "a green hook on dirty data." It was worse. The hook is red, the data is already changed, and the lock is stuck. If someone looks only at the red X in Actions and assumes production did not move, they miss a split catalog. If someone looks only at "the twenty-five empty rows were filled," they miss that the lock is still migrating, and the next deploy will face a database that claims a migration is in flight.

To compare a fix, I force-pushed lab-prod back to seed ca87554d28e4 while keeping experiment A's dirty tip on the tag experiment-a-lab-prod-dirty and the branch lab-prod-after-experiment-a, then temporarily set the workflow to cancel-in-progress: false. That force-push is a lab operation, and it is disclosed here.
SHA-B1 9b2e2ce3765282a62cae89abfb8647fa55bdbfcb was pushed at 18:50:09, with the rule restored to internal. Run 47511386014 was created at 18:50:12 and entered in_progress at 18:50:14. At 18:50:16, SHA-B2 d408f6b0870ab72a5f9a557ce9a6354e823871b6 changed the default back to web and was pushed. Run 47511396816 appeared immediately and stayed pending for the whole of B1's backfill; after B1 finished and before a runner picked it up, it was also observed as queued. B1 was not cancelled. At 18:52:58 it printed DEPLOY_DONE ... backfilled=30, all thirty orders were internal, and status returned to live. B2's job started only at 18:53:03. At 18:53:05 it saw DEPLOY_FETCHED total=30 partner_internal=30 missing=0 deploy_status=live, then BACKFILL_START rule=web pending=0, and at 18:53:08 DEPLOY_DONE ... backfilled=0. The catalog was still thirty internal rows; none were rewritten as web. The second deploy ran the newer SHA, but only after the in-flight migration had finished and the database was consistent.
Queuing keeps two deploys from writing at the same time. It does not replace a narrower gate: if some other entry point, retry, or misconfiguration starts a second deploy while status is still migrating, the script should exit non-zero, or resume the same migration safely, and must not continue filling blanks under a different rule. I demonstrated that mutex locally with the same scripts/deploy.py (ENFORCE_DEPLOY_MUTEX=1). After a simulated mid-backfill cancel leaving internal=10 missing=20 status=migrating, the second invocation printed DEPLOY_BLOCKED reason=already_migrating, exited 1, and left the counts and the lock unchanged. That is not an overlapping race on GitHub Actions, because once cancel-in-progress is false, the second run waits for the first to finish, and the lock is usually live by the time it starts. The mutex is defense in depth, not what experiment B observed on Actions. Do not treat the local result as a GitHub run.
After experiment B was recorded, I briefly disabled Actions on the lab repository so a restore would not start a fifth deploy, force-pushed main back to 72fdbc44fd96 (still cancel-in-progress: true), force-pushed lab-prod back to f102e45, and re-enabled Actions. The run list still contains only the four runs above; no fifth run was created. Experiment B's commits remain on the experiment-b branch and the corresponding tags. The recommended gate was therefore not made the live required workflow on this lab.
Steelman: the second SHA is newer, so why finish an outdated deploy?
The strongest objection is this: SHA-B is now main. It represents the newer product decision — leftover orders should be web, not internal. Finishing SHA-A means knowingly writing the old value onto twenty-five rows after the rule has changed. Cancelling the old deploy and letting the new one take over is what continuous delivery is for. If the backfill is idempotent, killing it and starting again should be safe.
The first half of that objection is right. The new SHA is newer, and the product decision may change. The mistake is in reading "take over" as "continue writing from the middle." When the cancel happened, SHA-A had already written five orders as internal. The new deploy did not rewrite those five as web, and it did not restore the table to "all missing partner_id" and apply the new rule from scratch. It only filled blanks. The result is neither "all internal" (the old rule completed) nor "all web" (the new rule applied). It is a cut at the moment the runner was killed. That is not a designed migration. It is an assignment decided by when a job was cancelled.
If you really want the new rule on every existing order, the right order is: let the migration that already started finish, or roll it back to a consistent point; then run a new, recorded migration that targets rows that already have a partner_id. That is a reviewable decision, not a side effect of a second deploy continuing on dirty data. Experiment B shows the first half of that order: let the in-flight backfill return the database to live with thirty consistent rows, then let the queued deploy run the latest SHA on that consistent database. Because existing rows were skipped idempotently, B2 did not quietly rewrite those thirty internal values. If the product still wants them to become web, that should be a separate migration, not something you get automatically by cancelling and trying again.
"The script is idempotent, so killing it is fine" also does not survive this run. Idempotence says that running the same rule again will not scramble values already written under that rule. It does not say that two different rules, applied in a relay, will produce a meaningful assignment. It also does not say the lock will be cleared. In experiment A, the second run never even pushed live, and migrating stayed on the remote. The next person to deploy faces an unreleased lock and a catalog that is already split.
A narrower optimization does hold: if this SHA is no longer the latest main, and the deploy has not yet started mutating the database, it can skip and let the latest SHA run. An optional "skip if stale" check must be gated on mutation not having started. Once deploy_state is migrating, or any row has been rewritten, the job must finish or roll back. It must not be SIGKILLed.
Trade-offs, and when this fix does not fit
Setting cancel-in-progress to false means a newer SHA may wait for a deploy that has already started. If the backfill takes three minutes, machine 2's merge does not take effect immediately. For a production migration, that delay is usually the correct one. If three minutes is unacceptable, the work is to make the migration shorter, restartable, and expand/contract — not to kill an in-flight write.
This should not be read as "never cancel any deploy." If a release is immutable and atomic — for example, switching traffic to a container that is already built, with no half-written old environment — cancelling an unfinished rollout is often safe. Preview apps and ephemeral environments per pull request can keep cancel-in-progress: true. Even then, if the same job also runs a schema migration that is not backward compatible, you still need a deploy lock. GitHub concurrency locks a job; it does not coordinate a database migration. If the team already has a real deploy queue (an in-house coordinator, or a dedicated release product), serialize mutations there, rather than asking a GitHub Actions concurrency group to be the migration coordinator. Even in that setup, if the job itself mutates shared state, do not set cancel-in-progress to true.
Restartable, expand/contract migrations reduce damage: a rerun skips rows already written, and an additive column can be added before it is backfilled. They do not replace the mutex. Cancelling a mutation in flight is still wrong. The experiment A script already skipped existing partner_id values, and the damage still happened, because that skip froze two rules side by side.
What was not tested
The lab did not run on Windows; machine 6 is out of scope. lab-prod is not a real merchant database. Fixture commits were not produced by a live coding model, and this post does not invent an "agents always do X" rate. The mutex was demonstrated locally only; I did not manufacture an overlapping two-writer race on GitHub. A rollback path was not implemented as an executable down-migration; the argument is about the required order — finish or roll back first. The repository has no branch protection and no required reviewers on a GitHub Environment. The final live push of the second experiment A deploy was remotely rejected with a sparse error; I did not turn that into a standalone reproducible failure. Experiment B force-pushed lab-prod to reset the stand-in database; after recording, Actions was briefly disabled so main and lab-prod could be restored to the experiment A tips. Those force-pushes happened only on the lab repository and are disclosed above.

What to copy tomorrow
Do not copy cancel-in-progress: true from pull-request CI onto a production deploy workflow that mutates shared state. Production deploys should queue: cancel-in-progress: false. Add a narrower lock as well: if the stand-in or the real database is already migrating, the new deploy must exit non-zero, or resume the same migration safely, and must not continue a backfill under a different rule on dirty data. Migrations should be restartable, and where possible they should expand then contract, but that does not replace the mutex. Once mutation has started, finish or roll back; do not SIGKILL a backfill in the middle. If a SHA is no longer latest and no mutation has started, it may skip and leave the work to the latest SHA; a queued deploy may then run that latest SHA once the database is consistent again. Watching the hook is not enough. Watch the deploy state and the data: experiment A's second run was a red X, twenty-five orders had already been written under the new rule, and the lock was still migrating.
Complete scripts, the buggy workflow, the recommended queuing workflow, the mutex flag, raw logs, and a git bundle: prod-deploy-cancelled-kit.tar.gz.