: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
fix(flags): retry last-called sync on ClickHouseAtCapacity (#72115)
Phil Haack1c8870f14f92
diff --git a/posthog/tasks/tasks.py b/posthog/tasks/tasks.pyindex aae776e94dbf..312cdd86a90e 100644--- a/posthog/tasks/tasks.py+++ b/posthog/tasks/tasks.py@@ -23,6 +23,7 @@ from posthog.clickhouse.client.limit import ConcurrencyLimitExceeded, limit_concfrom posthog.clickhouse.query_tagging import Feature, Product, get_query_tags, tag_queriesfrom posthog.cloud_utils import is_cloudfrom posthog.errors import CH_TRANSIENT_ERRORS, CHQueryErrorTooManySimultaneousQueries+from posthog.exceptions import ClickHouseAtCapacityfrom posthog.exceptions_capture import capture_exceptionfrom posthog.metrics import pushed_metrics_registryfrom posthog.models.event.new_events_schema import events_read_table, use_new_events_schema@@ -1177,7 +1178,9 @@ def _queue_delete_team_recordings(team_ids: list[int], deleted_by: str) -> None:base=PushGatewayTask,ignore_result=True,queue=CeleryQueue.FEATURE_FLAGS_LONG_RUNNING.value,- autoretry_for=CH_TRANSIENT_ERRORS,+ # sync_execute wraps TOO_MANY_SIMULTANEOUS_QUERIES/CANNOT_SCHEDULE_TASK into+ # ClickHouseAtCapacity, so it must be listed alongside the raw CH error classes.+ autoretry_for=(*CH_TRANSIENT_ERRORS, ClickHouseAtCapacity),retry_backoff=30,retry_backoff_max=120,max_retries=3,diff --git a/products/feature_flags/backend/test/test_feature_flag_sync.py b/products/feature_flags/backend/test/test_feature_flag_sync.pyindex 4f1bbf255922..9172a7d79ef5 100644--- a/products/feature_flags/backend/test/test_feature_flag_sync.py+++ b/products/feature_flags/backend/test/test_feature_flag_sync.py@@ -9,6 +9,7 @@ from django.test import override_settingsfrom django.utils import timezone as tzfrom posthog.errors import CH_TRANSIENT_ERRORS, CHQueryErrorTooManyBytes+from posthog.exceptions import ClickHouseAtCapacityfrom posthog.tasks.tasks import sync_feature_flag_last_calledfrom products.feature_flags.backend.models.feature_flag import FeatureFlag@@ -550,10 +551,13 @@ class TestSyncFeatureFlagLastCalledChunking(BaseTest):self.flag1.refresh_from_db()assert self.flag1.last_called_at is None- def test_no_retry_on_too_many_bytes(self) -> None:+ def test_autoretry_for_membership(self) -> None:"""CHQueryErrorTooManyBytes should not be in the autoretry_for tuple"""autoretry_for = sync_feature_flag_last_called.autoretry_forassert CHQueryErrorTooManyBytes not in autoretry_for# Transient errors should still be retriedfor error_cls in CH_TRANSIENT_ERRORS:assert error_cls in autoretry_for+ # sync_execute wraps capacity errors (code 202) into ClickHouseAtCapacity,+ # so the wrapped form must be retryable too+ assert ClickHouseAtCapacity in autoretry_for