plan: Mail architecture (MA1–MA9) #915
Closed
kayg
wants to merge 0 commits from
plan/mail-architecture into dev
pull from: plan/mail-architecture
merge into: kayg:dev
kayg:main
kayg:port/tasks-float-2
kayg:fix/train-1116-2
kayg:fix/train-1116-3
kayg:fix/train-1116-1
kayg:fix/flake-1134
kayg:fix/server-1182
kayg:dev
kayg:port/notes-float-3c
kayg:docs/auto-update-ig
kayg:feat/dav-transport
kayg:port/tasks-float-1
kayg:wip/mail1011-sv-order-1116
kayg:fix/flake-1179
kayg:fix/flake-1178
kayg:fix/guards-1153-fsio-split
kayg:fix/guards-1153-notes-split-we
kayg:fix/guards-1153-notes-lib
kayg:fix/guards-1153-notes-home
kayg:fix/guards-1153-ui-primitives
kayg:fix/guards-1153-primitives-e2e
kayg:fix/guards-1153-visibility-doc
kayg:feat/paper-grey-1116
kayg:fix/flake-1165
kayg:fix/flake-1119
kayg:docs/imap-766-plan-v2
kayg:fix/e2e-unique-ports
kayg:t3/paged-search-reconcile-final
kayg:wip/mail1011-final-1115
kayg:docs/tasks-float-port
kayg:perf/editor-first-paint-1c
kayg:feat/imap-notes-fetch
kayg:feat/imap-notes-projection
kayg:feat/imap-notes-readonly
kayg:feat/imap-notes-auth
kayg:feat/imap-notes-server-foundation
kayg:wip/mail1011-txn-ownvocab-1115
kayg:wip/mail1011-txn-novocab-1115
kayg:perf/p1117-final-harness
kayg:perf/single-shot-repeats
kayg:port/tasks-matrix
kayg:wip/mail1011-txn-1115
kayg:fix/static-gates-1155
kayg:feat/files-s1-identity-r7
kayg:fix/files-r7-idle-loop
kayg:fix/daily-train-1152
kayg:port/notes-float
kayg:fix/editor-tables-test-types
kayg:port/notes-float-listscript
kayg:feat/tasks-actions
kayg:port/notes-float-phone-preload
kayg:perf/sound-comparator
kayg:port/notes-float-listscroll
kayg:port/notes-float-budgets
kayg:port/notes-float-suite-fix-b
kayg:port/notes-float-sidebar-fix
kayg:port/notes-float-trim
kayg:port/notes-float-3-lists
kayg:fix/attachments-meta-capability
kayg:docs/carddav-writes-v2-plan
kayg:feat/contacts-companion-pure
kayg:issue/carddav-read-perf-fix-r2
kayg:issue/carddav-read-r2
kayg:port/notes-float-devsync2
kayg:review/calendar-2
kayg:review/switcher-a-pills
kayg:port/notes-float-switcher-a
kayg:port/port-tables-2
kayg:review/switcher-ends
kayg:wip/whiteboard-s1-1114
kayg:port/port-tables
kayg:wip/mail1011-perfneutral
kayg:review/photo-tint
kayg:port/notes-float-shell
kayg:wip/local/collections-db
kayg:wip/local/mail-p1
kayg:wip/local/cold-growth-on-tiering
kayg:wip/local/tiering-v3-s1
kayg:wip/local/wal1051-cap
kayg:wip/local/tiering-v3-s1-resume
kayg:wip/local/index-position-startup-scan
kayg:port/notes-float-flat
kayg:port/notes-float-promote
kayg:wip/handover/mail1011-candidate
kayg:wip/handover/files-s1-candidate
kayg:port/notes-float-shell-only
kayg:port/notes-float-perf
kayg:feat/whiteboard-s1
kayg:feat/tiering-v5
kayg:fix/app-switch-hitch
kayg:wip/local/files-s1-dev-v4-final
kayg:feat/files-s1-dev-v4
kayg:fix/c2-glass-shared
kayg:feat/flat-lists
kayg:wip/handover/whiteboard-s1-resume
kayg:wip/att-lazy-861
kayg:feat/switcher-browse
kayg:wip/att-lazy-860
kayg:feat/tasks-float
kayg:recovered/flat-backup-candidate
kayg:perf/stalls-1054-kc
kayg:land/ai-toolbar
kayg:feat/collections-db
kayg:feat/collections-db-fixes
kayg:codex/mail-1011-redesign-20261111
kayg:fix/ai-toolbar
kayg:backup/macos-vm/st3-head
kayg:perf/trim-candidate-phonestack
kayg:feat/switcher-three
kayg:fix/1051-index-idle-checkpoint
kayg:perf/stalls-1054-kb
kayg:perf/stalls-1054-k
kayg:perf/stalls-1054-r3
kayg:fix/c2-contrast-tail
kayg:perf/stalls-1054-r3-preview
kayg:feat/collections-before
kayg:feat/tiering-v4
kayg:fix/timelog-caret
kayg:wip/local/tasks-actions
kayg:docs/tasks-writes-v2-plan
kayg:st3-r3
kayg:feat/pass8
kayg:review/calendar-2-before-1111
kayg:wip/tiering-v3-cold4
kayg:perf/stalls-1054-r2
kayg:fix/suite-A4
kayg:fix/suite-A5-probe
kayg:fix/suite-A6
kayg:fix/suite-A3
kayg:fix/suite-A2
kayg:fix/suite-A5
kayg:fix/suite-A1
kayg:wip/local/attachments-861-fix
kayg:feat/contrast
kayg:wip/local/ports-861
kayg:storage/wal-checkpoint-off-save-1051
kayg:wip/local/mail-1011-reconcile-20261110
kayg:feat/style-sheet-fixes
kayg:feat/money-round
kayg:perf/stalls-1054
kayg:wip/tiering-v3-cold5
kayg:t3/mail-1011-liveness
kayg:feat/iphone-fixes
kayg:feat/notes-approve
kayg:wip/local/shrow-work
kayg:feat/files-s1-identity
kayg:feat/quickfix
kayg:wip/tiering-v3-cold
kayg:wip/local/shared-row-swipes
kayg:backup/macos-vm/pfx-B
kayg:backup/macos-vm/pfx-C
kayg:backup/macos-vm/pfx-D
kayg:feat/contrast-r1
kayg:feat/tiering-v3-s2-tags
kayg:feat/folder-drop
kayg:t3/photos-s1
kayg:feat/tiering-v3-s1-namespace
kayg:wip/local/photos-s1
kayg:t3/photos-plan-slice-one
kayg:recovered/backup/p1b-61505
kayg:t3/paged-search-reconcile
kayg:t3/smooth-pane-transitions
kayg:t3/index-position-startup-scan
kayg:fix/private-staging-759b-r2
kayg:backup/macos-vm/hk/hk1009/pr877
kayg:backup/macos-vm/hk/hk1009/pr878
kayg:docs/undo-block-ids-plan
kayg:fix/undo-768
kayg:backup/macos-vm/hk/hk1009/pr875
kayg:backup/macos-vm/hk/hk1009/pr904
kayg:proto/block-identity-v7d
kayg:backup/macos-vm/hk/hk1009/pr846
kayg:backup/macos-vm/hk/hk1009/pr860
kayg:backup/macos-vm/hk/hk1009/pr861
kayg:backup/macos-vm/hk/hk1009/pr849
kayg:backup/macos-vm/hk/hk1009/pr848
kayg:backup/macos-vm/hk/hk1009/pr853
kayg:backup/macos-vm/hk/hk1009/pr957
kayg:backup/macos-vm/hk/hk1009/pr893
kayg:backup/macos-vm/hk/hk1009/pr889
kayg:backup/macos-vm/hk/hk1009/pr902
kayg:docs/imap-notes-plan
kayg:docs/quota-plan-2
kayg:fix/parallel-test-flakes
kayg:docs/calendar-backend-v2-plan
kayg:feat/calendar-ical-converter
kayg:backup/macos-vm/hk/hk1009/pr808
kayg:docs/contacts-import-v2-plan
kayg:issue/610-pm-midnight
kayg:feat/calendar-v2-s1-containment
kayg:backup/macos-vm/hk/hk1009/pr854
kayg:backup/macos-vm/hk/hk1009/pr845
kayg:backup/macos-vm/hk/hk1009/pr917
kayg:docs/dav-recorder-v2-plan
kayg:plan/previews-865
kayg:plan/save-log-durable-entry
kayg:backup/macos-vm/hk/hk1009/pr934
kayg:fix/e2e-data-on-ram
kayg:backup/macos-vm/hk/hk1009/pr888
kayg:feat/appwindow3
kayg:feat/appwindow2
kayg:feat/appwindow
kayg:feat/money-p1
kayg:feat/keys-sheet
kayg:review/calendar-2-themes
kayg:feat/smooth-cursor
kayg:fix/float-style
kayg:review/calendar-2-float
kayg:release/2026-11-06-hotfix
kayg:archive/port/rows-drop-code
kayg:archive/port/rows-actions
kayg:archive/port/rows
kayg:scratch/tasks-894-ui-gates
kayg:review/calendar-2-night-wip
kayg:recovered/flaky/toast-reduced
kayg:release/2026-11-05
kayg:archive/flaky/rows-drop-fixed
kayg:archive/flaky/rows-actions
kayg:archive/flaky/rows
kayg:sim/bm15-final
kayg:sim/bm15-bis-932
kayg:sim/bm15-bis-909
kayg:sim/bm15
kayg:sim/bm15-bis-887
kayg:perf/tiering-option-b
kayg:fix/sw-lazy-precache
kayg:archive/plan/save-log-durable-entry
kayg:mock/money-fix2
kayg:archive/fix/e2e-data-on-ram
kayg:mock/appearance-all
kayg:mock/pill-press
kayg:mock/pill-press-mac
kayg:backup/macos-vm/appearance-after
kayg:mock/auto-swipes
kayg:mock/mail-actions
kayg:backup/macos-vm/mock/mail-actions
kayg:mock/money-static
kayg:archive/review/standards-917
kayg:perf/tiering-761-fix
kayg:mock/type-audit
kayg:mock/third-pane
kayg:feat/contacts-import-v2-s1
kayg:perf/executor-hot-path
kayg:archive/port/hidden-blocks
kayg:archive/port/devices
kayg:scratch/executor-on-894
kayg:scratch/executor-spans2
kayg:scratch/executor-spans
kayg:archive/port/rows-drop
kayg:feat/tiering-761-d-scale
kayg:feat/tiering-761-c-index
kayg:feat/tiering-761-b-reader
kayg:archive/review/sharing-pr3-review-9fec3d1f
kayg:perf/ports-lazy-budgets
kayg:feat/tiering-761-a-migration
kayg:archive/review/sharing-pr3-review
kayg:archive/review/sharing-pr3-review-code
kayg:archive/plan/previews-865
kayg:archive/port/port-attachments-3
kayg:archive/port/contacts-merge
kayg:fix/motion-audit-859
kayg:fix/motion-audit-859-mac
kayg:archive/port/port-pickers
kayg:archive/port/port-tables-2
kayg:archive/port/port-tables
kayg:recovered/local/sharing-s1-pr2-room-snapshot-candidate
kayg:archive/fix/parallel-test-flakes-code-minipc01
kayg:docs/imap-766-readonly-slice
kayg:feat/dav-recorder-v3
kayg:research/788-diagnosis
kayg:archive/fix/parallel-test-flakes
kayg:archive/perf/pr792-cold-index-edit
kayg:docs/sharing-slice-1
kayg:recovered/feat/dav-recorder-v2
kayg:recovered/feat/dav-recorder-v2-edd7bbb
kayg:spike/imap-766-s0-cases
kayg:archive/fix/undo-768
kayg:recovered/feat/dav-recorder
kayg:recovered/feat/dav-recorder-901acd4
kayg:feat/contacts-import
kayg:perf/cold-growth-on-764
kayg:perf/cold-growth-on-tiering
kayg:recovered/feat/tasks-set-status
kayg:feat/tasks-move-reorder
kayg:feat/tasks-delete-promote-duplicate
kayg:feat/carddav-writes
kayg:perf/quota-on-tiering
kayg:perf/quota-simple
kayg:perf/cold-growth-on-quota-stack
kayg:recovered/perf/cold-growth-on-tiering
kayg:feat/calendar-identity
kayg:feat/calendar-event-parser
kayg:feat/calendar-props-maps
kayg:port/glass-when-ring
kayg:recovered/feat/tiering-761-s1-wip-8132a84
kayg:recovered/feat/tiering-761-s1-wip-9da4094
kayg:recovered/feat/tiering-761-s1-wip-724512c
kayg:recovered/feat/tiering-761-s1-wip-66e667e
kayg:recovered/feat/tiering-761-s1
kayg:wip/6by32-01-tier-761-s1-pause-20261030
kayg:spike/imap-766-s0
kayg:wip/6by32-02-calternal-pause-20261030
kayg:wip/8by64-01-review-688-pause-20261030
kayg:wip/6by32-01-verify-744-pause-20261030
kayg:wip/6by32-01-verify-742-pause-20261030
kayg:fix/private-staging-759b
kayg:wip/6by32-01-review-748-pause-20261030
kayg:wip/6by32-01-review-733c-pause-20261030
kayg:wip/6by32-01-review-733b-pause-20261030
kayg:review/calendar-month
kayg:wip/local/bm15-trash
kayg:plan/759b-staging
kayg:review/767b-tests
kayg:review/preview-2026-10-29
kayg:docs/tiering-731-plan
kayg:wip/c6b02-review-733d
kayg:wip/c6b02-bm1-full-a
kayg:docs/deploy-plan
kayg:fix/storage-owner-liveness-642
kayg:fix/storage-fix-7
kayg:feat/tiering-731
kayg:wip/tiering-731-first-attempt
kayg:perf/idle-honest-2
kayg:fix/storage-private-tmp-642-dev
kayg:fix/storage-exact-file-quarantine-642
kayg:perf/one-flush-save
kayg:review/calendar-static
kayg:review/indexing-ring
kayg:review/when-field-2
kayg:proto/block-identity-2-review
kayg:proto/block-identity-review
kayg:review/when-field
kayg:issue/tasks-create-ids
kayg:issue/tasks-create
kayg:review/combined
kayg:review/task-polish
kayg:review/top-buttons
kayg:review/q1-q5
kayg:archive/integ325-293
kayg:archive/integ325-ci
kayg:issue/calendar-adr
kayg:archive/old/train/2026-10-23bk2
kayg:archive/old/train/2026-10-23bk
kayg:issue/469-mockup-9a
kayg:issue/smart-tasks-mockup
kayg:issue/469-menus
kayg:issue/652-signout-flake
kayg:issue/652-history-fix7
kayg:issue/652-history-fix6
kayg:archive/old/issue/spring-check-perf
kayg:issue/spring-check-perf
kayg:issue/659-rename-fast
kayg:archive/old/train/2026-10-21ar
kayg:issue/search-hardening-3
kayg:issue/652-history-fix5
kayg:issue/660-port-sheets-glass
kayg:issue/652-history-fix4
kayg:issue/652-history-fix3
kayg:issue/652-history-fix2
kayg:issue/652-history-flake
kayg:train/2026-10-21an
kayg:issue/settings-admin-port
kayg:issue/search-port
kayg:train/2026-10-20am
kayg:issue/storage-split-fix2
kayg:issue/storage-split
kayg:archive/old/issue/folder-ids-fix
kayg:train/2026-10-20al
kayg:archive/old/issue/folder-ids
kayg:train/2026-10-20ak
kayg:issue/tables-mockup
kayg:train/2026-10-19aj
kayg:train/2026-10-19ai
kayg:issue/469-merge-fixes
kayg:issue/sidebar-band
kayg:archive/old/issue/608-settings-spec
kayg:train/2026-10-19ah
kayg:issue/swipe-offscreen
kayg:train/2026-10-19ag
kayg:archive/old/issue/590-nlp-adr
kayg:archive/old/issue/587-event-after-write-2
kayg:train/2026-10-19af
kayg:archive/old/issue/587-event-after-write
kayg:issue/469-pill-room-c
kayg:issue/469-pill-room
kayg:train/2026-10-19ae
kayg:issue/469-narrow-handle
kayg:issue/397-ios-swipe-2
kayg:issue/469-desk-fixes
kayg:archive/old/issue/auto-update-adr
kayg:issue/469-filter-gap
kayg:issue/469-port-1b
kayg:issue/442-opacity-flake
kayg:issue/327-web-fast-3
kayg:archive/old/issue/469-port-1
kayg:issue/469-port-1
kayg:issue/327-web-fast-2
kayg:archive/old/issue/327-web-fast
kayg:archive/old/issue/425-stt-bench-vq1
kayg:archive/old/issue/445-no-bleed
kayg:archive/old/issue/400-swipe-mockup-2
kayg:issue/426-client-review
kayg:issue/426-client-2
kayg:issue/426-client
kayg:archive/old/issue/476-safe-area-lab
kayg:archive/old/issue/445-top-light
kayg:issue/471-blocks-mockup
kayg:archive/old/issue/448-links-app-2
kayg:archive/old/issue/448-links-app
kayg:archive/old/issue/398-cold-links
kayg:issue/434-442-small-2
kayg:issue/434-442-small
kayg:archive/old/issue/398-unload
kayg:archive/old/issue/445-bottom-band
kayg:issue/445-bottom-band
kayg:issue/351-rem-3
kayg:issue/351-rem-2
kayg:issue/351-rem
kayg:archive/old/issue/327-first-note
kayg:issue/395-width-phone
kayg:archive/old/issue/327-typing
kayg:issue/396-ios-edges
kayg:issue/397-ios-swipe
kayg:archive/old/issue/327-notes-index
kayg:issue/345-347-contrast-empty-2
kayg:archive/old/issue/44-arenas
kayg:issue/44-arenas
kayg:archive/integ325
kayg:archive/old/issue/327-perf-harness
kayg:archive/old/issue/44-thp
kayg:issue/44-thp
kayg:archive/old/issue/285-sticky-pills
kayg:archive/old/issue/44-trim-3
kayg:issue/44-trim-3
kayg:archive/old/issue/165-cards
kayg:archive/old/issue/165-picker-2
kayg:archive/old/issue/212-multi-select
No reviewers
Labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
kayg/calternal!915
Loading…
Reference in a new issue
No description provided.
Delete branch "plan/mail-architecture"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Needs kayg's review. Do not merge. Design only (no code, no measurements). Plan:
docs/plans/mail-architecture.md.Covers MA1-MA9: components and data flow, storage layout and schemas (
state.db/mail.db/bodies.db+.emlmirror), stable message identity, sizes and big-O, sync/backfill/connection limits, device tiers (spine, headers, bodies), search changes, action pipeline and offline queue, send/undo/send-later, remote content and HTML cleaning, wrapped-key credential design with an explicit threat table, Apple Mail proxy on the shared IMAP front-end, deep links, failure table with user-facing words, perf budgets, the scaling and spam-scroll tests for the first PR, phased PR sequence with gates, and 20 numbered open questions (each with a recommendation).Findings worth a look:
SearchProvider::list(user)returns every item at startup; it does not scale to millions of messages. Needslist_sincein a separate search PR.Mail/files.imap-uidand bumps UIDVALIDITY when unproven.Refs #868.
Part of Calternal Mail planning. 🤖 Generated with Claude Code
Review: mail architecture plan (docs/plans/mail-architecture.md @ plan/mail-architecture)
I checked the plan against
origin/dev:crates/core/src/search.rs,crates/search/src/indexer.rs,crates/store,crates/engine/src/execute.rs,crates/imap-uid,docs/storage.mdand ADRs 0011, 0044, 0046, 0047, 0059, 0062, 0069.Claims that check out: the search trait really does have
list()at startup and per-entrytouched(). There is no IMAP listener anywhere incrates/(onlyimap-uid). Store is one FIFO writer thread per user..emlis unclaimed text, so it goes on HDD under the 0062 tiering amendment. ADR 0046 really does say "Mail is stored as Maildir".Sections that are fine as written: §2 (crate split,
Caps-driven trait), §7 backfill passes and push, §14 deep links, §19 build-or-buy. The over-engineering risk is low. Mode P is deferred to P11, which is right.P1: must fix before approval
P1-1. §3 Identity: the rules contradict each other, and a move can mint a new id.
dup_of". With identical headers, the fingerprint is identical, so rule 1 always wins and rule 4 can't happen.COPYis a second message at the provider, but rule 1 folds it into one msg id. Thenmail.trashon that id is ambiguous: which placement does it act on? And §15 "provider delete → remove placements; mirror file → Trash" moves the only mirror file to Trash while the other copy still exists./mail/m/<old>(ML7) now breaks, which is exactly what §3 promises can't happen.X-GM-MSGID, JMAPid, IMAPOBJECTIDEMAILID(RFC 8474; the plan uses OBJECTID only for mailboxes). Fingerprint is the fallback only.P1-2. §10 Device outbox op id loses repeated intents.
execute.rs: same key + same payload hash → replay the stored result) returns the first result, and the third action never runs. The thread stays unread, and the server-sideop(INSERT OR IGNOREon the hash of the key) drops it too.change_seqfor the target (the base), or a per-Installation monotonic counter, in the id.P1-3. §10 / §15 Send recovery still has a double-send path.
APPEND, which runs after SMTP. A crash after the final.but before theAPPENDtherefore always finds nothing in Sent, and the mail gets sent again. The §15 row "SMTP refused or timeout … 4xx retried 3 times" also lumps a timeout after the final.(unknown outcome) in with a real 4xx.submittingintoconnecting(safe to retry) anddata_sent(from the moment the final.is written, never retry automatically). Persist the SMTP reply before theAPPEND.data_sentwith no recorded reply: look in Sent only where the provider saves Sent itself (Gmail, JMAP). Everywhere else go straight tounknownwith the existing sentence.., after the reply, after the APPEND.P1-4. §4 / §13 Bcc and envelope recipients have nowhere to live.
outgoingstores onlymime. The proxy "picks the account by the From header and hands it to the same send pipeline".RCPT TO, so they are silently not delivered. Or, if a pipeline puts Bcc in the headers to keep it, the Bcc list leaks to every recipient.outgoing.rcpt(an envelope list) andmail_from. The composer strips Bcc from the MIME and keeps it in the envelope. The proxy uses itsRCPT TOlist verbatim.Bcc:header.P1-5. §8 The spine can't render the lists Gate 2 is about.
id, last date, sender, subject, unread, flags, category, count. There is no account, no folder or label set, and no per-folder sort key (thread_folder.last_msdiffers fromthread.last_ms, e.g. Sent versus Inbox).Archiveor the Unified Inbox past the 5,000-thread headers window. The device can't tell which spine rows belong to that list or in what order, so it shows blanks or asks the server. That breaks Gate 2 for every list except one.thread_foldermembership in compact form (folder rid, role, category, last_ms, unread), about 16 B per membership. Re-state the size: Gmail threads average 2–3 labels.spam_scroll_contenttest must cover a non-Inbox folder and the Unified Inbox, not only the Inbox.P1-6. §4 / §8 / §9 Rebuildable
mail.dbresetschange.sequnder every device and search cursor.mail.dbis "drop and rebuild" (§15), butchange.seqlives in it. After a rebuild, seq restarts at 1. A device holding cursor 2,000,000 sees "nothing new" for days, and search's plannedlist_since(watermark)skips everything.mail_epoch(random, written at create) instate.dband in every cursor. An epoch mismatch → re-read the spine and do a full search reconcile.mail.dbwhile a device and search are mid-stream; both converge.P1-7. §13 Proxy without CONDSTORE makes Apple Mail's flag sync O(N) per folder per poll.
UID FETCH 1:* (FLAGS). On a 100k-message unified Archive, that is 100k rows per folder per refresh, per Mac, forever. It is the exact per-device O(mailbox) cost the requirements forbid.serde_json::Value(ActionResponse), so a1:*answer would be a single huge Value, which breaks the 8 MB per-connection limit.HIGHESTMODSEQ, derived fromchange.seq+ epoch) in P9, not "later".proxy_uid≤ 500 rows per call) and streams the replies.P1-8. §12 Threat table: "a backup without the server's key file: Safe" is false with today's backup procedure.
docs/storage.mdbacks up the whole SSDsystem/tree together withusers/("copying both trees together").system/invite.keyis in that set, andsystem/mail.key"like invite.key" would be too.state.dbandmail.key, so every app password in it can be read in Always-on mode.mail.keyoutside the coordinated backup set, with its own escrow step instorage.md(or systemd-creds/TPM from day one). Or correct the row to "Not safe" and say so in Settings.mail.key.P1-9. §11 Network-safety list misses the ranges this deployment actually lives on.
*.vpn.kayg.org).::ffff:0:0/96, NAT6464:ff9b::/96, 6to42002::/16, ULAfc00::/7,0.0.0.0/8, and the server's own public addresses.<img>pointing at each range and at a NetBird hostname; none is connected to.P2: should fix in the plan
P2-1. §4 / §10 Overlay keyed by
msgalone.overlay(msg PK, op_id, …), two pending ops on one message (archive, then flag) collide. Rolling back op A drops op B's change as well.state.db) before or without atomically applying the result tomail.db. The thread flickers back, and a crash between the two leaves stale state until the next delta.(msg, op_id), or derive it from the pendingoprows. Apply tomail.dbfirst, then clear the overlay (idempotent).P2-2. §4 Journal hints plus a private
changetable supersede ADR 0044; this isn't a "clarification" (Q13).mail.changedhints.changeretention and compaction (one row per ref, latest kind). Otherwise a 2M-message backfill leaves 2M+ rows forever.P2-3. §9 The search change is only half of it.
reconcile()also loadsindex.stamps(p.id())into aHashMapof every held item: 2M entries per start, even withlist_since.P2-4. §5 Startup sweep and orphan detection need a walk of
Mail/..tmpswept at start" and "finished file with no row (matched by id in its name)" can only be found by walking up to 2M files. §5 itself forbids that.Mail/<account>/.incoming/(same filesystem) and sweep only that directory. Order the steps as:mail.dbrow withmirror_state = pending+ target path → tmp → rename →ok. On restart, look only atpendingrows.Mail/. Quota must come from counters, never fromdu.P2-5. §15 "Rebuild from
.emlnames + provider" doesn't work as written.msg id → fingerprintmap instate.db(about 50 B × 2M ≈ 100 MB, so state it), or say the rebuild parses headers (the first 8 KB) in the background with a stated rate and budget. With P1-1(a), the provider id makes most of this unneeded.P2-6. §3 / §13 Same fingerprint, different bytes.
List-*).BODY[]for that placement serves the wrong bytes (RFC822.SIZEmismatch confuses Mail.app).BODY[]go per content hash; the msg id may point at several content hashes.P2-7. §13 UIDVALIDITY bump must come from the authority, and category churn re-UIDs.
state.db, a restore could reuse an old UIDVALIDITY.state.dbdata. State that the counters there are only a cache.Inboxis "People only", so every category re-run or override moves messages out and back in. Each re-entry needs a new UID, and a background re-categorisation of 10k messages makes Mail.app re-download 10k. Give the background category lane a churn budget, or keep the unified Inbox membership stable once exposed.P2-8. §13 Sent duplicates and identities.
APPENDs to Sent itself, often before our post-send copy exists, so the "drop if already in Sent" check misses it and both copies land.APPENDbe the copy (dedupe by Message-ID inoutgoing).account.addressis a single column, but Fastmail aliases and Gmail send-as are common. A legitimate From then gets 553. Add anidentitytable.P2-9. §11 Fetching images at ingest for the whole history.
url_hash → content_hash, statetable (cleaned HTML is written before images exist, so it must reference a URL id), and/mail/img/*scoped to the requesting user's cache.P2-10. §8 The spine on web and phones.
P2-11. §16 / §17 / §18 Gates that can't run as written.
spam_scroll_contentandspam_scroll_framesare in P1, but the UI is P6. Move them to P6, or give P1 a minimal list view.mailintegration branch, or each PR with a thin UI.P3: nice to fix
X-Calternal-Draft-Idand dedupe at start. State who wins when Apple Mail edits the same draft.mail.delete_foreverand mass provider-side deletes both put files in Calternal Trash for 30 days, against explicit intent, and the count goes against quota. Make delete_forever skip Trash./, NUL, control characters, NFC, 255-byte limit, trailing dots). Subjects in file names show up on every synced device, so check that against the privacy line in §14 ("ids carry no subject").state.dbcommit is one fsync. Perf-01/02 contended fsync is 60+ ms. Use group commit, or state the budget for quiet disks only.BODY[]reading file offsets. Say the action hands back a file handle or stream.imap.mailorsmtp.mail": pick one (rec:imap.mailcovers both, since it's one macOS account)..eml. Under 0062, a claim would pull the whole mirror (120 GB worst case) onto SSD.sandboxwithoutallow-same-origin. List the attributes the rewriter covers (srcset,<picture><source>,background=, SVG<image href>,poster,image-set(),@import,@font-face). The CSP is the backstop.Counts: P1 9 · P2 11 · P3 13
Revision 2 pushed (head
309c4c4a). Mapping of review comment 77512 to the plan (section numbers are indocs/plans/mail-architecture.md). Also folded in MB1–MB10 and MA7b (section 21); answered Q items removed; "journal" replaced by "save log" throughout.P1
identity_moves)(epoch, seq), new state, per-Installation counter);op_idstest (§17)held→connecting→data_sent→replied→copied→sent;data_sentfsynced before the final.; reply persisted before APPEND; timeout after.is unknown, not 4xx; JMAP/Gmail look-up, plain IMAP goes straight tounknown; four kill-point tests; §15 rows splitoutgoing.mail_from,rcpt, MIME never holds Bcc; §10 Bcc rules; §13 proxy uses RCPT TO verbatim; test in §17send_state_machine(folder, role, category, sort_ms, unread), size restated (~140 B/thread); Gate 2 now covers Inbox, Archive, Sent, label, category, Unified Inbox (§16, §17)mail_epochinstate.dband in every cursor; retention/compaction ofchange; §9 search watermark; §15 rebuild row;change_feed_epochtestproxy_change, mod-seqs instate.db/authority, pagedmail.proxy_page≤ 500, O(changes) gate; P10 gatesecrets/mail.keyin its own root outside every backup,docs/storage.mdchanges listed, escrow command, CI test that a backup tarball has no keynetguardcrate; fixtures incl. NetBird host and rebindingP2
(msg, op_id); §10 step 4 apply tomail.dbfirst, then clear overlaymail.changes);changeretention in §4.incoming/→ rename; recovery looks only atpendingrows and.incoming/; table of every Home walker; quota from countersid_mapinstate.db(~120 MB at 2M); §5 rebuild path and ratecontenttable: one file per content hash;BODY[]per content versionstate.dbis a cache, ADR needed for the bump deviation; unified Inbox membership frozen at first exposure (no category churn)caps.saves_sent; §4identitytable (MB9)img_reftable;/mail/img/*scoped to the userP3 (all fixed in the text except two, §22): 1 §7 tokens not sockets · 2 §6 basic-IMAP expunge lag stated · 3 §10 drafts
X-Calternal-Draft-Idand Apple-edit rule · 4 accepted: superseded by MB2 · 5 §4 file-name rule and privacy line · 6 accepted (group commit, quiet-disk budget, contended figure reported) · 7 §13 stream/handle · 8 §13imap.mailcovers submission · 9 §8 both ADR 0046 lines · 10 §4 no plugin may claim.eml· 11 §15 removal words · 12 §12prf_saltinstate.db· 13 §11 attribute list and sandbox withoutallow-same-origin.Open for kayg: Q16 (how PRs land), Q17 (gate scale), Q18 (sign-in code in push payload), Q19, Q20, Q21 are new; the rest keep their numbers' recommendations (renumbered).
Re-review: mail architecture plan, revision 2 (head
309c4c4a)Checked
docs/plans/mail-architecture.md@309c4c4aagainst review 77512, mapping 77514 andorigin/dev:crates/core/src/search.rs,crates/search/src/indexer.rs,crates/store/src/{lib,writer}.rs,crates/engine/src/execute.rs,crates/imap-uid,docs/storage.md,perf/README-perf-vms.md, ADR 0044/0046/0069.Code facts used below:
storekeeps idempotency receipts for 7 days (idempotency_retention), then prunes them.storeruns one transaction per commit withsynchronous=NORMAL(FULL only forOnce). There is no group commit today.imap-uidis a model crate that nothing depends on (only its own Cargo.toml). No server flag or root configures an authority yet.docs/storage.mdhas two roots (--data,--state), andsystem/(withinvite.key) is in the state backup.The revision is a real improvement. Most P1s are properly closed. What's left is mostly new edge cases inside the new rules, plus four items that are only partly fixed.
1. First-review findings
op_idstest.data_sentfsynced before the final., reply persisted before APPEND, plain IMAP goes straight tounknown, kill points.mail_from,rcpt, MIME without Bcc, proxy uses RCPT TO verbatim, test.sort_ms, size restated, Gate 2 covers six lists.mail_epoch … random at create, never reset. Built from the schema, this brings the original silent-skip bug back. "Starts with the same epoch only if the rebuild proves it can continue numbering" is undefined, and a rebuild after losingmail.dbcan never prove that. Fix: a rebuild always means a new epoch. Store the epoch with thechangetable (inmail.db, created with it) or rotate it instate.dbinside the rebuild, and delete the "never reset" comment.proxy_change,mail.proxy_page, O(changes) gate.--secretsroot outside the coordinated backup, storage.md changes listed, escrow, CI tarball test. This matches the real two-root layout.(msg, op_id), apply tomail.dbfirst, then clear.mail.changes),changecompaction.indexer.rs:221-223..incoming/,pendingrows only, walker table, counters for quota.id_mapinstate.db; header-parse fallback with a stated rate.msg idwith several content versions. Rule 2 says the same fingerprint in the same folder = a newmsg idwithdup_of. The common case (a list copy and a direct Cc copy both in Inbox) matches both rules and gets different answers. Fix: rule 2 decides placement vs duplicate. Rule 6 applies only within one placement chain (cross-folder), and adup_ofrow has its own single content version. Say so in one sentence and add the in-Inbox case toidentity_moves.imap-uidis unused and has no configured root. §13a adds--secretsand doesn't mention the authority root at all. Fix: name the authority's location (rec: the same host-owned--secretsroot, outside backups, so one root holds all non-restorable host state). Put it in §13a's storage.md change list, in P0's ADR, and in P10's scope. Also say the authority hands out mod-sequences in reservations like UIDs (4096), or every flag change becomes a host-file fsync.identitytable.img_ref, per-user scope.Not fully fixed: 4 (P1-6, P2-6, P2-7, P2-11).
2. New findings
P1
N-1. §10 Partial
RCPT TOacceptance re-sends to the recipients who already got it.452 4.2.2 mailbox full(or a450). DATA goes through, the final reply is 250, and A and B have the mail.outgoing(e.g.rcpt_state BLOB, one code per recipient) before DATA. Automatic retries and Send again go only to recipients without a 2xx. Recipients with a 5xx produce one sentence ("Couldn't deliver to c@…: their mailbox is full"), and the rest counts as sent. Also, if every RCPT fails, don't send DATA.send_state_machine: each recipient gets exactly one copy across all retries.P2
N-2. §8 Lists show silent gaps below the spine's low-water mark.
sort_ms, which can be much older than the thread'slast_ms. Example: Sent rows for threads that got replies later, or Archive rows filed long ago in threads with fresh activity.B(the oldestlast_msthe device holds), the device has some rows for Sent or Archive but not all of them. Rows from threads outside the cap fall between them.B. It shows a list that looks complete but skips messages, with no prompt to ask the server. The person concludes the mail is gone. "The list ends at what we have and says so" doesn't trigger, because the list doesn't end; it has holes.Bper account. In every list, the device copy is authoritative only for rows withsort_ms ≥ B, and below that it switches to server pages (prefetched as for beyond-cap). Gate 2 andspam_scroll_contentgain a case "folder whose old rows interleave with threads outside the cap" and a "mid-fill" case.N-3. §10 A replay after 7 days re-runs an old action.
storeidempotency_retention). The serveroprow is the only other guard, and §10 never says how long applied ops are kept (the natural design deletes or clears them).state.db(the counter is already in the op id). An op whose counter ≤ the stored high-water for its Installation is answered as a replay, forever. The outbox sends in counter order. Add the case "retry after receipt pruning" toop_ids.N-4. §3 Rule 2 races inside one delta: "move out and back" becomes a duplicate.
add uid 900andexpunge uid 5for the same fingerprint.msg idwithdup_of. The expunge then removes the last placement of the original id, which goes to the tombstone and Recently deleted./mail/m/<old>link now says "in Recently deleted" while the mail sits in Inbox under a new id.dup_of, check whether the matching placement still exists at the provider (oneUID SEARCH UID <n>or the batch's expunge set). Add the fixture "move out and back within one delta window".N-5. §3 / §5 Removing and re-adding an account changes every
msg id.msg id = blake3-128(account ‖ provider key), andaccount.idis a fresh BLOB on add. §5 says "Re-adding the same address finds the files bymsg idand reuses them", and §15 drops indexes on removal..emlfiles are re-downloaded next to themselves.provider + normalised address, kept inid_map/ tombstones), not the row id. On removal, keepid_maprows for the 30-day window like other tombstones, so a re-add inside it re-attaches. Add the fixture "remove, re-add same address: links still open, no second file".N-6. §13 Proxy submission: when Mail.app gets its reply, and what happens on a retry.
outgoingis durable (then upstream failures must come back as a bounce or DSN, otherwise they are lost) or after the upstream reply (then a slow upstream exceeds Mail.app's timeout, Mail.app retries the submission, and the mail is sent twice).outgoing" is written for the SentAPPEND, not for submission.outgoingis durable. Dedupe submissions on(account, Message-ID, rcpt set)againstoutgoing(a repeat returns 250 and does nothing). An upstream refusal produces a local DSN into the account's Inbox in the proxy tree, plus the app's failure line. Add a test: submit twice with the same Message-ID, exactly one upstream send.N-7. §13 After a
mail.dbrebuild orstate.dbrestore, Mail.app keeps stale flags and stale UIDs.proxy_uidstores only(vid, uid, msg), not the flags last exposed. After amail.dbrebuild, flags come fresh from the provider. Any change that happened while the oldmail.dbwas broken or not yet synced never gets aproxy_changerow, soCHANGEDSINCEreports nothing and Mail.app keeps the old flags forever.state.dbcache lacks UIDs that were handed out after the backup. The authority keeps the floor, so the messages get new UIDs above it. But nothing records that the old UIDs vanished, so QRESYNC'sVANISHED (EARLIER)and CONDSTORE clients keep ghost copies.mail.dbrebuild, give every exposed message one new mod-sequence (one O(N) pass, background lane), or store exposed flag bits inproxy_uidand diff them. (b) When theproxy_foldercache is behind the authority (next_uidlower), bump UIDVALIDITY for that folder, even though the floor is proved. That is the only state Mail.app recovers from cleanly. Add both to the P10 gate.proxy_changehas no retention. Compact it to one row per(vid, uid)likechange, and above a retention horizon answer QRESYNC with the client's known-UIDs path (RFC 7162 §3.2.5.2) instead of keeping history forever.N-8. §11 / §2
netguarddoesn't cover provider connections and autodetect.netguardis shared with backdrops and the image proxy only. Butaccountsconnects server-side to a person-chosen host and port ("any host"). Autodetect follows URLs and SRV records from the address's domain (autoconfig,.well-known/jmap). JMAP session objects hand backapiUrl/downloadUrl/eventSourceUrlthat the server then calls.100.64.0.0/10mesh hosts or127.0.0.1on any port. The failure sentences ("couldn't verify mail.example.com's certificate", timeouts versus refusals) tell them what answered.mail-imap/mail-jmap/mail-smtp/ autodetect / JMAP-session connection goes throughnetguard's resolve-once connector with the same deny-list (any port allowed only for the configured provider host). Add an admin allow-list for self-hosted mail on a private network (pairs with Q12). Fixtures: an IMAP host resolving to100.64.x.x, and a JMAP session whosedownloadUrlpoints at127.0.0.1.N-9. §16 The 100k raw-gate family has no disk margin on the perf VMs.
(seed, index)and streams them (no source corpus on disk). The run aborts ifdfwould cross 15 GB at any window, not only at start. If free space is under ~25 GB, the gate runs at 50k and says so in the report.N-10. §18 "P1 is the one exception" isn't true: the search PR is a second backend-only landing.
list_since, in-index watermark) "lands just before" P2. It has no UI and goes to dev on its own, which breaks the 10-26 rule the same way P1 does, but it isn't listed or asked about in Q16.N-11. §10 / §19 The send state machine needs a hook
lettredoesn't have.data_sentmust be fsynced between writing the body and writing the final., and the reply must be persisted before anything else.lettre's transport and itsSmtpConnection::message()write the data and the terminating.in one call and return only the final response. Per-RCPT replies (N-1) aren't exposed either.P3
EmailSubmissionobjects (RFC 8621 lets servers purge them). Check the$sent-style evidence or bound the window (do the lookup within minutes, elseunknown).id_mapsize.msg16 +provider_key≤ 20 +fp32 +thread16 +path_hash+ row overhead, plus two secondary indexes (provider key, fp), comes to about 180–220 B per message, so ~400 MB at 2M, not ~120 MB. Restate it; it's backed up.COPY→mail.move. There is nomail.copyaction, and a cross-accountMOVE(unified folder → another account's folder) is undefined. Addmail.copyand answer cross-account MOVE/COPY withNOand a plain text.Inbox/…while the mail lives in Archive. Rename to the surviving placement's folder when the file's path folder no longer has a placement.state.dbneeds its own writer with group commit, anddata_sent/repliedneed FULL (or an explicitfsync). Call it new code in §4 instead of "follows the store crate's model", and put it in P1's gate.bodies.db, images and the search share count (rec: no, they are caches).mail.keymakes olderstate.dbbackups need re-sign-in. Escrow should keep the previous key ids, or the docs should say a rotation invalidates older backups' S wraps.Counts: new P1 1 · new P2 10 · new P3 8 (plus one related P3 under N-7). First-review findings not fully fixed: 4 (P1-6, P2-6, P2-7, P2-11).
Revision 3 pushed (head
34617a97) — the last patch round, with simplification. Mapping of re-review 77518. Section numbers refer todocs/plans/mail-architecture.md.Simplification
docs/plans/mail-apple-proxy.md: requirements, the findings that belong to it, and the interfaces the main plan owes it (§13). Still decided, scheduled as P10 (starts after P8; submission needs P9).First-review findings still open
mail.db'smetatable and is created with the database; a rebuilt or restoredmail.dbis a new file with a new random epoch. "Never reset / continue numbering" removed from schema and prose; §15 row and §5 say the same--secretsroot (named in §13a and the proxy stub); mod-seq reservations and the ADR for the UIDVALIDITY bump listed therelist_sincePR (now P1b) are named as the two approved backend-only exceptions (kayg Q16); P0 is docs, not a behaviour landing. Every other PR carries UI from the latest mockupNew findings
outgoing_rcpt: pending/accepted/delivered/deferred/refused/unknown); RCPT replies persisted before DATA; no DATA if nobody accepted;data_sentFULL-fsynced before the terminator; retries and Send again only for recipients who did not get it; sentence names who did and didn't; test mixed 250/452/550B; lists authoritative only aboveB, server pages below; Gate 2 gains the interleaving and mid-fill cases (§16/§17/P6)state.db, replays answered forever, outbox sends in counter order; test retry after receipt pruningakey(provider + normalised address),id_mapkept 30 days on removal; fixture remove then re-add (§5, §15)netguardcovers every outbound mail connection incl. provider hosts, autodetect, JMAP session URLs; admin allow-list for private networks (Q9); fixtures(seed, index); default 50k raw family (~4 GB), 100k only when ≥ 10 GB headroommail-smtpover rustls with a hook before the terminator and per-recipient results;lettreonly for building MIME; spiked in P1 (Q11)P3
id_map~200 B/message, ~400 MB at 2M, restatedmail.copyadded, cross-account move/copy not offered in v1; the proxy side is in its stubstate_committest in P1proxy_changeretentionAlso recorded: Q16 approved, Q20 (CONDSTORE + QRESYNC both in v1; "extremely performant") — §21. Open questions renumbered Q1–Q16, each with a recommendation.
Review round 3: mail architecture plan, revision 3 (head
34617a97)Checked
docs/plans/mail-architecture.mdanddocs/plans/mail-apple-proxy.md@34617a97against review 77518, mapping 77519,origin/devdocs/storage.md(a coordinated backup copies the wholeusers/tree, somail/mail.dbandmail/state.dbare in it) and ADR 0047 (the Installation is part of the op id; the plan doesn't say where the device stores the Installation id or its counter).Summary. The simplification worked. Moving the proxy out, keeping one send state machine and one identity rule list makes the plan much easier to check, and most round-2 items are properly closed. But this is round 3 and it still finds new P1s. Both sit in the new mechanisms: restore and the epoch, and the per-Installation counter. Under our rule, fix them by simplifying, not by adding more rules. Each finding below suggests the smallest change I could find.
1. Round-2 findings
mail.dbmetaand is created with the file, and §4, §5 and §15 agree. A file-level restore brings back the oldmetarow, so the claim "a rebuilt or restoredmail.dbis a new file with a new random epoch" (§4, §15) is false. See R-1--secretsroot is named in §13a item 1 and in the stub, along with the reservations and the ADRB= the oldest threadlast_msthe device holds. Every membership hassort_ms ≤ last_ms, so any row withsort_ms ≥ Bbelongs to a thread inside the spine. The argument holdsakey. Edge cases in R-4(account, Message-ID, recipient set)". §10 and the schema have no such key. See R-6(seed, index), and the run defaults to 50k. The arithmetic fits perf-02 (8 GB above the floor, 5.6 GB usable, 4 GB needed)mail-smtpis in-house, with Q11 and the P1 spike. New edges in R-3 and R-5Not fully fixed: 2 (P1-6, N-6).
2. New findings
P1
R-1. Restoring a backup brings back an old epoch (changes silently skipped) and old queued intent (mail sent twice, later moves undone).
docs/storage.mdcopiessystem/and all ofusers/together, so a standard backup holdsmail.db(with itsmeta.epoch) andstate.db.mail.dbis at(E, seq 800). Phones already hold(E, 1000). The server keeps working and writes seq 801…1000 for different changes. A phone asks for changes since 1000, gets nothing, and has silently missed 200 changes. Search's in-index watermark does the same thing. This is the original P1-6 bug, coming back through restore.state.dbat T hasoutgoingrows inheld/pending/acceptedandoprows that were applied after T. At start the timer heap releases the held mail, so the mail goes out a second time. The Actor replays the ops, so the provider moves threads back to where they were at T, undoing everything the person did after T.mail.dbandbodies.dbout of the backup set. They are caches, so say so in the §13astorage.mdchange list. A restore then always rebuilds, and a rebuild already gets a new epoch.--secretsroot (written with eachstate.dbcheckpoint, or simply the start time). Ifstate.db's copy doesn't match it at open, the file was restored. In that case: rotate to a new epoch, put every non-finaloutgoingrow intounknown(shown as "check Sent before sending again"), and put pendingoprows on hold until a person confirms them, never replaying them automatically.state.db+mail.dbwhile a device holds a newer cursor and one send was held at backup time. The device re-reads, and nothing is sent or moved.R-2. The per-Installation high-water drops real actions whenever counter order ≠ send order.
counter_conflict: the device renumbers above the high-water and resends.op_ids.P2
R-3. The SMTP final-reply timeout isn't specified, so the generic 10 s read timeout would turn large sends into
unknown.., and 5 minutes for MAIL/RCPT. Submission servers that scan a 20 MB attachment, or that are slow, routinely take more than 10 s.unknownat once, with "Check Sent before sending again". The person presses Send again and the recipients get it twice. The server finished delivering after we stopped waiting.mail-smtpuses the RFC 5321 timeouts, the final-reply timeout scales with message size (at least 10 min), and the reply stays readable while the connection is open. Only a dropped connection or a crash leads tounknown. Add "slow final reply (90 s)" as a fake-server case insend_state_machine, expectingdeliveredand nounknown.R-4.
akey = provider + address: address edits and host changes can attach a different mail to an old id.mail.account_updateexists and the plan doesn't say whetherakeychanges with it. If it changes, every lookup(akey, provider key)misses, every message gets a new id, every ML7 link breaks, and the mirror is downloaded again. If it doesn't change, a later re-add under the new address doesn't match. Say:akeyis fixed when the account is created, an update never rewrites it, and a re-add matches on it.akeydoesn't identify the server instance. Suppose the person movesme@kayg.orgfrom one server to another under the same account, or removes it and re-adds it within 30 days on a new host. The new server's provider keys come from its own namespace. Stalwart's JMAP/IMAP ids, for example, are short counters, and JMAP ids are only unique per JMAPaccountId. Rule 2 finds a tombstonedid_maprow with an equal provider key and re-attaches an unrelated message to the oldmsg id. Old links in notes then open the wrong mail, and it joins the old thread.fpalso matches. If it doesn't, fall through to rule 3. Also include the JMAPaccountIdin the provider key. Fixture: re-add on a different host whose ids collide with the old ones; no old link opens the new mail.R-5. The send state machine has states with no exit, so a crash in the RCPT phase leaves a mail stuck and unsent.
acceptedis only left throughdelivered/deferred/refused(after the final reply) orunknown("between step 3 and a persisted reply"). A crash or dropped connection after RCPT replies are stored but beforedata_sentleaves recipientsacceptedforever. Automatic retries pick up onlydeferred, and Send again onlydeferred/refused/unknown. Nothing sends it, and no sentence appears.send_state_machinecan't assert one.MAIL FROMrefused (e.g. 553 send-as not allowed, 552 SIZE): every recipient waits forever.DATAanswered 4xx/5xx before354.AUTHfailure in the middle of a send.acceptedwith nodata_sent→pending(nothing was delivered: step 3's own argument).DATAbefore 354, 4xx → alldeferred; 5xx → allrefused, with the server's text.needs_sign_in, and the recipients staypending.R-6. The proxy's dedupe interface isn't in the main plan.
(account, Message-ID, recipient set)". §10 has no such rule, andoutgoinghasmessage_idbut no unique key. The app path is covered by the executor's idempotency key. The proxy path has nothing, so the proxy plan would build against an interface that doesn't exist. That's the N-6 double send.rcpt_hash(sorted, normalised envelope recipients) andUNIQUE(account, message_id, rcpt_hash)tooutgoing, and one sentence in §10: a repeat with the same key returns the existing row.refused/deferredresult does. A deliberate resend from Mail.app must not be swallowed silently..emlstream. The interface table points at §10 for it, but §10's read list has onlymail.page.R-7. An optimistic change, or its rollback, never reaches other devices' caches.
state.db, while the change feed (change,(epoch, seq)) lives inmail.db. Reads returneffective = provider + overlay, so device B can cache a thread as archived frommail.page/mail.changeswhile A's archive is pending.mail.dbnever changed, so nochangerow is written. Device B keeps showing the thread archived until something else touches it, and its cursor says it's up to date.change. It's a cross-database write, so do it after thestate.dbcommit and redo it on start for ops newer than the last emitted one, like the hints in step 1. Test: two devices, provider refuses the move, and both end showing Inbox.R-8. The in-house SMTP client doesn't say how it keeps replies matched to commands (TLS upgrade, pipelining).
RCPT. If they get out of step, a refused recipient is recorded asaccepted("a@ got it" when they didn't), or an accepted one asdeferred, which leads to a second copy on retry.250-replies.P3
id_mapand duplicates. Rule 3 says a fingerprint-only mint goes under a unique(akey, fingerprint)key, butdup_ofrows share that fingerprint, so the unique key either rejects them or they aren't inid_map. In the second case, a rebuild can't tell which of two same-folder copies was the original, and links to the duplicate can swap or break.(akey, fp, n), withnthe order of arrival, and let the rebuild assign by UID order.repliedtriggers anAPPEND. A send that needed one retry for a deferred recipient leaves two copies in Sent.deliveredrecipient, keyed byoutgoing.id.3. Rule check (3 rounds)
This round still found new P1/P2s: 2 P1 and 6 P2. Under the rule, the author should simplify, not patch where possible:
mail-smtp(no pipelining, implicit TLS preferred, RFC timeouts, a transition table).R-3, R-4, R-6 and R-7 are one sentence or one key each. I'd expect a revision 4 that does only this to be checked in one pass.
Counts: new P1 2 · new P2 6 · new P3 3. Round-2 findings not fully fixed: 2 (P1-6, N-6).
kayg referenced this pull request2026-11-04 09:02:23 +00:00
kayg referenced this pull request2026-11-04 09:02:23 +00:00
Superseded by #920 (v4, simplified), following the 3-round rule: mail's own op queue, counters, cursors and epochs are gone, and the shared gaps are filed as #918 and #919. The R-1…R-8 mapping is in §20 of the new plan. Leaving this PR open for kayg to close.
Superseded by #920 (merged).
Pull request closed