: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(experiments): use the `query_to` date as the signal for last refresh instead of `completed_at`. (#64451)
Rodrigo Iloro35ba2196679f
diff --git a/frontend/src/scenes/experiments/experimentMetricsLogic.test.ts b/frontend/src/scenes/experiments/experimentMetricsLogic.test.tsindex c98972fb1c0e..cdf0893dc3c0 100644--- a/frontend/src/scenes/experiments/experimentMetricsLogic.test.ts+++ b/frontend/src/scenes/experiments/experimentMetricsLogic.test.ts@@ -40,6 +40,7 @@ const baseRecalculation = {created_at: '2026-06-10T00:00:00Z',started_at: null,completed_at: null,+ query_to: null,is_existing: false,results: [],}@@ -52,6 +53,7 @@ const completedRecalculation = {started_at: new Date().toISOString(),// Fresh by default (within the 24h window) so tests using this fixture don't auto-trigger.completed_at: new Date().toISOString(),+ query_to: '2026-06-10T00:05:00Z',results: [{ metric_uuid: PRIMARY_METRIC_UUID, status: 'completed', result: primaryResult, error_message: null },{ metric_uuid: SECONDARY_METRIC_UUID, status: 'completed', result: secondaryResult, error_message: null },@@ -388,8 +390,7 @@ describe('experimentMetricsLogic', () => {expect(logic.values.recalculationProgress).toEqual({ completed: 2, total: 2 })expect(logic.values.isRecalculating).toBe(false)- // lastRefresh comes from the completed run's completion time.- expect(logic.values.lastRefresh).toEqual(completedRecalculation.completed_at)+ expect(logic.values.lastRefresh).toEqual(completedRecalculation.query_to)})it('defaults progress to zeroes and lastRefresh to null when there is no recalculation', () => {diff --git a/frontend/src/scenes/experiments/experimentMetricsLogic.ts b/frontend/src/scenes/experiments/experimentMetricsLogic.tsindex e5edbb4cd8d1..45f48d154df1 100644--- a/frontend/src/scenes/experiments/experimentMetricsLogic.ts+++ b/frontend/src/scenes/experiments/experimentMetricsLogic.ts@@ -193,7 +193,7 @@ export const experimentMetricsLogic = kea<experimentMetricsLogicType>([total: recalc?.total_metrics ?? 0,}),],- lastRefresh: [(s) => [s.currentRecalculation], (recalc): string | null => recalc?.completed_at ?? null],+ lastRefresh: [(s) => [s.currentRecalculation], (recalc): string | null => recalc?.query_to ?? null],}),listeners(({ actions, values, props, cache }) => {const flagEnabled = (): boolean => !!values.featureFlags[FEATURE_FLAGS.EXPERIMENTS_METRICS_RECALCULATION]diff --git a/products/experiments/backend/models/experiment.py b/products/experiments/backend/models/experiment.pyindex e2f1b75a44f6..de6dfa89dcb3 100644--- a/products/experiments/backend/models/experiment.py+++ b/products/experiments/backend/models/experiment.py@@ -382,9 +382,9 @@ class ExperimentMetricsRecalculation(TeamScopedRootMixin, UUIDModel):# Internal: written by the discovery activity, used by the service to recompute recalc fingerprints. Not exposed by the API serializer.metric_uuids = models.JSONField(default=list)- # Internal: single data-window end shared by all metrics in the run. Set once when the run starts; every metric+ # Single data-window end shared by all metrics in the run. Set once when the run starts; every metric# (including retries) uses this value so all metrics cover the same window and retries overwrite rather than- # orphan rows. Not exposed by the API serializer.+ # orphan rows. Exposed by the API serializer as the data freshness cutoff for the run's results.query_to = models.DateTimeField(null=True, blank=True)trigger = models.CharField(max_length=30, choices=Trigger, default=Trigger.MANUAL)diff --git a/products/experiments/backend/presentation/serializers.py b/products/experiments/backend/presentation/serializers.pyindex e9eac97ba44b..62a9357ec354 100644--- a/products/experiments/backend/presentation/serializers.py+++ b/products/experiments/backend/presentation/serializers.py@@ -737,6 +737,14 @@ class ExperimentMetricsRecalculationSerializer(serializers.Serializer):created_at = serializers.DateTimeField(read_only=True, help_text="When the job was created")started_at = serializers.DateTimeField(read_only=True, allow_null=True, help_text="When processing started")completed_at = serializers.DateTimeField(read_only=True, allow_null=True, help_text="When processing completed")+ query_to = serializers.DateTimeField(+ read_only=True,+ allow_null=True,+ help_text=(+ "Upper time bound the metrics in this run were calculated against (the data freshness cutoff). "+ "Shared by every metric in the run; null until processing starts"+ ),+ )is_existing = serializers.BooleanField(read_only=True, required=False, help_text="True if returning an existing job rather than a newly created one")diff --git a/products/experiments/backend/recalculation.py b/products/experiments/backend/recalculation.pyindex 0e9e7246e7f6..e5d85e98e3c4 100644--- a/products/experiments/backend/recalculation.py+++ b/products/experiments/backend/recalculation.py@@ -104,6 +104,7 @@ def build_job_payload("created_at": recalc.created_at,"started_at": recalc.started_at,"completed_at": recalc.completed_at,+ "query_to": recalc.query_to,}if is_existing is not None:payload["is_existing"] = is_existingdiff --git a/products/experiments/backend/test/test_metrics_recalculation_serializer.py b/products/experiments/backend/test/test_metrics_recalculation_serializer.pyindex aa7da7c83865..6364b22e2b65 100644--- a/products/experiments/backend/test/test_metrics_recalculation_serializer.py+++ b/products/experiments/backend/test/test_metrics_recalculation_serializer.py@@ -25,6 +25,7 @@ class TestExperimentMetricsRecalculationSerializer(BaseTest):"created_at": "2026-05-28T10:00:00Z","started_at": "2026-05-28T10:00:01Z","completed_at": None,+ "query_to": "2026-05-28T10:00:01Z",}data = ExperimentMetricsRecalculationSerializer(payload).dataassert data["status"] == "in_progress"@@ -32,6 +33,7 @@ class TestExperimentMetricsRecalculationSerializer(BaseTest):assert data["experiment_id"] == 7assert data["trigger"] == "manual"assert data["completed_at"] is None+ assert data["query_to"] == "2026-05-28T10:00:01Z"# Field is metric_errors (not errors) to avoid shadowing DRF's Serializer.errors property.assert data["metric_errors"] == {"m1": {"step": "calculation", "message": "boom"}}assert "errors" not in datadiff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.tsindex c4eb6562c437..745912d4d2e7 100644--- a/products/experiments/frontend/generated/api.schemas.ts+++ b/products/experiments/frontend/generated/api.schemas.ts@@ -897,6 +897,11 @@ export interface ExperimentMetricsRecalculationApi {* @nullable*/readonly completed_at: string | null+ /**+ * Upper time bound the metrics in this run were calculated against (the data freshness cutoff). Shared by every metric in the run; null until processing starts+ * @nullable+ */+ readonly query_to: string | null/** True if returning an existing job rather than a newly created one */readonly is_existing: boolean/** Per-metric results computed by this run, scoped by the run's recalc fingerprint */diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex d48b2a603881..65bc8df6d412 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -20403,6 +20403,11 @@ export namespace Schemas {* @nullable*/readonly completed_at: string | null;+ /**+ * Upper time bound the metrics in this run were calculated against (the data freshness cutoff). Shared by every metric in the run; null until processing starts+ * @nullable+ */+ readonly query_to: string | null;/** True if returning an existing job rather than a newly created one */readonly is_existing: boolean;/** Per-metric results computed by this run, scoped by the run's recalc fingerprint */