: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(warehouse-sources): let resume cdc through a self-managed lag marker (#105943)
Daniel RCcfcc694ba7a7
diff --git a/products/warehouse_sources/backend/facade/source_management.py b/products/warehouse_sources/backend/facade/source_management.pyindex c0e98059ec3c..e51a61e9a1e3 100644--- a/products/warehouse_sources/backend/facade/source_management.py+++ b/products/warehouse_sources/backend/facade/source_management.py@@ -22,6 +22,7 @@ _LAZY = {"CDCRepairError": "cdc.repair","CDCRepairInProgress": "cdc.repair","repair_cdc_source": "cdc.repair",+ "SELF_MANAGED_LAG_REASON": "cdc.broken","purge_buffer_prefix": "cdc.buffer","CDC_SEQ_COLUMN": "cdc.batcher","ClickHouseConnectionError": "sources.clickhouse.clickhouse",diff --git a/products/warehouse_sources/backend/presentation/views/external_data_source/change_data_capture.py b/products/warehouse_sources/backend/presentation/views/external_data_source/change_data_capture.pyindex a4a8b2930869..d787af5201e6 100644--- a/products/warehouse_sources/backend/presentation/views/external_data_source/change_data_capture.py+++ b/products/warehouse_sources/backend/presentation/views/external_data_source/change_data_capture.py@@ -24,6 +24,7 @@ from products.warehouse_sources.backend.facade.models import (from products.warehouse_sources.backend.facade.source_management import (DEFAULT_LAG_CRITICAL_THRESHOLD_MB,DEFAULT_LAG_WARNING_THRESHOLD_MB,+ SELF_MANAGED_LAG_REASON,CDCRepairError,CDCRepairInProgress,CDCSourceAdapter,@@ -653,8 +654,11 @@ class ExternalDataSourceCDCMixin(base.ExternalDataSourceViewSetBase):)# A broken source has lost its slot/publication — resuming would just re-fail on the- # next tick. Route the user to Repair CDC, which recreates them (and re-syncs).- if any((schema.sync_type_config or {}).get("cdc_broken") for schema in cdc_schemas):+ # next tick. Route the user to Repair CDC, which recreates them (and re-syncs). The+ # self-managed lag marker is the exception: that slot is intact, and the marker clears only+ # once capture runs and brings the lag down, so refusing here would never let it clear.+ broken_markers = [(schema.sync_type_config or {}).get("cdc_broken") for schema in cdc_schemas]+ if any(marker and marker.get("reason") != SELF_MANAGED_LAG_REASON for marker in broken_markers):return Response(status=status.HTTP_400_BAD_REQUEST,data={"message": "The replication slot or publication was lost. Use Repair CDC to recreate it."},diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.pyindex 75c4df65a4f8..46345e0414bd 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py@@ -12147,10 +12147,12 @@ class TestResumeCDC(APIBaseTest):f"/api/environments/{self.team.pk}/external_data_sources/{source.pk}/resume_cdc/",)- def _cdc_schema(self, source: ExternalDataSource, *, broken: bool = False) -> ExternalDataSchema:+ def _cdc_schema(+ self, source: ExternalDataSource, *, broken_marker: dict[str, str] | None = None+ ) -> ExternalDataSchema:config: dict[str, t.Any] = {"cdc_mode": "streaming"}- if broken:- config["cdc_broken"] = BROKEN_MARKER+ if broken_marker:+ config["cdc_broken"] = broken_markerreturn ExternalDataSchema.objects.create(name="orders",team_id=self.team.pk,@@ -12204,23 +12206,37 @@ class TestResumeCDC(APIBaseTest):assert "cdc_extraction_paused" not in schema.sync_type_configassert schema.sync_halted is False+ @parameterized.expand(+ [+ # A lost slot/publication: resume must route to Repair, and not even probe the source.+ ("slot_lost", BROKEN_MARKER, 400),+ ("marker_without_a_reason", {"at": "2026-06-29T10:40:00+00:00"}, 400),+ # The slot is intact, and the marker clears only once capture runs and the lag drops.+ ("self_managed_lag", {"reason": "critical_lag_self_managed", "at": "2026-09-22T15:02:21+00:00"}, 200),+ ]+ )+ @patch(+ "products.warehouse_sources.backend.presentation.views.external_data_source.base.sync_cdc_extraction_schedule"+ )@patch("products.warehouse_sources.backend.presentation.views.external_data_source.base.unpause_cdc_extraction_schedule")@patch(- "products.warehouse_sources.backend.temporal.data_imports.sources.postgres.cdc.adapter.PostgresCDCAdapter.get_status"+ "products.warehouse_sources.backend.temporal.data_imports.sources.postgres.cdc.adapter.PostgresCDCAdapter.get_status",+ return_value={"slot_exists": True, "publication_exists": True, "lag_bytes": 128},)- def test_resume_cdc_rejected_when_broken_marker(self, mock_get_status, mock_unpause) -> None:- # A lost slot/publication is marked cdc_broken — resume must route to Repair, not unpause- # (and must not even probe, since the source is known-broken).+ def test_resume_cdc_with_a_broken_marker(+ self, _name, marker, expected_status, mock_get_status, mock_unpause, _mock_sync+ ) -> None:source = _make_postgres_source(self.team.pk, self.user, cdc_enabled=True)- self._cdc_schema(source, broken=True)+ self._cdc_schema(source, broken_marker=marker)response = self._resume(source)- assert response.status_code == 400- assert "Repair CDC" in response.json()["message"]- mock_unpause.assert_not_called()- mock_get_status.assert_not_called()+ assert response.status_code == expected_status, response.content+ if expected_status == 400:+ assert "Repair CDC" in response.json()["message"]+ assert mock_unpause.called is (expected_status == 200)+ assert mock_get_status.called is (expected_status == 200)@patch("products.warehouse_sources.backend.presentation.views.external_data_source.base.unpause_cdc_extraction_schedule"