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.

fix(managed-warehouse): give registration workers 32Gi (#92102)

James Greenhill5092bdf9a68d
diff --git a/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py b/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py
index b9b212f2e05a..4f68075c2fcb 100644
--- a/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py
+++ b/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py
@@ -76,7 +76,17 @@ _DUCKGRES_CANCEL_MARGIN = dt.timedelta(minutes=1)
_DUCKGRES_CANCEL_MAX_ATTEMPTS = 10
_DUCKGRES_CANCEL_RETRY_SECONDS = 0.5
_DUCKGRES_CANCEL_TIMEOUT_SECONDS = 5.0
-_DUCKGRES_REGISTER_WORKER_OPTIONS = "-c duckgres.worker_cpu=4 -c duckgres.worker_memory=16Gi"
+# Registration materializes a whole import generation through
+# `CREATE TABLE ... AS SELECT * FROM read_parquet(<glob>)`, so peak memory
+# tracks the generation's parquet size, not the batch size. A duckgres worker
+# is also reused across the sequential sessions one registration run opens, and
+# DuckDB does not release buffer-pool pages back to the OS between them, so the
+# pod's RSS ratchets toward its DuckDB memory_limit plus the allocations that
+# limit does not govern (Arrow batches, libpq buffers, the Go runtime). At 16Gi
+# that left too little margin and the worker was OOM-killed mid-registration,
+# which surfaces to the client as a lost connection. Keep CPU low -- this is an
+# IO-bound scan -- but leave memory room to absorb a large generation.
+_DUCKGRES_REGISTER_WORKER_OPTIONS = "-c duckgres.worker_cpu=4 -c duckgres.worker_memory=32Gi"
# Duckgres cancel fires one minute before this deadline. One attempt: a
# StartToClose timeout has an unknown catalog outcome, so a retry could race
# the original CALL.
diff --git a/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py b/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py
index 81334d4415c3..2c57b92adf50 100644
--- a/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py
+++ b/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py
@@ -1,3 +1,4 @@
+import re
import uuid
import datetime as dt
import contextlib
@@ -244,7 +245,7 @@ def test_copy_activity_uses_s3_copy_and_local_duckgres_postgres_connection(monke
connect.assert_called_once_with(
"postgresql://duckgres",
autocommit=True,
- options="-c duckgres.worker_cpu=4 -c duckgres.worker_memory=16Gi",
+ options="-c duckgres.worker_cpu=4 -c duckgres.worker_memory=32Gi",
)
assert s3.copy_calls == [
(
@@ -350,7 +351,7 @@ def test_production_register_connection_requests_right_sized_duckgres_worker(
password="example-password",
autocommit=True,
application_name="ducklake-register",
- options="-c duckgres.worker_cpu=4 -c duckgres.worker_memory=16Gi",
+ options="-c duckgres.worker_cpu=4 -c duckgres.worker_memory=32Gi",
)
@@ -1176,6 +1177,24 @@ def _mock_activity_workload_metrics(monkeypatch):
return metrics
+def test_register_worker_memory_stays_above_the_oom_floor() -> None:
+ """Registration workers must keep enough memory to materialize a generation.
+
+ The exact-string assertions elsewhere in this module pin whatever value is
+ configured; they pass just as happily on a value too small to run. This
+ pins the floor instead. Registration reads a whole generation through
+ read_parquet, and a duckgres worker's RSS ratchets across the sequential
+ sessions one run opens, so dropping this below 32Gi reintroduces the
+ OOM-kill that shows up as a lost connection mid-registration.
+ """
+ options = registration_module._DUCKGRES_REGISTER_WORKER_OPTIONS
+ match = re.search(r"duckgres\.worker_memory=(\d+)Gi", options)
+ assert match is not None, f"worker_memory must be set in Gi: {options!r}"
+ assert int(match.group(1)) >= 32, (
+ f"registration worker memory is {match.group(1)}Gi, below the 32Gi floor: {options!r}"
+ )
+
+
def _activity_inputs() -> DuckLakeRegisterDataImportsActivityInputs:
return DuckLakeRegisterDataImportsActivityInputs(
team_id=1,