Skip to content

feat(web): prune expired webhook events in bounded batches - #6603

Merged
pandemicsyn merged 2 commits into
mainfrom
ci/prune-webhook-events
Sep 23, 2026
Merged

pandemicsyn merged 2 commits into
mainfrom
ci/prune-webhook-events

Conversation

@pandemicsyn

@pandemicsyn pandemicsyn commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a CRON_SECRET-protected cleanup endpoint scheduled every five minutes.
  • Retain webhook events for 60 days, then delete at most 500 oldest expired rows per run. Return and emit deleted count and whether more rows remain.
  • Use the existing IDX_webhook_events_created_at index for the bounded age-ordered ID lookup; no schema migration is needed.

Operational notes

  • This is a separate PR from the mobile-only deploy filtering change.
  • Expiring rows also removes their delivery signatures and Bitbucket processed observations. Deliveries older than 60 days no longer benefit from this table for deduplication or historical ordering.
  • The observed table size was about 405 GB, mostly TOAST. Deletes generate WAL and make space reusable after vacuum; they do not immediately shrink on-disk relation size. Monitor cron duration, WAL, replication lag, and vacuum during catch-up.

Verification

  • pnpm --filter web test --runInBand src/app/api/cron/cleanup-webhook-events/route.test.ts (5 passing)
  • pnpm --filter web typecheck
  • pnpm exec oxlint --config .oxlintrc.json apps/web/src/app/api/cron/cleanup-webhook-events/route.ts apps/web/src/app/api/cron/cleanup-webhook-events/route.test.ts
  • pnpm exec oxfmt apps/web/src/app/api/cron/cleanup-webhook-events/route.ts apps/web/src/app/api/cron/cleanup-webhook-events/route.test.ts
  • git diff --check

@pandemicsyn
pandemicsyn marked this pull request as ready for review September 22, 2026 23:41
@kilo-code-bot

kilo-code-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • apps/web/src/app/api/cron/cleanup-webhook-events/route.ts
  • apps/web/src/app/api/cron/cleanup-webhook-events/route.test.ts
  • apps/web/vercel.json

Verified against current HEAD 90daf266: the bounded select (limit BATCH_SIZE + 1) / inArray delete on the primary db matches the established cleanup-api-request-log pattern, the age-ordered lookup can use the existing IDX_webhook_events_created_at index from the baseline migration, no foreign keys reference webhook_events (so the delete cannot fail on dependent rows), auth fails closed when CRON_SECRET is unset, and hasMore cannot under-report (limit(501) with a 500-row slice).


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

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.

2 participants