fix: harden runtime delivery and data consistency #31

Merged
isyuricunha merged 1 commit from fix/runtime-safety-delivery-consistency into main 2026-08-25 18:14:40 +00:00
isyuricunha commented 2026-08-25 18:04:50 +00:00 (Migrated from github.com)

Summary

This PR hardens runtime reliability and removes several data-consistency failure modes across the bot, API, and dashboard.

Anti-Raid reliability

  • persists raid lifecycle state so interrupted raids can recover safely
  • atomically claims raid activation under concurrent joins
  • keeps the configured five-minute detection window intact
  • gates hostile joins before welcome/autorole/support work
  • snapshots and restores the exact previous @everyone channel permissions
  • adds focused recovery/concurrency tests and a recovery index

Durable Discord delivery

  • adds a persistent DiscordDelivery outbox with dedupe keys, leases, retry backoff, and terminal-failure handling
  • moves Giveaway result/edit/winner DMs to durable delivery intents
  • moves AniList notifications, Support notifications/role synchronization, and FreeGames announcements onto the same delivery boundary
  • keeps domain-state persistence and delivery intent creation atomic
  • prevents stale Support role-removal work from undoing a later renewal

API and data consistency

  • changes the Members dashboard to database-first server pagination/filtering instead of fetching an entire Discord guild on page load
  • keeps member username/avatar snapshots fresh from Discord member/user events
  • reuses the canonical guild-admin authorization boundary in Members and Support routes
  • makes Support config GETs read-only when no row exists
  • serializes Support-plan writes per guild with PostgreSQL advisory transaction locks, enforcing the 25-active-plan limit and normalized-name uniqueness under concurrency
  • validates Giveaway entry min/max choices after matching and deduplication

Database

  • adds 20260825163000_antiraid_reliability
  • adds 20260825164500_discord_delivery_outbox
  • reconciles the Anti-Raid recovery index in Prisma schema
  • full migration replay from baseline: 43 migrations applied successfully
  • Prisma migration drift check: no difference detected

Validation

Final validation ran against a fresh PostgreSQL 16 instance with database integration tests enabled:

  • git diff --check ✅
  • pnpm lint ✅
  • pnpm type-check ✅
  • pnpm test ✅
  • pnpm build ✅
  • pnpm knip ✅
  • fresh migration replay ✅
  • zero schema/migration drift ✅
  • concurrent Support-plan invariant test against real PostgreSQL ✅

The branch was squashed after validation and is exactly one commit ahead of main.

## Summary This PR hardens runtime reliability and removes several data-consistency failure modes across the bot, API, and dashboard. ### Anti-Raid reliability - persists raid lifecycle state so interrupted raids can recover safely - atomically claims raid activation under concurrent joins - keeps the configured five-minute detection window intact - gates hostile joins before welcome/autorole/support work - snapshots and restores the exact previous `@everyone` channel permissions - adds focused recovery/concurrency tests and a recovery index ### Durable Discord delivery - adds a persistent `DiscordDelivery` outbox with dedupe keys, leases, retry backoff, and terminal-failure handling - moves Giveaway result/edit/winner DMs to durable delivery intents - moves AniList notifications, Support notifications/role synchronization, and FreeGames announcements onto the same delivery boundary - keeps domain-state persistence and delivery intent creation atomic - prevents stale Support role-removal work from undoing a later renewal ### API and data consistency - changes the Members dashboard to database-first server pagination/filtering instead of fetching an entire Discord guild on page load - keeps member username/avatar snapshots fresh from Discord member/user events - reuses the canonical guild-admin authorization boundary in Members and Support routes - makes Support config GETs read-only when no row exists - serializes Support-plan writes per guild with PostgreSQL advisory transaction locks, enforcing the 25-active-plan limit and normalized-name uniqueness under concurrency - validates Giveaway entry min/max choices after matching and deduplication ## Database - adds `20260825163000_antiraid_reliability` - adds `20260825164500_discord_delivery_outbox` - reconciles the Anti-Raid recovery index in Prisma schema - full migration replay from baseline: **43 migrations applied successfully** - Prisma migration drift check: **no difference detected** ## Validation Final validation ran against a fresh PostgreSQL 16 instance with database integration tests enabled: - `git diff --check` ✅ - `pnpm lint` ✅ - `pnpm type-check` ✅ - `pnpm test` ✅ - `pnpm build` ✅ - `pnpm knip` ✅ - fresh migration replay ✅ - zero schema/migration drift ✅ - concurrent Support-plan invariant test against real PostgreSQL ✅ The branch was squashed after validation and is exactly one commit ahead of `main`.
Sign in to join this conversation.
No description provided.