AI usage generates a fragile codebase
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
AI usage generates a fragile codebase
I can only speculate as to the reasons why I was laid off from Meta in May, but I suspect that one of the reasons is that I was a little bit more resistant to adopting AI/LLMs as coding tools than some of my peers. Don’t get me wrong, I generated at least 90% of my code using AI in my last few months there, which was the minimum for a decent rating. But AI didn’t 10X the amount of code I was writing. It didn’t even 2X it.
我只能推测五月份我被 Meta 解雇的原因,但我怀疑其中一个原因是我对采用 AI/大语言模型作为编程工具的态度,比我的一些同事稍微抵触了一些。别误会,在 Meta 的最后几个月里,我至少有 90% 的代码是使用 AI 生成的,这已经是获得良好评价的最低要求了。但 AI 并没有让我的代码产出量提升 10 倍,甚至连 2 倍都没有达到。
I was focused on code quality. I saw the code being pushed by some of my peers who were heavily reliant on AI, and I saw that it was brittle code. There were many subtle issues that would lead to tech debt in the long term, and even some glaring issues were ignored by very good programmers. For instance, I saw one of the best programmers on my team try to merge code that used javascript events for mouseover CSS effects rather than using the :hover selector, which is a totally unscalable way of writing mouseovers.
我当时专注于代码质量。我看到一些过度依赖 AI 的同事提交的代码,发现那些代码非常脆弱。其中存在许多会导致长期技术债务的细微问题,甚至连一些非常优秀的程序员也会忽略掉明显的缺陷。例如,我看到团队中最优秀的程序员之一试图合并一段代码,该代码使用 JavaScript 事件来实现鼠标悬停的 CSS 效果,而不是使用 :hover 选择器——这是一种完全无法扩展的鼠标悬停实现方式。
Now I’m employed at another large tech company and I’ve fully made the switch to generating 100% of my code using AI because that’s the expectation today. Still, I can see lots of people becoming aware that this isn’t a sustainable way to continue development of a large scale SaaS product. AI tends to solve the problems that can fit within its context window very well, but it’s totally oblivious to the long term issues that can’t be understood in that relatively small frame.
现在我受雇于另一家大型科技公司,我已经完全转向使用 AI 生成 100% 的代码,因为这是当今的要求。尽管如此,我还是看到许多人开始意识到,对于大规模 SaaS 产品的持续开发而言,这并不是一种可持续的方式。AI 往往能很好地解决其上下文窗口内的问题,但对于那些无法在相对狭窄的框架内被理解的长期问题,它却完全无能为力。
In this post I’m going to list four ways that AI usage results in a fragile codebase that isn’t resilient to the demands of highly available and highly scalable SaaS applications.
在这篇文章中,我将列出 AI 使用导致代码库变得脆弱的四种方式,这些代码库无法满足高可用性和高可扩展性 SaaS 应用的需求。
By the way, every word of this article was written by a human. Even though the following image was generated by AI, this article isn’t AI slop.
顺便提一下,这篇文章的每一个字都是由人类撰写的。尽管下方的图片是由 AI 生成的,但这篇文章绝非 AI 垃圾内容。
Here are the four most common ways that I have seen AI generating a fragile codebase.
以下是我所见过的 AI 生成脆弱代码库的四种最常见方式。
One of the most obvious failures of modern LLMs is that they tend to write simplistic automated test cases that don’t cover the things that matter to humans. Frequently I see AI agents writing lots of tests of get/set methods which are trivial and don’t typically require much testing. When AI writes e2e tests, they tend to only cover the cases which are already covered in the codebase. In other words, the AI writes tests only covering one type of user, or only covering surface level interactions. This creates massive gaps in the test coverage that are invisible to developers because they aren’t captured by the line level coverage metric.
现代大语言模型最明显的失败之一,就是它们倾向于编写过于简单的自动化测试用例,而这些用例往往无法覆盖人类真正关心的内容。我经常看到 AI 代理编写大量针对 get/set 方法的测试,这些方法微不足道,通常不需要太多测试。当 AI 编写端到端(e2e)测试时,它们往往只覆盖代码库中已有的案例。换句话说,AI 编写的测试只覆盖了一种类型的用户,或者只覆盖了表层的交互。这在测试覆盖率中造成了巨大的缺口,而开发者对此一无所知,因为这些缺口无法被行级覆盖率指标捕捉到。
AI also tends to write overly complex code. It frequently uses two or three helper methods when a single one would suffice. It tries to follow coding guidelines, such as DRY, to a fault, without realizing that the added complexity of that rigidity makes the code more difficult for human developers to debug or understand.
AI 也倾向于编写过于复杂的代码。它经常在只需要一个辅助方法时,却使用了两三个。它试图遵循诸如 DRY(不要重复自己)之类的编码准则,却走到了极端,没有意识到这种僵化所带来的额外复杂性,反而让代码更难被人类开发者调试或理解。
And that’s the third issue with AI codebases: Humans don’t understand them. The longer a company relies on AI agents to generate the code, the fewer developers are going to understand the codebase. This means that developers can’t do the things that are necessary to build a resilient codebase. They don’t understand the data structures and algorithms well enough to see when a pull request contains a new abstraction that doesn’t work with the pre-existing structures.
这就是 AI 代码库的第三个问题:人类无法理解它们。一家公司依赖 AI 代理生成代码的时间越长,能理解代码库的开发者就越少。这意味着开发者无法完成构建弹性代码库所必需的工作。他们对数据结构和算法的理解不够深入,无法判断一个合并请求(PR)中包含的新抽象是否与现有结构兼容。
AI moves too quickly for human developers to maintain a high quality bar. Each pull request comes faster than the prior one and has to be reviewed in even less time. This leads to developers skimming the code and missing crucial details that result in long term tech debt. Small quality issues like testing gaps and poorly named variables accrue in the codebase until it becomes a morass of spaghetti code.
AI 的迭代速度太快,人类开发者难以维持高质量标准。每一个合并请求都比上一个来得更快,且必须在更短的时间内完成审查。这导致开发者只能草草浏览代码,从而错失关键细节,进而导致长期的技术债务。测试缺口和命名不当的变量等微小的质量问题在代码库中不断累积,最终使其变成一团混乱的“意大利面条式代码”。
If you’re unsure whether coding agents are harming your codebase or not, then you might look for the following symptoms of a fragile, AI-generated codebase.
如果你不确定编程代理是否正在损害你的代码库,那么你可以观察以下脆弱的 AI 生成代码库的症状。
When you switched the department over to agentic coding did the number of incidents slowly start rising? At first when we were all using agents to generate massive amounts of code, it didn’t seem that different from traditional coding. The PRs came and were merged and everything seemed alright. But oh, there was that one p0 that came in at the end of the month, then there were two SEVs the following month. Then even more the next month. Now, after a year or two of agentic coding, it seems like there’s an incident every weekend. AI coding agents are the reason why there are more incidents impacting customers.
当你将部门转向代理式编程时,事故数量是否开始缓慢上升?起初,当我们都使用代理生成大量代码时,它看起来与传统编程并无太大区别。合并请求被提交并合并,一切似乎都很正常。但是,月底出现了一个 P0 级事故,接着下个月出现了两个严重事故(SEV)。再下个月,事故更多了。现在,经过一两年的代理式编程,似乎每个周末都会发生事故。AI 编程代理正是导致影响客户的事故增多的原因。
Not only are there more incidents, but the incidents take longer to be mitigated. The fact is that the human developers on your team now have a more shallow understanding of the codebase. If your coding agent can’t find the issue that your customers are facing, then humans are going to have to dig through a codebase that is highly complex and poorly tested. They will essentially be entering unfamiliar territory, so it takes longer for them to figure out what is going wrong. Hence, companies lose more and more money to incidents that take longer to resolve.
不仅事故变多了,而且事故的缓解时间也变长了。事实是,你团队中的人类开发者现在对代码库的理解更加肤浅。如果你的编程代理无法找到客户所面临的问题,那么人类就必须深入挖掘一个高度复杂且测试不足的代码库。他们本质上是在进入一个陌生的领域,因此需要更长的时间才能弄清楚哪里出了问题。因此,公司因事故解决时间延长而损失的资金也越来越多。
When humans don’t spend time in the code, they fail to see all of the use cases. They fail to understand how actual humans are using the code because they aren’t ensuring that the AI is instrumenting analytics and catching all the errors properly. Hence, invisible errors start appearing in the codebase. Errors are uncaught and only visible to real world users, as opposed to the types of users that are being tested in automated tests or in developer manual testing.
当人类不花时间阅读代码时,他们就无法看到所有的使用场景。他们无法理解真实人类是如何使用代码的,因为他们没有确保 AI 正确地植入分析工具并捕获所有错误。因此,隐形错误开始出现在代码库中。这些错误未被捕获,只有真实世界的用户才能察觉,而自动化测试或开发者手动测试所模拟的用户类型却无法发现它们。
And that leads to the ultimate problem with AI codebases: they weren’t made for humans. AI codebases are software made by AI for AI. They aren’t being tailored to the way that human users use the product, and they aren’t being tailored for the way human developers need to maintain the product. The experience degrades on both the user and the developer side, leading to a vicious cycle of enshittification.
这导致了 AI 代码库的终极问题:它们不是为人类而造的。AI 代码库是 AI 为 AI 制作的软件。它们没有针对人类用户使用产品的方式进行定制,也没有针对人类开发者维护产品的方式进行优化。用户和开发者两端的体验都在恶化,从而导致了“垃圾化”(enshittification)的恶性循环。
The fact of the matter is that for a product to satisfy human customers, it has to be infor
事实是,为了让产品满足人类客户,它必须是……(原文中断)