Skip to content

bug(db): non-atomic upsert/insert, orphan purge race, SQLite retention cutoff format mismatch #332

Closed

Description

@ajianaz

Problems

  1. digest.rs:82-134 processes events one by one; upsert_issue then insert_event are separate statements. If insert fails, issue counts are bumped with no event row; failures are only logged and dropped.
  2. purge_orphan_issues (sqlite.rs:836, postgres.rs:834) DELETE FROM issues WHERE id NOT IN (SELECT issue_id FROM events) can delete an issue just upserted before its event is inserted, and removes resolved/ignored issues whose events aged out (history lost).
  3. SQLite retention (sqlite.rs:829, 844) compares RFC3339 received_at (T separator) against datetime('now', '-N days') (space separator): text compare is off by up to a day; Postgres behaves differently.

Fix

  • Wrap each batch in one transaction.
  • Purge orphans only with AND last_seen < cutoff, inside a transaction; keep resolved/ignored.
  • Bind a Rust-computed RFC3339 cutoff on both backends (also purge_stale_auth_attempts).

Found in static audit of develop @ db3ca67.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:highP1 - Fix soon

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions