Skip to content

fix(l3): an inference test for every kind of upstream - #108

Merged
fylorn merged 1 commit into
mainfrom
fix/chatgpt-inference-test
Sep 23, 2026
Merged

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

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

What was wrong

The inference test (L3) only built a probe for Anthropic and OpenAI Chat upstreams. Everything else got an inference test does not support a {protocol} upstream yet, so nothing was sent — including a ChatGPT account, which is the one kind of upstream whose speed you cannot check anywhere else.

What changed

  • The probe comes out of the same encoder forwarding uses (convert::encode, new). "What does a request look like in this format" now has one answer instead of a hand-written copy that drifts from what is really sent — that drift is what makes "forwarding works, the test fails" impossible to chase down. Anthropic, OpenAI Chat, OpenAI Responses, Gemini and ChatGPT accounts all get a probe now.
  • ChatGPT accounts keep the three differences the Codex backend insists on, taken from the forwarding path: the generating endpoint is {base}/responses, max_output_tokens is refused, and the identity headers are ThinkWatch's own.
  • The stream is read with the dialect's own parser (convert::Reader, new) instead of looking for keywords in the bytes. The first token is the first token of that format — the Codex backend sends its stream with no Content-Type, so nothing that sniffs content types would have found it — and an error reported inside a 200 stream now fails the test instead of passing silently.
  • Models that reason get room to reason. Reasoning tokens are output tokens: a limit of 8 makes a reasoning model spend its whole budget before it says a word, and then the test has measured nothing. The price data set already says which models reason (supports_reasoning), so those get 512 and the rest stay at 8. It is a bound, not an expectation — answering "Hi" uses far less, and the result reports the real usage.
  • An upstream that takes no output limit has no amount either. A ChatGPT account's estimate shows an empty limit and an empty cost rather than a number that was made up, and the total goes empty with it (free billing is still 0).
  • A result's error is a Msg, so the app can say it in its own language. CONTROL_API_VERSION goes to 11.

Tests

  • tw-gateway/tests/chatgpt.rs: the inference test against the fake Codex backend — request shape (/responses, no output limit, streaming, honest identity), first token timed, usage read from a stream that carries no Content-Type; and a refused run that carries what the backend said.
  • tw-gateway/src/l3.rs: every protocol gets a streaming probe of its own shape, the ChatGPT probe matches the backend's rules, the reasoning headroom rule, and the estimate for an upstream with no limit.
  • tw-dialect/src/convert.rs: encoding a request that has no client behind it, reading the first real token and the usage out of a stream, and an error inside a stream.

🤖 Generated with Claude Code

The inference test only knew how to write an Anthropic or an OpenAI Chat
request. The other three protocols returned "an inference test does not
support a Chatgpt upstream yet, so nothing was sent", so a ChatGPT
account — the one kind of upstream you cannot test any other way — could
not be timed at all.

The probe request now comes out of the same encoder a forwarded request
goes through (`convert::encode`), so there is one answer to "what does a
request look like in this format" instead of a hand-written copy that
drifts. The ChatGPT account keeps the three differences the Codex backend
insists on, the same ones forwarding applies: the path is `/responses`,
there is no output limit, and the identity headers say ThinkWatch.

Two things fall out of reading the stream with the dialect's own parser
(`convert::Reader`) instead of looking for keywords in the bytes: the
first token is the first token of that format (the Codex backend sends no
Content-Type, so sniffing content types would not have found it), and an
error reported inside a 200 stream is now a failed test rather than a
silent success.

Also:

- Models that reason get room to reason. Reasoning tokens are output
  tokens, so a limit of 8 makes a reasoning model spend everything before
  it says a word, and the test measures nothing. The price sheet says
  which models those are; they get 512, everything else stays at 8.
- An upstream that takes no output limit has no amount either. The
  estimate shows an empty limit and an empty cost instead of a number
  that was made up, and the total goes empty with it.
- The error on a result is a `Msg` now, so the app can say it in its own
  language. It used to be an English sentence that the Chinese UI printed
  as is.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 1f13cba into main Sep 23, 2026
1 check passed
@fylorn
fylorn deleted the fix/chatgpt-inference-test branch September 23, 2026 02:00
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