oliver-zehentleitner / maity

clean-up: Mail and notifications: prune account records and mail bookkeeping, drop the legacy outbox update

Sign in to report

tsk-3ar6h2s0kff5 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 (seq 125423). (Code names are written without backticks: the inline body cannot carry them.)

Order: do this after tsk-dv8f620hjebf (in progress), which changes mail/outbox.py (send_due, the stuck rows). Item 2 touches the same file.

1. debt / docs drift: account records and the mail bookkeeping tables are never pruned, though the contract says records are "kept 90 days"

  • Files: notifications/records.py:7 and 19 (KEPT = 90 days, docstring "Kept 90 days"); docs/api.md:2018 and 22598 ("kept 90 days"). Nothing deletes account_record except account deletion (account_deletion.py:618). items.py:704, records.py:116 and 135 only filter by at >= now - KEPT.
  • The same goes for:
  • mail_item_sent: written at mailer.py:392, never pruned, and read in full per human on every pass at mailer.py:178-181.
  • notification_position: positions.py:113-145. last_used_at is written on every read and read by nothing, and no sweep exists, although context/notifications.md b735056d says "kept at least 30 days after last use".
  • mail_delivery: outbox.py:77. The counters only read the last hour (settings.py:190-219, mailer.py:331-347).
  • What's wrong: session_created records hold the IP, browser and OS of every sign-in, and they stay for good, against the 90-day promise. The other tables only grow, and the mailer's sent set grows with them.
  • Proposal: add an hourly sweep to an existing worker (outbox.Worker already runs forget_old). It deletes:
  • account_record past 90 days;
  • mail_item_sent older than the 30-day item window plus a margin;
  • mail_delivery older than a day;
  • notification_position unused for 30 days.

Bound the mailer's sent read to the window.

  • Open question: what happens to an open inbox record (registration_pending, mail_disabled, agents_not_listening) older than 90 days? Keep it until its matter closes, or reissue it? not_listening_digest.py:295-297 already reasons about records leaving the window, so check it before deleting.
  • Effort: S. Risk: low to medium (data deletion; the open-record question above).

2. debt: outbox.forget_old keeps a one-off legacy UPDATE that can no longer match, run every 5 seconds

  • Files: mail/outbox.py:330-348 (the first UPDATE, or_(body != "", cast(headers, String) != "{}")). It is called from outbox.Worker._run every INTERVAL = 5 s (outbox.py:29 and 351). hub/context/mail.md c77fd991: "A row that left before this change loses its text on the next sweep."
  • What's wrong: every terminal state goes through _finish (outbox.py:228-236), which already blanks body and headers. The UPDATE was only for rows that left before that change (#544, late October), and those are past the 7-day KEPT and deleted. So it is a compatibility path in an alpha, and it casts JSON to text over the table every 5 s.
  • Proposal: remove the first UPDATE and keep the DELETE. Mark the sentence in mail.md c77fd991 as done.
  • Effort: S. Risk: low. Only a row that left the queue without _finish would keep its text, and no such path exists (_settle, send_due). Re-check that after tsk-dv8f620hjebf, which adds a failed path for poison rows.

Left out as duplicates: none. Existing cards searched: retention, prune, forget_old, mail/outbox.py, account_record.