三人、七台电脑。1 到 3 号机跑编码代理,4、5 号机审查,6 号机做 Windows 验证,7 号机负责合入。1 号机上的代理这天已经在 feat/refund-reason 上开工:给 refund_order 加一个可选的 reason,方便仓储记下退款原因。改写函数签名的时候,它把 shipped 从 LOCKED_STATUSES 里拿掉了。测试已经红了:test_shipped_order_cannot_be_refunded 不再抛出 RefundError。这单还没交审查,也本来不该发。
然后来了一张紧急工单。线上给顾客看的退款提示写成了 canot,要改成 cannot。工单写得很窄:只动 src/shop/messages.py,从当前生产也就是 origin/main 拉分支。1 号机的工作目录还停在那条功能分支上。代理从当前 HEAD 拉了 hotfix/canot-typo,改了那一个字,推了上去。
这个仓库的生产部署不看 pull request,只看分支名。deploy.yml 写着:推到 main、hotfix/** 或 release/**,就进入 deploy-production 作业。作业里没有测试,没有 GitHub Environment,也没有人点批准。推送本身就是发版。功能分支 feat/refund-reason 不会触发部署,所以未完成的退款改动一直停在 1 号机上,看起来还安全。可一旦这条改动被带进一个名字以 hotfix/ 开头的分支,它就会跟那个错字一起被部署出去。
这正是这次发生的事。
我在 GitHub 上建了一个公开的实验室仓库 shuizhengqi1/iotxing-lab-hotfix-from-feature-20261204。店铺数据是 zhou@shop.invalid 这一类,卡号后四位是 1111,都不是真实商户。夹具提交是按常见的分单写法准备的,并没有再开一个编码模型来生成这些 diff。仓库没有分支保护,也没有给 production 配必批人;线上的工作流就是上面那份无闸门的 deploy.yml。祖先闸门是在本地跑的,作为推荐修法放在 scripts/hotfix_ancestry_gate.py 和 scripts/deploy-gated.yml 里,没有被设成这个实验室仓库的必检工作流。实验室没有在 Windows 上跑测试。部署作业并不对接真实生产环境,它在被推送的 SHA 上跑一次已发货退款探测,用来标明「如果这就是发到生产的那棵树,顾客会得到什么」。
为什么改一个错字会把未完成的退款带上生产
热修分支的第一件事不是改字,而是选父提交。工单说从 origin/main 拉。代理看到的是当前工作目录里的 HEAD。1 号机当时停在 feat/refund-reason,HEAD 已经包含那次把 shipped 拿掉的改动。从这里执行 git checkout -b hotfix/canot-typo,再怎么只改 messages.py,git log main..HEAD 里都会多出那次退款改写。git diff --name-only main...HEAD 里也会出现 src/shop/refund.py。对 Git 来说这很正常:hotfix 分支继承了它出发的那一点。
第二件事是仓库把分支名当成了发版开关。团队当初配 hotfix/** 和 release/**,往往是为了线上出事时少走一道 PR。这个习惯在人比较少、热修都从主干手拉的时候,勉强能用。代理把两个条件同时放大了:它干活时工作目录很少干净地停在 main 上,又很愿意按工单里的「hotfix」来起分支名。于是「从哪来」和「叫什么」被拆开了。叫对了名字,父提交却是错的。
第三件事是这份部署作业不跑测试。功能分支上已经有两则失败:test_shipped_order_cannot_be_refunded,以及对照顾客文案的那则测试。若发版前在同一 SHA 上跑 pytest -q,这次推送过不了。可工作流里没有这一步,所以红测试挡不住绿的部署勾。
还有一个容易看走眼的地方。热修是直接部署分支上的 SHA,并不先合进 main。事后若有人只看主干,会以为生产还停在种子提交上:错字还在,已发货退款也还锁着。真正跑起来的,是 hotfix/canot-typo 那个提交。
7 号机如果只看 GitHub 上 main 的勾,会得出和事实相反的结论。种子提交的部署运行 47319693837 是成功的,探测也是 rejected。hotfix 那次成功运行 47319695455 用的是另一个 ref。两条运行在同一分钟里都打了绿勾,作业名还都叫 deploy-production。若通知只说「生产部署成功」,而不写 ref 和 SHA,值班的人会以为主干刚又发了一次,不会想到发上去的是功能分支上那棵未完成的树。
实验室里实际跑出来的结果
种子提交 62a343ad251d(62a343ad251d33b521f2765b8ef943649a9fc90f)在 2026-12-04 18:50:09(Asia/Shanghai)落在 main 上。顾客文案里是 canot,LOCKED_STATUSES 仍包含 shipped 和 delivered。pytest -q 是 8 passed。对已发货订单 ord_1002 的探测是 PROBE_RESULT=rejected。把 main 推上 GitHub 之后,运行 47319693837 于 18:50:39 开始,18:50:47 成功,日志里是:
DEPLOY_START ref=refs/heads/main sha=62a343ad251d33b521f2765b8ef943649a9fc90f
PROBE_RESULT=rejected reason=order ord_1002 status shipped canot be refunded
DEPLOY_DONE ref=refs/heads/main sha=62a343ad251d33b521f2765b8ef943649a9fc90f
功能分支提交 f829218dee78(f829218dee78b051cca20c843901fc445aac8f2d)在 18:50:11 写上 feat/refund-reason。refund_order 多了 reason 参数,却在改写时丢掉了 shipped。同一分钟里 pytest -q 是 2 failed, 6 passed,失败的正是已发货不可退的两则。探测变成 PROBE_RESULT=allowed,ord_1002 的状态变成 refunded,还带上了 refund_reason=probe。把这条功能分支推上去以后,Actions 里没有出现对应的 deploy-production 运行。feat/** 不在触发名单里。
实验 A 从这条功能分支拉出 hotfix/canot-typo,提交 4a2d36bfa5a8(4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8)在 18:50:14 只改了 messages.py,把 canot 写成 cannot。相对 main,历史上却有两层:
4a2d36b hotfix: correct canot typo in refund locked message
f829218 wip: add refund reason, still editing locked statuses
文件列表是 src/shop/messages.py 和 src/shop/refund.py。测试仍然是 2 failed, 6 passed。本地那份故意写坏的 scripts/simulate_deploy.sh 不跑测试,直接探测,结果是 allowed。GitHub 上的同名工作流也是这样:运行 47319695455 于 18:50:39 开始,18:50:48 成功。它没有问任何人,也没有因为测试失败而停下来:
DEPLOY_START ref=refs/heads/hotfix/canot-typo sha=4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8
PROBE_RESULT=allowed order={'id': 'ord_1002', 'email': 'chen@shop.invalid', 'status': 'refunded', 'amount': 880, 'card_last4': '1111', 'address': 'Ningbo', 'refund_reason': 'probe'}
DEPLOY_DONE ref=refs/heads/hotfix/canot-typo sha=4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8
实验 B 回到 main,再拉 hotfix/canot-typo-from-main。提交 5e22930e07be(5e22930e07bed69a0cd4cad40e1ff39054d496e6)在 18:50:16,相对 main 只有 typo 那一层,diff 只有 messages.py。pytest -q 是 8 passed。探测是 rejected,文案已经是 cannot。运行 47319696000 同样在没有人批准的情况下部署成功,不过这棵树上已发货订单仍不能退。


这和 live 支付已经打开,production 的批准还在等待 里的问题不同。那篇是作业已经挂在受保护的 environment 上,后来改了名字,GitHub 自动建出一个未受保护的同名环境。今天的工作流里根本没有 environment。触发条件只是分支名,批准从来没有进入过这条路径。
祖先闸门能拦住什么,拦不住什么
我写了一个本地脚本 scripts/hotfix_ancestry_gate.py。它做两件很窄的事。第一,git merge-base 必须等于当前 main,也就是这条热修得包含此刻的主干,而不是落在一截过期的历史上。第二,main 到 HEAD 之间改过的路径,只能是 src/shop/messages.py、README.md 或 docs/。工单既然说只改顾客文案,超出这个范围就应该失败。
在实验 A 的 SHA 上,对 main 跑闸门,输出是:
GATE_REF=hotfix/canot-typo
GATE_HEAD=4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8
GATE_BASE=62a343ad251d33b521f2765b8ef943649a9fc90f
GATE_MERGE_BASE=62a343ad251d33b521f2765b8ef943649a9fc90f
GATE_COMMITS<<<
4a2d36b hotfix: correct canot typo in refund locked message
f829218 wip: add refund reason, still editing locked statuses
>>>
GATE_FILES<<<
src/shop/messages.py
src/shop/refund.py
>>>
GATE=fail reason=disallowed_paths src/shop/refund.py
退出码是 1。值得注意的是,这里的 merge-base 其实就等于 main:功能分支是从当前主干拉的,祖先检查第一项并不会单独报警。真正把它拦住的,是文件列表里的 refund.py。如果只写「必须基于最新主干」,这次仍然会放行,因为基于最新主干并不等于「只有 typo 这一层」。
在实验 B 上,同样的脚本输出 GATE=pass,退出码 0,文件列表里只有 messages.py。它证明闸门不会误伤一份干净的错字热修。可它也提醒你:B 在实验室里一样被那份无闸门的工作流直接部署了。闸门解决的是「带上了不该带的提交」,不是「热修分支可以绕过审查」。
scripts/deploy-gated.yml 把这道闸门放进 hotfix/** 的部署路径:先跑祖先检查,再在同一个 SHA 上跑 pytest,通过了才继续。main 的部署不走这道白名单,因为主干上本来就会改 refund.py。即便如此,这份推荐工作流也还不是完整的发版制度。一个真实的仓库仍应给生产作业加上带必批人的 Environment,或者干脆取消按分支名部署,只接受合进 main 的发布,或只接受一次人工发布的 GitHub Release。

代价,以及什么时候不要这样做
先说最快的修法:不要让生产部署只看 hotfix/** 这种名字。代理很会按工单里的词来起分支,1 到 3 号机又经常同时开着功能分支。把「hotfix」写进分支名,不再等于「这是从生产拉出来的紧急修复」。代价是,以前那种「出了事推一个 hotfix 分支就能上」的通道会变慢。若你仍然需要一条快速通道,就给它单独做一套手续:从 origin/main 拉,跑测试,并让一个人对 production Environment 签字。不要把手续省回一个分支前缀。
祖先闸门的代价是误拦。真正要改 refund.py 的热修,会被 disallowed_paths 挡住。这时不该把 src/shop/ 整目录加进白名单,否则闸门立刻失去意义。这类改动应该回到 pull request,交给 4、5 号机看,再合进 main。闸门只适合「文案、文档、README」这种预先声明过的窄范围。范围一宽,它就只是又一道会绿的检查。
第一项检查「merge-base 等于当前 main」也会在主干刚前进时把合法热修拦住,这是故意的:主干刚合进别的 PR,热修需要先 rebase 再发,否则你又会回到「测试绿的是十分钟前的主干」那种组合问题。若团队热修极多、主干又推得很快,闸门会频繁要求更新。这是吞吐量和安全的交换,不是脚本写错了。
这套办法也有明确做不到的地方。实验室没有在 Windows 上跑,6 号机那一侧的行为我没有证据。夹具提交不是现场的编码模型写出来的,我不能把「代理一定会从功能分支拉 hotfix」说成统计结论;我能说的是,当工作目录不在 main 上、工单又带了 hotfix 这个词时,这条路径是通的,而且现有的分支名触发不会拦住它。闸门没有被设成这个实验室仓库的必检工作流,所以我没有在 GitHub 上演示「加了闸门之后,同一条 hotfix/canot-typo 会被 Actions 拒绝」。本地退出码和文件列表是有的,线上那一次成功的部署,记录的是未加闸门的工作流。
最后,即使热修只改了 messages.py,也仍可能把错误的文案发到生产。闸门不审中文对不对,只审是不是多带了别的文件。审查仍然要有人做。
明天可以先做的事
- 打开仓库里所有「推到某类分支名就部署生产」的工作流。把
hotfix/**、release/**、prod/**从触发条件里拿掉,或改成只在main和一次经过审查的 Release 上部署。若必须保留热修通道,加上带必批人的 production Environment,并在被部署的 SHA 上跑和主干相同的测试。 - 把
hotfix_ancestry_gate.py这类检查放进热修通道:不仅要求基于当前main,还要限制main..HEAD的路径。把允许的路径写进仓库,而不是写进某台机器的习惯。 - 在
AGENTS.md里写明:热修必须从origin/main新建工作树或检出,禁止从当前功能分支改名或拉出hotfix/。这只能减少误用,不能代替服务器端检查。把「必须从 origin/main 拉热修」写进说明文件,只能改变代理先尝试的那一步。它拦不住已经从功能分支拉好的hotfix/被推上去,也拦不住一个人接受了代理建议的那条命令。服务器端的分支名触发不读AGENTS.md。要拦,只能改工作流,或在工作流里加闸门。若团队还想给代理一条不容易走错的命令,可以在仓库里放一个open-hotfix.sh:先git fetch origin main,再从origin/main开一棵新的 worktree,而不是在当前检出上改名。脚本仍然代替不了服务器端检查,它只是让「从哪拉」不再依赖工作目录碰巧停在哪里。 - 部署成功之后,不要只看
main是否还锁着已发货退款。要看这次部署作业检出的是哪一个 ref、哪一个 SHA。实验室里主干一直是安全的,被发到「生产」的却是功能分支上的那棵树。
我的结论很具体:按分支名部署,等于把发版开关交给了「当前工作目录」和「分支起名」这两件代理最容易随手做的事。从功能分支拉出来的 hotfix/,即使只改了一个错字,也会把还没审查、测试已经红掉的退款改动一起发出去。先砍掉这种触发条件,再补祖先闸门和必批人;不要指望工单上写了「从 main 拉」,工作目录就会自动回到 main。
完整脚本、闸门、推荐工作流、git bundle 和原始输出:hotfix-from-feature-kit.tar.gz。
Three people, seven computers. Machines 1 to 3 run coding agents, 4 and 5 review, 6 does Windows validation, and 7 merges. On machine 1 the agent was already mid-ticket on feat/refund-reason: add an optional reason to refund_order so the warehouse can record why a paid order was refunded. While rewriting the signature, it dropped shipped from LOCKED_STATUSES. The tests were already red: test_shipped_order_cannot_be_refunded no longer raised RefundError. The work had not been sent for review, and it was not supposed to ship.
Then an urgent ticket arrived. The customer-facing refund message in production said canot; it should say cannot. The ticket was narrow: touch only src/shop/messages.py, and cut the branch from current production, meaning origin/main. Machine 1's working directory was still on the feature branch. The agent created hotfix/canot-typo from the current HEAD, fixed the one typo, and pushed.
This repository does not deploy production from a pull request. It deploys from a branch name. deploy.yml says: a push to main, hotfix/**, or release/** starts the deploy-production job. The job has no tests, no GitHub Environment, and no required reviewer. The push is the release. The feature branch feat/refund-reason does not trigger a deploy, so the unfinished refund change looked safe sitting on machine 1. The moment that change is carried onto a branch whose name starts with hotfix/, it ships with the typo.
That is what happened.
I published a public lab repository, shuizhengqi1/iotxing-lab-hotfix-from-feature-20261204. The shop data uses addresses like zhou@shop.invalid and card last-four 1111; it is not a real merchant. The fixture commits were prepared the way a split ticket is usually written; I did not open a coding model to generate the diffs. The repo has no branch protection and no required reviewers on a production environment. The live workflow is the ungated deploy.yml above. The ancestry gate was run locally and is shipped as the suggested fix in scripts/hotfix_ancestry_gate.py and scripts/deploy-gated.yml; it was not made a required workflow on this lab repo. There was no Windows run. The deploy job does not talk to a real production system. It runs a shipped-refund probe on the SHA that was pushed, to show what a customer would get if that were the tree that went to production.
Why fixing a typo shipped an unfinished refund
The first decision on a hotfix branch is not the typo. It is the parent commit. The ticket said to start from origin/main. The agent sees HEAD in the current working directory. Machine 1 was on feat/refund-reason, whose HEAD already contained the change that dropped shipped. From there, git checkout -b hotfix/canot-typo will keep that refund rewrite in git log main..HEAD even if the new commit only edits messages.py. git diff --name-only main...HEAD will also list src/shop/refund.py. Git is doing what it always does: a hotfix branch inherits the point it started from.
The second decision is that the repository treats a branch name as the release switch. Teams add hotfix/** and release/** so a production incident can skip a pull request. That is barely tolerable when people are few and every hotfix is cut from trunk by hand. Agents enlarge both conditions at once: their working directory is rarely sitting cleanly on main, and they are eager to name a branch after the word "hotfix" in the ticket. "Where it came from" and "what it is called" come apart. The name is right; the parent is wrong.
The third decision is that the deploy job does not run tests. The feature branch already had two failures: test_shipped_order_cannot_be_refunded, and the test that checks the customer-facing string. pytest -q on the same SHA would have blocked the push. The workflow has no such step, so a red test suite cannot stop a green deploy check.
There is one more place this is easy to misread. A hotfix deploys the SHA on the branch; it does not merge into main first. If someone later looks only at trunk, production still appears to be the seed commit: the typo is still there, and shipped refunds still look locked. What actually ran is the commit on hotfix/canot-typo.
If machine 7 only looks at the green check on main in GitHub, it will reach the opposite of the truth. The seed deploy, run 47319693837, succeeded, and its probe was rejected. The successful hotfix run 47319695455 used a different ref. Both runs went green in the same minute, and both jobs are named deploy-production. If the notification only says that a production deploy succeeded, and does not name the ref and SHA, the person on duty will think trunk just shipped again, and will not guess that the tree that went out was the unfinished one from the feature branch.
What the lab actually did
The seed commit 62a343ad251d (62a343ad251d33b521f2765b8ef943649a9fc90f) landed on main at 2026-12-04 18:50:09 (Asia/Shanghai). The customer string still said canot. LOCKED_STATUSES still contained shipped and delivered. pytest -q was 8 passed. The probe against shipped order ord_1002 was PROBE_RESULT=rejected. After main was pushed, run 47319693837 started at 18:50:39 and succeeded at 18:50:47. The log was:
DEPLOY_START ref=refs/heads/main sha=62a343ad251d33b521f2765b8ef943649a9fc90f
PROBE_RESULT=rejected reason=order ord_1002 status shipped canot be refunded
DEPLOY_DONE ref=refs/heads/main sha=62a343ad251d33b521f2765b8ef943649a9fc90f
The feature commit f829218dee78 (f829218dee78b051cca20c843901fc445aac8f2d) landed on feat/refund-reason at 18:50:11. refund_order gained a reason parameter and lost shipped in the same rewrite. In that same minute, pytest -q was 2 failed, 6 passed, and the failing cases were the two shipped-refund tests. The probe became PROBE_RESULT=allowed: ord_1002 turned refunded and carried refund_reason=probe. Pushing that feature branch did not start a deploy-production run. feat/** is not in the trigger list.
Experiment A cut hotfix/canot-typo from that feature branch. Commit 4a2d36bfa5a8 (4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8) at 18:50:14 changed only messages.py, replacing canot with cannot. Relative to main, history still had two layers:
4a2d36b hotfix: correct canot typo in refund locked message
f829218 wip: add refund reason, still editing locked statuses
The file list was src/shop/messages.py and src/shop/refund.py. Tests were still 2 failed, 6 passed. The deliberately naive local script scripts/simulate_deploy.sh runs no tests and probes immediately; the result was allowed. The same workflow on GitHub did the same: run 47319695455 started at 18:50:39 and succeeded at 18:50:48. It asked no one, and it did not stop because tests were red:
DEPLOY_START ref=refs/heads/hotfix/canot-typo sha=4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8
PROBE_RESULT=allowed order={'id': 'ord_1002', 'email': 'chen@shop.invalid', 'status': 'refunded', 'amount': 880, 'card_last4': '1111', 'address': 'Ningbo', 'refund_reason': 'probe'}
DEPLOY_DONE ref=refs/heads/hotfix/canot-typo sha=4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8
Experiment B went back to main and cut hotfix/canot-typo-from-main. Commit 5e22930e07be (5e22930e07bed69a0cd4cad40e1ff39054d496e6) at 18:50:16 is the typo layer alone; the diff is only messages.py. pytest -q was 8 passed. The probe was rejected, and the message already said cannot. Run 47319696000 also deployed successfully with no approval, but on that tree a shipped order still cannot be refunded.


This is a different footgun from live payments were already on while the production approval was still waiting. That post was about a job that already used a protected environment, then a rename, after which GitHub auto-created an unprotected environment with the new name. Today's workflow has no environment at all. The trigger is only the branch name. Approval never entered the path.
What the ancestry gate catches, and what it does not
I wrote a local script, scripts/hotfix_ancestry_gate.py. It does two narrow things. First, git merge-base must equal current main, so the hotfix includes trunk as it is now, not a stale stretch of history. Second, the paths changed between main and HEAD may only be src/shop/messages.py, README.md, or docs/. The ticket said to touch only the customer string; anything outside that range should fail.
On experiment A's SHA, the gate against main printed:
GATE_REF=hotfix/canot-typo
GATE_HEAD=4a2d36bfa5a896b0f16c094bb23afb3765b8b2d8
GATE_BASE=62a343ad251d33b521f2765b8ef943649a9fc90f
GATE_MERGE_BASE=62a343ad251d33b521f2765b8ef943649a9fc90f
GATE_COMMITS<<<
4a2d36b hotfix: correct canot typo in refund locked message
f829218 wip: add refund reason, still editing locked statuses
>>>
GATE_FILES<<<
src/shop/messages.py
src/shop/refund.py
>>>
GATE=fail reason=disallowed_paths src/shop/refund.py
The exit code was 1. Notice that the merge-base actually is main: the feature branch was cut from current trunk, so the first ancestry check does not fire by itself. What stops it is refund.py in the file list. A rule that only says "must be based on latest main" would still have passed, because being based on latest main is not the same as "the typo layer only."
On experiment B, the same script printed GATE=pass, exit 0, with only messages.py in the file list. That shows the gate does not block a clean typo hotfix. It also reminds you that B was still deployed by the ungated workflow in the lab. The gate addresses "you brought commits you should not have brought." It does not mean a hotfix branch may skip review.
scripts/deploy-gated.yml puts this gate on the hotfix/** deploy path: run the ancestry check, then run pytest on the same SHA, and only then continue. Deploys from main do not use the path allowlist, because trunk is supposed to change refund.py. Even so, this recommended workflow is not a complete release process. A real repository should still attach a production Environment with required reviewers, or drop branch-name deploys entirely and only ship from a merge to main, or from a human-published GitHub Release.

Costs, and when not to do this
The fastest fix is to stop deploying production from a name like hotfix/**. Agents will name branches after words in the ticket, and machines 1 to 3 often have a feature branch checked out. Putting "hotfix" in the branch name no longer means "this is an emergency fix cut from production." The cost is that the old "just push a hotfix branch" path gets slower. If you still need a fast path, give it its own procedure: start from origin/main, run the tests, and have a person sign the production Environment. Do not collapse that procedure back into a branch prefix.
The ancestry gate's cost is false refusal. A genuine hotfix that must change refund.py will fail with disallowed_paths. Do not add the whole src/shop/ tree to the allowlist; the gate would immediately stop meaning anything. That kind of change should go back to a pull request, to machines 4 and 5, and then into main. The gate is only for a narrow, declared range: copy, docs, README. Widen the range, and it becomes one more check that goes green.
The first check — merge-base equals current main — will also refuse a legitimate hotfix when trunk has just moved. That is deliberate. If another pull request has just landed, the hotfix needs to rebase before it ships, or you are back to "the tests were green against trunk from ten minutes ago." Teams with many hotfixes and a fast-moving main will be asked to update often. That is a throughput-versus-safety trade, not a bug in the script.
There are also things this work does not show. There was no Windows run, so I have no evidence about machine 6. The fixture commits were not written by a live coding model, so I cannot treat "an agent will always cut a hotfix from a feature branch" as a measured rate. What I can say is that when the working directory is not on main and the ticket contains the word hotfix, this path is open, and a branch-name trigger will not close it. The gate was not made a required workflow on the lab repo, so I did not demonstrate on GitHub that the same hotfix/canot-typo push would be rejected after the gate was installed. I do have the local exit code and the file list. The successful Actions deploy records the ungated workflow.
Finally, even a hotfix that only edits messages.py can still ship the wrong sentence. The gate does not judge whether the copy is right; it only judges whether extra files came along. A person still has to review.
What you can do tomorrow
- Open every workflow that deploys production on a branch-name pattern. Remove
hotfix/**,release/**, andprod/**from the trigger, or deploy only frommainand from a reviewed Release. If you must keep a hotfix path, add a production Environment with required reviewers, and run the same tests you run on trunk on the SHA that will be deployed. - Put a check like
hotfix_ancestry_gate.pyon that hotfix path: require currentmainas the base, and restrict the paths inmain..HEAD. Keep the allowlist in the repository, not in one machine's habits. - Write in
AGENTS.mdthat a hotfix must start from a new worktree or checkout oforigin/main, and must not be renamed or branched off the current feature branch ashotfix/. That only reduces mistakes. It does not replace a server-side check. Writing that hotfixes must be cut from origin/main in an instructions file only changes the first thing an agent tries. It does not stop ahotfix/that has already been cut from a feature branch from being pushed, and it does not stop a person from accepting the command the agent suggested. A branch-name trigger on the server does not readAGENTS.md. To actually stop it, you have to change the workflow, or put a gate in the workflow. If you also want a command that is harder for an agent to start from the wrong place, keep anopen-hotfix.shin the repo: rungit fetch origin main, then create a new worktree fromorigin/main, instead of renaming the current checkout. That script still does not replace the server-side check. It only stops the starting point from depending on wherever the working directory happens to sit. - After a successful deploy, do not only ask whether
mainstill locks shipped refunds. Look at which ref and which SHA the deploy job checked out. In the lab, trunk stayed safe. What was sent to "production" was the tree from the feature branch.
The conclusion is specific: deploying by branch name hands the release switch to the two things an agent is most likely to do casually — use the current working directory, and name the branch after the ticket. A hotfix/ cut from a feature branch will ship unreviewed, already-red refund changes even when the new commit only fixes a typo. Remove that trigger first, then add the ancestry gate and required reviewers. Do not assume that because the ticket said "cut from main," the working directory will already be on main.
Full scripts, the gate, the recommended workflow, a git bundle, and the raw output: hotfix-from-feature-kit.tar.gz.