oliver-zehentleitner / maity
clean-up: Mail and notifications: one key derivation, one address normalizer, one chat read mark, duplicated validators and loops
tsk-8vdegd61y70v Done An agent
From the clean-up audit tsk-hgnbapyw7hnh, area 12 (Mail and notifications). Read at 80647565; all line numbers are from that commit. Finding numbers are the audit's (seqs 125423 and 125453). (Code names are written without backticks: the inline body cannot carry them.)
Order: item 17 touches mail/settings.py, which tsk-q4zynccy5t0b (in progress, new mail budgets) also changes. Do 17 after it. The other items have no order.
4. duplication / design: "HKDF of MAITY_SECRET_KEY, else a random 32-byte key stored at first use" is written three times, the generic part inside mail/address.py
- Files:
- mail/address.py:61-93 (LOCK_PEPPER, prepare, _hmac_key);
- notifications/positions.py:40 and 59-82 (KEY_NAME, prepare, _key, a near-verbatim copy of address.prepare);
- auth/known_sources.py:49-58 (_key, which reads addresses.LOCK_PEPPER from the mail module).
- What's wrong: the derivation is copied, and the two prepares differ in one way. address.prepare wipes its pepper once an instance key is set (address.py:70-74); positions.prepare keeps its key.
- Proposal: secretbox.purpose_key(conn, secret_key, purpose, fallback_name) plus secretbox.prepare_fallback(engine, secret_key, name), used by the three callers.
- Open question: is a fallback key wiped when an instance key arrives? Decide once, for both.
- Effort: S. Risk: low. The info strings must stay byte-identical, or positions, lock rows and known sources become invalid.
6. duplication: registration.normalized is mail.address.normalized, with callers split between the two
- Files: registration.py:54-57 (its docstring: "The same as mail.address.normalized") and mail/address.py:52-55.
- Callers of the copy: invitation_mail.py:47, registration_accounts.py:96, routes/invitations.py:176, routes/registration.py:193 and 332.
- Callers of the original: preferences.py:696, account_deletion.py:668, cli.py:324, routes/auth.py:184, routes/email_sign_in.py:152, routes/password_reset.py:136.
- Proposal: delete registration.normalized and point its callers at mail.address.normalized.
- Effort: S. Risk: low.
7. duplication: two implementations move a conversation's read mark forward
- Files: routes/events.py:759-793 (remember_read: UPDATE, then SELECT, then a savepoint INSERT) and notifications/listing.py:430-451 (_move_chat_mark: an ignoring_duplicates INSERT, then UPDATE). Each rings the bell its own way (events.py:761-766, listing.py:398; wakeups.ring is PostgreSQL-only either way).
- Proposal: one conversation_read "move forward, never back" function (e.g. in conversation_list.py) that both call.
- (Moving listing.ignoring_duplicates, listing.py:402-409, to db.py for the hub's other upsert sites is cross-area and left to the shared card.)
- Effort: S. Risk: low to medium. Chat read marks are hot; keep never-backwards and test both engines.
8. debt: duplicated kind lists, a dead constant, trivial wrappers in notifications/
- items.KINDS (items.py:24) and preferences.KINDS (preferences.py:37) are the same tuple, and both are used: routes/notifications.py:26 takes the first, routes/mail_links.py:27 the second. preferences.DEFAULTS["browser"]["kinds"] (preferences.py:59-65) restates it a third time. One KINDS; derive the browser defaults from it.
- records.PERSONAL (records.py:39-43) has no reader in hub/, web/ or cli/. Delete it.
- items.names, items.addressed and items._may_concern (items.py:299-338) only forward to _names, _addressed and may_concern_member. listing._slugs (listing.py:90-92) only forwards to namespace.full_names. Make the targets public and drop the forwarders.
- Effort: S. Risk: none.
17. duplication: mail settings are validated twice, for the environment and for the admin's PATCH
- "tls: none needs a loopback host" is checked three times: mail/environment.py:115, settings.py:258 (patch) and settings.py:292 (tls_refusal).
- The ASCII printable username and password check: environment.py:121-122 and 194, and again as settings._ascii (settings.py:297-299).
- The sender check: environment.parse_sender (environment.py:93-103), and again as settings._sender (settings.py:302-310).
- Proposal: one set of validators in environment.py (ascii_secret, sender_ok, tls_host_refusal), used by parse, patch and tls_refusal.
- Effort: S. Risk: low.
18. duplication: the keyset "read in growing chunks until the page is full" loop is written twice in items.py
- Files: notifications/items.py:381-424 (_paged, over event by (at, seq)) and 450-483 (_records_paged, over account_record by (at, n)). They share the before/tie predicate, the min(size * 4, CHUNK) growth, and the sort and cut.
- Proposal: one generic _chunked(...) that both call. Keep the first-chunk sizes.
- Effort: S. Risk: low (the load and listing tests cover it).
Left out as duplicates: none. Searched: HKDF, registration.normalized, remember_read, tls_refusal, mail/settings.py, items.py.
Notes
Lotse · Nov 18, 2026, 16:44 UTC
Closed by lotse: #1787 squash-merged at abf21bc7 (2026-11-18; tqgb A1319 + vhqe A1320 APPROVE on 863efe78, ci-ok incl. hub-postgresql). The holder e7y8 could not report (git refused in its session after the restart). vhqe's P3-1 (remember_read race outcome unnamed/untested) goes to the hub roll-up card.