Skip to content

Run the inference speed test the way each upstream expects - #28

Merged
fylorn merged 1 commit into
mainfrom
fix/inference-speed-test
Sep 17, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/inference-speed-test

Conversation

@fylorn

@fylorn fylorn commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What was wrong

The L3 speed test sent every upstream the same request: an Anthropic body to /v1/messages, with no anthropic-version, through the default HTTP client. Every one of these was reported to the user as "this upstream does not work":

  • Upstreams behind a proxy were unreachable. Only the OAuth token refresh used the upstream's own client. The probe itself went out directly.
  • The official Anthropic API returns 400 without anthropic-version.
  • OpenAI chat upstreams returned 404, since /v1/messages is not their route.

Separately, selecting a subscription upstream voided the quote's total. The subscription item has no amount, and the total treated that the same as an unpriced model, so the cost of every other upstream in the batch disappeared.

What changed

  • l3::probe_request picks the path, body and headers from the protocol. Anthropic gets anthropic-version. OpenAI chat goes to /v1/chat/completions and asks for usage in the stream. Responses and Gemini have no probe yet: they say so and send nothing.
  • speed_run sends the probe through client_for(provider), the same client forwarding uses.
  • Estimate / SpeedEstimate gain subscription. total_micros skips subscription items, and is still None when a per-token item has no price. A subscription is taken from billing: subscription in the config as well as from quota headers.

Tests

  • crates/tw-control/tests/speed.rs:
    • The upstream's hostname does not resolve and its proxy is a local server, so the run only succeeds through the proxy. It fails when speed_run is switched back to the default client; I checked.
    • A quote with a subscription upstream still has a total.
  • Unit tests for the Anthropic and OpenAI probes, and for a protocol without a probe sending nothing.
  • cargo fmt --check, clippy -D warnings, cargo test --workspace: all pass.
  • scripts/smoke.sh: 48 passed, 0 failed, 1 over target without regressing (memory 36 MB against 30 MB, same as before).

🤖 Generated with Claude Code

The L3 speed test built one request for every upstream: an Anthropic body
posted to /v1/messages, without anthropic-version, through the default
HTTP client. Three things went wrong with that, and each was reported to
the user as "this upstream does not work":

- Upstreams behind a proxy were unreachable. Only the OAuth token refresh
  used the upstream's own client; the probe itself went out directly.
- The official Anthropic API rejects a request without anthropic-version
  with a 400.
- OpenAI chat upstreams got a 404, since /v1/messages is not their route.

The probe now picks its path, body and headers from the protocol, and
runs through the upstream's own client. Protocols without a probe yet
(Responses, Gemini) say so and send nothing, rather than sending a
request that is bound to fail.

The quote's total also stops treating a subscription upstream like an
unpriced one. Both have no amount, but only "per-token and unknown" makes
a total untrustworthy; selecting a subscription upstream used to hide the
cost of every other upstream in the batch. A subscription is also taken
from the config's `billing`, not only from quota headers seen so far.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit 53806b0 into main Sep 17, 2026
2 checks passed
@fylorn
fylorn deleted the fix/inference-speed-test branch September 17, 2026 02:54
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.

1 participant