crbench//

← all cases

Raw query uses the HogQL table alias 'logs' instead of the physical 'logs_distributed'

Tier 2 hard python · local · real merged PR from PostHog/posthog #60356

Ground-truth defects

d1 · correctness · high
A new usage-report query runs raw `FROM logs` through sync_execute() on the logs cluster. HogQL resolves its `logs` table to the physical `logs_distributed` table, and production's logs cluster has no table named `logs`: the `logs` Distributed table that migration 0214 creates exists only in local and test schemas, which is why the PR's test passes. In production the query fails, and since the new query runs unconditionally it aborts the whole usage-report run that feeds billing (reverted the next day in #60611).

The change under review

diff (truncated — full diff)
diff --git a/posthog/tasks/test/__snapshots__/test_usage_report.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.ambr
index a9ddd52e5801..1152c2a2c94b 100644
--- a/posthog/tasks/test/__snapshots__/test_usage_report.ambr
+++ b/posthog/tasks/test/__snapshots__/test_usage_report.ambr
@@ -74,6 +74,19 @@
 # name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.13
   '''
   
+  SELECT team_id,
+         SUM(count) as count
+  FROM app_metrics2
+  WHERE app_source='logs'
+    AND metric_name='records_ingested'
+    AND timestamp >= '2022-01-10 00:00:00'
+    AND timestamp < '2022-01-10 23:59:59'
+  GROUP BY team_id
+  '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.14
+  '''
+  
   SELECT team_id,
          multiIf(replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python', 'unknown') AS library,
          count(1) as total
@@ -85,7 +98,7 @@
            library
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.14
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.15
   '''
   
   SELECT team_id,
@@ -97,7 +110,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.15
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.16
   '''
   
   SELECT team_id,
@@ -109,7 +122,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.16
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.17
   '''
   
   SELECT team_id,
@@ -121,7 +134,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.17
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.18
   '''
   
   SELECT team_id,
@@ -133,7 +146,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.18
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.19
   '''
   
   SELECT team_id,
@@ -145,18 +158,6 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.19
-  '''
-  
-  SELECT team_id,
-         count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
-  FROM events
-  WHERE timestamp >= '2022-01-10 10:00:00'
-    AND timestamp < '2022-01-10 12:00:00'
-    AND event NOT IN ['$feature_flag_called', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']
-  GROUP BY team_id
-  '''
-# ---
 # name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.2
   '''
   
@@ -174,6 +175,18 @@
 # name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.20
   '''
   
+  SELECT team_id,
+         count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+  FROM events
+  WHERE timestamp >= '2022-01-10 10:00:00'
+    AND timestamp < '2022-01-10 12:00:00'
+    AND event NOT IN ['$feature_flag_called', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']
+  GROUP BY team_id
+  '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.21
+  '''
+  
   SELECT team_id,
          count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
   FROM events
@@ -183,7 +196,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.21
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
   '''
   
   SELECT team_id,
@@ -195,7 +208,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.23
   '''
   
   SELECT team_id,
@@ -207,7 +220,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.23
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
   '''
   
   SELECT team_id,
@@ -219,7 +232,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
   '''
   
   SELECT team_id,
@@ -231,7 +244,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.26
   '''
   
   SELECT team_id,
@@ -243,7 +256,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.26
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.27
   '''
   
   SELECT team_id,
@@ -257,7 +270,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.27
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.28
   '''
   
   SELECT team_id,
@@ -271,7 +284,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.28
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.29
   '''
   
   SELECT team_id,
@@ -285,35 +298,35 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.29
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3
   '''
   
   SELECT team_id,
-         count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+         multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+         count(1) as count
   FROM events
   WHERE timestamp >= '2022-01-10 06:00:00'
     AND timestamp < '2022-01-10 08:00:00'
-    AND event NOT IN ['$feature_flag_called', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']
-    AND person_mode IN ('full',
-                        'force_upgrade')
-  GROUP BY team_id
+  GROUP BY team_id,
+           metric
+  HAVING metric != 'other'
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.30
   '''
   
   SELECT team_id,
-         multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
-         count(1) as count
+         count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
   FROM events
   WHERE timestamp >= '2022-01-10 06:00:00'
     AND timestamp < '2022-01-10 08:00:00'
-  GROUP BY team_id,
-           metric
-  HAVING metric != 'other'
+    AND event NOT IN ['$feature_flag_called', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']
+    AND person_mode IN ('full',
+                        'force_upgrade')
+  GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.30
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.31
   '''
   
   SELECT team_id,
@@ -327,7 +340,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.31
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.32
   '''
   
   SELECT team_id,
@@ -341,7 +354,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.32
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.33
   '''
   
   SELECT team_id,
@@ -355,7 +368,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.33
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.34
   '''
   
   SELECT team_id,
@@ -369,7 +382,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.34
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.35
   '''
   
   SELECT team_id,
@@ -383,7 +396,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.35
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.36
   '''
   
   SELECT team_id,
@@ -397,7 +410,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.36
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.37
   '''
   
   SELECT team_id,
@@ -411,7 +424,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.37
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.38
   '''
   
   SELECT team_id,
@@ -425,7 +438,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.38
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.39
   '''
   
   SELECT team_id,
@@ -441,7 +454,21 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.39
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
+  '''
+  
+  SELECT team_id,
+         multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+         count(1) as count
+  FROM events
+  WHERE timestamp >= '2022-01-10 08:00:00'
+    AND timestamp < '2022-01-10 10:00:00'
+  GROUP BY team_id,
+           metric
+  HAVING metric != 'other'
+  '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.40
   '''
   
   SELECT team_id,
@@ -464,21 +491,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
-  '''
-  
-  SELECT team_id,
-         multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
-         count(1) as count
-  FROM events
-  WHERE timestamp >= '2022-01-10 08:00:00'
-    AND timestamp < '2022-01-10 10:00:00'
-  GROUP BY team_id,
-           metric
-  HAVING metric != 'other'
-  '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.40
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.41
   '''
   
   SELECT team_id,
@@ -501,7 +514,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.41
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.42
   '''
   
   SELECT team_id,
@@ -525,7 +538,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.42
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.43
   '''
   
   SELECT team_id,
@@ -548,7 +561,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.43
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.44
   '''
   
   SELECT team_id,
@@ -572,7 +585,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.44
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.45
   '''
   
   SELECT team_id,
@@ -599,7 +612,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.45
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.46
   '''
   
   SELECT distinct_id as team,
@@ -613,7 +626,7 @@
   GROUP BY team
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.46
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.47
   '''
   
   SELECT distinct_id as team,
@@ -627,7 +640,7 @@
   GROUP BY team
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.47
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.48
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -644,7 +657,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.48
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.49
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -661,7 +674,21 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.49
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
+  '''
+  
+  SELECT team_id,
+         multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+         count(1) as count
+  FROM events
+  WHERE timestamp >= '2022-01-10 10:00:00'
+    AND timestamp < '2022-01-10 12:00:00'
+  GROUP BY team_id,
+           metric
+  HAVING metric != 'other'
+  '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.50
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -678,21 +705,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
-  '''
-  
-  SELECT team_id,
-         multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
-         count(1) as count
-  FROM events
-  WHERE timestamp >= '2022-01-10 10:00:00'
-    AND timestamp < '2022-01-10 12:00:00'
-  GROUP BY team_id,
-           metric
-  HAVING metric != 'other'
-  '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.50
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.51
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -709,7 +722,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.51
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.52
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -726,7 +739,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.52
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.53
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -743,7 +756,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.53
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.54
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,
@@ -761,7 +774,7 @@
   GROUP BY team_id
   '''
 # ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.54
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.55
   '''
   WITH JSONExtractInt(log_comment, 'team_id') as team_id,
        JSONExtractString(log_comment, 'query_type') as query_type,

Leaderboard for this case

hard · 0 of 9 bots fully caught it (0% solve rate) · 0% avg coverage.

#BotResultCaughtCoverageFindingsFalse alarms
1 Claude Code (Opus 5.5) miss 0/1 0.0% 3 0
2 cursor miss 0/1 0.0% 0 0
3 Drape (Review) miss 0/1 0.0% 3 0
4 greptile miss 0/1 0.0% 1 0
5 Mjolnir (Sonnet 5.5) miss 0/1 0.0% 0 0
6 qodo miss 0/1 0.0% 1 0
7 Cubic miss 0/1 0.0% 3 1
8 Drape (Deep Review) miss 0/1 0.0% 4 1
9 Mjolnir (Opus 5.5) miss 0/1 0.0% 2 1

Bot results

Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact medium
`_get_all_usage_data` now calls the new query against the logs cluster (`workload=Workload.LOGS`) with no try/except. The `@retry` decorator re-raises after 3 tries, so if the logs cluster fails, report generation fails for every org, billable counters included. Before this change the logs metrics came only from app_metrics2. [grounded: diff] [consensus 3/3: valid=3]
uncertain
Other `Workload.LOGS` queries in the repo (products/logs, products/tracing) also leave out `ch_user`, so dropping `ClickHouseUser.BILLING` here is likely deliberate for the logs cluster. The claim that the query will hit the scan-bytes limit or time out is speculative, and nothing shown confirms it. [uncertain: no evidence quoted] [consensus 3/4: uncertain=3, valid=1]
valid · impact low
The new Temporal spec wrapper re-runs the app_metrics2 records query that the separate `teams_with_logs_records_in_period` spec already runs. That is a real duplicate query and can see a different snapshot from the other run. The impact is small because the result is only used as a pre-filter. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
posthog/tasks/usage_report.py:1928
The billing usage report now depends on the Logs ClickHouse cluster. `get_teams_with_sdk_logs_records_in_period` runs an unguarded query against `logs` with `Workload.LOGS`, which connects to a separate cluster, and it runs early in `_get_all_usage_data`. The report only uses it for informational per-SDK counts. Even so, if that cluster is down, slow, or rejects the query after retries (for example by hitting the scan-bytes ceiling the docstring warns about), the exception aborts the whole usage report for every org, including billable counters. Before this change the report only read `app_metrics2` on the main cluster for logs. Non-billing per-SDK counts should be best-effort: catch the error and default to empty results.
posthog/tasks/usage_report.py:1766
This query does not set `ch_user=ClickHouseUser.BILLING`, which the other logs usage queries pass, and it puts every team_id that produced logs into one inline `IN` list. It then scans `resource_attributes['telemetry.sdk.name']` across all of those teams' rows for the full day. Pre-filtering by team_id does not cut much when most of the volume comes from teams that are already in the list, so on large days the query can still hit the scan-bytes limit or time out. Combined with the hard failure described above, that can block report generation.
posthog/temporal/usage_report/queries.py:191
`_sdk_logs_records` re-runs `get_teams_with_logs_records_in_period` inside its own spec, even though the `teams_with_logs_records_in_period` spec already runs that query. The app_metrics2 query therefore runs twice per Temporal report. The two runs can also see different snapshots, so the team pre-filter may not match the reported `logs_records_in_period`.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
The Temporal registry already runs the `teams_with_logs_records_in_period` spec. The new `_sdk_logs_records` runs the same app_metrics2 query again, so it executes twice per run. The query is fairly light, so calling it 'expensive' overstates the cost. [grounded: diff] [consensus 3/3: valid=3]
invalid
`has_non_zero_usage` already left out `logs_records_in_period` and `logs_bytes_in_period` before this change. The new SDK counters are a subset of logs records, so an org whose only usage is logs was already skipped. The change does not create or worsen this gap. [invalid: contradiction] [consensus 3/3: invalid=3]
minor · impact low
The canned sdk_logs payload is seeded but no test checks the resulting `*_logs_records_in_period` fields. This is a missing assertion, not a claim that the code behaves wrongly. [grounded: diff] [consensus 3/3: minor=3]
raw comments (4)
posthog/temporal/usage_report/queries.py:191
<!-- cubic:v=de0fb4cc-3d12-4de0-996b-3ff0904d4a23 --> <!-- cubic:review-run=47a8a08d-7a1a-55da-933b-fc7337c3af36 --> <!-- metadata:{"confidence":10} --> P2: Every Temporal usage-report run now executes the expensive logs-records aggregation twice. Combine the total and SDK results into one query activity, or pass the first query's team IDs/result into the SDK query instead of re-running it. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At posthog/temporal/usage_report/queries.py, line 191: <comment>Every Temporal usage-report run now executes the expensive logs-records aggregation twice. Combine the total and SDK results into one query activity, or pass the first query's team IDs/result into the SDK query instead of re-running it.</comment> <file context> @@ -179,6 +180,18 @@ def _exceptions_captured(begin: datetime, end: datetime) -> dict[str, list[list[ + path passes in). Returns rows keyed by SDK suffix, remapped to `all_data` keys by the + `multi_keys_mapping` below. + """ + team_ids_with_logs = [int(row[0]) for row in get_teams_with_logs_records_in_period(begin, end)] + return get_teams_with_sdk_logs_records_in_period(begin, end, team_ids_with_logs=team_ids_with_logs) + </file context> ``` </details>
posthog/tasks/usage_report.py:234
<!-- cubic:v=578ea6b9-7e17-44df-a59c-34f2fc9763f6 --> <!-- cubic:review-run=47a8a08d-7a1a-55da-933b-fc7337c3af36 --> <!-- metadata:{"confidence":7} --> P2: When an organization has only SDK-tagged log ingestion, these new counters remain nonzero but `has_non_zero_usage()` stays false, so `send_all_org_usage_reports()` skips the billing queue. Include log usage in the nonzero-usage predicate so SDK log counts reach billing. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At posthog/tasks/usage_report.py, line 234: <comment>When an organization has only SDK-tagged log ingestion, these new counters remain nonzero but `has_non_zero_usage()` stays false, so `send_all_org_usage_reports()` skips the billing queue. Include log usage in the nonzero-usage predicate so SDK log counts reach billing.</comment> <file context> @@ -229,6 +229,13 @@ class UsageReportCounters: logs_mb_in_period: int + # Per-SDK split of logs_records_in_period, which on its own has no SDK dimension. Keyed off the + # telemetry.sdk.name resource attribute each SDK sets on every record. See SDK_TELEMETRY_NAMES. + web_logs_records_in_period: int + ios_logs_records_in_period: int + react_native_logs_records_in_period: int </file context> ``` </details>
posthog/temporal/tests/usage_report/test_aggregate_activity.py:99
<!-- cubic:v=04e8091e-fead-42fd-97c1-23455ea1cc2a --> <!-- cubic:review-run=47a8a08d-7a1a-55da-933b-fc7337c3af36 --> <!-- metadata:{"confidence":6} --> P3: The seeded `sdk_logs_records` data is never asserted, so the new spec's fan-out into `teams_with_*_logs_records_in_period` is untested. Add assertions in `test_aggregate_writes_chunks_and_manifest` (e.g. `by_org[str(org_a.id)]["web_logs_records_in_period"] == 9`, `ios == 4`, and `by_org[str(org_b.id)]["react_native_logs_records_in_period"] == 6`) so a regression in `multi_keys_mapping` is caught, matching the pattern the test already uses for the other fan-outs. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At posthog/temporal/tests/usage_report/test_aggregate_activity.py, line 99: <comment>The seeded `sdk_logs_records` data is never asserted, so the new spec's fan-out into `teams_with_*_logs_records_in_period` is untested. Add assertions in `test_aggregate_writes_chunks_and_manifest` (e.g. `by_org[str(org_a.id)]["web_logs_records_in_period"] == 9`, `ios == 4`, and `by_org[str(org_b.id)]["react_native_logs_records_in_period"] == 6`) so a regression in `multi_keys_mapping` is caught, matching the pattern the test already uses for the other fan-outs.</comment> <file context> @@ -96,6 +96,14 @@ def _canned_query_payload(query_name: str, team_a_id: int, team_b_id: int, *extr } if query_name == "api_queries_metrics": return {"count": [(team_b_id, 100)], "read_bytes": [(team_b_id, 5_000_000)]} + if query_name == "sdk_logs_records": + return { + "web": [(team_a_id, 9)], </file context> ``` </details>
PR-level
<!-- cubic:review-summary:start --> **3 issues found** across 5 files <!-- cubic:review-summary:end --> <details> <summary>Prompt for AI agents (unresolved issues)</summary> ```text Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately. <file name="posthog/temporal/usage_report/queries.py"> <violation number="1" location="posthog/temporal/usage_report/queries.py:191"> P2: Every Temporal usage-report run now executes the expensive logs-records aggregation twice. Combine the total and SDK results into one query activity, or pass the first query's team IDs/result into the SDK query instead of re-running it.</violation> </file> <file name="posthog/tasks/usage_report.py"> <violation number="1" location="posthog/tasks/usage_report.py:234"> P2: When an organization has only SDK-tagged log ingestion, these new counters remain nonzero but `has_non_zero_usage()` stays false, so `send_all_org_usage_reports()` skips the billing queue. Include log usage in the nonzero-usage predicate so SDK log counts reach billing.</violation> </file> <file name="posthog/temporal/tests/usage_report/test_aggregate_activity.py"> <violation number="1" location="posthog/temporal/tests/usage_report/test_aggregate_activity.py:99"> P3: The seeded `sdk_logs_records` data is never asserted, so the new spec's fan-out into `teams_with_*_logs_records_in_period` is untested. Add assertions in `test_aggregate_writes_chunks_and_manifest` (e.g. `by_org[str(org_a.id)]["web_logs_records_in_period"] == 9`, `ios == 4`, and `by_org[str(org_b.id)]["react_native_logs_records_in_period"] == 6`) so a regression in `multi_keys_mapping` is caught, matching the pattern the test already uses for the other fan-outs.</violation> </file> ``` </details> <sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/68/ai_pr_review_github_delivery_6f7c8085da099c52a9506591707db65ddfd50087c416acdfad2bdb5e0c98645f?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F68)</sub> <!-- cubic:review-post:ai_pr_review_github_delivery_6f7c8085da099c52a9506591707db65ddfd50087c416acdfad2bdb5e0c98645f:680957064bbcf00f355769a78202d464bc151dc5:47a8a08d-7a1a-55da-933b-fc7337c3af36 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
The new Temporal wrapper re-runs the same app_metrics2 aggregation that the `teams_with_logs_records_in_period` spec already runs. That duplication is real, but it costs little because the app_metrics2 query is cheap. [grounded: diff] [consensus 3/3: valid=3]
valid · impact medium
The new query goes to the separate Logs cluster (`workload=Workload.LOGS`), and nothing catches its errors inside `_get_all_usage_data`. Once the retries are used up, any failure there aborts the whole billing report. That dependency is new in this change. [grounded: diff] [consensus 3/3: valid=3]
invalid
The logs table has a minmax skip index on `timestamp` with granularity 1. A `timestamp` range filter therefore does prune granules, so the claim that the query can't prune by time and scans other days does not hold. [invalid: contradiction] [consensus 3/4: invalid=3, valid=1]
valid · impact low
The per-SDK counts are bucketed by the log record's `timestamp`, while the total comes from app_metrics2 `records_ingested` bucketed by metric time. Late or backdated logs can therefore land in a different period from the total. This is plausible, but the impact is low because the per-SDK fields are informational. [grounded: diff] [consensus 3/4: valid=3, uncertain=1]
raw comments (4)
posthog/temporal/usage_report/queries.py:191
**Logs records query runs twice in Temporal path** `_sdk_logs_records` runs `get_teams_with_logs_records_in_period` again to get team ids, even though the `teams_with_logs_records_in_period` spec already runs that same app_metrics2 aggregation. Accept the duplication knowingly, or derive the team ids from a cheaper DISTINCT team_id query. ``` posthog/temporal/usage_report/queries.py:183 def _sdk_logs_records(begin: datetime, end: datetime) -> dict[str, list[tuple[int, int]]]: posthog/temporal/usage_report/queries.py:184 """Wrap `get_teams_with_sdk_logs_records_in_period` so the spec is self-contained. posthog/temporal/usage_report/queries.py:186 The underlying query needs the set of team_ids that produced any logs as a primary-key posthog/temporal/usage_report/queries.py:187 pre-filter; we derive it here from `get_teams_with_logs_records_in_period` (which the Celery posthog/temporal/usage_report/queries.py:449 QuerySpec( posthog/temporal/usage_report/queries.py:450 name="teams_with_logs_records_in_period", posthog/temporal/usage_report/queries.py:451 fn=get_teams_with_logs_records_in_period, posthog/temporal/usage_report/queries.py:452 ), posthog/tasks/usage_report.py:1711 def get_teams_with_logs_records_in_period( posthog/tasks/usage_report.py:1712 begin: datetime, ```
posthog/tasks/usage_report.py:1928
**Logs cluster failure now blocks billing usage report** The per-SDK breakdown scans raw `logs` on the separate Logs cluster, unguarded inside `_get_all_usage_data`. A timeout, scan-limit error or Logs outage now fails the whole billing report. Wrap the `get_teams_with_sdk_logs_records_in_period` call in try/except and fall back to empty lists. ``` posthog/tasks/usage_report.py:1926 logs_records_rows = get_teams_with_logs_records_in_period(period_start, period_end) posthog/tasks/usage_report.py:1927 team_ids_with_logs = [int(row[0]) for row in logs_records_rows] posthog/tasks/usage_report.py:1928 sdk_logs_by_suffix = get_teams_with_sdk_logs_records_in_period( posthog/tasks/usage_report.py:1929 period_start, period_end, team_ids_with_logs=team_ids_with_logs posthog/clickhouse/client/connection.py:203 if workload == Workload.LOGS: posthog/clickhouse/client/connection.py:204 return { posthog/clickhouse/client/connection.py:205 "host": settings.CLICKHOUSE_LOGS_CLUSTER_HOST, posthog/clickhouse/client/connection.py:206 "port": settings.CLICKHOUSE_LOGS_CLUSTER_PORT, posthog/clickhouse/client/connection.py:207 "database": settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE, posthog/clickhouse/client/connection.py:208 "user": settings.CLICKHOUSE_LOGS_CLUSTER_USER, ```
posthog/tasks/usage_report.py:1774
**Per-SDK logs query can't prune by time** It filters on `timestamp` only. The table key is (team_id, time_bucket, …) and it's partitioned by expiry, so the primary key can't skip other days. The team_id pre-filter covers nearly every logging team, so it barely helps. Add `time_bucket` bounds derived from begin/end. ``` posthog/tasks/usage_report.py:1766 """ posthog/tasks/usage_report.py:1767 SELECT posthog/tasks/usage_report.py:1768 team_id, posthog/tasks/usage_report.py:1769 resource_attributes['telemetry.sdk.name'] AS sdk_name, posthog/clickhouse/test/__snapshots__/test_schema.ambr:2669 `time_bucket` DateTime MATERIALIZED toStartOfDay(timestamp) CODEC(DoubleDelta, ZSTD(1)), posthog/clickhouse/test/__snapshots__/test_schema.ambr:2732 PARTITION BY toDate(original_expiry_timestamp) posthog/clickhouse/test/__snapshots__/test_schema.ambr:2733 PRIMARY KEY (team_id, time_bucket, service_name, resource_fingerprint, severity_text, timestamp) posthog/clickhouse/test/__snapshots__/test_schema.ambr:2734 ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, severity_text, timestamp) products/logs/backend/logs_query_runner.py:157 time_bucket >= toStartOfInterval({{date_from}},toIntervalMinute(10)) ```
posthog/tasks/usage_report.py:1774
**Per-SDK log counts don't match total records** The SDK split filters on the client-set log `timestamp`, while `logs_records_in_period` uses app_metrics2 ingestion time. Logs that arrive late or are backdated fall in a different period than the total. Filter on `observed_timestamp` (ingest time) so it matches the app_metrics2 totals. ``` posthog/tasks/usage_report.py:1772 WHERE team_id IN %(team_ids)s posthog/tasks/usage_report.py:1773 AND timestamp >= %(begin)s posthog/tasks/usage_report.py:1774 AND timestamp < %(end)s posthog/tasks/usage_report.py:1775 AND resource_attributes['telemetry.sdk.name'] IN %(sdk_names)s posthog/tasks/usage_report.py:1718 SELECT team_id, SUM(count) as count posthog/tasks/usage_report.py:1719 FROM app_metrics2 posthog/tasks/usage_report.py:1720 WHERE app_source='logs' AND metric_name='records_ingested' AND timestamp >= %(begin)s AND timestamp < %(end)s posthog/tasks/usage_report.py:1721 GROUP BY team_id ```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
The new `_sdk_logs_records` wrapper runs the app_metrics2 records query again, and the existing `teams_with_logs_records_in_period` spec also runs it in the same workflow. This is real but cheap duplicate work. [grounded: diff] [consensus 3/3: valid=3]
valid · impact medium
The change adds a new Logs-cluster query to `_get_all_usage_data` with no try/except around it. Its own docstring says this cluster has a scan-bytes ceiling. If the query still fails after retries, the exception propagates and the whole usage report fails, all for a non-billing breakdown metric. [grounded: diff] [consensus 3/3: valid=3]
valid · impact medium
execute.py decides kill-switch exemption from `ch_user`, regardless of workload, and Product.LOGS does not reset it to BILLING. The new query omits `ch_user=ClickHouseUser.BILLING`, so the kill-switch caps apply to it but not to its sibling billing queries. [grounded: tree posthog/clickhouse/client/execute.py] [consensus 3/3: valid=3]
raw comments (3)
posthog/temporal/usage_report/queries.py:191
**Logs records query runs twice in Temporal path** `_sdk_logs_records` calls `get_teams_with_logs_records_in_period` again, even though the `teams_with_logs_records_in_period` spec already runs the same app_metrics2 query in the same workflow. ``` posthog/temporal/usage_report/queries.py:183 def _sdk_logs_records(begin: datetime, end: datetime) -> dict[str, list[tuple[int, int]]]: posthog/temporal/usage_report/queries.py:184 """Wrap `get_teams_with_sdk_logs_records_in_period` so the spec is self-contained. posthog/temporal/usage_report/queries.py:186 The underlying query needs the set of team_ids that produced any logs as a primary-key posthog/temporal/usage_report/queries.py:187 pre-filter; we derive it here from `get_teams_with_logs_records_in_period` (which the Celery ```
posthog/tasks/usage_report.py:1926
**Logs-cluster failure now blocks the whole usage report** The new per-SDK query runs inside `_get_all_usage_data` on the Logs cluster, which its docstring says can hit a scan-bytes limit. If it fails after retries, the exception aborts the whole report. Catch the failure, capture the exception, and fall back to empty per-SDK rows. ``` posthog/tasks/usage_report.py:1926 logs_records_rows = get_teams_with_logs_records_in_period(period_start, period_end) posthog/tasks/usage_report.py:1927 team_ids_with_logs = [int(row[0]) for row in logs_records_rows] posthog/tasks/usage_report.py:1928 sdk_logs_by_suffix = get_teams_with_sdk_logs_records_in_period( posthog/tasks/usage_report.py:1929 period_start, period_end, team_ids_with_logs=team_ids_with_logs ```
posthog/tasks/usage_report.py:1784
**Kill switch can cap the new logs query** Without `ch_user=ClickHouseUser.BILLING`, this query is not exempt from the ClickHouse kill switch. When the kill switch is on, its execution time and bytes read get capped, so it can fail where the sibling billing queries don't. Pass `ch_user=ClickHouseUser.BILLING` like the other usage queries. ``` posthog/tasks/usage_report.py:1766 """ posthog/tasks/usage_report.py:1767 SELECT posthog/tasks/usage_report.py:1768 team_id, posthog/tasks/usage_report.py:1769 resource_attributes['telemetry.sdk.name'] AS sdk_name, ```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
In the Temporal path, `_sdk_logs_records` calls `get_teams_with_logs_records_in_period` again, even though the separate `teams_with_logs_records_in_period` QuerySpec already runs it. That is a redundant app_metrics2 aggregation, and the two independent runs can see different team sets. The Celery path reuses a single result. The effect is mostly extra load plus a small consistency window, so it is a real but minor issue. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
posthog/temporal/usage_report/queries.py:190
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Duplicate logs aggregation** The Temporal path now runs `get_teams_with_logs_records_in_period` once through its existing query spec and again here. This adds a redundant `app_metrics2` aggregation to every report. Because the two query specs run independently, they can also observe different team sets while logs are being ingested, so the per-SDK counters may not match the report's total log-record counters. Reusing one result would avoid the extra load and consistency window.
PR-level
<h3>Greptile Summary</h3> This PR adds per-SDK log-record usage counters for web and mobile SDKs across both the legacy and Temporal usage-report paths. - Queries log records by `telemetry.sdk.name` after prefiltering eligible teams. - Adds five counters to team, organization, and serialized usage reports. - Registers the SDK split as a Temporal multi-output query. - Adds focused usage-report and aggregation test coverage. <h3>Confidence Score: 4/5</h3> The PR appears safe to merge, with a non-blocking opportunity to avoid a redundant Temporal aggregation and its consistency window. Counter construction, aggregation, serialization, and multi-output handling are complete; the remaining concern is that the Temporal implementation independently executes the same prerequisite query twice. **Files Needing Attention:** posthog/temporal/usage_report/queries.py <details><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | posthog/tasks/usage_report.py | Adds SDK-name mapping, grouped log-record query, new counters, and legacy report integration. | | posthog/temporal/usage_report/queries.py | Registers the SDK log split as a multi-output query but redundantly reruns its prerequisite aggregation. | | posthog/tasks/test/test_usage_report.py | Adds integration coverage for supported SDK attribution and deliberate exclusions. | | posthog/temporal/tests/usage_report/test_aggregate_activity.py | Extends canned multi-output data and correctly models empty multi-query payloads. | | posthog/tasks/test/__snapshots__/test_usage_report.ambr | Updates SQL snapshots for the additional logs queries and resulting query ordering. | </details> <details open><summary><h3>Flowchart</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart LR A[app_metrics2 records_ingested] --> B[Eligible team IDs] B --> C[Query logs by telemetry.sdk.name] C --> D[Per-team SDK counters] D --> E[Organization aggregation] E --> F[Serialized usage report] ``` </details> <!-- greptile_other_comments_section --> <sub>Reviews (1): Last reviewed commit: ["Update posthog/tasks/test/\_\_snapshots\_\_/..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/f7b5b6185524bd46f0bc77cb3929da19adc3a85a) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64289014)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
invalid
The query does lack an explicit time_bucket bound. But logs32 has a granularity-1 minmax skip index on timestamp, so the timestamp predicates can still prune granules from other days. The claimed scan of each team's full retained history therefore doesn't follow. At most the pruning is a bit less efficient than going through the primary key. [invalid: contradiction] [consensus 3/5: invalid=3, valid=2]
valid · impact medium
The change adds a query on Workload.LOGS that runs inline in _get_all_usage_data, and in the Temporal path as a regular spec, with no fallback. If the Logs cluster fails after the retries, the whole usage report is aborted for every organization, including billable metrics unrelated to logs. Before this change the report had no Logs-cluster dependency. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
posthog/tasks/usage_report.py:1765
[P2] Per-SDK logs query doesn't prune by `time_bucket`, so the team pre-filter barely limits the scan · — `logs32` is sorted by `(team_id, time_bucket, …)`. `time_bucket` is a MATERIALIZED column, so ClickHouse can't work out a `time_bucket` range from the `timestamp ›= / ‹` bounds. The partitions are keyed on `original_expiry_timestamp`, so they don't help either. The only key pruning left is `team_id IN team_ids_with_logs`. That list is every team that ingested logs in the period, which in practice is nearly every team with rows in the table, so it removes little data. As written, the query can read `resource_attributes` across each such team's entire retained history instead of just the report day. This is exactly the scan-bytes/timeout risk the docstring says the pre-filter avoids. Other logs queries add an explicit `toStartOfDay(time_bucket)` range next to the per-row timestamp bounds for this reason (see `products/logs/backend/count_query_runner.py:47-50`). The impact goes beyond a slow query. In the Celery path, `get_teams_with_sdk_logs_records_in_period` now runs eagerly inside `_get_all_usage_data`, so if it times out or hits the Logs cluster limit after its retries, the whole billing usage report fails, not just these informational per-SDK counters
posthog/tasks/usage_report.py:1926
[P2] Logs cluster failures now abort the entire usage report This new query is the only usage-report query that runs on `Workload.LOGS`. That makes the Logs cluster a hard dependency of billing for the first time. It runs inline in `_get_all_usage_data`, and in the Temporal path as a regular `QuerySpec`. If the query still fails after its retries, the whole run fails and no organization's usage report is sent. That includes billable metrics that have nothing to do with logs. Two things can cause the failure: the Logs cluster being unavailable, or the query hitting the per-query scan-bytes ceiling the docstring mentions. The `team_ids_with_logs` pre-filter probably won't help much with that ceiling. It comes from `app_metrics2` `records_ingested`, which ingestion writes for essentially every team that has rows in `logs`, so the query still reads `resource_attributes` for a full day of every logging team's data. The per-SDK split is only an informational breakdown. It would be safer to degrade to empty results on failure, for example by catching the error and returning `{suffix: [] ...}`, rather than letting it block billing reports.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
The registry keeps the `teams_with_logs_records_in_period` QuerySpec, and the new `sdk_logs_records` spec calls `get_teams_with_logs_records_in_period` again. So the Temporal path runs the app_metrics2 records query twice per report, and a retry of the new activity runs it again. The duplication is real and this change added it. It is a small inefficiency on a cheap aggregate query, not a correctness bug. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
posthog/temporal/usage_report/queries.py:192
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> 1\. Usage reports repeat a billing query <code>🐞 Bug</code> <code>➹ Performance</code> <pre> <b><i>_sdk_logs_records</i></b> calls <b><i>get_teams_with_logs_records_in_period</i></b> even though the Temporal registry independently runs that same function for its own output. Every Temporal report therefore scans and aggregates the logs application metrics twice, and retries of the new activity repeat both that scan and the subsequent per-SDK query. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` ### Issue description The Temporal usage-report workflow executes `get_teams_with_logs_records_in_period` once through its existing query specification and again inside `_sdk_logs_records`. Refactor the integration so the per-SDK query derives its team-ID prefilter from the already-produced records result rather than repeating the ClickHouse query. ### Fix Focus Areas - posthog/temporal/usage_report/queries.py[183-192] - posthog/temporal/usage_report/queries.py[449-464] - posthog/temporal/usage_report/workflow.py[92-98] ### Recommended Fix Represent the aggregate records and per-SDK records as one dependent or multi-output operation, or pass the existing records result into the SDK query activity. Preserve both existing aggregation keys while ensuring `get_teams_with_logs_records_in_period` executes only once per workflow attempt. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
PR-level
<h3>PR Summary by Qodo</h3> Report log record usage by SDK <code>✨ Enhancement</code> <code>🧪 Tests</code> <code>🕐 20-40 Minutes</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <details> <summary>AI Description</summary> <dl> <dd> <br/> ><pre> >• Adds per-SDK log record counters for web and supported mobile SDKs. >• Prefilters log scans to active teams to respect ClickHouse scan limits. >• Integrates counters into Celery and Temporal reports with end-to-end coverage. ></pre> </dd> </dl> </details> <details> <summary>Diagram</summary> <dl> <dd> <br/> ```mermaid graph TD A[("App metrics")] -->|team IDs| B["Eligible teams"] --> D["SDK log query"] --> E["SDK buckets"] --> F["Celery aggregation"] --> H["Usage reports"] C[("Logs table")] -->|records| D E --> G["Temporal queries"] --> H ``` </dd> </dl> </details> <details> <summary>High-Level Assessment</summary> <dl> <dd> <br/> >The following are alternative approaches to this PR: <details> <summary><b>1. Pre-aggregate SDK ingestion metrics</b></summary> <dl> <dd> - ➕ Avoids scanning raw logs during each usage-report run - ➕ Removes dependence on an app-metrics eligibility prefilter - ➕ Scales with aggregate cardinality rather than record volume - ➖ Requires ingestion-pipeline and app_metrics2 schema changes - ➖ Needs migration or backfill planning for historical reports - ➖ Adds SDK-dimensional cardinality to ingestion metrics </dd> </dl> </details> >**Recommendation:** The PR&#x27;s prefiltered raw-log query is the best incremental approach because it reuses existing telemetry attributes and avoids ingestion changes while respecting scan limits. If report volume or query cost grows materially, recording SDK-dimensional counters during ingestion would be the stronger long-term design. </dd> </dl> </details> <details> <summary> Files changed (5) <code> +329 / -133 </code> </summary> <dl> <dd> <br/> <details> <summary>Enhancement (2) <code> +114 / -1 </code></summary> <dl> <dd> <details> <summary>usage_report.py<code>Aggregate log records by SDK</code> <code>+89/-1</code></summary> <br/> >Aggregate log records by SDK > ><pre> >• Adds five SDK-specific log counters and queries the logs table by telemetry SDK name. The query is restricted to teams with aggregate log ingestion, then its results are incorporated into team and organization reports. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/65/files#diff-87e14b80cf403a45c1161ddcaed987b1addafdaeb20500d6979321495f74db10'>posthog/tasks/usage_report.py</a> </details> <details> <summary>queries.py<code>Register per-SDK logs query for Temporal</code> <code>+25/-0</code></summary> <br/> >Register per-SDK logs query for Temporal > ><pre> >• Wraps the SDK query with its required active-team lookup and registers it as a multi-output query. Each SDK bucket maps to the same flat usage-data keys produced by the Celery path. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/65/files#diff-725c2355e18ba5b53bba26f5cd1857a768a5fc65f5ebaa8d4ca88905c62b3192'>posthog/temporal/usage_report/queries.py</a> </details> </dd> </dl> </details> <details> <summary>Tests (3) <code> +215 / -132 </code></summary> <dl> <dd> <details> <summary>test_usage_report.ambr<code>Refresh usage-report SQL snapshots</code> <code>+131/-131</code></summary> <br/> >Refresh usage-report SQL snapshots > ><pre> >• Adds the logs-record eligibility query to captured SQL and renumbers affected snapshots. The regenerated expectations also reflect the reordered event and logs metric queries. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/65/files#diff-8aa5e862e4f0bcebb0bd680759bf812fbd785acb9804cc6a38f3b751ff0f7e52'>posthog/tasks/test/__snapshots__/test_usage_report.ambr</a> </details> <details> <summary>test_usage_report.py<code>Test per-SDK log usage reporting</code> <code>+74/-0</code></summary> <br/> >Test per-SDK log usage reporting > ><pre> >• Creates log fixtures with web, mobile, server, and missing SDK attributes. Verifies organization and team counters include supported client SDKs while excluding server, unattributed, and ineligible-team records. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/65/files#diff-5c8e377f5e38e74c2a76a02ef8ee62a0d29aed05b1bfb3ddc0d4d31ae4014f4d'>posthog/tasks/test/test_usage_report.py</a> </details> <details> <summary>test_aggregate_activity.py<code>Cover Temporal multi-output SDK metrics</code> <code>+10/-1</code></summary> <br/> >Cover Temporal multi-output SDK metrics > ><pre> >• Adds canned per-SDK log results to aggregation tests. Empty query fixtures now distinguish multi-output dictionaries from single-output row lists. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/65/files#diff-fe13d9343536be2cb6b17b9a52812f90ed3c1731126b1a7cbd6f0432bd320bfa'>posthog/temporal/tests/usage_report/test_aggregate_activity.py</a> </details> </dd> </dl> </details> </dd> </dl> </details>
PR-level
<h3>Code Review by Qodo</h3> <code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <br/> <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> <details> <summary> 1. Usage reports repeat a billing query <code>🐞 Bug</code> <code>➹ Performance</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>_sdk_logs_records</i></b> calls <b><i>get_teams_with_logs_records_in_period</i></b> even though the Temporal registry >independently runs that same function for its own output. Every Temporal report therefore scans and >aggregates the logs application metrics twice, and retries of the new activity repeat both that scan >and the subsequent per-SDK query. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[posthog/temporal/usage_report/queries.py[R191-192]](https://github.com/drape-io/crbench-qodo-2026-09/pull/65/files#diff-725c2355e18ba5b53bba26f5cd1857a768a5fc65f5ebaa8d4ca88905c62b3192R191-R192)</code> > >```diff >+ team_ids_with_logs = [int(row[0]) for row in get_teams_with_logs_records_in_period(begin, end)] >+ return get_teams_with_sdk_logs_records_in_period(begin, end, team_ids_with_logs=team_ids_with_logs) >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >The new wrapper explicitly invokes the records query before invoking the SDK query, while a separate >registered specification invokes the records query independently. The workflow executes every >registered specification, and each activity can be attempted three times; by contrast, the Celery >path stores the records rows and reuses them to derive the SDK prefilter. ></pre> > > <code>[posthog/temporal/usage_report/queries.py[183-192]](https://github.com/drape-io/crbench-qodo-2026-09/blob/6cba123380db82fef8909a6be338d9f1d1113f50/posthog/temporal/usage_report/queries.py/#L183-L192)</code> > <code>[posthog/temporal/usage_report/queries.py[449-464]](https://github.com/drape-io/crbench-qodo-2026-09/blob/6cba123380db82fef8909a6be338d9f1d1113f50/posthog/temporal/usage_report/queries.py/#L449-L464)</code> > <code>[posthog/temporal/usage_report/workflow.py[92-98]](https://github.com/drape-io/crbench-qodo-2026-09/blob/6cba123380db82fef8909a6be338d9f1d1113f50/posthog/temporal/usage_report/workflow.py/#L92-L98)</code> > <code>[posthog/temporal/usage_report/workflow.py[157-167]](https://github.com/drape-io/crbench-qodo-2026-09/blob/6cba123380db82fef8909a6be338d9f1d1113f50/posthog/temporal/usage_report/workflow.py/#L157-L167)</code> > <code>[posthog/tasks/usage_report.py[1926-1930]](https://github.com/drape-io/crbench-qodo-2026-09/blob/6cba123380db82fef8909a6be338d9f1d1113f50/posthog/tasks/usage_report.py/#L1926-L1930)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >### Issue description >The Temporal usage-report workflow executes `get_teams_with_logs_records_in_period` once through its existing query specification and again inside `_sdk_logs_records`. Refactor the integration so the per-SDK query derives its team-ID prefilter from the already-produced records result rather than repeating the ClickHouse query. > >### Fix Focus Areas >- posthog/temporal/usage_report/queries.py[183-192] >- posthog/temporal/usage_report/queries.py[449-464] >- posthog/temporal/usage_report/workflow.py[92-98] > >### Recommended Fix >Represent the aggregate records and per-SDK records as one dependent or multi-output operation, or pass the existing records result into the SDK query activity. Preserve both existing aggregation keys while ensuring `get_teams_with_logs_records_in_period` executes only once per workflow attempt. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-context:start --> <details><summary><strong>Context sources</strong></summary> <div>Review mode: <code>🧠 Deep</code>: This changes production usage-report and Temporal query logic across multiple independent paths, including ClickHouse aggregation, SDK classification, data shaping, and tests, creating a high density of subtle correctness risks.</div> <!-- qodo-context:end --> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:start --> <details> <summary><strong>Tip of the day</strong></summary> <br/> <pre>💡 Did you know, you can reply &#x27;qodo&#x27; on any finding to push back, ask questions, or dig deeper</pre> <a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:end --> <!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/6cba123380db82fef8909a6be338d9f1d1113f50 --> <a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>