: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
chore(warehouse-sources): remove the byte-bounded extraction flag (#110328)
Daniel RC3dd1eba24bdc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.pydeleted file mode 100644index 051ff52c5dee..000000000000--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/byte_bounded_extraction_flag.py+++ /dev/null@@ -1,61 +0,0 @@-from django.db import InterfaceError, OperationalError--import structlog-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--logger = structlog.get_logger(__name__)--BYTE_BOUNDED_EXTRACTION_FLAG = "warehouse-byte-bounded-extraction"---def is_byte_bounded_extraction_enabled(team_id: int, source_type: str) -> bool:- """Gate for bounding extraction batches by accumulated bytes rather than a sampled row count.-- `source_type` rides along as a person property so the rollout widens one driver at a time- from the flag itself. The drivers differ in what a smaller fetch costs them — a Postgres- server cursor pays a round trip per fetch where MySQL reads from an unbuffered stream — so- they are worth validating separately.-- Fails closed: any error means "off", which keeps the row-count batching.- """- try:- team = retry_on_db_connection_drop(lambda: Team.objects.only("uuid", "organization_id").get(id=team_id))- except Team.DoesNotExist:- return False- except (OperationalError, InterfaceError) as e:- # retry_on_db_connection_drop already retried once; a second OperationalError/InterfaceError- # here is the same app-DB connectivity blip class import_data_sync._handle_import_error- # treats as non-reportable elsewhere (pooler drop, or this worker briefly out of file- # descriptors) - not a bug in this gate, so it shouldn't page anyone.- logger.warning(- "is_byte_bounded_extraction_enabled: transient app-DB error, failing closed",- error=str(e),- exc_info=True,- )- return False- except Exception as e:- capture_exception(e)- return False-- try:- return bool(- posthoganalytics.feature_enabled(- BYTE_BOUNDED_EXTRACTION_FLAG,- str(team.uuid),- groups={"organization": str(team.organization_id), "project": str(team.id)},- person_properties={"team_id": str(team.id), "source_type": source_type},- 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 Falsediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/batching.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/batching.pyindex e36684c1c386..3eea1bbf58ea 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/batching.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/batching.py@@ -12,8 +12,8 @@ sees, because the pod dies before a single Arrow table reaches it.What actually bounds memory here is the fetch, not the flush. `fetch(n)` materialises all `n`rows before it returns — for a Postgres server cursor that is a `FETCH FORWARD n` whose wholeresult libpq buffers client-side — so a page is resident in full before any batch is yielded.-The old loop asked for `chunk_size` rows however wide they were, which is precisely how a heavy-region became gigabytes. Two bounds, then, doing two different jobs:+A loop that asks for `chunk_size` rows however wide they are is precisely how a heavy region+becomes gigabytes. Two bounds, then, doing two different jobs:* `max_page_rows` bounds one fetch, so what is resident before the first yield is bounded. Thisis the memory bound. Callers that can measure their own rows pass a size derived from that@@ -29,9 +29,6 @@ read, so an abrupt jump in row size is paid for at whatever page size preceded ithat page small enough to survive is `max_page_rows` — either a driver's own measurement of itswidest row, or `MAX_FETCH_PAGE_ROWS` when it has none. A single row larger than the budget isyielded on its own, the same way `_split_table` yields a lone oversized row.--`byte_bounded` carries the rollout gate. With it off nothing is measured and both bounds come-off `max_rows` alone, which is the fetch-a-chunk-and-yield-it loop every driver ran before."""from __future__ import annotations@@ -48,7 +45,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.conRowT = TypeVar("RowT")# Payload a batch may accumulate before it is flushed. The same budget the row-count estimate-# was derived from, so a table of evenly sized rows keeps batching exactly as it did before.+# is derived from, so a table of evenly sized rows fills a batch at that row count.EXTRACT_BATCH_MAX_BYTES = DEFAULT_TABLE_SIZE_BYTES# Default rows per fetch for a driver that passes no `max_page_rows` of its own. A fetch is the@@ -124,9 +121,9 @@ def _value_bytes(value: Any) -> int:return _SCALAR_VALUE_BYTES-def _page_rows(largest_row_bytes: int, *, max_rows: int, max_bytes: int | None, max_page_rows: int) -> int:+def _page_rows(largest_row_bytes: int, *, max_rows: int, max_bytes: int, max_page_rows: int) -> int:ceiling = min(max_rows, max_page_rows)- if max_bytes is None or largest_row_bytes <= 0:+ if largest_row_bytes <= 0:return ceilingreturn max(1, min(ceiling, max_bytes // largest_row_bytes))@@ -135,23 +132,21 @@ def fetch_row_batches(fetch: Callable[[int], Sequence[RowT] | None],*,max_rows: int,- byte_bounded: bool,max_bytes: int | None = None,max_page_rows: int | None = None,) -> Iterator[list[RowT]]:- """Yield row batches bounded by `max_rows`, and by accumulated bytes when `byte_bounded`.+ """Yield row batches bounded by `max_rows` and by accumulated bytes.`fetch(n)` returns up to `n` rows, and an empty sequence (or None, which some DB-APIdrivers return instead) once the result set is drained — `cursor.fetchmany` for a driver,`iter_row_batches` for an already-streaming source.- Under `byte_bounded` it is called with a page size derived from the widest row seen so far,- never with `max_rows` outright, so the caller's chunk size bounds the batch and not the fetch.+ It is called with a page size derived from the widest row seen so far, never with+ `max_rows` outright, so the caller's chunk size bounds the batch and not the fetch.- `max_page_rows` is a caller-imposed ceiling that holds either way, for a driver whose own- limits cap a single fetch.+ `max_page_rows` is a caller-imposed ceiling, for a driver whose own limits cap a single fetch."""- budget = (EXTRACT_BATCH_MAX_BYTES if max_bytes is None else max_bytes) if byte_bounded else None- page_ceiling = max_page_rows or (MAX_FETCH_PAGE_ROWS if byte_bounded else max_rows)+ budget = EXTRACT_BATCH_MAX_BYTES if max_bytes is None else max_bytes+ page_ceiling = max_page_rows or MAX_FETCH_PAGE_ROWSbatch: list[RowT] = []batch_bytes = 0@@ -165,14 +160,14 @@ def fetch_row_batches(widest_in_page = 0page_bytes = 0- measured, fixed_bytes = _measure_plan(page[0]) if budget is not None else ((), 0)+ measured, fixed_bytes = _measure_plan(page[0])for row in page:- row_bytes = _planned_row_bytes(row, measured, fixed_bytes) if budget is not None else 0+ row_bytes = _planned_row_bytes(row, measured, fixed_bytes)widest_in_page = max(widest_in_page, row_bytes)page_bytes += row_bytes# Flush *before* appending whatever would overflow, never after, or a nearly full# batch could still take a further full-sized row (mirrors the repartition rewrite).- if batch and budget is not None and batch_bytes + row_bytes > budget:+ if batch and batch_bytes + row_bytes > budget:yield batchbatch = []batch_bytes = 0@@ -191,7 +186,7 @@ def fetch_row_batches(# the same estimate as the one just read, which is what makes its size predictable enough# to budget for. Below that, a batch still spans as many fetches as it takes to fill —# a driver reading 1000 rows at a time would otherwise yield a batch per fetch.- if batch and budget is not None and batch_bytes + page_bytes > budget:+ if batch and batch_bytes + page_bytes > budget:yield batchbatch = []batch_bytes = 0@@ -210,7 +205,6 @@ def iter_row_batches(rows: Iterable[RowT],*,max_rows: int,- byte_bounded: bool,max_bytes: int | None = None,max_page_rows: int | None = None,) -> Iterator[list[RowT]]:@@ -219,7 +213,6 @@ def iter_row_batches(return fetch_row_batches(lambda n: list(islice(row_iterator, n)),max_rows=max_rows,- byte_bounded=byte_bounded,max_bytes=max_bytes,max_page_rows=max_page_rows,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.pydeleted file mode 100644index 3d5b3c1cf4eb..000000000000--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_byte_bounded_extraction_flag.py+++ /dev/null@@ -1,60 +0,0 @@-import pytest-from unittest.mock import MagicMock, patch--from django.core.exceptions import ObjectDoesNotExist-from django.db import OperationalError--from products.warehouse_sources.backend.temporal.data_imports.sources.common.byte_bounded_extraction_flag import (- is_byte_bounded_extraction_enabled,-)--_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.common.byte_bounded_extraction_flag"---class TestByteBoundedExtractionFlagFailsClosed:- def test_flag_service_error_returns_false(self):- with (- patch(f"{_MODULE}.Team") as team_cls,- patch(f"{_MODULE}.posthoganalytics.feature_enabled", side_effect=RuntimeError("flags endpoint down")),- ):- team_cls.objects.get.return_value.uuid = "u"- assert is_byte_bounded_extraction_enabled(1, "MySQL") is False-- @pytest.mark.django_db- def test_missing_team_returns_false(self):- assert is_byte_bounded_extraction_enabled(999999999, "MySQL") is False-- def test_transient_db_connection_drop_is_retried(self):- with (- patch(f"{_MODULE}.Team") as team_cls,- patch(f"{_MODULE}.posthoganalytics.feature_enabled", return_value=True),- ):- team_cls.objects.only.return_value.get.side_effect = [- OperationalError("[Errno -2] Name or service not known"),- MagicMock(),- ]- assert is_byte_bounded_extraction_enabled(1, "MySQL") is True-- def test_persistent_db_connection_error_fails_closed_without_reporting(self):- # retry_on_db_connection_drop retries an OperationalError/InterfaceError once; a second- # failure of the same kind (e.g. this worker briefly out of file descriptors) is still a- # transient app-DB blip, not a bug in this gate, so it must not reach error tracking.- with (- patch(f"{_MODULE}.Team") as team_cls,- patch(f"{_MODULE}.capture_exception") as capture_exception,- ):- team_cls.DoesNotExist = ObjectDoesNotExist- team_cls.objects.only.return_value.get.side_effect = OperationalError("[Errno 24] Too many open files")- assert is_byte_bounded_extraction_enabled(1, "Postgres") is False-- capture_exception.assert_not_called()-- def test_source_type_reaches_the_flag_for_per_driver_targeting(self):- with (- patch(f"{_MODULE}.Team") as team_cls,- patch(f"{_MODULE}.posthoganalytics.feature_enabled", return_value=True) as feature_enabled,- ):- team_cls.objects.get.return_value.uuid = "u"- assert is_byte_bounded_extraction_enabled(1, "MySQL") is True-- assert feature_enabled.call_args.kwargs["person_properties"]["source_type"] == "MySQL"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_sql_batching.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_sql_batching.pyindex 7b7739931cf4..e9571530ed69 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_sql_batching.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_sql_batching.py@@ -84,14 +84,14 @@ class TestFetchRowBatches:def test_batches_on_the_row_count_when_rows_are_evenly_sized(self) -> None:cursor = _FakeCursor(_narrow(250))- batches = list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=100, max_bytes=1_000_000))+ batches = list(fetch_row_batches(cursor.fetchmany, max_rows=100, max_bytes=1_000_000))assert [len(batch) for batch in batches] == [100, 100, 50]def test_flushes_early_once_the_byte_budget_is_reached(self) -> None:cursor = _FakeCursor(_wide(40, value_bytes=1024))- batches = list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=10_000, max_bytes=8 * 1024))+ batches = list(fetch_row_batches(cursor.fetchmany, max_rows=10_000, max_bytes=8 * 1024))assert all(sum(estimate_row_bytes(row) for row in batch) <= 8 * 1024 for batch in batches)assert sum(len(batch) for batch in batches) == 40@@ -100,7 +100,7 @@ class TestFetchRowBatches:rows = _narrow(50) + _wide(50, value_bytes=4096, start=50)cursor = _FakeCursor(list(rows))- batches = list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=1_000, max_bytes=16 * 1024))+ batches = list(fetch_row_batches(cursor.fetchmany, max_rows=1_000, max_bytes=16 * 1024))assert [row for batch in batches for row in batch] == rows@@ -108,14 +108,14 @@ class TestFetchRowBatches:rows = [(0, "s"), (1, "x" * 4096), (2, "s")]cursor = _FakeCursor(rows)- batches = list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=1_000, max_bytes=1_024))+ batches = list(fetch_row_batches(cursor.fetchmany, max_rows=1_000, max_bytes=1_024))assert batches == [[rows[0]], [rows[1]], [rows[2]]]def test_shrinks_the_fetch_page_once_wide_rows_appear(self) -> None:cursor = _FakeCursor(_narrow(MAX_FETCH_PAGE_ROWS) + _wide(2_000, value_bytes=1024, start=MAX_FETCH_PAGE_ROWS))- list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=1_000_000, max_bytes=8 * 1024))+ list(fetch_row_batches(cursor.fetchmany, max_rows=1_000_000, max_bytes=8 * 1024))assert cursor.page_sizes[0] == MAX_FETCH_PAGE_ROWSassert cursor.page_sizes[-1] <= 8@@ -124,7 +124,7 @@ class TestFetchRowBatches:# A single outlier must not pin the read to tiny pages for the millions of rows behind it.cursor = _FakeCursor([(0, "x" * 65_536), *_narrow(20_000)])- list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=1_000_000, max_bytes=64 * 1024))+ list(fetch_row_batches(cursor.fetchmany, max_rows=1_000_000, max_bytes=64 * 1024))assert min(cursor.page_sizes) == 1assert cursor.page_sizes[-1] == MAX_FETCH_PAGE_ROWS@@ -141,7 +141,7 @@ class TestFetchRowBatches:def test_page_never_exceeds_the_lowest_ceiling(self, _name: str, kwargs: dict, expected: int) -> None:cursor = _FakeCursor(_narrow(10))- list(fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_bytes=1_000_000, **kwargs))+ list(fetch_row_batches(cursor.fetchmany, max_bytes=1_000_000, **kwargs))assert set(cursor.page_sizes) == {expected}@@ -153,9 +153,7 @@ class TestPageAlignedFlush:# a batch on its own, so carrying the remainder would double residency for one more row.cursor = _FakeCursor(_wide(50, value_bytes=1000))- batches = list(- fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=1_000, max_bytes=12_000, max_page_rows=10)- )+ batches = list(fetch_row_batches(cursor.fetchmany, max_rows=1_000, max_bytes=12_000, max_page_rows=10))assert [len(batch) for batch in batches] == [10, 10, 10, 10, 10]@@ -164,30 +162,16 @@ class TestPageAlignedFlush:# fetch just because the page boundary arrived.cursor = _FakeCursor(_narrow(100))- batches = list(- fetch_row_batches(cursor.fetchmany, byte_bounded=True, max_rows=1_000, max_bytes=12_000, max_page_rows=10)- )+ batches = list(fetch_row_batches(cursor.fetchmany, max_rows=1_000, max_bytes=12_000, max_page_rows=10))assert [len(batch) for batch in batches] == [100]-class TestByteBoundedOff:- def test_batches_and_fetches_on_the_row_count_alone(self) -> None:- # The rollout gate has to leave the old loop exactly as it was: one fetch of the chunk- # size, one batch per fetch, whatever the rows weigh.- cursor = _FakeCursor(_wide(250, value_bytes=4096))-- batches = list(fetch_row_batches(cursor.fetchmany, byte_bounded=False, max_rows=100, max_bytes=8 * 1024))-- assert [len(batch) for batch in batches] == [100, 100, 50]- assert set(cursor.page_sizes) == {100}--class TestIterRowBatches:def test_batches_an_already_streaming_source(self) -> None:rows = _narrow(5)- assert list(iter_row_batches(iter(rows), byte_bounded=True, max_rows=2, max_bytes=1_000_000)) == [+ assert list(iter_row_batches(iter(rows), max_rows=2, max_bytes=1_000_000)) == [rows[0:2],rows[2:4],rows[4:5],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.pyindex 23ee25bf47b4..296c8aa63989 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@@ -167,9 +167,6 @@ class SourceInputs:# 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`.- byte_bounded_extraction: bool = False# Temporal's attempt number for this activity, starting at 1. A source can read a retry# differently from a first run, because the first run has already shown what fails.activity_attempt: int = 1diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.pyindex 9a58422b6ae8..5bdce8e9f556 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py@@ -997,9 +997,7 @@ class MSSQLImplementation(SQLSourceImplementation[MSSQLSourceConfig, pymssql.Con# the schema to what came back instead of failing the Arrow build.read_schema = restrict_schema_to_columns(arrow_schema, column_names)- for rows in fetch_row_batches(- cursor.fetchmany, max_rows=chunk_size, byte_bounded=inputs.byte_bounded_extraction- ):+ for rows in fetch_row_batches(cursor.fetchmany, max_rows=chunk_size):yield table_from_iterator((dict(zip(column_names, row)) for row in rows),read_schema,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.pyindex 15cbf0073285..e60c66ec9767 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py@@ -1938,9 +1938,7 @@ class MySQLImplementation(SQLSourceImplementation[MySQLSourceConfig, pymysql.Con# the query actually returned instead of failing the batch build.read_schema = restrict_schema_to_columns(arrow_schema, column_names)- for batch in fetch_row_batches(- ss_cursor.fetchmany, max_rows=chunk_size, byte_bounded=inputs.byte_bounded_extraction- ):+ for batch in fetch_row_batches(ss_cursor.fetchmany, max_rows=chunk_size):yield table_from_iterator((dict(zip(column_names, row)) for row in batch),read_schema,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/partitioned_tables.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/partitioned_tables.pyindex 62e1f8c2040d..c90a530912f6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/partitioned_tables.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/partitioned_tables.py@@ -373,7 +373,6 @@ def iterate_date_windows(chunk_size: int,arrow_schema: pa.Schema,logger: FilteringBoundLogger,- byte_bounded: bool = False,fetch_rows: int | None = None,initial_window: timedelta | int | float | None = None,max_window_multiplier: int = 30,@@ -448,9 +447,7 @@ def iterate_date_windows(cur.execute(query)columns = [c.name for c in cur.description or []]window_schema = restrict_schema_to_columns(arrow_schema, columns)- for rows in fetch_row_batches(- cur.fetchmany, max_rows=chunk_size, byte_bounded=byte_bounded, max_page_rows=fetch_rows- ):+ for rows in fetch_row_batches(cur.fetchmany, max_rows=chunk_size, max_page_rows=fetch_rows):rows_this_window += len(rows)yield table_from_iterator((dict(zip(columns, r)) for r in rows),@@ -604,7 +601,6 @@ def iterate_partitions(chunk_size: int,arrow_schema: pa.Schema,logger: FilteringBoundLogger,- byte_bounded: bool = False,fetch_rows: int | None = None,incremental_field: Optional[str] = None,incremental_field_type: Optional[IncrementalFieldType] = None,@@ -646,9 +642,7 @@ def iterate_partitions(cur.execute(query)columns = [c.name for c in cur.description or []]partition_schema = restrict_schema_to_columns(arrow_schema, columns)- for rows in fetch_row_batches(- cur.fetchmany, max_rows=chunk_size, byte_bounded=byte_bounded, max_page_rows=fetch_rows- ):+ for rows in fetch_row_batches(cur.fetchmany, max_rows=chunk_size, max_page_rows=fetch_rows):rows_this_partition += len(rows)yield table_from_iterator((dict(zip(columns, r)) for r in rows),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.pyindex 35fb29fc55db..523e5fa0d832 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py@@ -2915,7 +2915,7 @@ def _size_sample_percent(row_estimate: int | None) -> float | None:def _get_table_chunk_size(- cursor: psycopg.Cursor, inner_query: sql.Composed, logger: FilteringBoundLogger, *, byte_bounded: bool = False+ cursor: psycopg.Cursor, inner_query: sql.Composed, logger: FilteringBoundLogger) -> _TableChunking:# Under autocommit each statement is its own transaction — a failure can't poison# subsequent commands, so no SAVEPOINT is needed. When called inside a shared@@ -2961,8 +2961,7 @@ def _get_table_chunk_size(# of pages that a small table usually misses entirely. Reading that as a one-byte row# derives a chunk of 150 million, and a chunk is what sizes the `FETCH` when no page cap# applies — so the read asks for the whole table in one page on exactly the tables whose- # row size is unknown. This stays off the gate: it is a defect in the arithmetic, not- # behavior worth preserving, and every other SQL source already floors this case.+ # row size is unknown. Every other SQL source floors this case the same way.row_size_bytes = row[0]if not row_size_bytes:logger.debug(f"_get_table_chunk_size: Nothing measured. Using DEFAULT_CHUNK_SIZE={DEFAULT_CHUNK_SIZE}")@@ -2983,9 +2982,8 @@ def _get_table_chunk_size(# The page cap sits fractionally below the chunk on any table whose p99 exceeds its p95,# which is most of them, so a bare comparison would report nearly every sync. An order of# magnitude is the point where the cap starts to matter: the read issues about ten times- # the `FETCH` calls per batch. Off the byte bound the caller ignores the cap and fetches the- # whole chunk, so reporting there would claim a cap that the read never applied.- if byte_bounded and chunking.fetch_rows * 10 <= chunking.batch_rows:+ # the `FETCH` calls per batch.+ if chunking.fetch_rows * 10 <= chunking.batch_rows:logger.info(measurements)else:logger.debug(measurements)@@ -3562,7 +3560,6 @@ def postgres_source(row_filters: Optional[list[ValidatedRowFilter]] = None,is_xmin: bool = False,xmin_cursor: Optional[SourceCursorManager[XminCursor]] = None,- byte_bounded_extraction: bool = False,activity_attempt: int = 1,resumable_source_manager: Optional[ResumableSourceManager[KeysetResumeState]] = None,) -> SourceResponse:@@ -3781,16 +3778,9 @@ def postgres_source()logger.debug(f"Using chunk_size_override: {chunk_size_override}")else:- chunking = _get_table_chunk_size(- cursor, inner_query_with_limit, logger, byte_bounded=byte_bounded_extraction- )+ chunking = _get_table_chunk_size(cursor, inner_query_with_limit, logger)chunk_size = chunking.batch_rows- # The page cap only exists to bound what one `FETCH` materialises, so- # it belongs behind the same gate as the byte bound it serves. Applied- # with the gate off it shrinks the fetch without ever flushing a batch:- # the read pays a round trip per page and still accumulates the whole- # table, which is worse than the single full-size fetch it replaced.- fetch_page_rows = chunking.fetch_rows if byte_bounded_extraction else None+ fetch_page_rows = chunking.fetch_rowslogger.debug("Getting rows to sync...")# For partitioned tables without an incremental cursor (initial@@ -4391,7 +4381,6 @@ def postgres_source(table_name=table_name,child_partitions=child_partitions,chunk_size=chunk_size,- byte_bounded=byte_bounded_extraction,fetch_rows=fetch_page_rows,arrow_schema=arrow_schema,logger=logger,@@ -4430,7 +4419,6 @@ def postgres_source(db_incremental_field_last_value=db_incremental_field_last_value,child_partitions=child_partitions,chunk_size=chunk_size,- byte_bounded=byte_bounded_extraction,fetch_rows=fetch_page_rows,arrow_schema=arrow_schema,logger=logger,@@ -4500,7 +4488,6 @@ def postgres_source(for rows in fetch_row_batches(cursor.fetchmany,max_rows=chunk_size,- byte_bounded=byte_bounded_extraction,max_page_rows=fetch_page_rows,):dicts = [dict(zip(column_names, row)) for row in rows]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex 34a6286987ac..8dd5ad478233 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -2039,7 +2039,6 @@ class PostgresSource(# Delta table before this read and a kept cursor would collapse it to one window.is_xmin=schema.is_xmin,xmin_cursor=self.get_cursor_manager(inputs) if schema.is_xmin else None,- byte_bounded_extraction=inputs.byte_bounded_extraction,activity_attempt=inputs.activity_attempt,resumable_source_manager=resumable_source_manager,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex 7154977f678b..770635a4f3de 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -7081,21 +7081,18 @@ class TestGetTableChunkSize:@parameterized.expand([- ("cap_binds_hard", True, 400.0, 3.0 * 1024 * 1024, "info"),- ("cap_at_exactly_ten_times", True, 1024.0, 10240, "info"),- ("cap_just_short_of_ten_times", True, 1024.0, 10239, "debug"),- ("cap_barely_moves", True, 400.0, 420.0, "debug"),- ("no_cap_at_all", True, 400.0, 400.0, "debug"),- ("cap_binds_but_byte_bound_off", False, 400.0, 3.0 * 1024 * 1024, "debug"),+ ("cap_binds_hard", 400.0, 3.0 * 1024 * 1024, "info"),+ ("cap_at_exactly_ten_times", 1024.0, 10240, "info"),+ ("cap_just_short_of_ten_times", 1024.0, 10239, "debug"),+ ("cap_barely_moves", 400.0, 420.0, "debug"),+ ("no_cap_at_all", 400.0, 400.0, "debug"),])- def test_the_probe_reports_at_info_only_when_an_applied_page_cap_binds(- self, _name, byte_bounded, p95, p99, expected_level- ):+ def test_the_probe_reports_at_info_only_when_the_page_cap_binds(self, _name, p95, p99, expected_level):cursor = self._ProbeCursor((p95, p99, int(p99)))logger = mock.Mock()- _get_table_chunk_size(cast(Any, cursor), sql.SQL("SELECT 1").format(), logger, byte_bounded=byte_bounded)+ _get_table_chunk_size(cast(Any, cursor), sql.SQL("SELECT 1").format(), logger)levels = [level@@ -8911,7 +8908,6 @@ def _run_windows(script, **overrides):"db_incremental_field_last_value": date(2026, 1, 1),"child_partitions": [],"chunk_size": 1000,- "byte_bounded": False,"arrow_schema": _arrow_schema(),"logger": structlog.get_logger(),"initial_window": timedelta(days=1),@@ -10111,7 +10107,6 @@ class TestExtractionByteBounds:script=[list(rows)],child_partitions=[self._child()],chunk_size=400,- byte_bounded=True,arrow_schema=self._schema(),)@@ -10122,21 +10117,6 @@ class TestExtractionByteBounds:oversized = [table.num_rows for table in tables if table_payload_bytes(table) > self.BUDGET]assert oversized == []- def test_gate_off_keeps_the_row_count_batching(self):- rows = [(i, self.BLOB) for i in range(400)]-- with patch.object(batching, "EXTRACT_BATCH_MAX_BYTES", self.BUDGET):- tables, factory = _run_windows(- script=[list(rows)],- child_partitions=[self._child()],- chunk_size=400,- byte_bounded=False,- arrow_schema=self._schema(),- )-- assert [table.num_rows for table in tables] == [400]- assert set(factory.fetch_sizes) == {400}-def test_fetch_pages_shrink_once_wide_rows_appear(self):rows = [(i, "s") for i in range(1000)] + [(i, self.BLOB) for i in range(1000, 2000)]@@ -10145,7 +10125,6 @@ class TestExtractionByteBounds:script=[list(rows)],child_partitions=[self._child()],chunk_size=100_000,- byte_bounded=True,arrow_schema=self._schema(),)@@ -10154,14 +10133,7 @@ class TestExtractionByteBounds:@pytest.mark.usefixtures("server_cursor_path")-class TestFetchPageGate:- """The page cap is the byte bound's own instrument, so the rollout gate has to hold it back too.-- Left applied with the gate off it shrinks the `FETCH` without ever flushing a batch: the read- pays a round trip per page and still accumulates the whole table into one batch, which is- strictly worse than the single full-size fetch it replaced.- """-+class TestFetchPageCap:class _Cursor:def __init__(self, *, named: bool, rows: list, fetch_sizes: list[int]):self._named = named@@ -10197,7 +10169,7 @@ class TestFetchPageGate:self._fetch_sizes = fetch_sizesdef cursor(self, *args, **kwargs):- return TestFetchPageGate._Cursor(named="name" in kwargs, rows=self._rows, fetch_sizes=self._fetch_sizes)+ return TestFetchPageCap._Cursor(named="name" in kwargs, rows=self._rows, fetch_sizes=self._fetch_sizes)def commit(self):return None@@ -10211,7 +10183,7 @@ class TestFetchPageGate:def __exit__(self, *args):return False- def _fetch_sizes(self, *, byte_bounded: bool) -> list[int]:+ def _fetch_sizes(self) -> list[int]:from contextlib import contextmanager@contextmanager@@ -10253,14 +10225,10 @@ class TestFetchPageGate:logger=structlog.get_logger(),db_incremental_field_last_value=None,team_id=1,- byte_bounded_extraction=byte_bounded,)list(cast(Iterable[Any], response.items()))return fetch_sizes- def test_gate_off_fetches_the_whole_chunk(self):- assert set(self._fetch_sizes(byte_bounded=False)) == {1000}-- def test_gate_on_fetches_the_measured_page(self):- assert max(self._fetch_sizes(byte_bounded=True)) == 7+ def test_a_read_fetches_the_measured_page(self):+ assert max(self._fetch_sizes()) == 7diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.pyindex 4b183a160455..929b1c253db3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/redshift.py@@ -705,7 +705,6 @@ def _stream_rows_as_arrow_batches(chunk_size: int,arrow_schema: pa.Schema,*,- byte_bounded: bool = False,primary_keys: list[str] | None = None,binary_reporter: BinaryColumnReporter | None = None,) -> Iterator[pa.Table]:@@ -725,9 +724,7 @@ def _stream_rows_as_arrow_batches(binary_reporter=binary_reporter,)- for rows in iter_row_batches(- cursor.stream(query, size=_libpq_rows_per_chunk()), max_rows=chunk_size, byte_bounded=byte_bounded- ):+ for rows in iter_row_batches(cursor.stream(query, size=_libpq_rows_per_chunk()), max_rows=chunk_size):if not column_names:# Only described once the first result arrives, so it can't be read before the loop.column_names = [column.name for column in cursor.description or []]@@ -740,7 +737,6 @@ def _fetch_arrow_batches(arrow_schema: pa.Schema,fetch_size: int | None = None,*,- byte_bounded: bool = False,primary_keys: list[str] | None = None,binary_reporter: BinaryColumnReporter | None = None,) -> Iterator[pa.Table]:@@ -762,9 +758,7 @@ def _fetch_arrow_batches(binary_reporter=binary_reporter,)- for rows in fetch_row_batches(- cursor.fetchmany, max_rows=chunk_size, byte_bounded=byte_bounded, max_page_rows=fetch_size or chunk_size- ):+ for rows in fetch_row_batches(cursor.fetchmany, max_rows=chunk_size, max_page_rows=fetch_size or chunk_size):yield to_arrow(rows)@@ -776,7 +770,6 @@ def _stream_arrow_batches(cursor_name: str,logger: FilteringBoundLogger,*,- byte_bounded: bool = False,primary_keys: list[str] | None = None,) -> Iterator[pa.Table]:"""Stream `query` as Arrow tables, holding only `chunk_size` rows in the worker at a time.@@ -809,7 +802,6 @@ def _stream_arrow_batches(query,chunk_size,arrow_schema,- byte_bounded=byte_bounded,primary_keys=primary_keys,binary_reporter=binary_reporter,):@@ -837,7 +829,6 @@ def _stream_arrow_batches(chunk_size,arrow_schema,fetch_size,- byte_bounded=byte_bounded,primary_keys=primary_keys,binary_reporter=binary_reporter,):@@ -2069,7 +2060,6 @@ class RedshiftImplementation(SQLSourceImplementation[RedshiftSourceConfig, psycoarrow_schema,f"posthog_{inputs.team_id}_{schema}.{table_name}",logger,- byte_bounded=inputs.byte_bounded_extraction,primary_keys=primary_keys,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py b/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.pyindex a55b24060889..dc5a03926f9b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py@@ -679,9 +679,7 @@ class TrinoImplementation(SQLSourceImplementation[TrinoSourceConfig, Any, Any],arrow_schema = restrict_schema_to_columns(read_plan.arrow_schema, column_names)converters = [read_plan.converters.get(name) for name in column_names]- for rows in fetch_row_batches(- cursor.fetchmany, max_rows=DEFAULT_CHUNK_SIZE, byte_bounded=inputs.byte_bounded_extraction- ):+ for rows in fetch_row_batches(cursor.fetchmany, max_rows=DEFAULT_CHUNK_SIZE):yield table_from_iterator((_row_to_dict(column_names, converters, row) for row in rows),arrow_schema,diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.pyindex b5f3e45a12c8..3edb82dec90e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py@@ -176,7 +176,6 @@ async def test_job_inputs_with_whitespace(activity_environment, team, **kwargs):row_filters=[],is_xmin=False,xmin_cursor=None,- byte_bounded_extraction=False,activity_attempt=1,resumable_source_manager=mock.ANY,)@@ -231,7 +230,6 @@ async def test_postgres_source_without_ssh_tunnel(activity_environment, team, **row_filters=[],is_xmin=False,xmin_cursor=None,- byte_bounded_extraction=False,activity_attempt=1,resumable_source_manager=mock.ANY,)@@ -298,7 +296,6 @@ async def test_postgres_source_with_ssh_tunnel_disabled(activity_environment, terow_filters=[],is_xmin=False,xmin_cursor=None,- byte_bounded_extraction=False,activity_attempt=1,resumable_source_manager=mock.ANY,)@@ -380,7 +377,6 @@ async def test_postgres_source_with_ssh_tunnel_enabled(activity_environment, tearow_filters=[],is_xmin=False,xmin_cursor=None,- byte_bounded_extraction=False,activity_attempt=1,resumable_source_manager=mock.ANY,)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.pyindex 40d53036163d..c43686ca1f80 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@@ -71,9 +71,6 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.basSourceExtractionNotImplementedError,error_message_matches,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.byte_bounded_extraction_flag import (- is_byte_bounded_extraction_enabled,-)from products.warehouse_sources.backend.temporal.data_imports.sources.common.cursor import (SourceCursorManager,build_cursor_manager,@@ -514,9 +511,6 @@ async def _import_data_with_reporting(inputs: ImportDataActivityInputs, logger:fanout_warehouse_reuse = await _warehouse_parent_reuse_available(new_source, schema, inputs.source_id, inputs.team_id, logger)- byte_bounded_extraction = await database_sync_to_async_pool(is_byte_bounded_extraction_enabled)(- inputs.team_id, str(source_type)- )# INFO so it's visible without DEBUG: confirms which parent-source path a fan-out# child took, and doubles as rollout-adoption telemetry. Only fan-out children# (schemas with required parents) log it; every other schema stays quiet.@@ -565,7 +559,6 @@ async def _import_data_with_reporting(inputs: ImportDataActivityInputs, logger:# A schema-level override (user-managed) wins over the source pin.api_version=new_source.resolve_api_version(schema.api_version or model.pipeline.api_version),fanout_warehouse_reuse=fanout_warehouse_reuse,- byte_bounded_extraction=byte_bounded_extraction,activity_attempt=activity.info().attempt if activity.in_activity() else 1,source_cursor=source_cursor_manager,)