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(mux): keep the aggregate window within Mux's standard retention (#87530)

Tom Owersdcbbdf9eaa4f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mux/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mux/settings.py
index 7d643151ccc8..839a3b908963 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mux/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mux/settings.py
@@ -8,11 +8,12 @@ from products.warehouse_sources.backend.types import IncrementalField, Increment
# retention than aggregates and the list endpoint isn't a bulk export, so we start modest; subsequent
# syncs track the `view_end` watermark forward from here.
VIDEO_VIEWS_INITIAL_LOOKBACK = timedelta(days=30)
-# Window for the full-refresh aggregate endpoints (errors, metric comparison). Mux Data retains
-# engagement/QoE metrics for ~13 months, so this pulls essentially everything Mux keeps; Mux clamps
-# the window to what's actually retained rather than erroring. The responses are small and replaced
-# each sync, so a wide window is cheap.
-AGGREGATE_LOOKBACK = timedelta(days=395)
+# Window for the full-refresh aggregate endpoints (errors, metric comparison). Mux Data's standard
+# retention for these metrics is 100 days; 13-month retention is a paid add-on not every account has.
+# A window past the account's retention is rejected with `400 invalid_timeframe` rather than clamped,
+# so stay within the 100-day floor every plan supports. The responses are small and replaced each
+# sync, so a wide window is cheap.
+AGGREGATE_LOOKBACK = timedelta(days=90)
@dataclass
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mux/tests/test_mux.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mux/tests/test_mux.py
index f61a76aaff8c..25dc4a3fa52d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mux/tests/test_mux.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mux/tests/test_mux.py
@@ -1,6 +1,6 @@
import json
from collections.abc import Iterable
-from datetime import UTC, datetime
+from datetime import UTC, datetime, timedelta
from typing import Any, cast
import pytest
@@ -373,8 +373,9 @@ class TestTimeframeParams:
assert abs((end - start) - int(VIDEO_VIEWS_INITIAL_LOOKBACK.total_seconds())) <= 5
def test_full_refresh_aggregate_uses_wide_lookback(self) -> None:
- # Aggregate endpoints ignore any watermark and window by the wide (~13 month) retention lookback,
- # so a sync summarizes essentially all the history Mux keeps rather than a trailing month.
+ # Aggregate endpoints ignore any watermark and window by the aggregate retention lookback, which
+ # stays within Mux's standard 100-day retention so the request isn't rejected as an invalid
+ # timeframe on accounts without the 13-month add-on.
params = _timeframe_params(
MUX_ENDPOINTS["errors"],
should_use_incremental_field=False,
@@ -383,6 +384,12 @@ class TestTimeframeParams:
start, end = params["timeframe[]"]
assert abs((end - start) - int(AGGREGATE_LOOKBACK.total_seconds())) <= 5
+ def test_aggregate_lookback_stays_within_standard_retention(self) -> None:
+ # A window past the account's retention is rejected with `400 invalid_timeframe`, not clamped.
+ # Mux's standard retention floor is 100 days, so the aggregate lookback must not exceed it —
+ # this guards against widening it back toward the 13-month add-on window every plan doesn't have.
+ assert AGGREGATE_LOOKBACK <= timedelta(days=100)
+
class TestMuxDataEndpoints:
@mock.patch(CLIENT_SESSION_PATCH)