Falsehoods Programmers Believe About ATProto

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Falsehoods Programmers Believe About ATProto

In the year 2010, Patrick McKenzie wrote and published the article “Falsehoods Programmers Believe About Names” — a list of reasonable-sounding assumptions about people’s names that not only were not true, but also (if assumed) would create bugs and even break software. That article started a whole genre of Falsehoods Programmers Believe articles. This article (“Falsehoods Programmers Believe About ATProto”) is one of my contributions to that genre. Every numbered statement below is false. Each one is followed by what is actually true — and where to read more. These are not made up for effect. Each one is backed by the specification, or by a live request to real ATProto servers (made in November 2026).

2010 年,Patrick McKenzie 撰写并发表了文章《程序员关于姓名的错误认知》(Falsehoods Programmers Believe About Names)——列举了一系列听起来合理但实际上不仅错误,而且(如果被采纳)会导致程序错误甚至崩溃的关于人名的假设。那篇文章开启了“程序员错误认知”系列文章的先河。本文(《程序员关于 ATProto 的错误认知》)是我对该系列的贡献。以下每一条编号陈述都是错误的。每一条之后都紧跟事实真相以及进一步阅读的指引。这些内容并非为了效果而编造,每一条都有规范支持,或由 2026 年 11 月对真实 ATProto 服务器的实时请求所证实。

Handles

句柄 (Handles)

A user’s handle never changes. Handles can change. The account’s DID is what is permanent — the accounts specification calls it (DIDs) “unique and immutable”. My handle changed! My handle was first reiver.bsky.social, then became reiver.myatproto.social, and then later became reiver.blacksky.team. You can see that if you dig through the data at plc.directory/did:plc:scewmn2pl3oz36mxme2b6czz/log/audit. (did:plc:scewmn2pl3oz36mxme2b6czz is my DID-PLC DID.) So, a handle is a good database key for a user. Use the DID. Store the handle only for display (cosmetic) purposes — and re-check what each DID’s handle is from time to time. But, you need to normalize the DID before using it. DIDs are URIs, and URI schemes are case-insensitive (RFC 3986) — so DID:plc:scewmn2pl3oz36mxme2b6czz and did:plc:scewmn2pl3oz36mxme2b6czz are the same DID. ATProto requires the normalized (lowercase) form: normalize DIDs when they come from user input, store and compare only the normalized form, and reject non-normalized DIDs that arrive in protocol data.

用户的句柄永远不会改变。实际上,句柄是可以改变的。账户的 DID 才是永久的——账户规范将其(DID)称为“唯一且不可变”。我的句柄就变过!我的句柄最初是 reiver.bsky.social,后来变成了 reiver.myatproto.social,之后又变成了 reiver.blacksky.team。如果你深入查看 plc.directory/did:plc:scewmn2pl3oz36mxme2b6czz/log/audit 中的数据,就能看到这一点。(did:plc:scewmn2pl3oz36mxme2b6czz 是我的 DID-PLC。)因此,句柄并不是用户数据库的理想主键。请使用 DID。仅将句柄用于显示(装饰性)目的,并时不时重新检查每个 DID 对应的句柄。但是,在使用 DID 之前,你需要对其进行标准化。DID 是 URI,而 URI 方案是不区分大小写的(RFC 3986)——所以 DID:plc:scewmn2pl3oz36mxme2b6czz 和 did:plc:scewmn2pl3oz36mxme2b6czz 是同一个 DID。ATProto 要求使用标准化(小写)形式:当 DID 来自用户输入时进行标准化,仅存储和比较标准化后的形式,并拒绝协议数据中出现的非标准化 DID。

When a user changes their handle, the first part stays the same — such as reiver.bsky.social → reiver.myatproto.social → reiver.blacksky.team. A new handle does not have to have anything in common with the old one. joeblow.bsky.social → me.example.com → bbqlover.net → ilikeicecream.com would be fine. Changing a handle just means pointing the account at a different domain — com.atproto.identity.updateHandle takes any valid handle, and only “Verifies handle validity”. For example, Bluesky’s own account (did:plc:z72i7hdynmk6r22z27h6tvur) started out as bluesky-team.bsky.social, and then became bsky.app. You can see that in its audit log at plc.directory/did:plc:z72i7hdynmk6r22z27h6tvur/log/audit. (Another reason to key users by DID, and not by any part of their handle.)

当用户更改句柄时,第一部分保持不变——例如 reiver.bsky.social → reiver.myatproto.social → reiver.blacksky.team。其实,新句柄不需要与旧句柄有任何共同之处。joeblow.bsky.social → me.example.com → bbqlover.net → ilikeicecream.com 也是完全可以的。更改句柄只是意味着将账户指向不同的域名——com.atproto.identity.updateHandle 接受任何有效的句柄,并且仅“验证句柄的有效性”。例如,Bluesky 自己的账户 (did:plc:z72i7hdynmk6r22z27h6tvur) 最初是 bluesky-team.bsky.social,后来变成了 bsky.app。你可以在其审计日志 plc.directory/did:plc:z72i7hdynmk6r22z27h6tvur/log/audit 中看到这一点。(这也是为什么应该通过 DID 而不是句柄的任何部分来索引用户的原因。)

You can trust a handle you saw five minutes ago. A handle can change at any moment. The user can switch to a new handle. The domain’s owner can point it at a different DID — or the domain can expire, and be registered by someone else. Or, its DNS record or /.well-known/atproto-did file can just disappear, and the handle stops resolving. The handle specification says “If the handle for a known DID is confirmed to no longer resolve, it should be marked as invalid.” So, a handle → DID mapping is only as good as when you last checked it. The specification recommends caching handle resolution “up to some lifetime”, and re-resolving “periodically”. Watch the firehose for #identity events, which announce handle changes. And, never use a cached handle to decide who someone is (for example, for permissions) — use the DID.

你以为五分钟前看到的句柄是可信的。实际上,句柄随时可能改变。用户可以切换到新句柄。域名的所有者可以将其指向不同的 DID——或者域名可能过期并被其他人注册。又或者,其 DNS 记录或 /.well-known/atproto-did 文件可能直接消失,导致句柄停止解析。句柄规范指出:“如果已知 DID 的句柄被确认不再解析,则应将其标记为无效。”因此,句柄到 DID 的映射仅在上次检查时有效。规范建议将句柄解析结果缓存“一定期限”,并“定期”重新解析。请关注 firehose 中的 #identity 事件,这些事件会宣布句柄变更。此外,永远不要使用缓存的句柄来确定某人的身份(例如用于权限控制)——请使用 DID。

Every user has a handle. An account might have no handle in its DID document (no at:// entry in alsoKnownAs), or a handle that no longer resolves back to it. The DID specification says “an account whose DID document does not contain a valid and confirmed handle can still participate in the atproto ecosystem. Software should be careful to either not display any handle for such account, or obviously indicate that any handle associated with it is invalid.” In API responses, such an account’s handle may show up as the special value handle.invalid — which “can not be used in most situations (search queries, API requests, etc).” And, the handle field on the firehose’s #identity event is optional. So, your code needs a “no handle” case.

每个用户都有句柄。实际上,账户的 DID 文档中可能没有句柄(alsoKnownAs 中没有 at:// 条目),或者句柄可能不再解析回该账户。DID 规范指出:“DID 文档中不包含有效且已确认句柄的账户,仍然可以参与 ATProto 生态系统。软件应谨慎处理,要么不显示此类账户的任何句柄,要么明确指出与其关联的任何句柄均无效。”在 API 响应中,此类账户的句柄可能会显示为特殊值 handle.invalid——该值“在大多数情况下(搜索查询、API 请求等)无法使用”。此外,firehose 的 #identity 事件中的 handle 字段是可选的。因此,你的代码需要处理“无句柄”的情况。

Every handle ends in .bsky.social. Any Internet domain can be a handle. And, other PDSes hand out their own — the blacksky.app PDS, for example, offers .blacksky.app, .myatproto.social, .cryptoanarchy.network, and others. Even if a user’s handle is not a .bsky.social handle now, their first handle was. A user’s first handle is whatever they got when their account was created — on whichever PDS they signed up with. com.atproto.server.createAccount just takes a “Requested handle for the account”, and each PDS offers its own domains. So, someone who signed up on blacksky.app might start out as alice.myatproto.social — and never have had a .bsky.social handle at all. You can see this in a DID’s audit log on plc.directory (https://plc.directory//log/audit) — the very first operation (the one that created the DID) shows the first handle, and the first PDS. For example, the audit log for did:plc:ub2k2k5zahuegnkkvxjk5y2w (plc.directory/did:plc:ub2k2k5zahuegnkkvxjk5y2w/log/audit) has just 1 operation — the one that created it, on November 13th, 2026. Its first handle was shadowoftruth.myatproto.social, and its first PDS was blacksky.app. It has never had a .bsky.social handle.

每个句柄都以 .bsky.social 结尾。实际上,任何互联网域名都可以作为句柄。此外,其他 PDS 会分发它们自己的域名——例如 blacksky.app PDS 提供 .blacksky.app、.myatproto.social、.cryptoanarchy.network 等。即使用户的句柄现在不是 .bsky.social,他们的第一个句柄也未必是。用户的第一个句柄是他们在创建账户时获得的——取决于他们注册时使用的 PDS。com.atproto.server.createAccount 仅接受“账户请求的句柄”,而每个 PDS 提供其自己的域名。因此,在 blacksky.app 上注册的人可能最初是 alice.myatproto.social,并且从未拥有过 .bsky.social 句柄。你可以在 plc.directory 上的 DID 审计日志中看到这一点——最初的操作(创建 DID 的操作)显示了第一个句柄和第一个 PDS。例如,did:plc:ub2k2k5zahuegnkkvxjk5y2w 的审计日志仅有 1 次操作——即 2026 年 11 月 13 日创建它的操作。其第一个句柄是 shadowoftruth.myatproto.social,第一个 PDS 是 blacksky.app。它从未拥有过 .bsky.social 句柄。

A handle is a third-level domain — like alice.bsky.social, alice.blacksky.app, or alice.myatproto.social. A handle can have any number of segments, as long as there are at least 2. example.com is a valid handle — and so is apple.banana.cherry.example.com. The handle specification only says “there must be at least two segments” (so a bare top-level domain like com is not allowed), each segment can be 1 to 63 characters, and the whole handle can be at most 253 characters. Its own examples include a.co, 8.cn, and XX.LCS.MIT.EDU; and the official test vectors include john.test.bsky.app, and a valid handle with 10 segments. Handles are resolved with DNS. With DNS (a TXT record at _atproto.

句柄是三级域名——比如 alice.bsky.social、alice.blacksky.app 或 alice.myatproto.social。实际上,句柄可以有任意数量的段,只要至少有 2 段即可。example.com 是一个有效的句柄——apple.banana.cherry.example.com 也是。句柄规范仅规定“必须至少有两个段”(因此不允许使用像 com 这样的纯顶级域名),每个段可以是 1 到 63 个字符,整个句柄最多 253 个字符。其自身的示例包括 a.co、8.cn 和 XX.LCS.MIT.EDU;官方测试向量包括 john.test.bsky.app 以及一个包含 10 个段的有效句柄。句柄通过 DNS 解析。使用 DNS(在 _atproto. 处设置 TXT 记录)。