Repository navigation
Report code mode calls in anonymous usage metrics - #7274
Merged
Merged
Conversation
The anonymous usage report says whether code mode is enabled (features: code_mode) but not whether it is used. Count tools/call requests for execute_tool_script as code_mode_calls, a subset of count, and add code_mode_tool_calls for the tool calls scripts make, which never reach the HTTP middleware. count keeps its meaning. Refs #4744 Co-Authored-By: Claude Opus 5.5 <[email protected]>
6 tasks done
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7274 +/- ##
=======================================
Coverage 81.88% 81.89%
=======================================
Files 915 915
Lines 92769 92784 +15
=======================================
+ Hits 75966 75984 +18
+ Misses 16798 16795 -3
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 16:12
This was referenced Nov 24, 2026
reyortiz3
approved these changes
Nov 24, 2026
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
The anonymous usage report says whether vMCP code mode is enabled (
features: code_mode, from #7145), not whether anyone uses it. Code mode scripts also make their tool calls inside vMCP, so those calls never pass through the HTTP usage middleware andcountundercounts the real tool traffic of a code mode deployment.tools/callrequests forexecute_tool_scriptare now also counted ascode_mode_calls. They stay incountandcalls_by_clientas before, socode_mode_callsis a subset ofcount, never added to it.code_mode_tool_calls: tool calls made from inside code mode scripts. The collector exposesAddCodeModeToolCalls; the vMCP wiring that feeds it is in the stacked PR (Observe vMCP code mode: usage-report tool calls, OTel metrics, spans and logs #7275, stacked on this one). It is never added tocount.omitempty, reset at midnight UTC with the other counts, and are plain integers (no names, no free-form data).docs/middleware.mdlists both fields in the report disclosure table.The middleware matches the tool name with a local constant pinned to
script.ExecuteToolScriptNameby a test, instead of importingpkg/script: every proxy links this package, andthv-proxyrunnerdoes not otherwise link the Starlark engine.Part of #4744 (adoption tracking).
Type of change
Test plan
task testcommand (go test -race -ldflags=-extldflags=-Wl,-w) on./pkg/usagemetrics/...and the other packages this stack touchesgo veton the changed packages (localtask lint-fixis broken on Go 1.27 export data)New tests: the middleware counts
execute_tool_scriptcalls only fortools/calland leavescountunchanged; the collector reports both fields, omits them at zero, ignores non-positiveAddCodeModeToolCalls, and resets them at the midnight flush.Does this introduce a user-facing change?
Yes, in the anonymous usage report only.
Before: a report carried
countandcalls_by_client(plus the profile).After: a vMCP report may also carry
code_mode_callsandcode_mode_tool_callswhen they are non-zero.countandcalls_by_clientare unchanged.Special notes for reviewers
stacklok/update-servicedecodes/api/v1/toolcountwith a plainjson.NewDecoder(noDisallowUnknownFields) ininternal/api/tool_count.go, andtelemetry.ParseUsageProfilereads named fields only. The new fields are therefore accepted and silently dropped; no request will fail. Storing them needs a matching change in update-service (as stacklok/update-service#476 did for Extend anonymous usage metrics with server profile #7145's fields) and Athena columns instacklok/infra. Not done here.thvproxy in front of a server that itself has a tool namedexecute_tool_scriptwould also count it as a code mode call. vMCP refuses such backends (vMCP authz-gate hardening: unify parse source, reserved-name guard, verb parity #5845), and the name is specific enough that this is accepted rather than gated on the profile.🤖 Generated with Claude Code