Skip to content

: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.

chore(warehouse-sources): remove the fan-out parent reuse feature flag (#103746)

Daniel RCcc4da443175c
diff --git a/.agents/skills/implementing-warehouse-sources/SKILL.md b/.agents/skills/implementing-warehouse-sources/SKILL.md
index da323f0eaefe..98ffe423d136 100644
--- a/.agents/skills/implementing-warehouse-sources/SKILL.md
+++ b/.agents/skills/implementing-warehouse-sources/SKILL.md
@@ -643,9 +643,9 @@ Requirements and behavior:
- **The parent must be a selectable schema of the same source** — it has to produce its own Delta table.
- **Soft dependency — the child falls back to the parent API.** Declare the parents by overriding `get_required_parent_schemas` on the source (wire it to `required_parents_from_endpoint_configs(ENDPOINTS, schema_name)`; add explicit entries for custom-iterator endpoints). That override is the only declaration: nothing surfaces the relationship through the API, so don't add a schema-payload field for it while the feature is unvalidated.
- Nothing in the API constrains the selection either: a child can be enabled without its parent, and a parent can be disabled or deleted while children sync. `_warehouse_parent_reuse_available` in `import_data_activity_sync` decides per run — a parent that is missing, disabled, not yet initially synced, or on any sync type other than merge or full refresh sends that run down the legacy parent-API path, so enabling the flag can never break a schema that syncs today. A parent that is merely mid-sync does not force the fallback, because `resolve_parent_table_ref` pins the read to the parent's last completed snapshot via Delta time travel.
+ Nothing in the API constrains the selection either: a child can be enabled without its parent, and a parent can be disabled or deleted while children sync. `_warehouse_parent_reuse_available` in `import_data_activity_sync` decides per run — a parent that is missing, disabled, not yet initially synced, or on any sync type other than merge or full refresh sends that run down the legacy parent-API path, so opting a child in can never break a schema that syncs today. A parent that is merely mid-sync does not force the fallback, because `resolve_parent_table_ref` pins the read to the parent's last completed snapshot via Delta time travel.
Never enable a parent as a side effect of enabling a child: parent syncs count toward the customer's billed rows.
-- **Feature-flagged.** The whole path is gated by the `warehouse-fanout-parent-reuse` flag (`is_fanout_warehouse_reuse_enabled`); with the flag off, opted-in endpoints silently keep the legacy parent-API path, so rollback is a flag flip.
+- **Small parents stay on the API.** A parent under `MIN_WAREHOUSE_PARENT_ROWS` (1,000 rows) is not worth opening: the Delta read has a fixed cost of a few seconds, more than paging a small listing, and that cohort measured slower when converted. The gate reads the parent table's `row_count`, so it applies per run without configuration. There is no feature flag any more; rollback is a revert.
- **Strictly streaming — never materialize the parent table.** The reader scans one projected batch at a time with column projection pushed down to the parquet read. Do not add `to_table`, global sorts, or seen-set dedupe to it — parents can be arbitrarily large, and the whole pipeline exists to avoid full-dataset memory. If a caller's semantics depend on parent order (the API returned sorted rows), rework them into per-row filters over the unordered stream (see Sentry's `issue_tag_values` cutoff handling) instead of sorting.
- **The usable sync types are an allow-list, not a deny-list.** Only merge and full refresh hold one row per key; append accumulates a row per sync and CDC keeps change history, so streaming either would fan the child out once per duplicate, and dedupe would need unbounded state. A new sync type has to opt in deliberately in `_parent_unusable_reason`.
- **Values carry Delta physical types, not the API's JSON types.** A timestamp comes back as a datetime rather than an ISO string, a nested object as a dict. Because the API fallback engages per run, projecting such a field through `include_from_parent` makes the child's column type flip between runs and trips the merge's type-drift guards. Only project fields whose physical type matches what the API returned (an id string is safe), or normalize in the caller.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/fanout_reuse_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/fanout_reuse_flag.py
deleted file mode 100644
index 3fb81169d35c..000000000000
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/fanout_reuse_flag.py
+++ /dev/null
@@ -1,48 +0,0 @@
-import django.db
-
-import posthoganalytics
-
-from posthog.exceptions_capture import capture_exception
-from posthog.models.team.team import Team
-from posthog.temporal.common.utils import retry_on_db_connection_drop
-
-FANOUT_WAREHOUSE_REUSE_FLAG = "warehouse-fanout-parent-reuse"
-
-
-def is_fanout_warehouse_reuse_enabled(team_id: int) -> bool:
- """Gate for reading fan-out parents from the warehouse instead of the parent API.
-
- Fails closed: any error means "off", which keeps the legacy parent-API path.
- Lives in a leaf module (no deltalake/pyarrow) so callers can import it without pulling
- the Delta reader stack into their import graph.
- """
- try:
- team = retry_on_db_connection_drop(lambda: Team.objects.only("uuid", "organization_id").get(id=team_id))
- except Team.DoesNotExist:
- return False
- except (django.db.OperationalError, django.db.InterfaceError) as e:
- # retry_on_db_connection_drop already retried once; a second failure is a genuinely
- # degraded DB, not a bug here (see repartition_controller.py's _is_flag_enabled).
- capture_exception(e)
- return False
- except Exception as e:
- capture_exception(e)
- return False
-
- try:
- return bool(
- posthoganalytics.feature_enabled(
- FANOUT_WAREHOUSE_REUSE_FLAG,
- str(team.uuid),
- groups={"organization": str(team.organization_id), "project": str(team.id)},
- group_properties={
- "organization": {"id": str(team.organization_id)},
- "project": {"id": str(team.id)},
- },
- only_evaluate_locally=False,
- send_feature_flag_events=False,
- )
- )
- except Exception as e:
- capture_exception(e)
- return False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_fanout_reuse_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_fanout_reuse_flag.py
deleted file mode 100644
index 1d8b4e7a2b3a..000000000000
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_fanout_reuse_flag.py
+++ /dev/null
@@ -1,72 +0,0 @@
-import pytest
-from unittest.mock import MagicMock, patch
-
-import django.db
-
-from posthog.models.team.team import Team
-
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag import (
- is_fanout_warehouse_reuse_enabled,
-)
-
-
-class TestFanoutReuseFlagFailsClosed:
- # Fail-closed is the contract every consumer relies on: a falsy result keeps the legacy
- # parent-API path. If the try/except narrows, a flag-service blip becomes failed sync runs.
-
- def test_flag_service_error_returns_false(self):
- with (
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.Team"
- ) as team_cls,
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.posthoganalytics.feature_enabled",
- side_effect=RuntimeError("flags endpoint down"),
- ),
- ):
- team_cls.objects.get.return_value.uuid = "u"
- assert is_fanout_warehouse_reuse_enabled(1) is False
-
- @pytest.mark.django_db
- def test_missing_team_returns_false(self):
- assert is_fanout_warehouse_reuse_enabled(999999999) is False
-
- def test_transient_db_connection_drop_retries_then_succeeds(self):
- # A pooled connection dropped once (pgbouncer recycle) must not be reported as an
- # exception nor fail the gate closed — the retry should recover it transparently.
- mock_team = MagicMock()
- with (
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.Team"
- ) as team_cls,
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.posthoganalytics.feature_enabled",
- return_value=True,
- ),
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.capture_exception"
- ) as mock_capture,
- ):
- team_cls.DoesNotExist = Team.DoesNotExist
- team_cls.objects.only.return_value.get.side_effect = [
- django.db.OperationalError("connection closed"),
- mock_team,
- ]
- assert is_fanout_warehouse_reuse_enabled(1) is True
- mock_capture.assert_not_called()
-
- def test_persistent_db_connection_drop_returns_false(self):
- # A second failure after the retry means a genuinely degraded DB, not a transient
- # blip — this should still be reported and the gate should still fail closed.
- with (
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.Team"
- ) as team_cls,
- patch(
- "products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag.capture_exception"
- ) as mock_capture,
- ):
- team_cls.DoesNotExist = Team.DoesNotExist
- team_cls.objects.only.return_value.get.side_effect = django.db.OperationalError("connection closed")
- assert is_fanout_warehouse_reuse_enabled(1) is False
- mock_capture.assert_called_once()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/typings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/typings.py
index 59c492538930..1e36c89ada88 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/typings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/typings.py
@@ -150,9 +150,8 @@ class SourceInputs:
# Effective vendor API version: the source instance's pin resolved through the source's
# `default_version`. Sources with a versioned vendor API thread it to their request layer.
api_version: Optional[str] = None
- # True when this schema is a fan-out child whose parent should be read from the warehouse
- # (flag on + parents verified synced). Evaluated once by the run-time gate in
- # `import_data_activity_sync` so sources don't re-evaluate the feature flag per run.
+ # True when this schema is a fan-out child whose parents are all readable from the
+ # warehouse. Evaluated once by the run-time gate in `import_data_activity_sync`.
fanout_warehouse_reuse: bool = False
# True when extraction batches should be bounded by accumulated bytes rather than by the
# sampled row count alone. Evaluated once per run alongside `fanout_warehouse_reuse`.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/stripe/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/stripe/test_stripe_source.py
index cf73259dc6d7..d92dd495344d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/stripe/test_stripe_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/stripe/test_stripe_source.py
@@ -1262,12 +1262,9 @@ class TestCreateWebhook:
# path walks parquet file order, and neither promises the other's ordering.
PROBED_CUSTOMERS = ["cus_credit_1", "cus_credit_2", "cus_gone", "cus_null_balance"]
-FANOUT_GATE = (
- "products.warehouse_sources.backend.temporal.data_imports.workflow_activities."
- "import_data_sync.is_fanout_warehouse_reuse_enabled"
-)
-# The mock account holds a handful of customers, far under the production size floor. These tests
-# cover the conversion itself; the floor is policy, covered by the gate's own unit tests.
+# The size floor is the only run-time switch between the two parent paths, so these tests set it
+# below the mock account's handful of customers to take the warehouse path and above it to take
+# the API path. The floor itself is policy, covered by the gate's own unit tests.
PARENT_SIZE_FLOOR = (
"products.warehouse_sources.backend.temporal.data_imports.workflow_activities."
"import_data_sync.MIN_WAREHOUSE_PARENT_ROWS"
@@ -1328,7 +1325,7 @@ async def _sync_parent_then_child(team, source, parent, child, mock_stripe_api,
calls_before = len(mock_stripe_api.get_all_api_calls())
expected_rows = sum(len(rows) for rows in CUSTOMER_BALANCE_TRANSACTIONS.values())
- with mock.patch(FANOUT_GATE, return_value=reuse_enabled), mock.patch(PARENT_SIZE_FLOOR, 0):
+ with mock.patch(PARENT_SIZE_FLOOR, 0 if reuse_enabled else len(CUSTOMERS) + 1):
response = await run_external_data_job_workflow(
team=team,
external_data_source=source,
@@ -1426,15 +1423,14 @@ async def test_a_missing_parent_schema_keeps_the_api_path(team, mock_stripe_api,
child = await _balance_transaction_child(external_data_source, team)
expected_rows = sum(len(rows) for rows in CUSTOMER_BALANCE_TRANSACTIONS.values())
- with mock.patch(FANOUT_GATE, return_value=True):
- await run_external_data_job_workflow(
- team=team,
- external_data_source=external_data_source,
- external_data_schema=child,
- table_name="stripe_customerbalancetransaction",
- expected_rows_synced=expected_rows,
- expected_total_rows=expected_rows,
- )
+ await run_external_data_job_workflow(
+ team=team,
+ external_data_source=external_data_source,
+ external_data_schema=child,
+ table_name="stripe_customerbalancetransaction",
+ expected_rows_synced=expected_rows,
+ expected_total_rows=expected_rows,
+ )
assert _listing_calls(mock_stripe_api), "with no parent table there is nothing to read but the API"
assert sorted(_child_calls(mock_stripe_api)) == PROBED_CUSTOMERS
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py
index 7903c77bed59..46f04345f6ef 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py
@@ -72,9 +72,6 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.byt
from products.warehouse_sources.backend.temporal.data_imports.sources.common.errors import (
is_transient_egress_proxy_error,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.fanout_reuse_flag import (
- is_fanout_warehouse_reuse_enabled,
-)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.history_window import (
history_start_for_schema,
)
@@ -207,9 +204,8 @@ async def _warehouse_parent_reuse_available(
"""Whether this run reads its fan-out parents from the warehouse instead of the parent API.
Reuse is an optimization, never a requirement: any parent the child can't read falls the
- whole run back to the legacy parent-API path, so enabling the flag can't break a schema
- that syncs today. Sources consume the result via `SourceInputs.fanout_warehouse_reuse`;
- this is the single feature-flag evaluation for the run.
+ whole run back to the legacy parent-API path, so it can't break a schema that syncs today.
+ Sources consume the result via `SourceInputs.fanout_warehouse_reuse`.
A parent that is mid-sync doesn't force the fallback: `resolve_parent_table_ref` pins the
read to the parent's last completed snapshot (Delta time travel), so a concurrent rewrite
@@ -218,8 +214,6 @@ async def _warehouse_parent_reuse_available(
required_parents = source.get_required_parent_schemas(schema.name)
if not required_parents:
return False
- if not await database_sync_to_async_pool(is_fanout_warehouse_reuse_enabled)(team_id):
- return False
for parent_name in required_parents:
parent = await database_sync_to_async_pool(get_schema_if_exists)(parent_name, team_id, source_id)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py
index 812787f3a469..b411a6e7b14e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py
@@ -1018,8 +1018,8 @@ def _parent(
[None, "disabled", "never_synced", "append_mode", "cdc_mode", "too_small", "unknown_size"],
)
async def test_unusable_parent_falls_back_to_the_api_path(parent):
- # A child enabled without its parent is a config that syncs today, so turning the flag on
- # must leave it working: fall back to the parent API instead of failing the run. Append and
+ # A child enabled without its parent is a config that syncs today, so reuse must leave it
+ # working: fall back to the parent API instead of failing the run. Append and
# CDC parents hold more than one row per key, so the reader must not stream them either. A
# parent under the size floor costs more to open than the listing it would replace.
parent_obj = None
@@ -1038,7 +1038,6 @@ async def test_unusable_parent_falls_back_to_the_api_path(parent):
with (
mock.patch.object(module, "database_sync_to_async_pool", new=_passthrough),
- mock.patch.object(module, "is_fanout_warehouse_reuse_enabled", return_value=True),
mock.patch.object(module, "get_schema_if_exists", return_value=parent_obj),
):
result = await module._warehouse_parent_reuse_available(
@@ -1062,7 +1061,6 @@ async def test_synced_parent_uses_the_warehouse_path(sync_type):
# because its drains merge on the primary key rather than appending.
with (
mock.patch.object(module, "database_sync_to_async_pool", new=_passthrough),
- mock.patch.object(module, "is_fanout_warehouse_reuse_enabled", return_value=True),
mock.patch.object(
module,
"get_schema_if_exists",
@@ -1079,7 +1077,7 @@ async def test_synced_parent_uses_the_warehouse_path(sync_type):
@pytest.mark.asyncio
async def test_fanout_gate_result_threaded_into_source_inputs():
# The gate's decision must reach the source via SourceInputs — if this wiring drops,
- # every child silently falls back to re-pulling the parent API with the flag on.
+ # every child silently falls back to re-pulling the parent API.
source = mock.MagicMock(spec=SimpleSource)
source.parse_config.return_value = {}
source.get_required_parent_schemas.return_value = ["issues"]
@@ -1089,7 +1087,6 @@ async def test_fanout_gate_result_threaded_into_source_inputs():
with (
_patched_activity_reaching_run(source, schema),
- mock.patch.object(module, "is_fanout_warehouse_reuse_enabled", return_value=True),
mock.patch.object(
module, "get_schema_if_exists", return_value=_parent(should_sync=True, initial_sync_complete=True)
),
@@ -1100,33 +1097,18 @@ async def test_fanout_gate_result_threaded_into_source_inputs():
assert source_inputs.fanout_warehouse_reuse is True
-async def test_parent_gate_inert_when_flag_disabled():
- with (
- mock.patch.object(module, "database_sync_to_async_pool", new=_passthrough),
- mock.patch.object(module, "is_fanout_warehouse_reuse_enabled", return_value=False),
- mock.patch.object(module, "get_schema_if_exists") as schema_lookup,
- ):
- result = await module._warehouse_parent_reuse_available(
- _fanout_source(), _fanout_child_schema(), uuid.uuid4(), 1, mock.AsyncMock()
- )
-
- assert result is False
- schema_lookup.assert_not_called()
-
-
@pytest.mark.asyncio
async def test_parent_gate_inert_for_sources_without_requirements():
source = mock.MagicMock(spec=SimpleSource)
source.get_required_parent_schemas.return_value = []
- with mock.patch.object(module, "is_fanout_warehouse_reuse_enabled") as flag_check:
+ with mock.patch.object(module, "get_schema_if_exists") as schema_lookup:
result = await module._warehouse_parent_reuse_available(
source, _fanout_child_schema(), uuid.uuid4(), 1, mock.AsyncMock()
)
assert result is False
- flag_check.assert_not_called()
+ schema_lookup.assert_not_called()
def _probe_model() -> mock.MagicMock: