Skip to content

fix(db): atomic record_event, safe orphan purge, RFC3339 retention cutoff - #352

Merged
ajianaz merged 2 commits into
developfrom
fix/332-db-atomicity
Oct 13, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/332-db-atomicity

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Closes #332

What

  • New Database::record_event (SQLite + Postgres): issue upsert and event insert run in one transaction; the digest pipeline uses it, so a failed event insert no longer leaves a bumped issue count.
  • purge_orphan_issues(days) now deletes only orphans that are not resolved/ignored and have last_seen older than the retention cutoff, in a single atomic statement (NOT EXISTS).
  • Retention cutoffs for events and auth attempts are Rust-computed RFC3339 values bound as parameters on both backends (replaces SQLite datetime('now', ...)).

Why

RFC3339 received_at (T separator) was compared against datetime('now') (space separator), skewing retention by up to a day. The orphan purge could delete a just-upserted issue before its event landed and discarded resolved/ignored history. Upsert + insert were separate statements.

Deferred / notes: the transaction is per event rather than per batch, so one bad event does not discard the rest of a batch. Postgres changes compile and mirror SQLite but are not exercised by a live Postgres test here.

Testing

New SQLite tests (failing before the fix, passing after): test_record_event_is_atomic, test_purge_old_events_cutoff_format, test_purge_stale_auth_attempts_cutoff_format, test_purge_orphan_issues_safety.
cargo fmt --check OK, cargo clippy --workspace --all-targets -- -D warnings clean, cargo test --workspace all passing.

🤖 Generated with Claude Code

ajianaz and others added 2 commits October 13, 2026 08:36
…toff (#332)

- record_event upserts issue + inserts event in one transaction (both backends); digest uses it
- purge_orphan_issues(days) only removes unresolved orphans with last_seen < cutoff
- bind Rust-computed RFC3339 cutoff for events/auth_attempts purge on both backends

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ajianaz
ajianaz merged commit a1de428 into develop Oct 13, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant