Skip to content
open.blog documentation
open.blog

ADR 0108: Retention runs from a dry run the site Admin confirms, quotas keep only hourly digests, and protection's schema is additive and opt in

Context#

ADR 0104 defines when text expires or is purged and leaves the job, tables and the function's adoption to #226. Purging is irreversible, so it must never surprise an owner and never reach comments a site did not opt in. #226 also requires that no raw IP address, user agent or cross-day identifier be stored: the existing hourly quota stores a salted digest of the client address that is the same every hour and day, kept for 48 hours. Hosted storage is a one-way door.

Decision#

  • Retention never runs on its own. The site Admin (an account bound in no shared publication, since a run spans every work) opens Moderation inbox → Retention:
    • Check what retention would do is a dry run (GET engagement/retention). Admin computes the run's cutoffs from participation.retention (ModerationPolicy::cutoffs): the times at or before which an item's state must have begun to owe a step, and before which an audit event may be deleted, plus whether comments are covered. The function lists candidate rows and decides each with retentionStep; Admin decides each again with ModerationPolicy::retention_due and keeps only those both agree on. It shows counts by step and kind, each item's facts (never text or names) and how many audit events are old enough. Nothing changes.
    • Run retention now needs a confirmation and sends the dry run's time (at most an hour old). Admin recomputes the plan for that time and sends the function at most 200 items with the version each was seen at; the function re-reads each, applies its step only while it is still at that version and still due, with the System actor (@retention, role system): expire through the moderation functions, purge through the deletion functions of ADR 0107. An unchecked box keeps old audit events; otherwise those at or before the audit cutoff are deleted. It reports what was expired, purged and skipped, and whether more is due.
    • The function refuses cutoffs that are not canonical UTC times at least a day before its own clock, and an audit cutoff later than the closed-item cutoff (ADR 0104's auditDays is at least closedDays), whatever it is sent, and touches comments only when told the site opted them in.
    • No scheduled job is added: #226 asks for retention jobs or manual cleanup, and an explicit, confirmed run is the conservative choice for an irreversible step. A schedule can call the same two routes later.
    • The shared fixture tests/fixtures/participation-protection.json, generated by the Rust policy, holds every retention step, deletion request and upholding; the function agrees with each case.
  • Quotas keep only hourly digests. The existing helper now digests the salt, bucket, hour and subject, so a stored row links nothing across hours, and the address and user agent never reach the database. Analytics keeps its daily visitor digest (salt, day, address, user agent), which changes every day and counts uniques within it. Receipts, reports, reports per item and replays reuse the same helper and table: a replay bound digests the client, the bucket and the submission for the hour and allows it once (comments and notes answer 409 duplicate; reports answer as if taken). A submission that fails to be stored releases its bound, so a retry is taken. Replay bounds apply with protection switched on, so a site that changes nothing keeps today's behaviour.
  • The schema is additive, opt in, and rolls back exactly. supabase/protection.sql (after openblog.sql and moderation.sql), and supabase/feedback.sql run again, then OPENBLOG_PROTECTION_ENABLED=true with OPENBLOG_MODERATION_ENABLED=true:
    • openblog_comments: purged_at timestamptz (nullable) and the check openblog_comments_purged_never_public (purged_at is null or status <> 'approved').
    • openblog_feedback: receipt_hash text (a 64-hex-digit digest, nullable) with the partial unique index openblog_feedback_receipt, purged_at timestamptz and the check openblog_feedback_purged_never_public.
    • openblog_comment_events and openblog_feedback_events: related uuid (nullable), the abuse report an upheld-report removal came from, so the item's event and the report's name each other; null on every other event.
    • New private tables openblog_abuse_reports (no reporter identity) and the insert-and-retention openblog_abuse_report_events, row level security on, public roles revoked.
    • Functions openblog_moderate_report, openblog_uphold_report, openblog_purge_comment, openblog_purge_report and openblog_erase_feedback, none security definer, executable only by the service role.
    • The service role may delete from openblog_comment_events, openblog_feedback_events and openblog_abuse_report_events, which only the retention run does. A BEFORE DELETE row trigger on each (openblog_keep_recent_audit_events, with its caller's rights like every function here) refuses to delete any event recorded in the last day, so no request, mistaken or forged, can erase today's record.
    • supabase/protection-rollback.sql drops exactly these, the triggers and their function, and revokes the delete grants, leaving every comment and note in its state; purged text stays gone, and a purged item stays closed. Unsetting the variable first returns the function to the inbox's schema.
  • Without it nothing changes. Without the variable /receipt, /reports and /admin/retention answer 404 unavailable, no receipt is issued, the inbox's protocol is full (or legacy) and offers no report, upholding or deletion; the static site works without any hosted service, and service credentials stay in Netlify, never in Admin's browser or a page.

Considered options#

  • A scheduled purge. Rejected for now: an irreversible step that runs unseen.
  • Purge from Admin alone, by id. Rejected: the function could not check the item is still due.
  • Keep the address digest stable for the quota window. Rejected: rows would link a reader's requests across hours for two days, the cross-day identifier #226 forbids.
  • Widen existing columns or make body nullable. Rejected: not additive; purging overwrites instead, and a check keeps purged rows private.

Consequences#

  • Owners see exactly what will be deleted before anything is, and comments stay theirs to keep until they opt in.
  • Retention, reader deletions and Admin deletions share one deletion function per store, each leaving an audit event without text.

View this page's source