Skip to content

feat(bench): name the counterfactual behind code-execution savings - #1203

Merged
Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
algis-dumbris:bench-baseline-mode
Sep 3, 2026
Merged

Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
algis-dumbris:bench-baseline-mode

Conversation

@algis-dumbris

Copy link
Copy Markdown
Contributor

Description

CodeExecSavingFor documents its baseline as "what an agent would have paid making this call itself" and silently means through this proxy. Those are two different questions, with two different answers from the same log — and a saving whose denominator is unstated cannot be quoted.

This adds BaselineMode and a -baseline flag to codeexecsaving:

  • direct (new default) — the agent is wired straight to the upstream MCP servers, no proxy in the path. Nothing truncates, so a sub-call's full pre-truncation response_bytes is exactly what it reads. The recorded truncation is an artefact of the record: subCallActivityResponseLimit cuts the stored string at 8 KB while subCallByteSizes measures the whole result, and the value handed to the sandbox is never cut.
  • proxy — today's behaviour, bit for bit. The agent calls through call_tool_*, where forwardContentResult cuts each content block at tool_response_limit, so counting the full size overstates the baseline and a truncated sub-call withholds the whole call.

Why the default changes

tool_response_limit is an mcpproxy feature. Charging the counterfactual agent for it answers "what did code execution save over call_tool_*" rather than "what did mcpproxy save me" — and the latter is what users mean. It also brings this figure into line with the harness's own denominator, modematrix's baselineCell: "the same agent doing the same tasks with every upstream tool inline".

The withhold it replaces is also not statistically neutral: it fires precisely on the largest responses, the ones with the most to save, so the surviving population was biased small in a way no exclusion counter showed as a magnitude. On a real 69-sub-call workload it withheld the entire measurement.

Direct mode never contributes silently

TruncatedSubCalls / TruncatedBaseline carry the component magnitude; TruncatedCalls / TruncatedCallSaving carry the whole-call figures proxy would have discarded (it drops the whole call, not the component — reporting only the component understates what the mode change bought). The CLI prints both beside any total that rests on them. PricedSavingUSD now enforces that money never rests on tolerated data, instead of relying on the loader happening never to tokenize cut text.

Unchanged in both modes: a truncated parent still withholds — its response is the proxy term and mcpproxy really did cut it, which no baseline choice repairs. ReasonTruncatedRetrieveOverstates is untouched; that is the opposite direction, where the log stores more than the agent consumed.

⚠️ Withheld-by-reason tallies are not comparable across modes. A call that reported truncated_sub_call_overstates_saving may now report the reason it was always going to hit second (mixed_cost_basis, sub_call_zero_bytes). That is a relabelling, not a change in the data.

Naming

internal/config already uses RoutingModeDirect = "direct" for a proxied mode that does truncate, so the value is glossed everywhere it is printed and the collision is called out in the BaselineDirect doc comment. Happy to rename to unproxied if you'd prefer the ambiguity gone permanently.

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • All existing tests pass

go build ./bench/..., go vet ./bench/..., go test ./bench/... and go test -race ./bench/... all clean. Changes are confined to bench/ (5 files).

Existing truncation tests were renamed, not deleted, and now pass BaselineProxy explicitly so they keep asserting the old semantics. New coverage: direct/proxy disagreement on one fixture, the zero value resolving to direct in one place, the baseline_mode stamp asserted on the struct tag (not a marshalled instance, which can never carry the zero value), and the proxy pre-pass pinned by reason ordering — without it that fixture reports mixed_cost_basis, so asserting the withhold alone would pass either way.

CodeExecSavingFor documented its baseline as "what an agent would have
paid making this call itself" and silently meant "through this proxy".
Those are two different questions with two different answers from the
same log, and a saving whose denominator is unstated cannot be quoted.

BaselineMode makes the choice explicit:

  direct (new default) — the agent is wired straight to the upstream MCP
    servers, no proxy in the path, so nothing truncates and a sub-call's
    full pre-truncation response_bytes is exactly what it reads. The
    recorded truncation is an artefact of the RECORD, not the workload:
    subCallActivityResponseLimit cuts the stored string at 8KB while
    subCallByteSizes measures the whole result.

  proxy — the previous behaviour, bit for bit. The agent calls through
    call_tool_*, where forwardContentResult cuts each content block at
    tool_response_limit, so counting the full size overstates the
    baseline and a truncated sub-call withholds the whole call.

Changing the default changes published meaning, deliberately.
tool_response_limit is an mcpproxy feature, so charging the
counterfactual agent for it answers "what did code execution save over
call_tool_*" rather than "what did mcpproxy save me". It also aligns
this figure with the harness's own denominator — modematrix's
baselineCell, "the same agent doing the same tasks with every upstream
tool inline". And the withhold it replaces was not statistically
neutral: it fired precisely on the largest responses, so the surviving
population was biased small with no counter showing the magnitude.

Direct mode never contributes silently. TruncatedSubCalls and
TruncatedBaseline carry the component magnitude, TruncatedCalls and
TruncatedCallSaving the whole-call figures proxy mode would have
discarded, and the CLI prints both beside any total that rests on them.
PricedSavingUSD now refuses a saving that tolerated truncation rather
than relying on the loader happening never to tokenize cut text.

A truncated parent still withholds in both modes: its response is the
proxy term and mcpproxy really did cut it, which no baseline repairs.
ReasonTruncatedRetrieveOverstates is untouched — that is the opposite
direction, where the log stores more than the agent consumed.

Withheld-by-reason tallies are not comparable across modes: a call that
reported truncated_sub_call_overstates_saving may now report the reason
it was always going to hit second.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 55.31915% with 42 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bench/cmd/codeexecsaving/main.go 0.00% 38 Missing ⚠️
bench/replaycorpus/codeexec.go 92.85% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit 6c2c3cb into smart-mcp-proxy:main Sep 3, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants