MCP response trimming replaces the largest values whole (often the top result) and ignores topN; `clickstack_table` has no `limit`, `having` or default order
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- clickhouse, typescript
調査の方向性
Start with packages/api/src/utils/trimToolResponse.ts and reproduce the trimming behavior with the self-contained repro.mts described in the issue. Then inspect the clickstack_table tool and compare its options with packages/api/src/mcp/tools/dashboards/schemas.ts. Done means long values are shortened before results are dropped, pattern results preserve requested topN where possible, grouped tables have bounded and ordered results, and the note describes what was cut.
索引モデルが issue の本文から書いたものです。
説明
Summary
When a tool result is over the size budget, trimToolResponse (packages/api/src/utils/trimToolResponse.ts) keeps the first items of an array and replaces any value that is still too big with {"__hdx_trimmed": true, "originalSize": N}. It never shortens a string. Because the budget is split equally across keys, the biggest values go first, and in pattern and log results the biggest values are usually the most important ones: long stack traces.
For clickstack_table, the tool has no limit, no having and no default ORDER BY, so a large grouped result is cut to its first rows in whatever order ClickHouse returned them.
Environment
HyperDX 2-nightly image (late Oct 2026) with ClickHouse 26.10.3. Code references checked on main at d08b2fa7 (2026-11-03, 2.43.1).
Steps to reproduce
clickstack_event_patternswithtopN: 30on a service whose top errors are multi-line stack traces.- The response has 10 patterns, and the top ones look like
{"rank":1,"pattern":{"__hdx_trimmed":true,"originalSize":7443},"whereSnippet":{"__hdx_trimmed":true,…},"samples":[{"__hdx_trimmed":true,…}]}.
Self-contained (repro.mts below; runs the real trimToolResponse from main on an event_patterns-shaped object with 3 long and 27 short patterns):
isTrimmed=true; topN requested=30, patterns returned=10
rank 1: pattern={"__hdx_trimmed":true,"originalSize":4736} whereSnippet={"__hdx_trimmed":true,…} samples[0]={"__hdx_trimmed":true,…}
rank 2: … same
rank 3: … same
rank 4: pattern="Short INFO line 0 took <*> ms" (complete)
clickstack_tablewith agroupBythat yields a few thousand groups and noorderBy: the response holds the first rows of an unordered result (one run: 2,638 rows in, about 75 out), plus "Result was trimmed".
Expected vs actual
| Expected | Actual | |
|---|---|---|
| Over-budget pattern result | the top N patterns, with long strings shortened (…(+6,900 chars)) and fewer samples |
10 patterns; the top 3 replaced by markers |
| Large grouped table | the top rows by the first select (or by orderBy), up to a limit |
the first rows in arbitrary order |
Impact
In 4 agent investigations on production-size data: the most frequent error pattern of one service (99.5% of its ERROR lines) came back as a marker in 3 of 4 calls; topN 15–30 returned 10 every time; 66 KB and 81 KB responses still overflowed the client; and table calls returned 89–12,194 unordered groups that were then cut.
Proposed fix
- In
trimToolResponse, shorten long strings (e.g. to 500–2,000 chars with a suffix saying how much was cut) before replacing values or dropping array items. - For pattern results, drop
samples(keep 1) before dropping patterns, and keep the requestedtopNwhen it fits after that. - Add
limit(default about 50) andhavingtoclickstack_table, as dashboard tiles already have (packages/api/src/mcp/tools/dashboards/schemas.ts:839,:947), and defaultORDER BYto the first select descending whengroupByis set. - Say in the
notewhat was cut (e.g. "20 patterns dropped, 3 strings shortened").
Related
- #2337: shared MCP helpers and error hints
repro.mts
// Repro for trimToolResponse (packages/api/src/utils/trimToolResponse.ts) on an
// event_patterns-shaped result: long values are replaced, not shortened, and the
// array is cut to 10 items regardless of topN.
// Run from <hyperdx>/packages/api: npx tsx <this file> ./src/utils/trimToolResponse.ts
import { pathToFileURL } from 'node:url';
const { trimToolResponse } = await import(pathToFileURL(process.argv[2]).href);
const stack = (n: number) => `java.lang.NullPointerException: Cannot invoke "Catalog.items()" (case ${n})\n` +
Array.from({ length: 90 }, (_, i) => `\tat com.example.svc.Layer${i}.call(Layer${i}.java:${i + 10})`).join('\n'); // ~7.4 KB
const pattern = (rank: number, text: string, count: number) => ({
rank, id: `p${rank}`, pattern: text, estimatedCount: count, sampleCount: count, shareOfTotal: 0,
whereSnippet: `Body:"${text.slice(0, 2000)}"`, samples: Array.from({ length: 5 }, () => text),
});
const patterns = [
...[0, 1, 2].map(i => pattern(i + 1, stack(i), 9950 - i)), // the 3 most frequent: long stack traces
...Array.from({ length: 27 }, (_, i) => pattern(i + 4, `Short INFO line ${i} took <*> ms`, 30 - i)),
];
const output = { summary: { totalCount: 100000, patternsReturned: patterns.length }, patterns, usage: 'shareOfTotal is …' };
const { data, isTrimmed } = trimToolResponse(output);
console.log(`isTrimmed=${isTrimmed}; topN requested=30, patterns returned=${data.patterns.length}`);
for (const p of data.patterns.slice(0, 4)) {
const show = (v: unknown) => (typeof v === 'string' ? `"${v.slice(0, 40)}…" (${v.length} chars)` : JSON.stringify(v));
console.log(`rank ${p.rank}: pattern=${show(p.pattern)} whereSnippet=${show(p.whereSnippet)} samples[0]=${show(Array.isArray(p.samples) ? p.samples[0] : p.samples)}`);
}
- 主要言語
- TypeScript
- スター
- 10.1k
- フォーク
- 527
- 平均マージ
- 1日 20時間
- マージ済み PR(30日)
- 186
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/ClickStack のほかの issue
-
external
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ClickHouse/ClickStack#3761 ·
メンテナーはふだん 1 日以内に返信
-
Metric chart with aggFn increase and a multi-column group-by fails: toString() gets several arguments対応中かも @CG-5228 が 26 日前に担当しました。 オープンexternal
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/ClickStack#3477 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Slack notifications for inline alerts fail when the chart-explorer link passes Slack's 3000-character block limit対応中かも @Tyagiquamar が 28 日前に担当しました。 オープンalerting bug external
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/ClickStack#3452 ·
メンテナーはふだん 1 日以内に返信
-
check-alerts worker: 13 error spans (mongodb.create, NamespaceExists) every minute because mongoose autoCreate is still on再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンbug external Needs Feedback
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ClickHouse/ClickStack#3308 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
count_distinct aggFn on metric tiles ignores valueExpression, always counts distinct metric Values対応中かも @Harshul1484 が 54 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ClickHouse/ClickStack#2311 ·
メンテナーはふだん 1 日以内に返信
ClickHouse/ClickStack の issue をすべて見る
似ている issue
-
Add: GTrekkerオープンcheck:passed streams:add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
area: ui Bug Payload OSS
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
payloadcms/payload#19839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
fix(auth): add the email OTP verification step to Pollar login対応中かも @akansnoro が今日担当しました。 オープンStellar Wave
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
safetrustcr/dApp-SafeTrust#584 · コメント 10 件 ·
メンテナーはふだん 1 日以内に返信
-
The manager preset saves launch definitions without the required file and digest pair対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
メンテナーはふだん 1 日以内に返信