Skip to content

Report code mode calls in anonymous usage metrics - #7274

Merged
rdimitrov merged 1 commit into
mainfrom
claude/vmcp-codemode-usage-counts
Nov 24, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
claude/vmcp-codemode-usage-counts

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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 and count undercounts the real tool traffic of a code mode deployment.

  • tools/call requests for execute_tool_script are now also counted as code_mode_calls. They stay in count and calls_by_client as before, so code_mode_calls is a subset of count, never added to it.
  • New code_mode_tool_calls: tool calls made from inside code mode scripts. The collector exposes AddCodeModeToolCalls; 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 to count.
  • Both fields are omitempty, reset at midnight UTC with the other counts, and are plain integers (no names, no free-form data).
  • The collector's counts are grouped in one struct guarded by the existing mutex, so every field resets together.
  • docs/middleware.md lists both fields in the report disclosure table.

The middleware matches the tool name with a local constant pinned to script.ExecuteToolScriptName by a test, instead of importing pkg/script: every proxy links this package, and thv-proxyrunner does not otherwise link the Starlark engine.

Part of #4744 (adoption tracking).

Type of change

  • New feature

Test plan

  • Unit tests: the task test command (go test -race -ldflags=-extldflags=-Wl,-w) on ./pkg/usagemetrics/... and the other packages this stack touches
  • Linting: CI-pinned golangci-lint v2.15.0 and go vet on the changed packages (local task lint-fix is broken on Go 1.27 export data)

New tests: the middleware counts execute_tool_script calls only for tools/call and leaves count unchanged; the collector reports both fields, omits them at zero, ignores non-positive AddCodeModeToolCalls, 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 count and calls_by_client (plus the profile).
After: a vMCP report may also carry code_mode_calls and code_mode_tool_calls when they are non-zero. count and calls_by_client are unchanged.

Special notes for reviewers

  • Receiving service. stacklok/update-service decodes /api/v1/toolcount with a plain json.NewDecoder (no DisallowUnknownFields) in internal/api/tool_count.go, and telemetry.ParseUsageProfile reads 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 in stacklok/infra. Not done here.
  • A plain thv proxy in front of a server that itself has a tool named execute_tool_script would 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

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]>
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.89%. Comparing base (44f7d63) to head (8a4591f).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov
rdimitrov merged commit 8d64314 into main Nov 24, 2026
48 of 49 checks passed
@rdimitrov
rdimitrov deleted the claude/vmcp-codemode-usage-counts branch November 24, 2026 19:04
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants