Skip to content

MCP trace breakdown reports top-N shares as shares of all matching child time #3763

Open

Description

@fernandezbaptiste

Hullo folks,

I’m doing some research for Tessl Code Review and ran it against your repo. It flagged a potential issue, and I figured it made sense to share it with you:

In clickstack_trace_breakdown, changing topN changes both grandTotalTimeMs and each operation's shareOfTotalTime, even when the matching traces stay the same.

The query limits its rows first, and the response then sums only those rows. Its hint describes the share as covering cumulative child time across all matching traces.

Reproduction

For two matching child operations, A = 60 ms and B = 40 ms, I ran the actual registered handler at ef81fe6d84b07c304888cd999f5e840fb050d05f with a stubbed ClickHouse client returning the requested top-N rows:

topN grandTotalTimeMs A.shareOfTotalTime
1 60 1
2 100 0.6

The handler's generated query contains LIMIT {topN:UInt32}. With topN=1, the response therefore describes A as 100% of total child time, even though B accounts for 40% in the fixture.

Expected behavior

Either calculate the denominator across all matching operations before limiting the output, or describe/name these fields as totals and shares of the returned rows. Otherwise an MCP consumer can interpret a truncated result as the complete cost breakdown.

Environment and validation

Current source commit: ef81fe6d84b07c304888cd999f5e840fb050d05f. This checks the real handler's response calculation with controlled query results; I did not run the SQL against a live ClickHouse instance. Reproduction on play.hyperdx.io: not attempted.

This was surfaced by an earlier review finding and is still present in the source checked above. Happy to share the harness or clarify anything.

Full transparency: I work at Tessl, and we've spotted that using Tessl Code Review - using repository-level context and specific review lenses that improve over time through feedback. That’s how this finding surfaced.

We’re just getting started and want to offer the tool free to open-source projects. If this is useful, happy to give you access.

Bap

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions