Repository navigation
test(drift): pin OpenRouter K9 to an endpoint that enforces max_tokens - #521
Merged
Merged
Conversation
DeepSeek R1's only OpenRouter endpoint (novita/fp8) ignored max_tokens: 16 on 8 of 16 measured calls, streaming reasoning past 1.2 MB with no length terminal, usage or [DONE]. That blew the 256 KiB cap on main. Move the live leg to qwen/qwen3-32b pinned to deepinfra/fp8, which ended bounded on 40 of 40 calls of the exact request (about 5.3 KB each). The request keeps max_tokens 16, require_parameters and disabled fallbacks, and the K9 contract checks are unchanged.
commit: |
A provider that ignores the budget can still end with finish_reason "length", so the length terminal alone does not prove the budget held. Inspecting the live provider stream now also requires usage.completion_tokens <= max_tokens. The localhost comparison keeps its current checks: aimock's usage estimate ignores max_tokens, and that is tracked separately. A mutation check sets completion_tokens to 17 and expects the budget-enforcing path to throw.
Contributor
Author
|
Merging with admin override over
All other checks pass, and the target test passed live twice locally (completion_tokens 16 both times). |
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.
Problem
OpenRouter K9 reasoning exhaustion > paid live provider agrees with actual localhost K9fails on main withOpenRouter K9 exceeded 256 KiB(openrouter-chat.drift.ts:224). It failed in Drift Tests runs 37981755809 and 37994194206, and in #520's drift-live-pr run 38091527077 (attempt 2).The oversized side is the live provider, not aimock.
deepseek/deepseek-r1has one OpenRouter endpoint,novita/fp8, and it often ignoresmax_tokens: 16.RED: measurements on the old pin (exact test request)
length, usage,[DONE]reasoning.max_tokens: 16addedThe unbounded calls were all
provider: "Novita", reasoning-only and about 380 B per chunk. They passed 256 KiB in about 25s and reached 1.22 MB at 120s with no finish reason, usage or[DONE]. No other limit parameter is allowed: the endpoint supports onlyreasoning,include_reasoningandmax_tokens, and the request setsrequire_parameters: true.Fix
Pin the live K9 leg to
qwen/qwen3-32bondeepinfra/fp8. The request keepsmax_tokens: 16,reasoning,stream_options.include_usage,allow_fallbacks: falseandrequire_parameters: true.inspectK9Streamand the K9 contract checks are unchanged. The localhost fixture is keyed onK9_REQUEST.model, so the comparison stays apples-to-apples with nosrc/change.The model's endpoints when pinned are
deepinfra/fp8($0.28/M out),tenstorrent/fp8andsiliconflow/fp8. Fallbacks stay off, so no other endpoint can take the leg over.Candidate measurements (exact request, 45s / 256 KiB)
Each call was checked by a port of
inspectK9Streamwith every check it makes:modelecho, exactreasoning_details(type: "reasoning.text",format: "unknown",index: 0),role: "assistant"withcontent: ""on reasoning deltas, noreasoning_contentortool_calls, no reasoning after thelengthterminal, usage after the terminal and not repeated, and a single[DONE]. A call counts only if all of those pass.completion_tokens16 on all 40Budget check on the live leg (second commit)
A provider that ignores the budget can still end with
finish_reason: "length". So inspecting the live provider stream now also requiresusage.completion_tokens <= max_tokens, through an explicitinspectK9Stream(raw, { enforceBudget: true })at the live call site.The localhost comparison keeps exactly the checks it had before. aimock's usage estimate (
src/helpers.ts:1538,ceil(chars / 4)) ignoresmax_tokensand reports 20 for the live 79-character reasoning. That is tracked separately, and this PR makes nosrc/change.RED (mutation): a local sensitivity check rewrites
completion_tokensto 17 and expects the budget-enforcing path to throw. Without the assertion:With the assertion it passes (1 passed). If the
enforceBudgetbranch is disabled (if (false && enforceBudget)), the same test fails again withexpected [Function] to throw an error.The run used
npx vitest run src/__tests__/drift/openrouter-chat.drift.ts --config vitest.config.drift.ts -t "OpenRouter K9"withOPENROUTER_API_KEYset:These runs include the budget check. The first commit's two GREEN runs also passed (5,310 B and 5,285 B).
The whole drift file with the key set: 9 / 9 passed. A local RED run of the old pin passed once (4,567 B), because the failure is intermittent. The RED evidence is the measurements above plus the CI failures.
Gates
pnpm typecheck,pnpm lint,pnpm format:checkandpnpm buildall pass.pnpm testpasses: 377 files, 14,073 passed and 3 skipped. Only the drift test file changes, so there is no public API or.d.tschange.