Repository navigation
perf(mcp-analytics): build the activity overview database once per request - #124269
Conversation
…quest get_activity_overview runs five HogQL queries in parallel threads, and each one built its own HogQL database. Traces show that build at about 220 ms per query, more than most of the ClickHouse work, and the threads compete for the GIL. Build one database and share it across the five queries, behind the existing shared-database kill switch. Generated-By: PostHog Desktop Task-Id: 92fc31f1-8930-45dc-8176-0be023916660
|
😎 Merged successfully - details. |
🤖 CI report
|
| File | Patch | Uncovered changed lines |
|---|---|---|
products/mcp_analytics/backend/logic.py |
91.7% | 677 |
🤖 Agents: add a test only if an uncovered line exposes a realistic regression that existing tests miss. Otherwise explain why no new test is needed under "How did you test this code?". Gap list: the patch-coverage artifact on this run (gh run download 353353773637798 -n patch-coverage), or the coverage-data block at the end of this comment.
Per-product line coverage (touched products)
| Product | Coverage | Lines |
|---|---|---|
platform_features |
██░░░░░░░░░░░░░░░░░░ 12.1% |
7 / 58 |
demo |
███████████░░░░░░░░░ 56.4% |
1,542 / 2,736 |
data_tools |
████████████░░░░░░░░ 60.9% |
95 / 156 |
warehouse_sources_queue |
█████████████░░░░░░░ 65.2% |
2,161 / 3,314 |
authorization |
████████████████░░░░ 79.7% |
181 / 227 |
batch_exports |
████████████████░░░░ 81.6% |
22,900 / 28,059 |
engineering_analytics |
█████████████████░░░ 85.0% |
11,463 / 13,482 |
commands |
█████████████████░░░ 85.5% |
1,618 / 1,893 |
mcp_analytics |
█████████████████░░░ 86.2% |
5,732 / 6,651 |
ml_inference |
█████████████████░░░ 86.3% |
524 / 607 |
apm |
█████████████████░░░ 86.6% |
1,616 / 1,866 |
posthog_ai |
██████████████████░░ 87.9% |
4,296 / 4,886 |
notebooks |
██████████████████░░ 88.5% |
15,330 / 17,321 |
dashboards |
██████████████████░░ 88.6% |
7,800 / 8,800 |
mcp_registry |
██████████████████░░ 89.0% |
1,596 / 1,794 |
warehouse_suggestions |
██████████████████░░ 89.2% |
3,275 / 3,672 |
webmcp |
██████████████████░░ 89.3% |
292 / 327 |
cohorts |
██████████████████░░ 89.6% |
8,568 / 9,559 |
product_tours |
██████████████████░░ 89.7% |
1,355 / 1,510 |
signals |
██████████████████░░ 90.0% |
89,149 / 99,033 |
visual_review |
██████████████████░░ 90.6% |
9,858 / 10,875 |
tasks |
██████████████████░░ 90.7% |
80,114 / 88,335 |
managed_warehouse |
██████████████████░░ 91.0% |
12,251 / 13,458 |
data_warehouse |
██████████████████░░ 91.1% |
15,326 / 16,822 |
canvas |
██████████████████░░ 91.2% |
8,189 / 8,980 |
aeo |
██████████████████░░ 91.2% |
1,602 / 1,756 |
autoresearch |
██████████████████░░ 91.4% |
11,618 / 12,705 |
data_modeling |
██████████████████░░ 91.5% |
10,755 / 11,758 |
cdp |
██████████████████░░ 91.5% |
10,282 / 11,238 |
today |
██████████████████░░ 91.6% |
3,976 / 4,341 |
business_knowledge |
██████████████████░░ 91.6% |
10,242 / 11,177 |
metrics |
██████████████████░░ 91.7% |
10,627 / 11,590 |
slack_app |
██████████████████░░ 91.7% |
21,646 / 23,601 |
wizard |
██████████████████░░ 91.7% |
6,870 / 7,490 |
streamlit_apps |
██████████████████░░ 91.9% |
3,139 / 3,415 |
error_tracking |
██████████████████░░ 92.1% |
19,004 / 20,643 |
conversations |
██████████████████░░ 92.3% |
30,540 / 33,101 |
review_hog |
██████████████████░░ 92.3% |
17,915 / 19,413 |
stamphog |
███████████████████░ 92.6% |
8,869 / 9,579 |
early_access_features |
███████████████████░ 92.6% |
1,339 / 1,446 |
managed_migrations |
███████████████████░ 92.6% |
1,630 / 1,760 |
alerts_platform |
███████████████████░ 92.8% |
8,192 / 8,830 |
notifications |
███████████████████░ 92.8% |
1,217 / 1,311 |
alerts |
███████████████████░ 92.9% |
10,060 / 10,831 |
web_analytics |
███████████████████░ 93.3% |
26,068 / 27,943 |
ai_training |
███████████████████░ 93.3% |
598 / 641 |
cross_project_dashboards |
███████████████████░ 93.4% |
880 / 942 |
surveys |
███████████████████░ 93.4% |
6,941 / 7,429 |
exports |
███████████████████░ 93.6% |
4,166 / 4,452 |
ai_gateway |
███████████████████░ 93.6% |
787 / 841 |
approvals |
███████████████████░ 93.7% |
4,994 / 5,331 |
context_layer |
███████████████████░ 93.8% |
3,981 / 4,244 |
mcp_store |
███████████████████░ 93.9% |
9,188 / 9,784 |
marketing_analytics |
███████████████████░ 93.9% |
21,234 / 22,605 |
ai_observability |
███████████████████░ 94.0% |
29,391 / 31,266 |
billing_alerts |
███████████████████░ 94.0% |
2,322 / 2,470 |
customer_analytics |
███████████████████░ 94.1% |
27,901 / 29,660 |
messaging |
███████████████████░ 94.1% |
4,959 / 5,271 |
workflows |
███████████████████░ 94.3% |
24,695 / 26,180 |
legal_documents |
███████████████████░ 94.4% |
2,313 / 2,451 |
logs |
███████████████████░ 94.4% |
19,309 / 20,457 |
replay_vision |
███████████████████░ 94.4% |
32,837 / 34,772 |
actions |
███████████████████░ 94.7% |
1,004 / 1,060 |
reminders |
███████████████████░ 94.8% |
760 / 802 |
experiments |
███████████████████░ 94.8% |
40,350 / 42,564 |
endpoints |
███████████████████░ 94.9% |
9,369 / 9,875 |
growth |
███████████████████░ 94.9% |
11,348 / 11,960 |
annotations |
███████████████████░ 95.1% |
1,095 / 1,151 |
skills |
███████████████████░ 95.2% |
7,630 / 8,015 |
uptime_monitoring |
███████████████████░ 95.3% |
306 / 321 |
access_control |
███████████████████░ 95.4% |
8,106 / 8,493 |
subscriptions |
███████████████████░ 95.6% |
13,601 / 14,228 |
data_catalog |
███████████████████░ 95.7% |
4,713 / 4,927 |
product_analytics |
███████████████████░ 95.8% |
29,875 / 31,195 |
feature_flags |
███████████████████░ 95.8% |
28,730 / 29,983 |
revenue_analytics |
███████████████████░ 95.9% |
1,877 / 1,958 |
data_quality |
███████████████████░ 96.0% |
8,561 / 8,915 |
tracing |
███████████████████░ 96.3% |
4,404 / 4,572 |
warehouse_sources |
███████████████████░ 96.5% |
481,271 / 498,684 |
security |
███████████████████░ 96.7% |
1,549 / 1,602 |
account_audits |
███████████████████░ 96.7% |
770 / 796 |
pulse |
███████████████████░ 97.1% |
2,023 / 2,083 |
analytics_platform |
████████████████████ 98.0% |
2,828 / 2,885 |
groups |
████████████████████ 98.2% |
1,838 / 1,871 |
field_notes |
████████████████████ 99.4% |
172 / 173 |
Report-only. Patch coverage = changed backend lines covered vs origin/master. Sorted lowest first.
Known gaps: lines covered only by Temporal tests show as uncovered; core line numbers may drift if master changed the same file.
|
Risk: No findings This PR builds one shared HogQL Database per activity-overview request and passes it to all five parallel queries (each with its own HogQLContext), gated by the existing HOGQL_SHARED_INSIGHT_DATABASE_ENABLED kill switch. I traced the security-relevant behavior and found no issues: the database is rebuilt per request with the calling user, its modifiers and access-control inputs are identical to what each per-query executor previously built, and the pattern matches the already-established shared-database design in query_runner.py. Sentinel reviewed |
There was a problem hiding this comment.
Approved.
The security-sensitive database reuse has current-head independent review and owning-team authorship. The code preserves caller identity and separate query contexts, with no unresolved substantive concerns.
- Author wrote 0% of the modified lines and has 7 merged PRs in these paths (familiarity MODERATE).
- PostHog Review (Standard) reviewed the current head: no findings.
- posthog[bot] reviewed the current head.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 34L, 1F substantive, 40L/2F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1b-small (40L, 2F, single-area, perf) |
| stamphog 2.6.1 | .stamphog/policy.yml @ 19afdd5 · reviewed head 19afdd5 |
|
Note 🤖 Automated comment by QA Swarm — not written by a human Multi-perspective review: router (cheap-first pass) + delegated lenses (qa-team, paul-reviewer, xp-reviewer, security-audit, engineering-systems-thinking as warranted) Verdict: ✅ APPROVE (round 1 @ 19afdd5)No actionable findings. Sharing one Key findingsNo inline findings. Two notes need no change:
ConvergenceBoth reviewers found no race. During parse, resolve, print and run, the database gets only locked lazy writes (foreign keys and revenue views). The unlocked Reviewer summaries
Automated by QA Swarm — not a human review |
Problem
Changes
HogQLContext, because the executor writes to the context while it runs.HOGQL_SHARED_INSIGHT_DATABASE_ENABLEDkill switch turns the sharing off. Then each query builds its own database, as before.How did you test this code?
Test rationale: the existing
TestActivityOverview.test_aggregates_window_and_extracts_error_messagesnow also asserts that one call builds the database once. It fails if a later change makes each query build its own database again. The existing filter and access-control tests in the same file cover that the shared database gives the same results.hogli ci:preflight --strict(ruff, format, semgrep) on the two changed files.Release status
Docs update
None.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Agent: Claude Code, Opus 5.5 (claude-opus-5-5)
gh pr listfound no open PR for this endpoint's latency. fix(mcp-analytics): resolve harness labels after grouping identity fields #122543 changes harness labels, which is other behavior.Created with PostHog Desktop