perf-mcp-interpretation
Interpret the mecatl perf MCP server's output to diagnose latency, goroutine leaks, GC pressure, allocation churn, and memory growth in a running mecatl harness. Use when connected to the mecatl perf MCP server (the perf:// resources or the query_metric / top_cpu_functions / capture_cpu_profile / top_allocations / list_slow_turns / capture_flight_recorder tools) and investigating why mecatl is slow, leaking, or growing. Covers tool routing/cost, reading pprof rankings and runtime metrics, and the leak/contention/GC signatures. NOT for generic Go profiling or non-mecatl MCP servers.
- License 许可
- Apache-2.0
- 所属仓库
- stacklok/mecatl
- 最近更新
- 2026-11-15
- Stars
- ★ 309
- Forks
- 29
01 前言 Front Matter
- name
- perf-mcp-interpretation
- metadata
- { "audience": "an AI agent driving or debugging a mecatl harness over the perf MCP server" }
- description
- Interpret the mecatl perf MCP server's output to diagnose latency, goroutine leaks, GC pressure, allocation churn, and memory growth in a running mecatl harness. Use when connected to the mecatl perf MCP server (the perf:// resources or the query_metric / top_cpu_functions / capture_cpu_profile / top_allocations / list_slow_turns / capture_flight_recorder tools) and investigating why mecatl is slow, leaking, or growing. Covers tool routing/cost, reading pprof rankings and runtime metrics, and the leak/contention/GC signatures. NOT for generic Go profiling or non-mecatl MCP servers.
- compatibility
- Requires a connection to the mecatl perf MCP server (mecated/mecatui --perf-mcp, mounted at /mcp on the loopback admin listener).
02 资源文件 2
- 参考文档references/output-shapes.md7.1 KB
- 参考文档references/signatures.md4.4 KB
03 SKILL.md 正文
Interpreting mecatl perf MCP output
mecatl is a streaming agentic loop. Its time is dominated by off-CPU waiting (on the model and on tool I/O), so the usual "run a CPU profile first" instinct measures the wrong thing. Diagnose by reading cheap numeric state first, and reach for the perturbing CPU tools only with a hypothesis to confirm.
Cost discipline — what to call, in what order
- Start cheap, read state.
perf://runtime/summary(goroutines, heap, GC, RSS, uptime) andperf://metrics/summary(latency-histogram quantiles) are free, point-in-time reads. Read them first, and re-readperf://runtime/summarya few times to see trends — a single snapshot rarely diagnoses anything. - Cheap tools next.
query_metric(one curated metric; omitmetric_nameto list names),top_allocations(heap rankings, no profiling window),list_slow_turns(per-turn timing) are all cheap and unlimited. - Perturbing tools last.
top_cpu_functionsandcapture_cpu_profilestart a live CPU profile that PERTURBS the process forduration_seconds, and are rate limited to one capture per cooldown window across both tools. Call them only to confirm a hypothesis, not to explore. A rate-limit hit comes back as anisErrorresult saying to retry — wait, do not retry-spam. - Never ingest raw blobs.
capture_cpu_profile(withinclude_raw_link) andcapture_flight_recorderreturn a user-audienceresource_linkto a loopback/debug/...endpoint. That link now surfaces as a TYPED BLOCK the model can see (URI + name + description) rather than a bare URI — but the model still receives only the reduced summary, never the raw blob bytes. A human downloads the linked artifact (withgo tool pprof/go tool trace); if the link ishttps://the model MAY fetch it via theFetchMcpResourcetool (SSRF-validated throughValidateMediaURL). Theperf://resources on this server are NOT https and stay server-readonly viaReadMcpResource. Do NOT try to read a linked raw artifact into model context; report the summary and point the user at the link (or fetch an https link only if you genuinely need its contents). If a perf tool's JSON result is large and you only need a subset of fields, filter it in memory withCallMcpWithQuery(server + tool +jq_filter) rather than narrowing the call — it runs the remote tool and applies a jq filter before the result enters context.
The MCP surface (what is actually there)
Resources (cheap, read-only, JSON):
perf://runtime/summary— goroutines, num_cpu, gomaxprocs, heap_allocs_total_bytes, heap_objects, total_memory_bytes, heap_object_bytes, gc_pause_count,gc_pause_p99_upper_bound_ns,rss_bytes, uptime_seconds,available[]. Note:heap_allocs_total_bytesis a cumulative COUNTER (bytes ever allocated) — a huge value (100+ GB on a long-lived process) is normal, not a leak; the leak signal is therss_bytes/heap_object_bytesslope.perf://runtime/memstats— memory-focused projection (heap_allocs_total_bytes, heap_objects, heap_object_bytes, total_memory_bytes, rss_bytes, available[]).perf://metrics/summary— every curated metric reduced: histograms → count + p50/p90/p99 bucket upper bounds (seconds); counters/gauges → a scalar value. Histograms and thetool_calls_total/tokens/turns_total/turn_empty_total/active_runscounters also carry a boundedby_rolebreakdown over the CLOSED engine role familymain|subagent|member|parallel|usermodel|child(the main engine vs the delegation children — the axis for "which agent family is burning latency/tokens"; never a session id or agent-def name).perf://pprof/{profile}— template,{profile}∈heap|goroutine|allocs|mutex|block; reduced top-15 functions (function, file basename, flat/cum values).
Tools (all read-only):
query_metric{metric_name?, quantile?, role?}— one curated metric; aggregated across all roles by default, or one role family's share withrole.top_cpu_functions{duration_seconds?, limit?}— perturbs, rate-limited.capture_cpu_profile{duration_seconds?, limit?, include_raw_link?}— perturbs, rate-limited.top_allocations{limit?}— heap top-N + total_heap_bytes.list_slow_turns{threshold_ms?, limit?, cursor?, role?}— cursor-paginated, newest first; each turn carries its bounded role family.capture_flight_recorder{}— size + one-line summary + user link (needs--flight-recorder).
See references/output-shapes.md for the exact field names of every tool's output (FuncStat, AllocStat, SlowTurn, MetricSummaryEntry).
Honest-precision caveat — do not over-trust the numbers
Every histogram quantile this server returns (in perf://metrics/summary,
query_metric, and gc_pause_p99_upper_bound_ns) is the upper bound of the
bucket the quantile rank falls in — NOT an interpolated exact quantile. The
field is literally named upper_bound for this reason. Read p99 as "at worst this
bucket's ceiling," not an exact value. Report it as an upper bound.
Interpreting the signatures
The full signature → diagnosis → next-step table is in references/signatures.md. Read it when you have a symptom to match. The essentials:
- Off-CPU workload. This loop mostly waits on the model/IO, so high CPU in
JSON decode/marshal, markdown render, or chunk decode is the real signal in
a CPU profile — that is on-CPU work on the hot streaming path. Rank by
flat(self time) for the hot leaf; usecum(includes callees) to find the responsible caller. - Goroutine leak.
goroutinesrising monotonically across successiveperf://runtime/summaryreads (not just spiking during a run) = a leak. Readperf://pprof/goroutineto see which functions hold the stuck goroutines; this corroborates the live goroutine watchdog. - Off-heap growth (the WASM-leak signature).
rss_bytesclimbing whileheap_object_bytes/total_memory_bytesstay flat = growth off the Go heap, invisible to pprof/heap and runtime metrics. (The historical cause was the RepoMap/tree-sitter WASM tool, since removed, but the pattern still stands for any off-heap consumer.) - GC-driven jitter.
gc_pause_p99_upper_bound_nsspikes and a risinggc_pause_count, alongside hightop_allocationson the streaming/chunk-decode path, explain inter-token jitter — GC pauses land between tokens. - User-felt latency = TTFT vs inter-token, split. Read
ttft_secondsandinter_token_max_secondsseparately (the mean hides both). Highttft= slow first byte; highinter_token_max= stutter the user feels mid-stream. - Dispatch contention.
mecatl_tool_queue_seconds(short nametool_queue_seconds) rising together withtool_duration_secondsp99 = the read-parallel / mutate-serial dispatcher is queueing: a slow mutating tool serially blocks queued mutations. Queue time without duration is just load; both together is the contention signal. - Tail latency. Averages lie. Use
list_slow_turnsto find the actual tail turns, thencapture_flight_recorderright after a slow turn to hand the human a trace window covering it.
Presence vs a real zero
available[] in the runtime/memstats snapshots lists which runtime/metrics fields
were actually published by this toolchain. A field absent from available[] was
not measured; a field present with value 0 is a real zero. gc_pause_count
is legitimately 0 before the first GC. query_metric returns an isError
"not present yet" for a metric with no observations — that means no relevant
activity has happened, not that the metric is broken.
Workflow
- Read
perf://runtime/summaryandperf://metrics/summary. - Match the symptom against the signatures above /
references/signatures.md. - Confirm with the cheap tool for that signature (
top_allocations,query_metric,list_slow_turns,perf://pprof/goroutine). - Only if you need function-level CPU attribution, spend the rate-limited
top_cpu_functions/capture_cpu_profileonce. - Report findings as numbers + an upper-bound caveat; point the user at any raw
resource_linkrather than ingesting it.
04 同仓库更多 Skills
repo-fact
Use when asked for this repository's registered fact or codeword. Loads the canonical answer format.
greet
Use when asked to greet someone with the ceremonial mecatl greeting. Loads the exact greeting format.
go-table-tests
Write idiomatic table-driven Go tests that stay offline and follow this repo's conventions.
commit-style
Write Conventional-Commits messages for this repo, with the required Co-Authored-By trailer.
tech-writer
Use when writing or substantively editing user-facing documentation: drafting a new page, rewriting or restructuring an existing one, adding a major section, or turning engineering material (PR descriptions, specs, release notes, rough notes) into docs. Writes clear, focused technical documentation following the Diataxis framework and Mecatl's canonical style guide. Use it even when the request doesn't mention writing quality; it governs how documentation gets written. Not for editorial review of finished work.
perf-optimization
Profile-driven performance optimization of mecatl using the offline benchmark + scenario harness. Use when optimizing allocations or latency, reducing allocs/op or memory, profiling a Go benchmark, pinpointing a hotspot with pprof, proving a win with benchstat, adding a regression benchmark, wiring profile-guided optimization (PGO), or investigating "why is this slow / allocating" or a suspected perf regression. Covers task bench, task perf:scenarios, memprofile -> pprof, benchstat A/B, allocs-first gating, PGO setup, and the discipline (follow the profile not the hypothesis; keep pure-perf changes byte-identical; mutation-test cache guards; skip the wrong abstraction). NOT for the live perf MCP server (use perf-mcp-interpretation) or non-mecatl Go profiling.