Skip to content

fix: Fix DataCloneError from MCP grouped bar/pie query#2723

Open
pulpdrew wants to merge 1 commit into
mainfrom
drew/fix-histogram-non-timeseries-display
Open

fix: Fix DataCloneError from MCP grouped bar/pie query#2723
pulpdrew wants to merge 1 commit into
mainfrom
drew/fix-histogram-non-timeseries-display

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an error that occurred when querying pie/bar charts over metrics sources via MCP. Metrics sources errored when being cloned in the convertToCategorical function.

How to test on Vercel preview

Test locally by asking your agent to query bar/pie tile on a dashboard via MCP on a metrics source.

References

  • Linear Issue:
  • Related PRs:

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 18cd601

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperdx-oss Ready Ready Preview, Comment Jul 23, 2026 9:18pm
hyperdx-storybook Ready Ready Preview, Comment Jul 23, 2026 9:18pm

Request Review

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Jul 23, 2026
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 1
  • Production lines changed: 26 (+ 180 in test files, excluded from tier calculation)
  • Branch: drew/fix-histogram-non-timeseries-display
  • Author: pulpdrew

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes MCP metric bar/pie tile queries by:

  • Materializing hydrated Mongoose metricTables subdocuments into structured-cloneable plain objects.
  • Adding integration coverage for grouped regular and exponential histogram bar charts.
  • Adding a patch changeset for @hyperdx/api.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failures remain within the scope of the previous review thread.

Important Files Changed

Filename Overview
packages/api/src/mcp/tools/query/helpers.ts Converts metric table mappings to plain objects before categorical chart cloning and raw SQL source-field construction.
packages/api/src/mcp/tests/dashboards/queryTile.int.test.ts Adds regression coverage for grouped regular and exponential histogram metric bar tiles queried through MCP.
.changeset/mcp-query-tile-metric-categorical-clone.md Records the MCP categorical metric query fix as an API patch release.

Reviews (2): Last reviewed commit: "fix: Fix DataCloneError from MCP grouped..." | Re-trigger Greptile

Comment on lines 117 to 127
},
{
enabled:
IS_EXPONENTIAL_HISTOGRAMS_ENABLED &&
!!metricSource.metricTables?.[MetricsDataType.ExponentialHistogram],
},
);

return {
gaugeMetrics: gaugeMetrics?.[0].value,
histogramMetrics: histogramMetrics?.[0].value,
sumMetrics: sumMetrics?.[0].value,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Unsupported histogram aggregations exposed

When a user selects an exponential-histogram metric while the series uses avg, sum, min, max, count_distinct, any, or a custom aggregation, the editor preserves that unsupported aggregation and the query renderer throws instead of returning chart data.

Knowledge Base Used:

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was originally on code that was removed after rebase. This feature is enabled now.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

E2E Test Results

All tests passed • 243 passed • 1 skipped • 991s

Status Count
✅ Passed 243
❌ Failed 0
⚠️ Flaky 0
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew
pulpdrew force-pushed the drew/fix-histogram-non-timeseries-display branch from 04e5227 to 18cd601 Compare July 23, 2026 21:14
@pulpdrew pulpdrew changed the title Drew/fix histogram non timeseries display fix: Fix DataCloneError from MCP grouped bar/pie query Jul 23, 2026
@github-actions github-actions Bot added review/tier-2 Low risk — AI review + quick human skim and removed review/tier-3 Standard — full human review required labels Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The fix is correct and complete: metricTables is a nested Mongoose sub-schema declared with { _id: false } whose fields are all String, so toPlainMetricTables().toObject() yields a fully structured-cloneable plain object with no residual ObjectId, resolving the DataCloneError thrown by structuredClone inside convertToCategoricalChartConfig for pie/bar metric tiles. Both call sites (builder path and raw-SQL path) are covered, and the == null / 'toObject' in x guards are safe for already-plain inputs.

🟡 P2 — recommended

  • packages/api/src/mcp/tools/query/helpers.ts:387 — The regression this PR fixes has no automated test: toPlainMetricTables is unexported, runConfigTile is never invoked by any test, and the convertToCategoricalChartConfig unit tests only pass plain object literals, so the metric + pie/bar clone path can silently break again.
    • Fix: Add a test that feeds a non-plain (Mongoose-like, .toObject()-bearing) metricTables through the categorical config path — or an integration test through runConfigTile with a metric source and displayType pie/bar — asserting it does not throw and yields a plain object.

Reviewers (3): correctness, testing, maintainability.

Testing gaps: No regression test guards the fixed DataCloneError path (metric source + pie/bar via MCP). This review ran in a degraded environment (Bash and WebFetch unavailable); the change was reconstructed and verified from the repository working tree at HEAD (18cd6012) rather than from a raw git diff, so confidence rests on direct source inspection of the affected files and their dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant