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(insights): return the resolved comparison range on saved insights (#125050)

Phil Haack520c64b38376
diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py
index 9d179770f743..1b7f87ccdb23 100644
--- a/posthog/api/test/dashboards/test_dashboard.py
+++ b/posthog/api/test/dashboards/test_dashboard.py
@@ -4045,6 +4045,7 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
},
},
"resolved_date_range": ANY,
+ "resolved_compare_date_range": None,
"action_names": None,
"query_status": None,
"query_scan": None,
diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.py
index b9976f88a795..d662e8218993 100644
--- a/posthog/api/test/test_sharing.py
+++ b/posthog/api/test/test_sharing.py
@@ -101,6 +101,15 @@ def mock_exporter_template(test_func):
return wrapper
+def _exported_data(response: HttpResponse) -> dict:
+ html = response.content.decode()
+ marker = '<script id="posthog-exported-data" type="application/json">'
+ start = html.index(marker) + len(marker)
+ end = html.index("</script>", start)
+ encoded_data = json.loads(html[start:end])
+ return json.loads(encoded_data) if isinstance(encoded_data, str) else encoded_data
+
+
@parameterized.expand(
[
["http://localhost:8000/something", "http://localhost:8000/something.png"],
@@ -1599,6 +1608,8 @@ class TestExportCacheKeyFlow(APIBaseTest):
"results": [{"count": 42, "note": marker}],
"last_refresh": "2024-01-01T00:00:00Z",
"timezone": "UTC",
+ "resolved_date_range": {"date_from": "2023-12-25T00:00:00Z", "date_to": "2023-12-31T23:59:59Z"},
+ "resolved_compare_date_range": {"date_from": "2023-12-18T00:00:00Z", "date_to": "2023-12-24T23:59:59Z"},
}
mock_query_cache_cls.return_value.lookup.return_value.entry = mock_entry
@@ -1646,6 +1657,16 @@ class TestExportCacheKeyFlow(APIBaseTest):
assert response.status_code == 200
assert b"warmed-by-the-exporter" in response.content
+ exported_insight = _exported_data(response)["insight"]
+ assert exported_insight["is_cached"] is True
+ assert exported_insight["resolved_date_range"] == {
+ "date_from": "2023-12-25T00:00:00Z",
+ "date_to": "2023-12-31T23:59:59Z",
+ }
+ assert exported_insight["resolved_compare_date_range"] == {
+ "date_from": "2023-12-18T00:00:00Z",
+ "date_to": "2023-12-24T23:59:59Z",
+ }
mock_query_cache_cls.assert_called_once_with(team_id=self.insight.team_id, cache_key=cache_key)
mock_calculate.assert_not_called()
@@ -1773,15 +1794,6 @@ class TestSharedAdhocQueryExport(APIBaseTest):
class TestExportRendererTokenFlow(APIBaseTest):
- @staticmethod
- def _exported_data(response: HttpResponse) -> dict:
- html = response.content.decode()
- marker = '<script id="posthog-exported-data" type="application/json">'
- start = html.index(marker) + len(marker)
- end = html.index("</script>", start)
- encoded_data = json.loads(html[start:end])
- return json.loads(encoded_data) if isinstance(encoded_data, str) else encoded_data
-
@parameterized.expand(
[
("exact", "https://example.com", "url_exact", "https://example.com"),
@@ -1822,7 +1834,7 @@ class TestExportRendererTokenFlow(APIBaseTest):
response = self.client.get(f"/exporter?token={get_render_access_token(asset)}")
assert response.status_code == status.HTTP_200_OK
- renderer_token = self._exported_data(response)["exportToken"]
+ renderer_token = _exported_data(response)["exportToken"]
claims = decode_jwt(renderer_token, PosthogJwtAudience.EXPORT_RENDERER)
assert claims["id"] == self.user.id
assert claims["team_id"] == self.team.id
diff --git a/posthog/caching/calculate_results.py b/posthog/caching/calculate_results.py
index d36311df39bd..20283726e620 100644
--- a/posthog/caching/calculate_results.py
+++ b/posthog/caching/calculate_results.py
@@ -181,25 +181,4 @@ def calculate_for_query_based_insight(
response = process_response
assert isinstance(response, dict)
- return InsightResult(
- # Translating `QueryResponse` to legacy insights shape
- # The response may not be conformant with that, hence these are all `.get()`s
- result=response.get("results"),
- has_more=response.get("hasMore"),
- columns=response.get("columns"),
- last_refresh=response.get("last_refresh"),
- cache_key=response.get("cache_key"),
- is_cached=response.get("is_cached", False),
- timezone=response.get("timezone"),
- next_allowed_client_refresh=response.get("next_allowed_client_refresh"),
- cache_target_age=response.get("cache_target_age"),
- timings=response.get("timings"),
- query_status=response.get("query_status"),
- hogql=response.get("hogql"),
- types=response.get("types"),
- resolved_date_range=response.get("resolved_date_range"),
- resolved_compare_date_range=response.get("resolved_compare_date_range"),
- action_names=response.get("action_names"),
- query_scan=response.get("query_scan"),
- warnings=response.get("warnings"),
- )
+ return InsightResult.from_response_dict(response)
diff --git a/posthog/caching/insight_result.py b/posthog/caching/insight_result.py
index d7b6f73bf52e..dc32f2e3e6d7 100644
--- a/posthog/caching/insight_result.py
+++ b/posthog/caching/insight_result.py
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from datetime import datetime
-from typing import Any, Optional
+from typing import Any, Optional, Self
from posthog.schema import QueryTiming
@@ -28,6 +28,31 @@ class InsightResult:
query_scan: Optional[dict] = None
warnings: Optional[list] = None
+ @classmethod
+ def from_response_dict(cls, response: dict[str, Any]) -> Self:
+ return cls(
+ # Translating `QueryResponse` to legacy insights shape
+ # The response may not be conformant with that, hence these are all `.get()`s
+ result=response.get("results"),
+ has_more=response.get("hasMore"),
+ columns=response.get("columns"),
+ last_refresh=response.get("last_refresh"),
+ cache_key=response.get("cache_key"),
+ is_cached=response.get("is_cached", False),
+ timezone=response.get("timezone"),
+ next_allowed_client_refresh=response.get("next_allowed_client_refresh"),
+ cache_target_age=response.get("cache_target_age"),
+ timings=response.get("timings"),
+ query_status=response.get("query_status"),
+ hogql=response.get("hogql"),
+ types=response.get("types"),
+ resolved_date_range=response.get("resolved_date_range"),
+ resolved_compare_date_range=response.get("resolved_compare_date_range"),
+ action_names=response.get("action_names"),
+ query_scan=response.get("query_scan"),
+ warnings=response.get("warnings"),
+ )
+
@dataclass(frozen=True)
class NothingInCacheResult(InsightResult):
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index 2dea1d52e17a..12fbbd1270a7 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -9928,6 +9928,7 @@ export interface InsightFilterOverrideContextApi {
}
/**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
* @nullable
*/
export type InsightApiResolvedDateRange = {
@@ -9935,6 +9936,15 @@ export type InsightApiResolvedDateRange = {
readonly date_to?: string
} | null
+/**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+export type InsightApiResolvedCompareDateRange = {
+ readonly date_from?: string
+ readonly date_to?: string
+} | null
+
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -10038,8 +10048,16 @@ export interface InsightApi {
readonly hogql: string | null
/** @nullable */
readonly types: readonly unknown[] | null
- /** @nullable */
+ /**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
+ * @nullable
+ */
readonly resolved_date_range: InsightApiResolvedDateRange
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ readonly resolved_compare_date_range: InsightApiResolvedCompareDateRange
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
diff --git a/products/dashboards/mcp/tools.yaml b/products/dashboards/mcp/tools.yaml
index adcf6f89d99a..ae765d727637 100644
--- a/products/dashboards/mcp/tools.yaml
+++ b/products/dashboards/mcp/tools.yaml
@@ -95,6 +95,7 @@ tools:
- tiles.*.insight.last_viewed_at
- tiles.*.insight.timezone
- tiles.*.insight.resolved_date_range
+ - tiles.*.insight.resolved_compare_date_range
- tiles.*.insight.filter_override_context
- created_by.uuid
- created_by.distinct_id
@@ -253,6 +254,7 @@ tools:
- tiles.*.insight.alerts
- tiles.*.insight.timezone
- tiles.*.insight.resolved_date_range
+ - tiles.*.insight.resolved_compare_date_range
- tiles.*.insight.filter_override_context
- created_by.uuid
- created_by.distinct_id
@@ -518,6 +520,7 @@ tools:
- tiles.*.insight.alerts
- tiles.*.insight.timezone
- tiles.*.insight.resolved_date_range
+ - tiles.*.insight.resolved_compare_date_range
- tiles.*.insight.filter_override_context
- created_by.uuid
- created_by.distinct_id
diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.ts
index e5269d3062e1..1868977b28a4 100644
--- a/products/desktop/packages/api-client/src/generated.ts
+++ b/products/desktop/packages/api-client/src/generated.ts
@@ -16362,10 +16362,20 @@ export namespace Schemas {
query_status: unknown;
hogql: string | null;
types: Array<unknown> | null;
+ /**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
+ */
resolved_date_range: Partial<{
date_from: string;
date_to: string;
}> | null;
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ */
+ resolved_compare_date_range: Partial<{
+ date_from: string;
+ date_to: string;
+ }> | null;
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
*/
@@ -19619,6 +19629,10 @@ export namespace Schemas {
date_from: string;
date_to: string;
}> | null;
+ resolved_compare_date_range: Partial<{
+ date_from: string;
+ date_to: string;
+ }> | null;
action_names: Record<string, string> | null;
query_scan: unknown;
warnings: _InsightResultWarnings | null;
diff --git a/products/product_analytics/backend/presentation/insight.py b/products/product_analytics/backend/presentation/insight.py
index cae24ded6ed2..bea1258dfb85 100644
--- a/products/product_analytics/backend/presentation/insight.py
+++ b/products/product_analytics/backend/presentation/insight.py
@@ -1,5 +1,6 @@
import json
import builtins
+import dataclasses
from collections import defaultdict
from collections.abc import Sequence
from copy import deepcopy
@@ -555,6 +556,16 @@ class _InsightResultWarnings(RootModel):
root: list[DataWarehouseSyncWarning | AccessControlFilterWarning]
+RESOLVED_DATE_RANGE_SCHEMA = {
+ "type": "object",
+ "nullable": True,
+ "properties": {
+ "date_from": {"type": "string", "format": "date-time"},
+ "date_to": {"type": "string", "format": "date-time"},
+ },
+}
+
+
@extend_schema_serializer(deprecate_fields=["dashboards"])
class InsightSerializer(InsightBasicSerializer):
result = serializers.SerializerMethodField()
@@ -606,7 +617,6 @@ class InsightSerializer(InsightBasicSerializer):
query_status = serializers.SerializerMethodField()
hogql = serializers.SerializerMethodField()
types = serializers.SerializerMethodField()
- resolved_date_range = serializers.SerializerMethodField(read_only=True)
action_names = serializers.SerializerMethodField(
read_only=True,
help_text="The name of each action the insight's series reference, keyed by action id. A series saved without "
@@ -668,6 +678,7 @@ class InsightSerializer(InsightBasicSerializer):
"hogql",
"types",
"resolved_date_range",
+ "resolved_compare_date_range",
"action_names",
"query_scan",
"warnings",
@@ -1117,16 +1128,7 @@ class InsightSerializer(InsightBasicSerializer):
def get_types(self, insight: Insight):
return self.insight_result(insight).types
- @extend_schema_field(
- {
- "type": "object",
- "nullable": True,
- "properties": {
- "date_from": {"type": "string", "format": "date-time"},
- "date_to": {"type": "string", "format": "date-time"},
- },
- }
- )
+ @extend_schema_field(RESOLVED_DATE_RANGE_SCHEMA)
def get_resolved_date_range(self, insight: Insight):
return self.insight_result(insight).resolved_date_range
@@ -1134,6 +1136,25 @@ class InsightSerializer(InsightBasicSerializer):
def get_action_names(self, insight: Insight):
return self.insight_result(insight).action_names
+ resolved_date_range = serializers.SerializerMethodField(
+ read_only=True,
+ help_text=(
+ "The period that this insight's query covered, with both ends resolved to timestamps."
+ " Null when the insight has no result yet or its query type does not report the range."
+ ),
+ )
+ resolved_compare_date_range = serializers.SerializerMethodField(
+ read_only=True,
+ help_text=(
+ "The earlier period that this insight's query compared against, with both ends resolved to timestamps."
+ " Null when comparison is off, when the insight has no result yet, or when its query type does not report the range."
+ ),
+ )
+
+ @extend_schema_field(RESOLVED_DATE_RANGE_SCHEMA)
+ def get_resolved_compare_date_range(self, insight: Insight):
+ return self.insight_result(insight).resolved_compare_date_range
+
@extend_schema_field(OpenApiTypes.ANY)
def get_query_scan(self, insight: Insight):
# A shared insight is read from outside the project, and the scan describes the
@@ -1323,23 +1344,11 @@ class InsightSerializer(InsightBasicSerializer):
# An entry cached before responses carried `action_names` lacks the field, and this shortcut
# skips the runner that fills it on a cache hit.
action_names = get_response_action_names(insight.team, upgrade(deepcopy(insight.query)))
- return InsightResult(
- result=cached_response.get("results"),
- has_more=cached_response.get("hasMore"),
- columns=cached_response.get("columns"),
- last_refresh=cached_response.get("last_refresh"),
+ return dataclasses.replace(
+ InsightResult.from_response_dict(cached_response),
cache_key=expected_cache_key,
is_cached=True,
- timezone=cached_response.get("timezone"),
- next_allowed_client_refresh=cached_response.get("next_allowed_client_refresh"),
- cache_target_age=cached_response.get("cache_target_age"),
- timings=cached_response.get("timings"),
- query_status=cached_response.get("query_status"),
- hogql=cached_response.get("hogql"),
- types=cached_response.get("types"),
action_names=action_names,
- query_scan=cached_response.get("query_scan"),
- warnings=cached_response.get("warnings"),
)
else:
EXPORT_QUERY_CACHE_MISS.inc()
diff --git a/products/product_analytics/backend/tests/api/test_insight.py b/products/product_analytics/backend/tests/api/test_insight.py
index b623149cd8dd..640007fbdd42 100644
--- a/products/product_analytics/backend/tests/api/test_insight.py
+++ b/products/product_analytics/backend/tests/api/test_insight.py
@@ -3283,7 +3283,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
self.maxDiff = None
assert activity == expected
- def test_insight_returns_cached_hogql(self) -> None:
+ def test_insight_returns_cached_query_response_fields(self) -> None:
insight = Insight.objects.create(
query={
"kind": NodeKind.INSIGHT_VIZ_NODE.value,
@@ -3299,6 +3299,8 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
}
],
"interval": "day",
+ "dateRange": {"date_from": "-7d"},
+ "compareFilter": {"compare": True},
},
},
team=self.team,
@@ -3315,14 +3317,20 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
self.assertNotIn("code", response) # Watching out for an error code
self.assertEqual(response["results"][0]["last_refresh"], None)
self.assertIsNone(response["results"][0]["hogql"])
+ self.assertIsNone(response["results"][0]["resolved_compare_date_range"])
- response = self.client.get(
- f"/api/projects/{self.team.id}/insights",
- data={"short_id": insight.short_id, "refresh": "true"},
- ).json()
+ with time_machine.travel("2012-01-15T04:01:34Z", tick=False):
+ response = self.client.get(
+ f"/api/projects/{self.team.id}/insights",
+ data={"short_id": insight.short_id, "refresh": "true"},
+ ).json()
self.assertNotIn("code", response)
self.assertIsNotNone(response["results"][0]["hogql"])
+ self.assertEqual(
+ response["results"][0]["resolved_compare_date_range"],
+ {"date_from": "2012-01-01T00:00:00Z", "date_to": "2012-01-08T23:59:59.999999Z"},
+ )
def test_insight_returns_cached_types(self) -> None:
insight = Insight.objects.create(
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index c83fa87d707d..f6170dc4f378 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -8858,6 +8858,7 @@ export const SearchMatchTypeEnumApi = {
} as const
/**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
* @nullable
*/
export type InsightApiResolvedDateRange = {
@@ -8865,6 +8866,15 @@ export type InsightApiResolvedDateRange = {
readonly date_to?: string
} | null
+/**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+export type InsightApiResolvedCompareDateRange = {
+ readonly date_from?: string
+ readonly date_to?: string
+} | null
+
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -8968,8 +8978,16 @@ export interface InsightApi {
readonly hogql: string | null
/** @nullable */
readonly types: readonly unknown[] | null
- /** @nullable */
+ /**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
+ * @nullable
+ */
readonly resolved_date_range: InsightApiResolvedDateRange
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ readonly resolved_compare_date_range: InsightApiResolvedCompareDateRange
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -8999,6 +9017,7 @@ export interface PaginatedInsightListApi {
}
/**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
* @nullable
*/
export type PatchedInsightApiResolvedDateRange = {
@@ -9006,6 +9025,15 @@ export type PatchedInsightApiResolvedDateRange = {
readonly date_to?: string
} | null
+/**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+export type PatchedInsightApiResolvedCompareDateRange = {
+ readonly date_from?: string
+ readonly date_to?: string
+} | null
+
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -9109,8 +9137,16 @@ export interface PatchedInsightApi {
readonly hogql?: string | null
/** @nullable */
readonly types?: readonly unknown[] | null
- /** @nullable */
+ /**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
+ * @nullable
+ */
readonly resolved_date_range?: PatchedInsightApiResolvedDateRange
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ readonly resolved_compare_date_range?: PatchedInsightApiResolvedCompareDateRange
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 96b5121414f3..e88c9d5d98c7 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -11266,6 +11266,7 @@ export namespace Schemas {
} as const;
/**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
* @nullable
*/
export type InsightResolvedDateRange = {
@@ -11273,6 +11274,15 @@ export namespace Schemas {
readonly date_to?: string;
} | null;
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ export type InsightResolvedCompareDateRange = {
+ readonly date_from?: string;
+ readonly date_to?: string;
+ } | null;
+
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -11376,8 +11386,16 @@ export namespace Schemas {
readonly hogql: string | null;
/** @nullable */
readonly types: readonly unknown[] | null;
- /** @nullable */
+ /**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
+ * @nullable
+ */
readonly resolved_date_range: InsightResolvedDateRange;
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ readonly resolved_compare_date_range: InsightResolvedCompareDateRange;
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -88856,6 +88874,7 @@ export namespace Schemas {
}
/**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
* @nullable
*/
export type PatchedInsightResolvedDateRange = {
@@ -88863,6 +88882,15 @@ export namespace Schemas {
readonly date_to?: string;
} | null;
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ export type PatchedInsightResolvedCompareDateRange = {
+ readonly date_from?: string;
+ readonly date_to?: string;
+ } | null;
+
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
@@ -88966,8 +88994,16 @@ export namespace Schemas {
readonly hogql?: string | null;
/** @nullable */
readonly types?: readonly unknown[] | null;
- /** @nullable */
+ /**
+ * The period that this insight's query covered, with both ends resolved to timestamps. Null when the insight has no result yet or its query type does not report the range.
+ * @nullable
+ */
readonly resolved_date_range?: PatchedInsightResolvedDateRange;
+ /**
+ * The earlier period that this insight's query compared against, with both ends resolved to timestamps. Null when comparison is off, when the insight has no result yet, or when its query type does not report the range.
+ * @nullable
+ */
+ readonly resolved_compare_date_range?: PatchedInsightResolvedCompareDateRange;
/**
* The name of each action the insight's series reference, keyed by action id. A series saved without a name displays this name.
* @nullable
diff --git a/services/mcp/src/tools/generated/dashboards.ts b/services/mcp/src/tools/generated/dashboards.ts
index b2dd84aa23dc..40171d89b913 100644
--- a/services/mcp/src/tools/generated/dashboards.ts
+++ b/services/mcp/src/tools/generated/dashboards.ts
@@ -115,6 +115,7 @@ const dashboardCreate = (): ToolBase<
'tiles.*.insight.last_viewed_at',
'tiles.*.insight.timezone',
'tiles.*.insight.resolved_date_range',
+ 'tiles.*.insight.resolved_compare_date_range',
'tiles.*.insight.filter_override_context',
'created_by.uuid',
'created_by.distinct_id',
@@ -294,6 +295,7 @@ const dashboardGet = (): ToolBase<
'tiles.*.insight.alerts',
'tiles.*.insight.timezone',
'tiles.*.insight.resolved_date_range',
+ 'tiles.*.insight.resolved_compare_date_range',
'tiles.*.insight.filter_override_context',
'created_by.uuid',
'created_by.distinct_id',
@@ -675,6 +677,7 @@ const dashboardUpdate = (): ToolBase<
'tiles.*.insight.alerts',
'tiles.*.insight.timezone',
'tiles.*.insight.resolved_date_range',
+ 'tiles.*.insight.resolved_compare_date_range',
'tiles.*.insight.filter_override_context',
'created_by.uuid',
'created_by.distinct_id',
diff --git a/services/mcp/tests/tools/dashboards.integration.test.ts b/services/mcp/tests/tools/dashboards.integration.test.ts
index 55da39eca0e2..4ff76f5cab55 100644
--- a/services/mcp/tests/tools/dashboards.integration.test.ts
+++ b/services/mcp/tests/tools/dashboards.integration.test.ts
@@ -278,6 +278,7 @@ describe('Dashboards', { concurrent: false }, () => {
'alerts',
'timezone',
'resolved_date_range',
+ 'resolved_compare_date_range',
] as const
async function createDashboardWithInsight(namePrefix: string): Promise<{ dashboardId: number }> {