References on frames and threading headers in the list projection - #12
Merged
Conversation
A frame is frozen at rest, so the properties worth pinning are the ones nobody can fix later: a three-deep References chain round-trips oldest first and folds inside the 78-character line limit, a value that is not a bracketed msg-id is refused, the list projection serves both headers without loading raw, the persist path caches them off a frame it did not build, and 0002 backfills legacy rows whose columns are null - including one whose raw is not valid UTF-8, which must not abort the statement.
An inbox page never loads raw, so a client could not thread it: the only place Message-ID and In-Reply-To lived was inside the frame. They join subject and from_address as cached columns, written on all three durable paths and backfilled from raw by 0002 so threading does not begin at the upgrade. References is emitted folded and oldest first, the order RFC 2822 defines and every threading client walks; In-Reply-To stays the single immediate parent. Every threading value is validated as a bracketed msg-id at the builder, which is the last point a caller can still be blamed - past it the bytes are frozen and an unthreadable header is unthreadable forever.
The data model block listed every principal_mail column, so it now lists the two cached threading columns as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An inbox page never loads
raw— the list projection is deliberatelybuilt from cached columns only — so a client had no way to thread it:
Message-IDandIn-Reply-Tolived nowhere but inside the frame.Frame.
buildMailFrameacceptsreferences(the thread's ancestry,oldest first, as RFC 2822 §3.6.4 defines it) and emits it as a folded
References:header inside the 78-character line limit.In-Reply-Tostays the single immediate parent. Every threading value —
messageId,inReplyTo, and eachreferencesentry — must be a bracketed msg-id(
<local@domain>), and aRangeErrorrefuses anything else: past thebuilder the bytes are frozen, and an unthreadable header written today is
unthreadable forever.
Decode.
decodeMailFramenow returnsmessageId,inReplyTo(
string | null) andreferences(string[], oldest first) parsedalongside the header map, so no reader re-derives them.
Projection.
principal_mailgainsmessage_idandin_reply_to,nullable text, cached exactly the way
subjectandfrom_addressare.All three durable paths write them —
writeMailboxMessage,deliverInboxItems(both acceptinReplyToandreferenceson theirinputs) and
createMailboxPersist, which takes them off the decode of aframe it did not build.
MailboxMessagegains an optionalinReplyTo;messageIdnow resolves header → cached column → row id, so the row idis the last resort rather than the list's only answer.
Migration
0002_mail_threading_headersadds both columns andbackfills them from each existing row's
raw, so threading does notsilently begin at the upgrade. The backfill searches only the header
section and decodes
rawas LATIN1 — a single non-UTF8 byte in one framewould otherwise abort the whole statement.
Tests: three-deep References round trip and folding, msg-id rejection,
list and detail agreeing on the headers, the persist path caching from an
inbound frame, and the backfill against a table seeded with legacy rows
(raw present, columns null, one of them invalid UTF-8).
bun run test,bun run typecheck,bun run buildand the reference-host acceptancesuite are all green locally.
Part of CL-7445
Fixes CL-7446