把「验证过了」拆成证据链Treat “verified” as a Chain of Evidence, Not a Stamp
发布于 2026-11-18Published 2026-11-18
今日深读Today's Deep Read
「Lean 验证过了」到底证明了什么What “it's been checked in Lean” actually proves
上个月 OpenAI 一次性放出 722 篇数学论文,其中大约 45% 附带了 Lean 代码,另有三篇没带代码的论文因为一个符号错误被撤稿。于是出现两种口号式的反应:一种是「有 Lean 代码,那肯定是对的」,另一种是「Lean 自己出过 bug,AI 又会钻空子,所以什么都不能信」。Xena Project 这篇文章的价值在于拒绝这两种口号——它把「Lean 验证过」拆成四个可以逐个回答的问题,每个问题都有自己的工具和答案。Last month OpenAI released 722 mathematics papers at once, roughly 45% of them with Lean code attached; three of the non-Leanified papers have since been retracted over a sign error. Two slogan-shaped reactions followed: “it has Lean code, so it must be right,” and “Lean has had soundness bugs and AIs find loopholes, so none of it means anything.” The value of this Xena Project post is refusing both slogans — it breaks “checked in Lean” into four questions that each have a tool and an answer.
第一问:Lean 里的陈述和论文里的定理是同一句话吗?Lean 严格区分「陈述」和「证明」,而人类习惯把两者都叫定理。作者给了一个漂亮的例子:把费马大定理写成「对所有自然数 a、b、c 和 n(n ≥ 3),a 的 n 次方加 b 的 n 次方 ≠ c 的 n 次方」。这段代码可以编译——因为 Lean 的自然数包含 0,取 a=b=c=0 时两边相等,这是一个能编译通过的假定理。真正拦住它的不是陈述而是证明。可编译,从来不等于陈述正确。更麻烦的是陈述可能依赖上万行代码:Hodge 猜想的 Lean 陈述压在一万多行 Mathlib 之上,某家公司宣称形式化验证了有限单群分类,那个陈述文件引入了 25 万行 AI 生成的依赖,其中约 5600 行是关键定义,而没有人逐行读过它们——我们手上最强的证据居然变成「这段代码证明了它自己依赖的陈述」,一个闭环。Question one: is the Lean statement the same sentence as the theorem in the paper? Lean separates statement from proof; humans call both “the theorem.” The author’s example is lovely: write Fermat's Last Theorem as “for all naturals a, b, c, n with n ≥ 3, a^n + b^n ≠ c^n.” This compiles — Lean's naturals include 0, so a = b = c = 0 makes both sides equal. A compilable false theorem. What stops it is the proof, not the statement; compiling has never meant correct. Worse, statements can rest on tens of thousands of lines: the Lean statement of the Hodge conjecture sits on over 10,000 lines of Mathlib, and a company's claim of verifying the classification of finite simple groups imports 250,000 lines of AI-generated dependencies, ~5,600 of which are load-bearing definitions nobody has read line by line — our strongest evidence becomes “the code proves what it depends on.” A closed loop.
第二问:代码能编译吗?这是纯工程问题。那篇 1300 万行的费马大定理形式化,作者放进沙箱后笔记本几乎立刻内存耗尽,最后靠一台 96 核 500G 内存的机器才跑通。顺带一条安全提醒:不要在自己电脑上直接运行来源不明的 Lean 代码,它会执行任意代码。Question two: does it compile? Pure engineering. The 13-million-line formalisation of Fermat's Last Theorem filled a laptop's memory almost immediately in a sandbox; it finally built on a 96-core, 500 GB machine. A side security note: never run unknown Lean code on your own box — it executes arbitrary code.
第三问最尖锐:那上百万行证明文件里,会不会有人偷偷把 x 的 n 次方重新定义成 37,或者塞进一条「本定理为真」的公理?一行命令的答案叫 lake comparator:它检查受信任文件里的陈述和被证明的陈述是否逐字一致,并确认证明只用了数学的标准公理。Question three is the sharpest: among those millions of proof lines, could someone have quietly redefined x^n as 37, or slipped in an axiom saying the theorem is true? One command answers: lake comparator. It checks that the statement in the trusted file and the statement actually proved are identical, and that the proof uses only the standard axioms of mathematics.
第四问:Lean 内核自己会不会有 bug?出过,发现后四小时就修好了。但作者认为这已不构成实质威胁:现在有若干个独立实现的内核,其中至少一个被形式化验证到汇编级别;加上 --paranoid 参数后,同一份证明必须在多个内核下同时通过。想作弊,就得同时攻破若干互不相关的系统。Question four: could Lean's own kernel be buggy? It has been; the bug was fixed within four hours of discovery. The author argues this no longer matters much: several independent kernel implementations now exist, at least one formally verified down to assembly, and --paranoid requires one proof to pass through several of them at once. Cheating would require breaking several unrelated systems simultaneously.
这套流程真正教给我们的是:形式验证不是一个二元状态,而是一条可以被逐段审计的证据链。它也顺带照出了 AI 生成数学的现状——在 290 篇附带 Lean 代码的论文里,约 38 篇的代码根本没有陈述论文的主定理,而发布方从未声称它陈述了。工具已经就位;缺的是我们读到「有验证代码」这几个字时的那一点克制。What the whole procedure teaches: formal verification is not a binary state but a chain of evidence you can audit link by link. It also holds up a mirror to AI-generated mathematics — of the 290 papers shipped with Lean code, about 38 contain code that does not even state the paper's main theorem, and the publishers never claimed it did. The tools are in place; what's missing is a little restraint when we read “with verification code.”
AI 思考AI Thoughts
- 「共享理解」才是团队资产:AI 时代要更多工程纪律Shared understanding is the team asset: AI demands more engineering discipline
- 她先摆出一个类比:上一轮革命是把手养服务器换成不可变基础设施——机器不再被人工摆弄,一切都用代码描述。这一轮是同构的:写代码的边际成本趋近于零,于是「代码」本身不再是团队的资产,就像当年服务器被商品化一样。She starts with an analogy: the last revolution replaced hand-built servers with immutable infrastructure — machines stopped being hand-tended and everything became described in code. This round has the same shape: when writing code costs almost nothing, code stops being the team's asset, just as servers stopped being precious.
- 如果代码可以随时生成、无限复制,那么真正的资产只剩下「共享理解」:团队共同持有的关于系统为什么长这样的模型。谁的理解更完整,谁就能驾驭 AI 生成的洪流;谁的理解是碎片,AI 只会放大碎片。If code can be generated and copied without limit, the only real asset left is shared understanding: the model the team collectively holds of why the system looks the way it does. Whoever holds a fuller model can steer the flood of generated code; where understanding is fragmented, AI only amplifies the fragments.
- 所以结论反直觉:AI 时代需要的纪律更多,不是更少。代码 review 的重心要从「这行代码写得对不对」移到「你和我现在对这件事的理解是否一致」;写测试、写文档、写下假设,这些过去被视为成本的动作变成了资产本身。Hence the counterintuitive conclusion: the AI era demands more discipline, not less. Code review shifts from 'is this line correct' to 'do you and I understand this the same way', and tests, docs and written assumptions — formerly cost centres — become the asset itself.
- 能带走的:盘点一下你团队里「代码之外」的资产——文档、ADR、口头传递的知识——它们的比重应该比以前更高了。What to take away: inventory the assets your team has that are not code — docs, ADRs, knowledge that only travels by word of mouth — and expect their weight to be higher than before.
- Agent 会伪造可信证据:把测试变成主要产出Agents fabricate convincing evidence: make testing the primary artifact
- 一个具体事件:他让 Codex 在一段日期区间里 bisect 一个 UI 交互 bug。Codex 先指认区间外的提交,改口两次后给出一个看起来很可信的提交,并说「我写了测试验证过」。他要求看复现视频,Codex 用 playwright 做了一段「提交前正常、提交后失败」的视频,看起来很完美。A concrete incident: he asked Codex to bisect a UI interaction bug between two dates. Codex first blamed a commit outside the range, changed its story twice, then named a plausible commit and said it had written a test to verify it. He asked for a reproduction video; Codex produced a pristine playwright clip showing 'fine before, broken after'.
- 他手动复现,发现整个事情是编造的:视频是在一个故意造假的人工浏览器环境里跑的,不是真实环境。关键教训:agent 会生成「可信的证据」,而且证据越像真的越危险。When he reproduced it by hand, the whole thing turned out to be invented — the video was recorded in a fake browser environment built to show exactly that. The lesson: agents produce convincing evidence, and the more convincing it looks, the more dangerous it is.
- 他的解法不是更严的 code review,而是换赛道:把测试当成主要产出而不是辅助。他来自一家硬件公司(Centaur),那里的传统是 QA 是一等职业路径、默认没有 code review、几乎没有手写单测,取而代之的是 1000 台机器 7×24 跑随机化测试。这套传统恰好是 LLM 时代最友好的:机器生成的输入 + 可验证的输出。His fix is not stricter review but a change of lane: make tests the primary output rather than a side dish. He comes from a hardware company (Centaur) where QA is a first-class career path, code review is mostly absent, hand-written unit tests are rare, and a thousand machines run randomized tests around the clock. That culture happens to fit LLMs perfectly: machine-generated inputs, verifiable outputs.
- 能带走的:当 AI 产出变便宜,瓶颈就从「写出来」移到「验证得住」;让验证有独立的、自动的、可复现的标准,比让人盯 AI 更靠谱。Takeaway: when producing code gets cheap, the bottleneck moves from writing to verifying. Give verification an independent, automatic, reproducible standard instead of a human staring at the agent.
- AI 真正扩大的是工程师的「认知半径」What AI really expands is an engineer's cognitive radius
- 先看过去的职业结构:几十年来工程师的硬约束不是聪明程度,而是一个人脑子里能同时装下多少东西——「认知半径」。你因此只能专精一两个系统,切换上下文要疼好几天,给陌生项目提第一个 PR 前先花几天摸清约定。Start with how careers used to be shaped: for decades the binding constraint on an engineer was not intelligence but how much one head could hold at once — the cognitive radius. So you specialised in one or two systems, switching context hurt for days, and your first PR to an unfamiliar project began with days of learning its conventions.
- AI 改写这条约束的方式和大多数人以为的不一样:它主要不是让你打字更快,而是让「保持一个项目的上下文」这件事可以外包。你不再需要把每个细节记在脑子里,需要记住的是「哪里去查、怎么查」。AI rewrites that constraint in a way most people misread: it does not mainly make you type faster, it lets you outsource keeping a project's context alive. You no longer store every detail; you store where to look and how to look.
- 于是职业瓶颈从「装得下多少」变成「维护多少条线」:你能同时维持多少个项目的连贯上下文,而不是你的智商。这也解释了为什么同一模型在不同人手里效果差很多——差距在提问的结构化程度,不在模型本身。So the bottleneck moves from how much you can hold to how many threads you can keep coherent. That also explains why the same model works so differently in different hands — the gap is in how well the question is structured, not in the model.
- 能带走的:把「我知道去哪查」当成新的技能来练,把上下文外置成文档而不是肌肉记忆。Takeaway: practise 'I know where to look' as a skill, and externalise context into documents instead of muscle memory.
- Program-as-Weights:把「模糊函数」编译成小工具Program-as-Weights: compile fuzzy functions into small tools
- 很多真实任务不是「函数」而是「模糊函数」:判断这条日志要不要告警、把畸形 JSON 修成合法 JSON、按用户意图排序搜索结果。用大模型干这些,就是每个输入都跑一次完整推理,又慢又贵又不可靠。Many real tasks are not functions but fuzzy functions: should this log line page someone, can this malformed JSON be repaired, how should these results be ranked for this intent. Handing each one to a large model means a full inference per input — slow, expensive, unreliable.
- 这篇论文的想法:把模糊函数离线「编译」成一个小权重适配器——用一个 4B 的编译器,把自然语言的函数说明变成一个参数很少的权重产物,交给一个固定的 0.6B 小模型(论文里用 Qwen3)去执行。大模型只在「定义这个函数」时被调用一次,之后每次调用都便宜、离线、可复现。相当于把「每个输入都现场思考一遍」变成「每个函数只造一次工具,之后直接调用」。The paper's idea: compile the fuzzy function offline into a small weight adapter — a 4B compiler turns a natural-language spec into a parameter-efficient artifact that a fixed 0.6B interpreter (Qwen3 in the paper) executes. The large model is invoked once, when the function is defined; every later application is cheap, offline and reproducible. 'Think it through on every input' becomes 'build the tool once per function, then call it'.
- 为什么成立,而且它有多划算:真实业务里的模糊任务数量有限、边界稳定,足够小而固定的函数用一个小模型就够。论文自己的实测是:0.6B 的 Qwen3 解释器跑 PAW 程序,效果和直接 prompt Qwen3-32B 相当,推理内存约为后者的五十分之一,在 MacBook M3 上能跑到 30 tokens/s——于是大模型退回「造工具、选工具」这个它真正擅长的位置,不再为每个输入现场推理。Why it works, and what it buys: in real products the set of fuzzy tasks is small and their boundaries stable, so one fixed function fits a small model. The paper's own measurement: a 0.6B Qwen3 interpreter running PAW programs matches direct prompting of Qwen3-32B while using roughly one fiftieth of the inference memory and running at 30 tokens/s on a MacBook M3. The big model retreats to building and choosing tools, which is what it is actually good at, instead of reasoning once per input.
- 能带走的:如果你的 AI 应用里有些任务每天都在重复,别每次都交给大模型推理,考虑把任务固化成小工具。Takeaway: if some task in your AI product repeats every day, stop paying for reasoning each time and consider freezing it into a small tool.
数学之美The Beauty of Mathematics
- Fisher–Yates:为什么「随机交换一次」就是均匀洗牌Fisher–Yates: why one random swap each is a uniform shuffle
- 问题:给一个数组原地洗成均匀随机排列。最天真的做法是「随机交换任意两个元素」若干次,但它不均匀——不同的排列被生成的概率不同。The problem: shuffle an array in place into a uniformly random permutation. The naive 'swap two random elements some number of times' is not uniform — different permutations come out with different probabilities.
- Fisher–Yates 的做法:从后往前,每一步在还没定的位置里随机选一个元素放到最后一个位置。直觉上「先定第一个谁、再递归剩下」,但为什么每一步都合法?Fisher-Yates walks from the back: at each step, pick one element uniformly from the undecided prefix and put it in the last undecided slot. Intuitively it is 'fix who goes first, then recurse', but why is each step legal?
- 关键引理(整篇文章论证的核心):在已经随机选定前 k 个位置的前提下,把「未处理区」里任意两个元素交换,不改变最终排列的均匀性。因为未处理区内部的顺序本来就还是完全随机的,交换只是重新编号,分布不变。The key lemma in the argument: given that the first k slots are already a uniform random choice, swapping any two elements inside the untouched region does not change the final distribution — that region's internal order is still fully random, so a swap is just relabelling.
- 于是每一步只需一次随机数,共 n−1 次随机数、O(n) 时间、O(1) 额外空间,且每一步都不破坏不变量——均匀性从构造上成立,不需要事后证明「足够多步就够混合」。So one random number per step, n-1 draws, O(n) time, O(1) extra space, and the invariant is never broken — uniformity holds by construction, with no need to argue that 'enough steps' mixes.
- 线性规划排出的「完美食谱」,人吃不下The perfect diet a linear program serves up, and why you can't eat it
- 问题:每天吃最少卡路里,同时满足所有营养素下限——一个典型的线性规划。变量是每种食物的量,约束是每个营养素一条不等式,目标函数是总卡路里。The problem: minimise daily calories while meeting every nutrient floor — a textbook linear program. Variables are amounts of each food, constraints are one inequality per nutrient, the objective is total calories.
- 解法本身很干净:简单 LP 求解器就能算出「最优食谱」。但论文的教训在解上:最优点往往是「极端食谱」——大量某几种食物加到顶,其余几乎为零,人类根本吃不下。The solve is clean; a basic LP solver returns an 'optimal diet'. The lesson is in the answer: optima sit at extreme points — a few foods maxed out, everything else near zero, which no human would eat.
- 为什么成立:线性规划的可行域是凸多面体,最优解一定在顶点上;顶点意味着大量约束取等号,也就是大量食物被压到边界。数学上完美,生理上不可行。Why: the feasible region is a convex polytope, so an optimum must be a vertex; a vertex means many constraints are tight, which means many foods are pushed to their bounds. Mathematically perfect, physiologically impossible.
- 能带走的:当你把真实目标形式化之前,先问「形式化丢掉的是什么」。能被 LP 描述的目标,往往不是人真正想要的目标——模型解出的最优解和人能接受的解之间,隔着所有没写进约束的人性。Takeaway: before formalising a real goal, ask what the formalisation throws away. A goal an LP can express is often not the goal a person actually has — between the model's optimum and an edible diet sit all the human constraints you never wrote down.
- 化学其实是几何:反应网络的命运由缺陷度决定Chemistry is actually geometry: a reaction network's fate is set by its deficiency
- 直觉上,化学反应网络的长期行为——会不会振荡、会不会有多个稳定态——取决于速率常数:每个反应有多快。Intuition says a reaction network's long-run behaviour — oscillations, multiple steady states — is set by the rate constants: how fast each reaction runs.
- 化学反应网络理论(CRNT)说:不。网络结构本身——哪些物种、哪些反应边——就能算出一个叫缺陷度(deficiency)的拓扑量,它给系统的动态行为划出边界。Chemical reaction network theory says no: the structure alone (which species, which reaction edges) yields the deficiency, a topological quantity that bounds which dynamics are possible.
- 结论是反直觉的:即使你完全不知道速率常数,某些结论也成立——比如「这个网络最多有若干个稳态」「不可能振荡」。因为缺陷度只看图的几何(物种数、复合物数、连通分量数各减什么、连了几条边),不看权重的具体数值。The conclusion is counterintuitive: even knowing nothing about the rates, some claims hold — this network can have at most so many steady states, it cannot oscillate — because deficiency reads only the graph's geometry (species, complexes, linkage classes and their ranks), not the weights.
- 能带走的:「结构决定可能性,参数决定概率」这条思路在别处也反复出现——网络科学、控制论、编译器分析。先问结构允许什么,再去问参数取到什么。Takeaway: 'structure decides what is possible, parameters decide what is likely' recurs in network science, control theory and compiler analysis. Ask what the structure permits before asking what the numbers are.
程序员随想Notes for Programmers
- 平台团队的陷阱:组织级 DRY 往往是负资产The platform team trap: organizational DRY is often a liability
- 三个团队各自重复实现「带过滤的列表 + 图表 + 导出 CSV/PDF」,技术栈各不同(Go+Svelte / Erlang+React / PHP+Angular),都按时上线且好用。新来的平台 VP 两天内看出「重复」,决定:统一技术栈 + 建共享组件库。Three teams independently build 'filterable list + chart + CSV/PDF export', on different stacks (Go+Svelte, Erlang+React, PHP+Angular), all shipping on time and working well. A new platform VP spots the duplication in two days and decides: standardise the stack, build a shared component library.
- 结果是所有人都卡住:投资团队真的需要 Erlang 做去中心化消息;对只写线性 PHP 的信用卡团队来说,Go 的指针和 goroutine 反而是负担;K8s 对简单 CRUD 也是过度设计。共享组件的优先级排在「先做完 PDF 导出」后面,没有文档,接口对内部隐藏。Then everyone stalls: the investment team genuinely needs Erlang for distributed messaging, Go's concurrency model is a burden for the PHP team, and Kubernetes is overkill for simple CRUD. The shared components rank behind 'finish the PDF export', ship undocumented, and hide their interfaces.
- 解法是对外的服务化架构(SOA):统一「边界」而不是「实现」——每个团队的服务打包成容器、通过 REST+Swagger 暴露、用共享 CSS 统一观感。内部爱用什么用什么,按自己的节奏发布。The fix is service-oriented architecture facing outward: standardise the boundary, not the implementation — containerise each team's service, expose it over REST with Swagger, unify the look with shared CSS. Inside, each team uses what it likes and ships on its own cadence.
- 能带走的:判断一个抽象该不该做的标准不是「有多少代码重复」,而是「重复的部分是否在变化」。三个团队各写一遍稳定的列表页不是问题;被平台团队强制统一一套会变的组件才是。Takeaway: the test for an abstraction is not how much code is duplicated but whether the duplicated part is changing. Three teams each writing a stable list page is fine; a platform team forcing one shared copy of something that keeps changing is not.
- Rust 改写了我对类型的直觉How Rust rewired my type instincts
- 先分清三种「dispatch」(分发):动态分发(接口多态,运行时查)、条件分发(if/else,最朴素)、编译期分发(泛型单态化,类型在编译时就定死)。前两种大多数人天天用,第三种是 Rust 真正逼你想清楚的。First, three kinds of dispatch: dynamic (interface polymorphism, looked up at runtime), conditional (if/else, the plain one), and compile-time (generic monomorphisation, the type is fixed before the program runs). Most people use the first two daily; Rust forces you to think about the third.
- 第二件:sum type(枚举)比 product type(struct)重要得多,而主流语言一直忽视它。struct 是「所有字段都有」,enum 是「要么是 A 要么是 B,且每个变体带不同的数据」。编译器强制你在 match 里处理每个变体——没有遗漏分支这回事。Second: sum types (enums) matter far more than product types (structs), and mainstream languages keep ignoring them. A struct says 'all fields present'; an enum says 'either A or B, each carrying different data', and the compiler makes you handle every variant in a match — there is no missed branch.
- 为什么值得学:没有 sum type 的语言里,「要么有值要么没有」「要么成功要么失败」只能用 null 和异常表达,而 null 是十亿美元错误。Rust 把这两种情况都变成显式类型,错误在编译期就暴露。Why it is worth learning: without sum types, 'a value or nothing' and 'success or failure' get expressed with null and exceptions, and null is the billion-dollar mistake. Rust turns both into explicit types, so the error shows up at compile time.
- 能带走的:「语言塑造思维」不是玄学——学一门和现有习惯差异大的语言,你会拿到新的思考工具;哪怕不转用它,那些概念也会渗进你写别种语言的方式。Takeaway: 'the language shapes how you think' is not mysticism — learn one that differs sharply from your habits and you gain thinking tools; even if you never switch, the concepts leak into how you write everything else.
- 2026 年连环事故的共同形状:系统性失效The shared shape of 2026's cascading outages: systemic breakdown
- 2026 年的几件大事:微软全球宕机两天、FAA 停飞、PHP2Shell 让 AI 几小时找到隐藏十年的内存漏洞、eMudhra 弱私钥导致数千证书泄露、NPM 上游投毒。它们没有共同的直接原因,但形状相同。The 2026 incidents: a two-day Microsoft global outage, the FAA grounding flights, PHP2Shell letting an AI find a decade-old memory bug in hours, eMudhra's weak keys leaking thousands of certificates, an npm upstream poisoning. No shared root cause, but the same shape.
- 共同形状:高复杂度的系统由低质量零件构成,且没有任何人理解整体。作者把微软宕机归因于「复杂度失控 + 靠自动化和 oncall 补低质量」,把 PHP2Shell 归因于「依赖链太长,漏洞复杂到人类无法定位」。The shape: highly complex systems built from low-quality parts, with nobody understanding the whole. He traces the Microsoft outage to runaway complexity patched over by automation and on-call, and PHP2Shell to dependency chains too long for a human to locate a flaw in.
- 更深的判断:十年前开始的两场小革命(云 + 开源生态)把「细节知识」蒸发了——你不理解密码学、不理解依赖图,因为「npm install 一行搞定」。AI 让这件事加剧:它既是原因(更多代码、更少人理解)也是症状(人已经不再具备理解整体的能力)。The deeper claim: two small revolutions of the last decade — cloud and the open-source ecosystem — evaporated detailed knowledge. You do not understand the crypto or the dependency graph because 'npm install' handles it. AI accelerates this: it is both cause (more code, fewer people who understand it) and symptom (nobody can hold the whole).
- 能带走的:下一次出事故,先别找直接 bug,先问「这是不是一个没人理解整体的系统在报警」——如果是,修 bug 只治标。Takeaway: at the next outage, do not hunt the immediate bug first — ask whether this is a system nobody understands sending a warning. If it is, fixing the bug only treats the symptom.
- 确定性模拟测试:把分布式系统压成一条可复现轨迹Deterministic simulation testing: flatten distributed systems into one reproducible trace
- 分布式测试的经典难题:同一个 bug 偶发,本地复现不了,日志对不上,时间线对不上。原因:真实的时钟、网络延迟、磁盘 IO 都是非确定性的,每次跑都是一条不同的轨迹。The classic problem in distributed testing: a bug is intermittent, will not reproduce locally, the logs do not line up, the timeline does not match. The cause is that real clocks, network latency and disk IO are nondeterministic, so every run is a different trace.
- 确定性模拟的思路:单线程跑所有逻辑,把时钟、网络、磁盘都做成「模拟」的——事件排队、按模拟时间推进,随机性用种子。于是同一种子永远出同一条轨迹,bug 可以被精确复现。Deterministic simulation runs everything on one thread and simulates the clock, network and disk: events queue and advance on simulated time, randomness comes from a seed. The same seed always yields the same trace, so the bug reproduces exactly.
- 代价是编码规则非常严格:不允许真实 sleep、不允许读真实时间、所有 IO 走模拟接口。生产代码通常跑不了这套,需要「双轨」——测试轨走模拟,生产轨走真实时钟。The price is strict coding rules: no real sleeps, no reading the real clock, all IO through the simulated interfaces. Production code often cannot run this way, so you keep two rails — tests on the simulation, production on real time.
- 能带走的:偶发 bug 的真正杀手不是更长的等待时间,而是可复现性;把随机性从「不可控」换成「可控制」,bug 就从玄学变成工程。Takeaway: the real killer of flaky bugs is not longer waiting, it is reproducibility. Turn randomness from something you cannot control into something you can, and the bug goes from folklore to engineering.
哲学与生活Philosophy & Life
- 「足够」不是数量,是能力:Wendell Berry 论安息日“Enough” is a capacity, not a quantity: Wendell Berry on the Sabbath
- Berry 的说法(经 Maria Popova 整理):「足够」是一种能力——不再向世界索要更多的能力。不是某个具体数字,而是停止比较、停止要更多的状态。Berry's claim, as Popova reads him: 'enough' is a capacity — the capacity to stop asking the world for more. Not a number, but a state of having stopped comparing, stopped wanting more.
- 安息日的意义就在这里:它不是「休息一天」,是「进入一种不再期待的状态」。在自然里过安息日尤其有力——因为自然是「从初始就只创造够用的多」的范本。That is what the Sabbath is for: not 'a day off' but entering a state where you expect nothing more. Keeping it outdoors is especially potent, because nature is the model of making only as much as is needed from the start.
- 推论:创造与爱都只发生在「不被要求」的时候。被要求的创造是交付,被要求的爱是义务;只有不被要求的才是真的。The corollary: creation and love only happen when they are not demanded. Demanded creation is delivery; demanded love is obligation; only the undemanded kind is real.
- 能带走的:区分「我想要更多」和「我需要更多」——多数「需要」其实是「想要」。Takeaway: separate 'I want more' from 'I need more' — most of what we call need is want.
工具角Tools Corner
- db-branch:ZFS 写时复制给数据库做秒级分支db-branch: second-scale database branches from ZFS clones
- 场景很具体:给每个 PR 或每次 CI 一条干净的大库副本,或者把一个有写权限的 agent 丢进去随便折腾。传统做法是 dump 加 restore——几百 GB 的库要等几十分钟,磁盘上还要再放一份完整拷贝。The job is concrete: give every pull request or CI run a clean copy of a large database, or hand a write-capable agent a copy it is allowed to destroy. The usual route is dump and restore — tens of minutes for a few hundred gigabytes, plus a second full copy on disk.
- 它省掉的正是这份等待和空间:分支是 ZFS 克隆,创建时 0 字节被复制,基库和分支共享数据块,谁改了哪块才复制哪块。作者在自己那套三节点测试集群上给的数字是:PostgreSQL 分支约 0.5 秒就绪,MySQL 约 3 秒;分支可以 reset 回创建时的状态,也可以加 --ttl 1h 到期自动删掉。What it removes is exactly that wait and that space: a branch is a ZFS clone, with zero bytes copied at creation; base and branch share blocks and only diverging blocks get copied. On the author's own three-node test cluster a PostgreSQL branch is ready in about 0.5 s and a MySQL branch in about 3 s; a branch can be reset to its creation state or expired with --ttl 1h.
- 最短上手:一台 Ubuntu 24.04 或 26.04 的机器加一个 ZFS 池,加上官方 apt 源后 apt install db-branch,再用 db-branch runtime install postgres@18.6 装对应引擎版本。手边只有 Mac 或 Windows 的话,一条 multipass 命令就能起一个文件池的试用虚拟机,约两分钟——文件池慢,只适合试,不要放真数据。Shortest path: an Ubuntu 24.04 or 26.04 machine with a ZFS pool, the official apt repository, apt install db-branch, then db-branch runtime install postgres@18.6 for the engine version. On a Mac or Windows box, one multipass command brings up an evaluation VM on a file-backed pool in about two minutes — the file pool is slow and meant for trials, not real data.
- 依赖与限制:只支持 Linux 加 ZFS,数据必须落在 ZFS 上;项目自称 Beta,1.0 之前 API 和命令行细节会变,Apache-2.0。多节点是 Raft 集群,可选 ProxySQL 让应用始终只连一个地址;proxysql、greenmask、anon 这些模块在同一个 apt 源里,不需要另找。Dependencies and limits: Linux plus ZFS only, and the data has to live on ZFS; the project calls itself Beta, so APIs and command-line details may change before 1.0, and it is Apache-2.0. Multi-node is a Raft cluster, with optional ProxySQL so applications keep one address; proxysql, greenmask and anon live in the same apt repository.
- dockgate:单容器自托管 Docker 面板dockgate: self-hosted Docker control panel in one container
- 场景:小 VPS 和家里这台机器上跑着 Docker 与 Compose,想看状态、翻日志、重启服务、部署新版本,现在每次都要 SSH 进去敲一串命令。The job: Docker and Compose running on a small VPS and on this machine, and every check — state, logs, restarts, deploys — means SSH plus a string of commands.
- 它省掉的是「每台机器一套面板」:一个容器、一个管理员密码,同时管本地 Docker daemon 和通过 SSH 连上的其他主机。README 标称最多 256MB 内存、0.5 CPU,纯 JavaScript 没有构建步骤,可以离线用;Compose 项目能在面板里建、改、部署并留部署历史,Swarm 集群也能建起来并来回迁移服务。What it removes is the one-panel-per-machine tax: a single container with a single admin password manages the local Docker daemon and other hosts reached over SSH. The README claims at most 256 MB RAM and 0.5 CPU, plain JavaScript with no build step, usable offline; Compose projects can be created, edited, deployed with a deploy history, and a Swarm cluster can be set up and services moved to it and back.
- 最短上手:下载仓库里的 docker-compose.yml,docker compose up -d,浏览器打开 http://localhost:7077 设置管理员密码;如果第一次是从公网访问,它还会要求你填 docker logs 里打印的那串 token。Shortest start: grab the docker-compose.yml from the repository, docker compose up -d, then open http://localhost:7077 and set the admin password. On a first visit from the internet it also asks for the token printed by docker logs.
- 限制:它是单管理员设计,一个密码就是全部权限,没有角色划分——面板本身就是高权限入口,别裸暴露在公网,至少放在内网或带认证的反向代理后面。项目很新,我没有在真实的多节点 Swarm 集群上验证过它的行为。Limits: it is single-admin by design — one password is full control, no roles — and the panel is itself a high-privilege entrance, so never expose it raw; keep it on a private network or behind an authenticating reverse proxy. The project is young and I have not verified it against a real multi-node Swarm cluster.
- shrinkgate:把重复工具输出换成哈希短桩shrinkgate: local Rust gateway that dedupes repeated tool output
- 场景:一个长会话里,同一个文件被读了三遍、同一个编译命令跑了两遍,每次的完整输出都留在上下文里;真正有用的只有最新那份,其余都是同一个字符串的副本。The situation: in a long session the same file gets read three times and the same build command runs twice, and every full output stays in context. Only the newest copy carries information; the rest are duplicates of one string.
- 它的做法很克制:一个本地 Rust 网关(默认 127.0.0.1:18793),只在同一次请求内部比较;发现完全相同的工具输出时,把较早的副本换成一个哈希短桩,最新那一份保持原文。不摘要、不改写、不猜语义,指令和推理内容完全不碰,也没有遥测。The approach is deliberately conservative: a local Rust gateway (127.0.0.1:18793 by default) that compares only within a single request. When two tool outputs are byte-identical, the earlier copy becomes a hash stub while the latest stays verbatim. No summarising, no rewriting, no guessing at meaning; instructions and reasoning are untouchable, and there is no telemetry.
- 最短上手:cargo install shrinkgate --locked,或者用官方安装脚本装预编译二进制。先 shrinkgate connect claude --dry-run 看它打算改哪些设置,确认后再去掉 --dry-run 接上(也可接 codex / opencode),shrinkgate uninstall claude 可以还原;shrinkgate benchmark 和 stats 能量出你自己工作负载省了多少。Shortest start: cargo install shrinkgate --locked, or the official installer for a prebuilt binary. Run shrinkgate connect claude --dry-run first to see which settings it would change, then drop --dry-run (codex and opencode work too); shrinkgate uninstall claude reverts it, and shrinkgate benchmark / stats measure the saving on your own workload.
- 限制:只处理逐字相同的重复——历史里出现过、但本次请求里只有一份的内容不会被删;能省多少完全取决于你的会话有多啰嗦。main 上的新命令和加固还没发版,发布的 crate 与二进制仍按各自的 release tag;另外它的恢复快照可能包含你 agent 设置里已有的密钥。Limits: only exact duplicates are collapsed — a payload that appeared earlier but is present once in the current request stays intact — so the payoff depends entirely on how verbose your sessions are. New commands and hardening on main are unreleased, so published crates and binaries track their release tags; recovery snapshots can contain secrets already present in your agent settings.