{"slug":"af-claude-code-ops-pitfalls","title":"af_ 系统运维灾难复盘：我把 7 个仓库交给 AI，丢了两次线上功能","description":"别让 AI 在没版本控制的机器上改代码，你会哭着补回来的","coverImage":"https://b.acofork.com/img/af-claude-code-ops-pitfalls-v2.webp","coverWidth":1200,"coverHeight":630,"date":"2026-07-29","tags":["AI"],"pinned":false,"wordCount":3746,"html":"<aside class=\"markdown-alert markdown-alert--caution\"><div class=\"markdown-alert-title\"><svg class=\"markdown-alert-icon\" aria-hidden=\"true\" width=\"18\" height=\"18\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 16h.01\"></path><path d=\"M12 8v4\"></path><path d=\"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z\"></path></svg><span>注意</span></div><div class=\"markdown-alert-body\"><p>本文使用 Claude Opus 5 编写。</p>\n</div></aside><h2 id=\"先说结论\">先说结论</h2><p>7 月 28 日那天早上，我的计划是「给全站做一轮性能优化，顺便把论坛的通知系统重构掉」。预计半天收工。</p>\n<p>实际上干了一整天，中间两次差点把线上功能丢光。</p>\n<p>事后复盘，五个坑长得完全不一样，但根子是同一个：<strong>我脑子里那张架构图，从来没有落到任何一个文件里。</strong> 我知道哪台机器跑的是哪份代码、哪个目录是活的、哪个是尸体——但这些东西 AI 一个字都读不到。于是它只能猜。</p>\n<p><em>而它猜得还挺自信的。</em></p>\n<p>这篇不是教程，是验尸报告。</p>\n<hr />\n<h2 id=\"案发现场-7-个仓库-2-台机器-0-个-remote\">案发现场：7 个仓库，2 台机器，0 个 remote</h2><p>af_ 是我这个站的全部家当，全站 SSR，由 7 个 GitHub 仓库组成：</p>\n<table>\n<thead>\n<tr>\n<th>仓库</th>\n<th>干什么的</th>\n<th>跑在哪</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>af_frontend</code></td>\n<td>主站前端</td>\n<td>公网 VPS，Express + supervisor</td>\n</tr>\n<tr>\n<td><code>af_blog-data</code></td>\n<td>博客正文和图</td>\n<td>边缘</td>\n</tr>\n<tr>\n<td><code>af_forum-backend</code></td>\n<td>论坛后端，Worker + D1</td>\n<td>公网 VPS，<code>wrangler dev</code></td>\n</tr>\n<tr>\n<td><code>af_draw-backend</code></td>\n<td>AI 生图后端</td>\n<td>局域网那台 GPU 盒子</td>\n</tr>\n<tr>\n<td><code>af_friends-data</code></td>\n<td>友链 / 赞助</td>\n<td>边缘</td>\n</tr>\n<tr>\n<td><code>af_files-data</code></td>\n<td>文件列表</td>\n<td>边缘</td>\n</tr>\n<tr>\n<td><code>af_comments-data</code></td>\n<td>giscus 评论</td>\n<td>不部署，纯数据</td>\n</tr>\n</tbody></table>\n<p>写出来挺规整的对吧。</p>\n<p>问题是，<strong>这张表是我在事故之后才写出来的</strong>。当天早上动手的时候，它只存在于我脑子里。</p>\n<p>更要命的是那天早上的真实状态：</p>\n<ul>\n<li>论坛后端的 <code>src/index.ts</code> <strong>不在任何 git 仓库里</strong>。所谓版本控制，是 <code>cp src/index.ts src/index.ts.bak-1785041280</code> 这样手工存快照，一共存了 8 个。哪个是线上正在跑的？<em>不知道，看时间戳猜呗。</em></li>\n<li>前端本地倒是有个 git 仓库，但<strong>没有任何 remote</strong>。全世界唯一一份源码在我这台 Windows 的硬盘上。</li>\n</ul>\n<p>这些 AI 全都不知道。它只看得见你给它的那个目录。</p>\n<hr />\n<h2 id=\"第一集-改了半小时-发现改的是一具尸体\">第一集：改了半小时，发现改的是一具尸体</h2><p>当天任务列表里有一条是「AI 生图端点检查」。</p>\n<p>生图后端历史上经历过一次 JSON → SQLite 的大重构：旧代码在 <code>node-server/</code>（V1），新代码在 <code>node-server-v2/</code>（V2）。supervisor 里的真相长这样：</p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">nDI       STOPPED\nnDI-v2    RUNNING   pid xxxxx   :9090</code></pre></div><p>V1 早就停了，V2 在跑。</p>\n<p>但 GitHub 上的 <code>af_draw-backend</code> 仓库里是另一幅景象：V1 目录是个<strong>不完整的残骸</strong>（<code>notify.ts</code> 这种关键文件从来就没被提交过），V2 目录<strong>根本没进过版本控制</strong>——它的源码只存在于那台机器的 <code>/root/nDI/node-server-v2/</code> 里。</p>\n<p>于是 Claude Code 打开仓库，看见一个叫 <code>node-server/</code> 的目录，非常合理地开始改里面的通知代码。</p>\n<p>改完，部署，测试。</p>\n<p><em>毫无反应。</em></p>\n<p>再改，再部署，再测试。还是毫无反应。</p>\n<p>半小时后我去 <code>supervisorctl status</code> 看了一眼才反应过来：<strong>它改了半天的是一具尸体。</strong> 而真正在跑的 V2 是用 <code>tsx</code> 直接跑源码的，改完还得 <code>supervisorctl restart</code> 才生效——就算改对了地方，不重启也一样没反应。</p>\n<blockquote>\n<p><strong>教训一号：源码只存在本地，被部署方只放构建产物。</strong></p>\n<p>远端放着源码、又不跟 git 同步的时候，AI 会从几个「看起来像」的目录里随机挑一个开始改。它没办法知道哪个是活的——因为这个信息压根不在代码里。</p>\n</blockquote>\n<hr />\n<h2 id=\"第二集-43-行的窟窿\">第二集：43 行的窟窿</h2><p>论坛通知系统的改造是那天的重头戏。</p>\n<p>重构 <code>notifyByType</code> 的时候，Claude Code 顺手删掉了一个废弃函数，TS 报错从 74 条掉到 65 条。看起来是好事。</p>\n<p>但提交前我扫了一眼 diff 的统计：文件从 <strong>6120 行变成 6077 行</strong>，净减 43 行。</p>\n<p>删一个废弃函数能删掉 43 行？<em>不对劲。</em></p>\n<p>翻 <code>src/index.ts.bak-*</code> 那堆手工快照，一路往前查，最后查明白了：早些时候做 QQ 绑定功能，是在一个<strong>不含限流逻辑的旧基线</strong>上开发的。开发完了整份文件覆盖上线。被那次覆盖悄悄抹掉的东西包括：</p>\n<ul>\n<li><strong>6 项限流配置</strong>（注册 IP 冷却、验证邮件重发间隔、登录失败锁定阈值……）</li>\n<li><strong><code>/api/user/sessions</code> 那三个会话管理端点</strong></li>\n<li><strong><code>readGeoFromHeaders</code></strong>（从 CF 头里取访客地理位置）</li>\n</ul>\n<p>最阴间的地方在于：数据库那边<strong>一点毛病都没有</strong>。<code>ip_rate_limits</code> 表好端端地在，<code>0013</code> 到 <code>0016</code> 号 migration 全都应用了。</p>\n<p>只是没有任何一行代码再去读它了。</p>\n<p>所以从那天起，同一个 IP 可以在 5 秒里注册 100 个号，登录爆破防护为零。<strong>而线上一切正常，监控一片绿。</strong></p>\n<p>前端也有同一种病。上一轮性能优化——CSS Link 预载头、Rolldown chunk 合并、hljs.css 按路由加载——<strong>只存在于 VPS 上的 <code>/root/svaf-next</code></strong>。那不是个 git 仓库。本地仓库对这些改动一无所知，我下一次在本地构建、上传，就会把它们全部盖掉。</p>\n<p><em>两条编辑线共用一个没有版本的文件，后写的赢。就这么简单。</em></p>\n<blockquote>\n<p><strong>教训二号：改完并且真的上线了，立刻提交。</strong></p>\n<p>别攒着。攒着的下场就是下次不小心整体撤销，一次丢一大片。</p>\n</blockquote>\n<hr />\n<h2 id=\"第三集-一对引号-让通知系统从出生那天起就是死的\">第三集：一对引号，让通知系统从出生那天起就是死的</h2><p>重构的时候要统一 <code>/internal/notify</code> 和 <code>/internal/notify/email</code> 两个端点。鉴权是常量时间比对，写得很规矩：</p>\n<div class=\"markdown-code\" data-language=\"typescript\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"></path><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 0-2-2V5a2 2 0 0 0-2-2h-1\"></path></svg><span>typescript</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-typescript\"><span class=\"hljs-keyword\">const</span> expected = <span class=\"hljs-title class_\">String</span>(env.<span class=\"hljs-property\">NOTIFICATION_SERVICE_TOKEN</span> || <span class=\"hljs-string\">\"\"</span>);\n<span class=\"hljs-keyword\">const</span> token = auth.<span class=\"hljs-title function_\">slice</span>(<span class=\"hljs-number\">7</span>); <span class=\"hljs-comment\">// 去掉 \"Bearer \"</span>\n<span class=\"hljs-keyword\">if</span> (token.<span class=\"hljs-property\">length</span> !== expected.<span class=\"hljs-property\">length</span>) <span class=\"hljs-keyword\">return</span> <span class=\"hljs-number\">401</span>;</code></pre></div><p><code>.dev.vars</code> 里是这么写的：</p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">NOTIFICATION_SERVICE_TOKEN=\"ns_c800e73e...\"</code></pre></div><p>看出来了吗？</p>\n<p>wrangler 读 <code>.dev.vars</code> 的规矩是「等号后面全都是值，<strong>不剥引号</strong>」。所以 <code>expected</code> 的真实值是 <code>\"ns_c800e73e...\"</code>——<strong>连那对双引号一起，70 个字符</strong>。调用方传过来的是 67 个。</p>\n<p>长度比对第一步就挂了。直接 401。</p>\n<p>这意味着<strong>从通知系统上线的那天开始，所有外部通知请求就没有一个通过过鉴权</strong>。</p>\n<p>那用户为什么一直能收到 QQ 通知？因为那是 <code>sendQQNotify</code> 那条直连 OneBot 的旁路发的，走的是另一个 token。邮件呢？<strong>一封都没发出去过。</strong> 老的 <code>/internal/notify/email</code> 被同一对引号拦在门外。</p>\n<p>这个坑跟那天的任何改动都没关系，它从配置那天起就躺在那儿。</p>\n<p><em>只是从来没有人问过一句「用户真的收到了吗」。</em></p>\n<blockquote>\n<p><strong>教训三号：部署后的第一条验证不是「接口返回 200 了吗」，是「人真的收到了吗」。</strong></p>\n</blockquote>\n<hr />\n<h2 id=\"第四集-ctx-waituntil-workers-里的无声杀手\">第四集：ctx.waitUntil，Workers 里的无声杀手</h2><p>通知重构完，QQ 能收到了，邮件死活不发。</p>\n<p>日志干干净净，一条报错都没有。<em>这是最讨厌的一种 bug。</em></p>\n<p>查到最后，是 Workers 运行时和 Node 的根本差异：</p>\n<div class=\"markdown-code\" data-language=\"typescript\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"></path><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 0-2-2V5a2 2 0 0 0-2-2h-1\"></path></svg><span>typescript</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-typescript\"><span class=\"hljs-comment\">// Node 里这样写完全没问题，Promise 会在后台自己跑完</span>\n<span class=\"hljs-title function_\">sendEmail</span>(email, subject, body, env).<span class=\"hljs-title function_\">catch</span>(<span class=\"hljs-function\">() =&gt;</span> {});\n<span class=\"hljs-keyword\">return</span> <span class=\"hljs-title function_\">jsonResponse</span>({ <span class=\"hljs-attr\">ok</span>: <span class=\"hljs-literal\">true</span> });\n\n<span class=\"hljs-comment\">// Workers 里，response 一返回，运行时立刻回收还没跑完的 Promise。</span>\n<span class=\"hljs-comment\">// 必须显式说一句「等我跑完」</span>\nctx.<span class=\"hljs-title function_\">waitUntil</span>(<span class=\"hljs-title function_\">sendEmail</span>(email, subject, body, env).<span class=\"hljs-title function_\">catch</span>(...));</code></pre></div><p><code>sendQQNotify</code> 恰好加过 <code>ctx.waitUntil</code>，所以 QQ 活着；<code>sendEmail</code> 没加，所以邮件被运行时无声无息地砍掉了。</p>\n<p>而那句 <code>.catch(() =&gt; {})</code> 又把所有异常吞得干干净净——<strong>既不发邮件，也不留痕迹</strong>。</p>\n<p>顺手全量 grep 了一遍 <code>ctx.waitUntil</code>，又捞出来一个：<code>/api/webhook/posts</code>（博客文章广播）里的 <code>sendOne</code> 同时调了 <code>sendEmailByTemplate</code> 和 <code>notifyByType</code>——前者直接发邮件，后者内部<strong>也</strong>发邮件。</p>\n<p><em>所以我每发一篇博客，订阅的人都收到两封。</em> 一直如此。</p>\n<blockquote>\n<p><strong>教训四号：Workers 里做 fire-and-forget 必须 <code>ctx.waitUntil()</code>，而且永远别写空的 <code>.catch(() =&gt; {})</code>。</strong></p>\n<p>那不叫容错，那叫毁尸灭迹。</p>\n</blockquote>\n<hr />\n<h2 id=\"第五集-这一集是我自己画蛇添足\">第五集：这一集是我自己画蛇添足</h2><p>通知系统的设计本来很清楚：<strong>调用方负责文案，论坛只做鉴权 + 偏好检查 + 渠道分派。</strong></p>\n<p>但我重构 <code>/internal/notify</code> 的时候手贱，在论坛这一侧加了个 switch，按 <code>type</code> 把消息重写了一遍：</p>\n<div class=\"markdown-code\" data-language=\"typescript\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"></path><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 0-2-2V5a2 2 0 0 0-2-2h-1\"></path></svg><span>typescript</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-typescript\"><span class=\"hljs-keyword\">case</span> <span class=\"hljs-string\">\"lora\"</span>:\n  emailSubject = <span class=\"hljs-string\">\"LoRA 模型审核结果\"</span>;\n  emailBody = <span class=\"hljs-string\">`&lt;p&gt;你的 LoRA 模型《<span class=\"hljs-subst\">${dName}</span>》<span class=\"hljs-subst\">${dAction}</span>。&lt;/p&gt;`</span>;\n  <span class=\"hljs-keyword\">break</span>;\n<span class=\"hljs-keyword\">case</span> <span class=\"hljs-string\">\"recommendation\"</span>:\n  emailSubject = <span class=\"hljs-string\">\"你的图片被推荐了\"</span>;\n  <span class=\"hljs-comment\">// ...</span></code></pre></div><p>生图后台原本发过来的是这个：</p>\n<blockquote>\n<p>用户 #1 推荐了精选图片\n图片: /path/img.png\n理由: 构图很好</p>\n</blockquote>\n<p>到了论坛这边，变成了「你的图片《精选图片》已被推荐」。</p>\n<p><strong>图片路径没了，推荐理由也没了。</strong> 我亲手把有用的信息揉成了一句废话。</p>\n<p>改回来只花了五分钟：删掉整个 switch，全部走 default 透传，<code>notifyLora</code> 和 <code>notifyRecommendation</code> 改回传原始的 <code>subject + body</code>。</p>\n<blockquote>\n<p><strong>教训五号：API 边界不清楚的时候，最容易做多。</strong></p>\n<p>透传比生成安全一万倍。消息内容永远由数据的生产者决定。</p>\n</blockquote>\n<hr />\n<h2 id=\"收尾-先把仓库治好-再谈别的\">收尾：先把仓库治好，再谈别的</h2><p>一整天下来，耗时最长的其实是两件跟业务代码毫无关系的事。</p>\n<p><strong>第一件，建仓库。</strong> 前端没有 remote，论坛后端根本不是 git 仓库。7 个仓库统一加 <code>af_</code> 前缀，按「后端源码必须私有」重设可见性，把 VPS 上那两份现役代码推上 GitHub。前端推之前还发现历史里躺着一个 166MB 的 zip 误提交，<code>git filter-repo</code> 清了一轮。</p>\n<p><strong>第二件，写 <code>AGENTS.md</code>。</strong> 就是上面那张表，加上部署形态、对外域名、可见性，以及两条铁律。以后任何一个 AI 会话在这个仓库里打开，第一件事就是把这张表读完。</p>\n<p><em>这两件事本来应该是第 0 天做的，我拖到了第 N 天。</em></p>\n<hr />\n<h2 id=\"后日谈-第二天我又把站拆了-然后又拼了回去\">后日谈：第二天我又把站拆了，然后又拼了回去</h2><p>以为写完 <code>AGENTS.md</code> 就天下太平了？<em>天真。</em></p>\n<p>7 月 29 号早上，我决定把站按业务拆成五个域：<code>www</code> 做门户、<code>blog</code> 放文章、<code>forum</code> 放论坛、<code>ai</code> 放生图、<code>2x.nz</code> 保持完整。听起来很清爽——每块业务一个域，路由表按目标裁剪，静态的三个丢到 Cloudflare Worker，论坛另起一个 <code>:3010</code> 进程，部署改成推 GitHub 触发 webhook。</p>\n<p>上午就干完了。技术上全都跑通了。</p>\n<p>然后我开始一条一条地发现代价：</p>\n<ul>\n<li><strong>路由表一裁，站内 <code>&lt;Link&gt;</code> 就废了。</strong> 别的业务的路由压根不在这份 bundle 里，跨业务的链接只能全部手写成绝对地址。</li>\n<li><strong>登录态是按 origin 隔离的。</strong> 于是我得为 <code>ai.2x.nz</code> 专门做一套跨域授权交接，token 走 URL fragment、<code>redirect_uri</code> 走白名单——<strong>为了拆域，凭空多出一套安全攸关的代码。</strong></li>\n<li><strong>静态站的预渲染清单必须穷举。</strong> 漏一条就是线上真 404，因为背后没有服务器给你兜底。</li>\n<li>最离谱的是：博客切出去之后，<strong><code>2x.nz/posts</code> 变成了 404</strong>。老用户最习惯的入口，就这么断了。</li>\n</ul>\n<p>下午我把整套东西全撤了。撤的时候还踩了两个新坑：</p>\n<p>其一，回退是从分域之前那个提交 checkout 回来的，那份 <code>run.sh</code> 的 mode 是 <code>100644</code>——<strong>可执行位丢了</strong>。supervisor 直接 exec 它，报 <code>ERROR (file is not executable)</code>，站挂了几十秒。<em>在 Windows 上开发、往 Linux 上部署的经典节目。</em></p>\n<p>其二，删子域 DNS 记录的时候，忘了这个 zone 上还挂着一条 <code>*.2x.nz</code> 通配 CNAME。删掉记录不等于这个域不存在了，而是它落到了通配指向的第三方 CDN 上——然后那边回了个指向自己的 301，<strong>死循环</strong>。</p>\n<p>所以最后那五个子域没有删记录，而是留着代理、挂一条 301 按路径把请求收回 <code>2x.nz</code>。指望「删掉就没了」是不成立的。</p>\n<blockquote>\n<p><strong>教训六号：架构改造的成本，从来不在「能不能做成」。</strong></p>\n<p>分域这件事，AI 一个上午就给我做完了，而且做得挺漂亮。问题是它做得越顺，我越晚意识到这个方向本身是错的。<strong>做得快，不代表该做。</strong></p>\n</blockquote>\n<hr />\n<h2 id=\"现在的全貌\">现在的全貌</h2><ul>\n<li>论坛通知统一入口 <code>/internal/notify</code>，纯透传 <code>{user_id, type, subject, body}</code>，按用户偏好分派 QQ / 邮件</li>\n<li>生图后台的 LoRA 审核、图片推荐全部走论坛这个统一接口，QQ 直推走 OneBot 旁路</li>\n<li>博客广播打 <code>/api/webhook/posts</code>，一次请求同时触发邮件 + QQ（<strong>不再发两遍了</strong>）</li>\n<li>前端 <code>/forum/me</code> 恢复了 QQ 绑定 + 7 类事件 × 2 渠道的高粒度通知偏好</li>\n<li><code>/posts</code> 页面总重量 <strong>3.3MB → 313KB</strong>（封面缩略图、头像压缩、CSS 预加载、chunk 合并、图标按需、论坛配图按需缩放）</li>\n<li>全站禁用 JavaScript 仍然能用，零 Suspense 流式占位</li>\n<li>域名回到一个：<code>2x.nz</code>。全部业务由 VPS 上<strong>一个</strong> SSR 进程提供</li>\n</ul>\n<hr />\n<h2 id=\"所以\">所以</h2><p>如果你也打算在这种多机多仓、还带着生产数据的环境里让 AI 改代码，我只有一条建议：</p>\n<p><strong>先把所有仓库建好、推上去、把架构写进 <code>AGENTS.md</code>，然后再开始改。</strong></p>\n<p>省下来的不是一两个小时，是一整天，和两条差点丢掉的线上功能。</p>\n<p>至于第二天那次拆域——那个坑 <code>AGENTS.md</code> 救不了你。<strong>AI 会非常高效地把你想做的事做完，它不负责告诉你这件事不该做。</strong> 这部分只能自己扛。</p>\n<p><em>现在那张表写在仓库最上面。下次它至少不会再改错机器了。</em></p>\n","toc":[{"id":"先说结论","text":"先说结论","depth":2},{"id":"案发现场-7-个仓库-2-台机器-0-个-remote","text":"案发现场：7 个仓库，2 台机器，0 个 remote","depth":2},{"id":"第一集-改了半小时-发现改的是一具尸体","text":"第一集：改了半小时，发现改的是一具尸体","depth":2},{"id":"第二集-43-行的窟窿","text":"第二集：43 行的窟窿","depth":2},{"id":"第三集-一对引号-让通知系统从出生那天起就是死的","text":"第三集：一对引号，让通知系统从出生那天起就是死的","depth":2},{"id":"第四集-ctx-waituntil-workers-里的无声杀手","text":"第四集：ctx.waitUntil，Workers 里的无声杀手","depth":2},{"id":"第五集-这一集是我自己画蛇添足","text":"第五集：这一集是我自己画蛇添足","depth":2},{"id":"收尾-先把仓库治好-再谈别的","text":"收尾：先把仓库治好，再谈别的","depth":2},{"id":"后日谈-第二天我又把站拆了-然后又拼了回去","text":"后日谈：第二天我又把站拆了，然后又拼了回去","depth":2},{"id":"现在的全貌","text":"现在的全貌","depth":2},{"id":"所以","text":"所以","depth":2}]}