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.

feat(schema): share dashboard auto-refresh interval via generated schema (#58003)

Paul D'Ambra99946d3fdff0
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 07f3b3c305a8..f390c89ace8d 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -11170,6 +11170,10 @@
"required": ["status", "proposalId", "toolName", "preview", "payload"],
"type": "object"
},
+ "DashboardAutoRefreshInterval": {
+ "const": 1800,
+ "type": "number"
+ },
"DashboardFilter": {
"additionalProperties": false,
"properties": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 72e02e6779ed..01f0ba8ef70a 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -5983,6 +5983,10 @@ export enum InfinityValue {
NEGATIVE_INFINITY_VALUE = -999999,
}
+export enum DashboardAutoRefreshInterval {
+ SECONDS = 1800,
+}
+
export type UsageMetricFormat = 'numeric' | 'currency'
export type UsageMetricDisplay = 'number' | 'sparkline'
diff --git a/frontend/src/scenes/dashboard/dashboardConstants.ts b/frontend/src/scenes/dashboard/dashboardConstants.ts
index 7c5527427b84..14a595767b89 100644
--- a/frontend/src/scenes/dashboard/dashboardConstants.ts
+++ b/frontend/src/scenes/dashboard/dashboardConstants.ts
@@ -1,4 +1,6 @@
-export const AUTO_REFRESH_INITIAL_INTERVAL_SECONDS = 1800
+import { DashboardAutoRefreshInterval } from '~/queries/schema/schema-general'
+
+export const AUTO_REFRESH_INITIAL_INTERVAL_SECONDS = DashboardAutoRefreshInterval.SECONDS
/**
* Cold-start one-shot threshold: if data is older than this when a shared dashboard loads,
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index ebe68589fa01..de1191dcec5d 100644
--- a/posthog/hogql_queries/query_runner.py
+++ b/posthog/hogql_queries/query_runner.py
@@ -18,6 +18,7 @@ from posthog.schema import (
CacheMissResponse,
CalendarHeatmapQuery,
ChartDisplayType,
+ DashboardAutoRefreshInterval,
DashboardFilter,
DateRange,
EndpointsUsageOverviewQuery,
@@ -194,10 +195,10 @@ def execution_mode_from_refresh(refresh_requested: bool | str | None) -> Executi
return ExecutionMode.CACHE_ONLY_NEVER_CALCULATE
-# Minimum age before a shared insight may honor `?refresh=force_blocking`. Must match the
-# frontend `AUTO_REFRESH_INITIAL_INTERVAL_SECONDS` (1800s) — drift would silently drop
-# periodic refresh ticks. Best-effort throttle, not a hard rate limit.
-SHARED_FORCE_BLOCKING_MIN_AGE = timedelta(minutes=30)
+# Minimum age before a shared insight may honor `?refresh=force_blocking`.
+# Sourced from the same generated schema as the frontend's auto-refresh interval so the
+# two cannot drift. Best-effort throttle, not a hard rate limit.
+SHARED_FORCE_BLOCKING_MIN_AGE = timedelta(seconds=DashboardAutoRefreshInterval().root)
_SHARED_MODE_WHITELIST = {
diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.py
index 74eaa3a7e752..7ed1cb0bb144 100644
--- a/posthog/hogql_queries/test/test_query_runner.py
+++ b/posthog/hogql_queries/test/test_query_runner.py
@@ -1,6 +1,4 @@
-import re
from datetime import UTC, datetime, timedelta
-from pathlib import Path
from typing import Any, Literal, Optional
from zoneinfo import ZoneInfo
@@ -43,7 +41,6 @@ from posthog.hogql.constants import LimitContext
from posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner
from posthog.hogql_queries.query_runner import (
- SHARED_FORCE_BLOCKING_MIN_AGE,
ExecutionMode,
QueryRunner,
get_query_runner,
@@ -1105,33 +1102,3 @@ class TestSharedInsightsExecutionMode(BaseTest):
last_refresh = None if last_refresh_offset is None else datetime.now(UTC) - last_refresh_offset
result = shared_insights_execution_mode(execution_mode, last_refresh=last_refresh)
self.assertEqual(result, expected_mode)
-
- def test_shared_force_blocking_min_age_matches_frontend_auto_refresh_interval(self) -> None:
- """Backend throttle must match frontend auto-refresh interval — drift would silently throttle periodic refreshes."""
- frontend_file = (
- Path(__file__).resolve().parents[3] / "frontend" / "src" / "scenes" / "dashboard" / "dashboardConstants.ts"
- )
- source = frontend_file.read_text()
-
- interval_match = re.search(
- r"export\s+const\s+AUTO_REFRESH_INITIAL_INTERVAL_SECONDS\s*=\s*(\d+)\s*",
- source,
- )
- assert interval_match, f"Could not find AUTO_REFRESH_INITIAL_INTERVAL_SECONDS in {frontend_file}"
- frontend_interval_minutes = int(interval_match.group(1)) // 60
-
- stale_match = re.search(
- r"export\s+const\s+SHARED_DASHBOARD_AUTO_FORCE_IF_STALE_MINUTES\s*=\s*AUTO_REFRESH_INITIAL_INTERVAL_SECONDS\s*/\s*60",
- source,
- )
- assert stale_match, (
- f"SHARED_DASHBOARD_AUTO_FORCE_IF_STALE_MINUTES must be derived from "
- f"AUTO_REFRESH_INITIAL_INTERVAL_SECONDS / 60 in {frontend_file}."
- )
-
- backend_minutes = int(SHARED_FORCE_BLOCKING_MIN_AGE.total_seconds() // 60)
- self.assertEqual(
- backend_minutes,
- frontend_interval_minutes,
- f"Backend ({backend_minutes}m) must equal frontend ({frontend_interval_minutes}m).",
- )
diff --git a/posthog/schema.py b/posthog/schema.py
index b7ab8e4a164d..f1879658586b 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -1287,6 +1287,10 @@ class DangerousOperationResponse(BaseModel):
toolName: str
+class DashboardAutoRefreshInterval(RootModel[Literal[1800]]):
+ root: Literal[1800] = 1800
+
+
class DataColorToken(StrEnum):
PRESET_1 = "preset-1"
PRESET_2 = "preset-2"