Skip to content

Alert Rules: integrate built-in spike/quota into AlertRule (#535) - #544

Merged
unjica merged 5 commits into
developfrom
feat/alert-rules-builtin-integration-535
Jul 18, 2026
Merged

unjica merged 5 commits into
developfrom
feat/alert-rules-builtin-integration-535

Conversation

@unjica

@unjica unjica commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Represent built-in error-spike and quota alerts as system-managed AlertRule rows (source=SYSTEM, stable migration_key, BUILTIN_* conditions)
  • Dual-write via PATCH /api/project/alert-settings; idempotent backfill job builtin-alert-rules-backfill
  • Preserve legacy fireProjectAlert categories + dedupe keys; CUSTOM CRUD/evaluators skip SYSTEM so no duplicate notifications
  • Docs cover migration, mixed deploy, and rollback

Closes #535. Parent vision #493 stays open.

Test plan

  • Apply migration 20260718140000_alert_rule_system_builtin
  • pnpm --filter api builtin-alert-rules-backfill -- --dry-run then without dry-run; re-run is a no-op
  • Alerts → Error spike / Ingest quota: change thresholds and confirm they persist; Custom rules list does not show SYSTEM rows
  • Disable error spike / quota warning and confirm ingest does not fire those; quota exceeded still fires at limit
  • Confirm AlertEvent dedupe keys remain alert:error_spike:… / quota:near|exceeded:…
  • PATCH/DELETE a SYSTEM rule id via alert-rules API → 403
  • pnpm --filter api test (alert-rules + builtin-alert-rules + quota-alert)

Made with Cursor

unjica and others added 2 commits July 18, 2026 11:02
Represent error-spike and quota alerts as idempotent system-managed AlertRule rows so Alert Rules is the canonical model while preserving legacy fireProjectAlert categories and dedupe keys.

Co-authored-by: Cursor <[email protected]>
Use BUILTIN_* condition types so older evaluators skip system rows, avoid ensure-on-read clobber, and tolerate concurrent create unique violations.

Co-authored-by: Cursor <[email protected]>
@unjica unjica added this to the v1.15.x — Alert Rules milestone Jul 18, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 367cc84. Configure here.

Comment thread apps/api/src/lib/builtin-alert-rules.ts Resolved
Match ingest and scheduled-evaluator tenant gates, and improve dry-run
preview to report would-create / would-update / unchanged.

Co-authored-by: Cursor <[email protected]>
@unjica

unjica commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the backfill tenant-gate review feedback:

  • Org gate: backfillBuiltinAlertRules now requires both project.deleted_at: null and organization.deleted_at: null, matching ingest + scheduled-evaluator.
  • Regression tests: assert the Prisma where clause includes the org filter, and that archived-org projects are outside the scan set.
  • Dry-run (nice-to-have): preview now distinguishes would-create / would-update / unchanged (including soft-deleted revive as would-update), instead of only counting missing keys.

No merge from this comment.

Unparseable ERROR_SPIKE / QUOTA_WARNING conditions must force enabled=false
so stale Project.alert_settings cannot keep built-in alerts firing.

Co-authored-by: Cursor <[email protected]>
@unjica
unjica merged commit b2955a5 into develop Jul 18, 2026
6 of 8 checks passed
@unjica
unjica deleted the feat/alert-rules-builtin-integration-535 branch July 18, 2026 09:17
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.

Alert Rules: integrate built-in spike/quota into AlertRule

1 participant