A 404 that wasn't: what running our own package registry taught us

A short update from the series on evidence-based agentic development. We run our own package registry for our private npm packages and Rust crates, behind a login. It’s one of the pieces of the stack we chose to own rather than rent, and it’s part of what my Build Stuff talk is about. This is what owning it has cost, in two incidents a day apart.

这是关于循证代理开发系列文章的简短更新。我们运行着自己的包注册表,用于存放私有的 npm 包和 Rust crate,并设有登录验证。这是我们选择“拥有”而非“租用”的技术栈组成部分之一,也是我 Build Stuff 演讲的主题。以下是我们在相隔一天发生的两次事故中,为这种“拥有”所付出的代价。

The 404 that wasn’t. On 16 October the release build for one platform asked the registry for a crate and got a 404. The sibling build had downloaded the same crate 23 minutes earlier. Nothing had been deleted. The storage layer had hiccuped for a moment, and our adapters turned every storage error into “not found”. Cargo treats a 404 as final, so one blip failed a whole release job.

并非 404 的 404 错误。10 月 16 日,一个平台的发布构建向注册表请求一个 crate 时收到了 404 错误。而 23 分钟前,同组的构建任务刚刚下载过同一个 crate。没有任何东西被删除。存储层出现了短暂的故障,而我们的适配器将所有的存储错误都转换成了“未找到”。Cargo 将 404 视为最终结果,因此一次小故障导致整个发布任务失败。

The fix is one rule: null means definitely absent. A real “no such blob” is a 404. Anything else that looks transient is retried, and if it still fails the registry answers 503 with a Retry-After, which cargo and npm both retry. A package manager believes what your registry says, so the registry mustn’t say “doesn’t exist” when it means “I couldn’t look”.

修复方案只有一条规则:空值(null)才意味着确实不存在。真正的“无此数据块”才是 404。任何其他看起来是瞬时的错误都会被重试;如果仍然失败,注册表会返回带有 Retry-After 的 503 错误,Cargo 和 npm 都会对此进行重试。包管理器会相信注册表的反馈,因此当注册表的意思是“我无法查询”时,绝不能说“不存在”。

The burst. The next day about 25 Linux and Windows builds started together, and for around 110 seconds the registry hit its database connection limit across some 40 index and download requests. We already retried, but the window was about 8 seconds, and every retry ran out. Cargo got HTTP 500.

突发流量。第二天,大约 25 个 Linux 和 Windows 构建任务同时启动,在约 110 秒的时间内,注册表在处理约 40 个索引和下载请求时达到了数据库连接限制。我们虽然已经设置了重试,但重试窗口期只有约 8 秒,所有重试都超时了。Cargo 收到了 HTTP 500 错误。

Three changes, each with a reason attached: Cache the hot reads. Tokens and crate versions are held per instance for 30 seconds, the crate index lists for 5. Not longer: a build that pins a version published seconds ago has to see it. And only found results are remembered, so a version that doesn’t exist yet never gets stuck as a cached miss.

我们做了三项更改,每项都有其理由:缓存热点读取。令牌和 crate 版本在每个实例中保留 30 秒,crate 索引列表保留 5 秒。不能更长:如果一个构建任务锁定了几秒钟前发布的版本,它必须能查看到。而且只记录已找到的结果,这样尚未存在的版本就不会被错误地缓存为“未找到”。

Give connections back sooner. Idle connections now release after 2 seconds instead of 20, so idle instances free their slots inside the burst. Retry for about 27 seconds, not 8. Cargo abandons a transfer slower than 10 bytes a second for 30 seconds, so waiting longer than that can’t help. The cache has a cost, and we wrote it down: a token revoked directly in the database can keep working for up to 30 seconds on an instance that already cached it.

更快地归还连接。空闲连接现在在 2 秒后释放,而不是 20 秒,这样空闲实例就能在突发流量期间腾出槽位。重试时间延长至约 27 秒,而非 8 秒。Cargo 会放弃传输速度低于每秒 10 字节且持续 30 秒的任务,因此等待超过这个时间没有意义。缓存是有代价的,我们记录了下来:在数据库中直接撤销的令牌,在已经缓存了该令牌的实例上可能还会继续生效长达 30 秒。

One more thing, because it’s the honest part. Five days later we reset our main branch to a release snapshot, and the reset silently dropped these fixes, along with two others, from the live line. We found out because we were checking, and re-applied all four. If a fix only exists in history, it doesn’t exist. The lesson I’d take for anything that sits underneath other people’s builds is that the meaning of your errors is part of your API. 404 is final. 503 gets retried.

还有一件事,因为这是最诚实的部分。五天后,我们将主分支重置为某个发布快照,这次重置静默地从生产线中丢弃了这些修复程序以及另外两个修复。我们是因为进行了检查才发现的,并重新应用了所有四个修复。如果一个修复只存在于历史记录中,那它就等于不存在。对于任何处于他人构建任务底层的东西,我得到的教训是:错误的含义也是 API 的一部分。404 是最终结果,503 则会触发重试。

Talking about this at Build Stuff 2026 This is one of the write-ups behind my talk at Build Stuff in Vilnius this December, the 15th edition, under the theme The Age of Agency. Control Your Fate at the Metal Wednesday 2 December, 15:00, Zeta 2. 45 minutes. If you’re coming, say hello. If you’re not yet, 2026SPEAKER_20 takes 20% off a ticket.

将在 Build Stuff 2026 上讨论此话题。这是我今年 12 月在维尔纽斯举行的第 15 届 Build Stuff 大会上演讲的背景文章之一,主题是“代理时代”(The Age of Agency)。演讲题目为“在底层掌控你的命运”(Control Your Fate at the Metal),时间是 12 月 2 日周三 15:00,地点在 Zeta 2,时长 45 分钟。如果你会来,请打个招呼。如果还没买票,使用 2026SPEAKER_20 可享受 8 折优惠。

I’m Kent Alstad. I build KandiForge, a toolchain for running software projects with AI agents under an evidence-based process. If you run your own registry, I’d like to know what it taught you.

我是 Kent Alstad。我开发了 KandiForge,这是一个用于在循证流程下通过 AI 代理运行软件项目的工具链。如果你也运行自己的注册表,我很想知道它教会了你什么。