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: execute queries sync when viewed shared notebook (#57722)

Reece Jones397eea87d82f
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index 3222452b7617..ebe68589fa01 100644
--- a/posthog/hogql_queries/query_runner.py
+++ b/posthog/hogql_queries/query_runner.py
@@ -206,6 +206,10 @@ _SHARED_MODE_WHITELIST = {
# when the throttle clock is younger than `SHARED_FORCE_BLOCKING_MIN_AGE`.
ExecutionMode.CALCULATE_BLOCKING_ALWAYS: ExecutionMode.CALCULATE_BLOCKING_ALWAYS,
ExecutionMode.RECENT_CACHE_CALCULATE_ASYNC_IF_STALE: ExecutionMode.RECENT_CACHE_CALCULATE_ASYNC_IF_STALE,
+ # Used by the shared-notebook inline query payload builder. Without this entry the
+ # request silently falls through to EXTENDED_CACHE_CALCULATE_ASYNC_IF_STALE, which causes
+ # the frontend to incorrectly render a "unsupported node" placeholder until the async calc finishes and a later reload picks up the warm cache.
+ ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALE: ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALE,
}
diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.py
index 4c481e6ab56f..74eaa3a7e752 100644
--- a/posthog/hogql_queries/test/test_query_runner.py
+++ b/posthog/hogql_queries/test/test_query_runner.py
@@ -1084,10 +1084,14 @@ class TestSharedInsightsExecutionMode(BaseTest):
ExecutionMode.RECENT_CACHE_CALCULATE_ASYNC_IF_STALE,
),
(
- "unlisted_blocking_if_stale_falls_back_to_extended_async",
+ "blocking_if_stale_passes_through",
+ # Used by the shared-notebook inline query payload builder. Must pass through so
+ # cold-cache loads block and return real results — falling back to async would
+ # ship a CacheMissResponse to the frontend, which renders the "unsupported node"
+ # placeholder until a later reload picks up the warmed cache.
ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALE,
None,
- ExecutionMode.EXTENDED_CACHE_CALCULATE_ASYNC_IF_STALE,
+ ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALE,
),
]
)
diff --git a/products/notebooks/backend/test/test_sharing.py b/products/notebooks/backend/test/test_sharing.py
index dcdd056e7b6c..e06ccb522358 100644
--- a/products/notebooks/backend/test/test_sharing.py
+++ b/products/notebooks/backend/test/test_sharing.py
@@ -403,10 +403,16 @@ class TestNotebookSharingGrantsInsightAccess(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)
body = response.json()
self.assertIn("inline_query_results", body)
- # Even on an empty events table the runner returns a response shape; key presence is
- # the contract we're locking in here.
self.assertIn("inline-node-1", body["inline_query_results"])
- self.assertIsInstance(body["inline_query_results"]["inline-node-1"], dict)
+ inline_result = body["inline_query_results"]["inline-node-1"]
+ self.assertIsInstance(inline_result, dict)
+ # Must be a real query response, not a CacheMissResponse — otherwise the frontend
+ # renders an empty `<Query cachedResults={...} inSharedMode />`, throws, and the
+ # SharedNodeErrorBoundary swaps in the "unsupported node" placeholder. This is the
+ # bug that made inline insights appear broken on the first shared-notebook view and
+ # "fix themselves" after a few reloads (once the async cache finished warming).
+ self.assertIn("results", inline_result)
+ self.assertFalse(inline_result.get("error"))
def test_shared_notebook_payload_inlines_referenced_insights(self) -> None:
"""The shared notebook payload pre-serializes every referenced saved insight so the