Repository navigation
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## claude/vmcp-codemode-metrics-ed9fe3 #7278 +/- ##
=======================================================================
+ Coverage 81.85% 81.88% +0.03%
=======================================================================
Files 916 919 +3
Lines 92886 93089 +203
=======================================================================
+ Hits 76031 76226 +195
- Misses 16850 16858 +8
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rdimitrov
marked this pull request as ready for review
November 24, 2026 17:53
This was referenced Nov 24, 2026
rdimitrov
requested review from
aponcedeleonch,
jerm-dro,
reyortiz3 and
tgrunnagle
November 24, 2026 18:59
rdimitrov
force-pushed
the
claude/vmcp-codemode-metrics-ed9fe3
branch
from
November 24, 2026 19:06
7441222 to
86f14c2
Compare
rdimitrov
force-pushed
the
claude/vmcp-codemode-otel-81ef10
branch
from
November 24, 2026 19:10
c65e842 to
6d73c51
Compare
Operators running vMCP with code mode cannot see how scripts behave: there is one debug line per script and no metric or span. Add per-install observability for execute_tool_script. - Metrics under the vMCP scope: toolhive_vmcp_script_executions, _duration, _tool_calls and _parallel_tasks, split by a status attribute (success, error, timeout, step_limit), plus a toolhive_vmcp_code_mode_enabled gauge on every server. - A codemode.ExecuteToolScript span per script with a codemode.CallTool child per inner call, under parallel() too. - Debug logs for script start and finish keyed by a script hash and session ID; the script body is never logged. The engine marks step-limit failures with script.ErrStepLimitExceeded, including inside parallel() children, and reports step count and parallel() fan-out through an optional Config.OnStats. Script results, limits and error messages are unchanged. Part of #4743 Part of #4744 Co-Authored-By: Claude Opus 5.5 <[email protected]>
rdimitrov
force-pushed
the
claude/vmcp-codemode-otel-81ef10
branch
from
November 24, 2026 21:20
6d73c51 to
8ce4408
Compare
rdimitrov
merged commit Nov 24, 2026
5c3e8f7
into
claude/vmcp-codemode-metrics-ed9fe3
28 checks passed
6 tasks done
rdimitrov
added a commit
that referenced
this pull request
Nov 24, 2026
…and logs (#7275) * Report code mode script tool calls in usage Tool calls a code mode script makes run inside vMCP and never reach the HTTP usage middleware, so the usage report does not see them. Add an optional OnScript observer to codemode.Config that receives the number of tool calls each script made, and have the vMCP CLI add it to the report as code_mode_tool_calls, separate from count. Part of #4744 Co-Authored-By: Claude Opus 5.5 <[email protected]> * Report pending script tool calls at day end Code mode script tool calls land when a script returns, so they can be pending while the day's count is zero: a script that straddled midnight, or the last script before shutdown. The midnight flush and the shutdown flush now also fire on pending code_mode_tool_calls, without adding them to count. Also align the OnScript doc with ScriptStats ("started", including failed and denied calls), note the accepted shutdown window for scripts still running past the HTTP drain, and document that code_mode_calls misses scripts reached through the optimizer's call_tool. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Add OTel metrics, spans and logs for code mode (#7278) Operators running vMCP with code mode cannot see how scripts behave: there is one debug line per script and no metric or span. Add per-install observability for execute_tool_script. - Metrics under the vMCP scope: toolhive_vmcp_script_executions, _duration, _tool_calls and _parallel_tasks, split by a status attribute (success, error, timeout, step_limit), plus a toolhive_vmcp_code_mode_enabled gauge on every server. - A codemode.ExecuteToolScript span per script with a codemode.CallTool child per inner call, under parallel() too. - Debug logs for script start and finish keyed by a script hash and session ID; the script body is never logged. The engine marks step-limit failures with script.ErrStepLimitExceeded, including inside parallel() children, and reports step count and parallel() fan-out through an optional Config.OnStats. Script results, limits and error messages are unchanged. Part of #4743 Part of #4744 Co-authored-by: Claude Opus 5.5 <[email protected]> * Count code mode calls made through the optimizer's call_tool (#7286) Count code mode calls made through call_tool With the vMCP optimizer on, clients reach code mode scripts through the optimizer's call_tool meta-tool, so code_mode_calls missed them and a report could show code_mode_tool_calls with no code_mode_calls. The usage middleware gains a WithCodeModeCall option. vMCP sets it when the optimizer is on, matching call_tool whose decoded target is execute_tool_script. Plain proxies never set it, since a backend there may have its own tool named call_tool. Co-authored-by: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #7275 (base
claude/vmcp-codemode-metrics-ed9fe3).Operators running vMCP with code mode cannot see how
execute_tool_scriptbehaves on their install. There is one debug line per script, and no metric or span. This PR adds per-install OTel observability for code mode: script metrics, tracing and logs (#4743), and the adoption signals in OTel (#4744).The fleet-wide adoption questions in #4744 are answered by the anonymous usage report (#7145, #7274, #7275, stacklok/update-service#492, stacklok/infra#6414), as the comment on #4744 explains. This PR adds the per-install OTel side, which each operator sees in their own Prometheus.
github.com/stacklok/toolhive/pkg/vmcp), built from the server'sMeterProvider, with astatusattribute (success/error/timeout/step_limit):toolhive_vmcp_script_executions(counter)toolhive_vmcp_script_duration(histogram, seconds, MCP semconv buckets)toolhive_vmcp_script_tool_calls(histogram of inner tool calls per script)toolhive_vmcp_script_parallel_tasks(counter of callables started byparallel())toolhive_vmcp_code_mode_enabled{server}is 1 or 0 on every vMCP server that has telemetry configured, including servers without code mode.tools/callintoolhive_mcp_tool_calls{tool}, and a script counts there once astool="execute_tool_script". The observability doc has the PromQL.codemode.ExecuteToolScriptspan per script, withscript.tool_count,script.parallel_used,script.parallel_calls,script.parallel_tasks,script.step_count,script.statusandscript.hash. Each inner tool call gets acodemode.CallToolchild span, including calls underparallel(). The backend client span nests under it.codemode: script startedandcodemode: script finishedat DEBUG, withscript_hash,session_id,status,duration,tool_calls,steps, theparallel()counts anderror. The script body is never logged.pkg/script): step-limit failures matchscript.ErrStepLimitExceeded, including a step limit hit inside aparallel()child. The error message is unchanged. A new optionalConfig.OnStatsreports the step count (script plusparallel()children) and theparallel()fan-out for eachExecute.codemode.ScriptStatsgainsOutcome,Duration,Steps,ParallelCallsandParallelTasks. TheOnScriptsignature and thecode_mode_tool_callsusage field from Observe vMCP code mode: usage-report tool calls, OTel metrics, spans and logs #7275 are unchanged.Closes #4743
Closes #4744
Type of change
Test plan
go test -raceonpkg/script/...,pkg/vmcp/codemode/...,pkg/vmcp/server/...,pkg/vmcp/cli/...)pkg/script/...,pkg/vmcp/codemode/...,pkg/vmcp/server/...: 0 issues)New tests:
parallel()child, an inner-call timeout whose error does not wrap the deadline, and argument errors.ManualReader: exact counts perstatus, tool call sums andparallel()tasks.tracetest.SpanRecorder: the script span is a child of the request span, there is onecodemode.CallToolchild per inner call (including those underparallel()), and the backend sees the inner call span as current.Telemetryconfigured, the caller's span stays current and nothing is recorded.NewTelemetry(nil, nil)is a working no-op.pkg/script:ErrStepLimitExceededat top level and inparallel(),OnStatscounts nestedparallel()calls and children's steps, and runs once even on failure.TestIntegration_CodeModeTelemetry): a real vMCP server with code mode on runs aparallel()script over HTTP. Scraping/metricsshowstoolhive_mcp_tool_calls_total{tool="execute_tool_script"} 1, no request-level sample for the inner tool, the four script metrics with exact values, andtoolhive_vmcp_code_mode_enabled 1. With code mode off, the gauge is0and no script metrics appear.task lint-fixcannot run on this machine (local golangci-lint cannot read Go 1.27 export data), so lint ran throughgo runof the CI-pinned version. E2E is left to CI.Changes
pkg/script/internal/core/{execute,stats}.goErrStepLimitExceededthroughOnMaxSteps; per-execution step andparallel()counters on the threadpkg/script/internal/builtins/parallel.goOnMaxStepsand the counters;parallel()reports its task countpkg/script/{script,executor}.goErrStepLimitExceeded,Stats,Config.OnStatspkg/vmcp/codemode/observer.goScriptOutcome, the extendedScriptStats, outcome classificationpkg/vmcp/codemode/telemetry.goTelemetryinstruments and spans (NewTelemetry)pkg/vmcp/codemode/decorator.go,config.goConfig.Telemetrywired intoexecute_tool_scriptpkg/vmcp/server/code_mode_telemetry.go,server.gocode_mode_enabledgaugedocs/operator/virtualmcpserver-observability.mdDoes this introduce a user-facing change?
Yes, for operators with vMCP telemetry configured:
/metricsexposestoolhive_vmcp_code_mode_enabledon every vMCP server, and the fourtoolhive_vmcp_script_*metrics when code mode is on. Traces gaincodemode.ExecuteToolScriptandcodemode.CallToolspans. The DEBUG log now has a start line and a finish line, keyed by script hash and session ID.Script results, error messages, limits, authorization and the usage-report fields do not change.
Special notes for reviewers
Naming. Every vMCP metric in this repo uses
toolhive_vmcp_*underscore names (backend, workflow and optimizer metrics, andtoolhive_vmcp_backend_revision_reclassifications, which is recent). No toolhive metric uses the dottedstacklok.<service>.*form, and there is no migration switch, so this PR follows the repo and the names in #4743. The outcome attribute isstatus, as #4743 asks and as thetoolhive_mcp_*metrics already use.Where this differs from the acceptance criteria. Each difference is deliberate, and the issues' owner accepted them as the criteria for closing both.
toolhive_vmcp_script_parallel_goroutines.parallel()runs its callables on a pool of at mostParallelMaxgoroutines (foreach.Concurrent), so a goroutine count mostly echoes the config.toolhive_vmcp_script_parallel_taskscounts the callables, which is the real fan-out. Accepted criterion: "countertoolhive_vmcp_script_parallel_tasksincrements by the number of callables eachparallel()call starts."toolhive_vmcp_tool_calls{method}counter.toolhive_mcp_tool_calls{tool}already counts every vMCPtools/callwith the tool name, so a second counter would double count. The doc has the PromQL, and the integration test proves the split. Accepted criterion: "the split is queryable fromtoolhive_mcp_tool_calls{tool="execute_tool_script"}, with example PromQL in the observability doc."vmcp_server_nameon the gauge. It usesserverinstead, the labeltoolhive_mcp_tool_callscarries, so the two join. The gauge is fixed per process: the operator rolls the vMCP pod when its config changes, so "updated on configuration change" holds.Logging level. Start and finish lines are DEBUG, including on failure. A failed script is the caller's mistake and can happen at request rate (
.claude/rules/go-style.md: silent success, callers do not set WARN volume).toolhive_vmcp_script_executions{status!="success"}is the operator signal.Session ID.
core.VMCP.CallToolhas no session parameter, so the decorator reads it withserver.ClientSessionFromContextfor logs only. Stateless Modern requests have no session, and theirsession_idis empty.Error text. Spans record the outcome only, never the error message, because Starlark errors can quote script data. The DEBUG log carries the message the caller already received.
Telemetry cannot break a script. A nil
Telemetryleaves the context and spans untouched. Recording is synchronous and non-blocking, and a panic while recording metrics is recovered.OnStatsruns on theExecutegoroutine before it returns.Size. The non-test, non-doc diff is about 690 lines across 11 files, over the 400-line guideline, and much of it is doc comments. If reviewers prefer, it splits cleanly into (1) the
pkg/scriptchanges (ErrStepLimitExceeded,Stats/OnStats) and (2) the codemode and server telemetry stacked on top.🤖 Generated with Claude Code