Skip to content

feat(alertd): cap alert SQL result at 100 rows#431

Open
passcod wants to merge 1 commit into
mainfrom
alertd-row-limit
Open

feat(alertd): cap alert SQL result at 100 rows#431
passcod wants to merge 1 commit into
mainfrom
alertd-row-limit

Conversation

@passcod
Copy link
Copy Markdown
Member

@passcod passcod commented May 29, 2026

🤖 Some alerts run SQL that returns a large number of rows; loading all of them into memory is wasteful when an alert only needs to know it fired and to template a sample.

This caps an SQL alert source at 100 rows, bounded at the database portal so excess rows are never pulled into memory:

  • The SQL source now opens a read transaction, binds the prepared statement to a portal, and fetches via query_portal with a ROW_LIMIT of 100, rather than buffering the entire result with query.
  • When a result hits the cap, a warning is logged (with the alert file and the limit) so operators know truncation happened.
  • Numerical thresholds and the rows template context therefore operate on at most 100 rows.

Adds a test asserting a 1000-row generate_series source is capped at 100.

Bound SQL ticket sources to at most 100 rows using a portal so excess
rows are never fetched into memory, and warn when the cap is hit.

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant