id: supabase-stale-pending-record-quarantine-sentinel
namespace: company.team
description: |
Audit Supabase tables for stale pending records, unconsumed webhook deliveries, or abandoned
transactions lingering beyond an operational TTL. Evaluates backlog volume against SLA thresholds,
dispatches structured Slack notifications, and safely transitions stale rows to a quarantined status.
inputs:
- id: supabase_url
type: STRING
displayName: Supabase Project REST URL
description: Base URL of the Supabase PostgREST API gateway, for example
http://localhost:8000 for local development or
https://<project-ref>.supabase.co for Supabase Cloud.
defaults: "http://localhost:8000"
- id: table_name
type: STRING
displayName: Target Table Name
description: Name of the Supabase table to audit for stale pending records or
unhandled webhook events.
defaults: "webhook_events"
- id: stale_threshold_hours
type: INT
displayName: Stale Threshold (Hours)
description: Age threshold in hours beyond which records remaining in pending
status are classified as stale.
defaults: 24
- id: critical_count_threshold
type: INT
displayName: Critical Accumulation Threshold
description: Stale record count at or above which the sentinel escalates the
classification from warning to critical backlog accumulation.
defaults: 50
- id: batch_size
type: INT
displayName: Evaluation Batch Limit
description: Maximum number of candidate records to inspect in a single sentinel
evaluation cycle.
defaults: 100
- id: auto_quarantine
type: BOOL
displayName: Automatic Quarantine Remediation
description: When true and dry_run is false, patches stale pending records to
status quarantined to unblock consumer queues.
defaults: false
- id: dry_run
type: BOOL
displayName: Dry Run Mode
description: When true, evaluates and logs stale records without applying
database update mutations.
defaults: true
- id: alert_mode
type: SELECT
displayName: Sentinel Alert Mode
description: Operating mode of the sentinel. ALERT dispatches a notification to
Slack when thresholds breach; AUDIT_ONLY logs findings without paging
on-call.
values:
- "ALERT"
- "AUDIT_ONLY"
defaults: "ALERT"
triggers:
- id: periodic_stale_audit_schedule
type: io.kestra.plugin.core.trigger.Schedule
description: Runs every 6 hours to audit Supabase tables for accumulating stale
pending records. Shipped disabled by default for safe initial setup.
cron: "0 */6 * * *"
disabled: true
inputs:
supabase_url: "http://localhost:8000"
table_name: "webhook_events"
stale_threshold_hours: 24
critical_count_threshold: 50
batch_size: 100
auto_quarantine: false
dry_run: true
alert_mode: "ALERT"
tasks:
- id: compute_stale_cutoff_timestamp
type: io.kestra.plugin.core.debug.Return
description: Compute the ISO-8601 timestamp cutoff based on current execution
time and stale_threshold_hours.
format: >-
{{ (now() | dateAdd(-inputs.stale_threshold_hours, 'HOURS')) |
date("yyyy-MM-dd'T'HH:mm:ssXXX") }}
- id: probe_stale_pending_records
type: io.kestra.plugin.supabase.Select
description: Query the target Supabase table using PostgREST syntax for records
with status pending created before the cutoff timestamp.
url: "{{ inputs.supabase_url }}"
apiKey: "{{ secret('SUPABASE_SERVICE_ROLE_KEY') }}"
table: "{{ inputs.table_name }}"
select: "id,status,created_at"
filter: "status=eq.pending&created_at=lt.{{
outputs.compute_stale_cutoff_timestamp.value }}"
order: "created_at.asc"
limit: "{{ inputs.batch_size }}"
- id: classify_stale_accumulation
type: io.kestra.plugin.core.debug.Return
description: Evaluate the count of matching records and classify backlog
severity into HEALTHY, WARNING_STALE_DETECTED, or CRITICAL_ACCUMULATION.
format: "{{ (outputs.probe_stale_pending_records.size | default(0)) == 0 ?
'HEALTHY' : ((outputs.probe_stale_pending_records.size | default(0)) >=
inputs.critical_count_threshold ? 'CRITICAL_ACCUMULATION' :
'WARNING_STALE_DETECTED') }}"
- id: route_sentinel_classification
type: io.kestra.plugin.core.flow.Switch
description: Branch execution based on stale record backlog classification to
notify on-call or execute safe quarantine updates.
value: "{{ outputs.classify_stale_accumulation.value | trim }}"
cases:
CRITICAL_ACCUMULATION:
- id: handle_critical_alert
type: io.kestra.plugin.core.flow.If
description: Verify alert_mode setting before dispatching critical backlog
notification.
condition: "{{ inputs.alert_mode == 'ALERT' }}"
then:
- id: send_critical_slack_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch critical stale record accumulation notification to Slack.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "CRITICAL: Supabase Stale Pending Record Accumulation Breach",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Supabase Critical Stale Records Breach"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Status:*\nCritical Accumulation"
},
{
"type": "mrkdwn",
"text": "*Table:*\n`{{ inputs.table_name }}`"
},
{
"type": "mrkdwn",
"text": "*Stale Records Count:*\n{{ outputs.probe_stale_pending_records.size }}"
},
{
"type": "mrkdwn",
"text": "*Threshold Limit:*\n{{ inputs.critical_count_threshold }}"
},
{
"type": "mrkdwn",
"text": "*Cutoff Timestamp:*\n`{{ outputs.compute_stale_cutoff_timestamp.value }}`"
},
{
"type": "mrkdwn",
"text": "*Auto-Quarantine:*\n`{{ inputs.auto_quarantine and not inputs.dry_run }}`"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Execution ID: `{{ execution.id }}` | Namespace: `{{ flow.namespace }}`"
}
]
}
]
}
else:
- id: log_critical_audit_only
type: io.kestra.plugin.core.log.Log
description: Record critical accumulation finding in audit log without paging
on-call.
message: "AUDIT ONLY: Critical stale record accumulation detected on Supabase
table {{ inputs.table_name }}. Found {{
outputs.probe_stale_pending_records.size }} stale records older
than {{ inputs.stale_threshold_hours }} hours."
- id: evaluate_remediation_gate
type: io.kestra.plugin.core.flow.If
description: Verify that auto_quarantine is true and dry_run is false before
applying database updates.
condition: "{{ inputs.auto_quarantine and not inputs.dry_run }}"
then:
- id: quarantine_stale_records
type: io.kestra.plugin.supabase.Update
description: Update status of stale pending records to quarantined to prevent
consumer retry storms.
url: "{{ inputs.supabase_url }}"
apiKey: "{{ secret('SUPABASE_SERVICE_ROLE_KEY') }}"
table: "{{ inputs.table_name }}"
data:
status: "quarantined"
filter: "status=eq.pending&created_at=lt.{{
outputs.compute_stale_cutoff_timestamp.value }}"
select: "id,status"
- id: log_quarantine_remediation
type: io.kestra.plugin.core.log.Log
description: Record count of successfully quarantined stale records.
message: "REMEDIATION: Successfully transitioned {{
outputs.quarantine_stale_records.updatedCount }} records on
table {{ inputs.table_name }} to status 'quarantined'."
else:
- id: log_remediation_skipped
type: io.kestra.plugin.core.log.Log
description: Log that remediation mutation was skipped due to dry_run or
auto_quarantine configuration.
message: "Remediation skipped for {{ outputs.probe_stale_pending_records.size }}
stale records on table {{ inputs.table_name }}.
auto_quarantine={{ inputs.auto_quarantine }}, dry_run={{
inputs.dry_run }}."
WARNING_STALE_DETECTED:
- id: handle_warning_alert
type: io.kestra.plugin.core.flow.If
description: Verify alert_mode setting before dispatching warning notification.
condition: "{{ inputs.alert_mode == 'ALERT' }}"
then:
- id: send_warning_slack_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch warning stale record notification to Slack.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "WARNING: Supabase Stale Pending Records Detected",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Supabase Stale Pending Records Warning"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Status:*\nStale Records Detected"
},
{
"type": "mrkdwn",
"text": "*Table:*\n`{{ inputs.table_name }}`"
},
{
"type": "mrkdwn",
"text": "*Stale Count:*\n{{ outputs.probe_stale_pending_records.size }}"
},
{
"type": "mrkdwn",
"text": "*Older Than:*\n{{ inputs.stale_threshold_hours }} hours"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Execution ID: `{{ execution.id }}` | Namespace: `{{ flow.namespace }}`"
}
]
}
]
}
else:
- id: log_warning_audit_only
type: io.kestra.plugin.core.log.Log
description: Record warning finding in audit log without paging on-call.
message: "AUDIT ONLY: Stale pending records detected on Supabase table {{
inputs.table_name }}. Found {{
outputs.probe_stale_pending_records.size }} records older than
{{ inputs.stale_threshold_hours }} hours."
HEALTHY:
- id: log_healthy_status
type: io.kestra.plugin.core.log.Log
description: Record nominal audit entry confirming zero stale pending records.
message: "HEALTHY: Zero stale pending records found on Supabase table {{
inputs.table_name }} older than {{ inputs.stale_threshold_hours }}
hours. PostgREST endpoint is healthy."
defaults:
- id: log_unknown_classification
type: io.kestra.plugin.core.log.Log
description: Record fallback log entry for unanticipated classification value.
message: "Unknown sentinel classification received: {{
outputs.classify_stale_accumulation.value }}"
- id: log_sentinel_audit_complete
type: io.kestra.plugin.core.log.Log
description: Record final audit entry maintaining an unbroken execution history
of sentinel verification passes.
message: "Supabase stale record audit pass complete. Status: {{
outputs.classify_stale_accumulation.value | trim }} | Table: {{
inputs.table_name }} | Inspected Count: {{
outputs.probe_stale_pending_records.size }} | Execution: {{ execution.id
}}."
errors:
- id: on_failure_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Out-of-band error handler alerting on-call if the Supabase endpoint
is unreachable or authentication fails.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Supabase stale record sentinel execution {{ execution.id }} FAILED for table {{ inputs.table_name }} in namespace {{ flow.namespace }}. Check Supabase endpoint reachability and service role credentials."
}