:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
# Products decide whether an alert is triggered. Shared lifecycle code owns state
# transitions, notification decisions, snoozing, and enable/disable behavior.
rules:
- id: logs-alert-state-direct-mutation
patterns:
- pattern-either:
- pattern: $ALERT.state = $VALUE
- pattern: $ALERT.consecutive_failures = $VALUE
- pattern: $ALERT.enabled = $VALUE
- pattern: $QUERY.update(..., state=$VALUE, ...)
- pattern: $QUERY.update(..., consecutive_failures=$VALUE, ...)
- pattern: $QUERY.update(..., enabled=$VALUE, ...)
message: |
Direct mutation of a logs alert's lifecycle fields bypasses its state
machine adapter. Route the change through
products.logs.backend.alert_state_machine.
languages: [python]
severity: ERROR
metadata:
category: correctness
subcategory: audit
confidence: HIGH
paths:
include:
- '/products/logs/backend/**/*.py'
- '/.semgrep/rules/security/tests/logs-alert-state-must-go-through-state-machine.py'
exclude:
- '/products/logs/backend/alert_state_machine.py'
- '/products/logs/backend/test/**'
- '/products/logs/backend/**/test_*.py'
- id: replay-vision-alert-state-direct-mutation
patterns:
- pattern-either:
- pattern: $ALERT.state = $VALUE
- pattern: $ALERT.consecutive_failures = $VALUE
- pattern: $ALERT.enabled = $VALUE
- pattern: $QUERY.update(..., state=$VALUE, ...)
- pattern: $QUERY.update(..., consecutive_failures=$VALUE, ...)
- pattern: $QUERY.update(..., enabled=$VALUE, ...)
message: |
Direct mutation of a replay vision alert's lifecycle fields bypasses its
state machine adapter. Route the change through
products.replay_vision.backend.alert_state_machine.
languages: [python]
severity: ERROR
metadata:
category: correctness
subcategory: audit
confidence: HIGH
paths:
include:
- '/products/replay_vision/backend/**/*.py'
- '/.semgrep/rules/security/tests/replay-vision-alert-state-must-go-through-state-machine.py'
exclude:
- '/products/replay_vision/backend/alert_state_machine.py'
- '/products/replay_vision/backend/tests/**'
- '/products/replay_vision/backend/**/test_*.py'
# Mutates HogFunction.enabled (delivery plumbing), not an alert.
- '/products/replay_vision/backend/api/delivery.py'
# Migrations mutate historical models from apps.get_model, so they
# cannot call the state machine.
- '/products/replay_vision/backend/migrations/**'
- id: billing-alert-state-direct-mutation
patterns:
- pattern-either:
- pattern: $ALERT.state = $VALUE
- pattern: $ALERT.consecutive_failures = $VALUE
- pattern: $ALERT.enabled = $VALUE
- pattern: $QUERY.update(..., state=$VALUE, ...)
- pattern: $QUERY.update(..., consecutive_failures=$VALUE, ...)
- pattern: $QUERY.update(..., enabled=$VALUE, ...)
message: |
Direct mutation of a billing alert's lifecycle fields bypasses its state
machine adapter. Route the change through
products.billing_alerts.backend.logic.state_machine.
languages: [python]
severity: ERROR
metadata:
category: correctness
subcategory: audit
confidence: HIGH
paths:
include:
- '/products/billing_alerts/backend/**/*.py'
exclude:
- '/products/billing_alerts/backend/logic/state_machine.py'
- '/products/billing_alerts/backend/test/**'
- '/products/billing_alerts/backend/**/test_*.py'
- id: insight-alert-state-direct-mutation
patterns:
- pattern-either:
- pattern: $ALERT.state = $VALUE
- pattern: $ALERT.enabled = $VALUE
- pattern: $QUERY.update(..., state=$VALUE, ...)
- pattern: $QUERY.update(..., enabled=$VALUE, ...)
message: |
Direct mutation of an insight alert's lifecycle fields bypasses its state
machine adapter. Route the change through
products.alerts.backend.insight_alert_state_machine.
languages: [python]
severity: ERROR
metadata:
category: correctness
subcategory: audit
confidence: HIGH
paths:
include:
- '/products/alerts/backend/**/*.py'
- '/posthog/tasks/alerts/**/*.py'
- '/posthog/temporal/alerts/**/*.py'
- '/.semgrep/rules/security/tests/insight-alert-state-must-go-through-state-machine.py'
exclude:
- '/products/alerts/backend/insight_alert_state_machine.py'
# Writes HogFunction.enabled (destination plumbing), not an alert.
- '/products/alerts/backend/logic/destinations.py'
- '/products/alerts/backend/test/**'
- '/products/alerts/backend/tests/**'
- '/products/alerts/backend/**/test_*.py'
- '/posthog/tasks/alerts/test/**'
- id: platform-alert-state-direct-mutation
patterns:
- pattern-either:
- pattern: $ALERT.state = $VALUE
- pattern: $ALERT.consecutive_failures = $VALUE
- pattern: $ALERT.enabled = $VALUE
- pattern: $QUERY.update(..., state=$VALUE, ...)
- pattern: $QUERY.update(..., consecutive_failures=$VALUE, ...)
- pattern: $QUERY.update(..., enabled=$VALUE, ...)
message: |
Direct mutation of shared alert lifecycle fields bypasses the shared mutator.
A source decides whether its data breached; the shared lifecycle decides what
that means. Route the change through
products.alerts_platform.backend.facade.api.record_outcomes.
languages: [python]
severity: ERROR
metadata:
category: correctness
subcategory: audit
confidence: HIGH
paths:
include:
- '/products/alerts_platform/backend/**/*.py'
- '/products/logs/backend/alert_source_cycle.py'
- '/products/logs/backend/platform_alert_backfill.py'
exclude:
# The sanctioned mutator: every other path reaches the rows through it.
- '/products/alerts_platform/backend/logic/platform_lifecycle.py'
- '/products/**/test/**'
- '/products/**/tests/**'
- '/products/**/test_*.py'