Skip to content

test(drift): pin OpenRouter K9 to an endpoint that enforces max_tokens - #521

Merged
jpr5 merged 2 commits into
mainfrom
fix/drift-openrouter-chat-k9
Oct 11, 2026
Merged

jpr5 merged 2 commits into
mainfrom
fix/drift-openrouter-chat-k9

Conversation

@jpr5

@jpr5 jpr5 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

OpenRouter K9 reasoning exhaustion > paid live provider agrees with actual localhost K9 fails on main with OpenRouter 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-r1 has one OpenRouter endpoint, novita/fp8, and it often ignores max_tokens: 16.

RED: measurements on the old pin (exact test request)

Batch Unbounded Bounded calls
4 calls, 120s / 4 MiB limit 2 / 4 4,567 B, 16 completion tokens, length, usage, [DONE]
6 calls, 60s / 300 KB limit 4 / 6 same
6 calls with reasoning.max_tokens: 16 added 2 / 6 same

The 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 only reasoning, include_reasoning and max_tokens, and the request sets require_parameters: true.

Fix

Pin the live K9 leg to qwen/qwen3-32b on deepinfra/fp8. The request keeps max_tokens: 16, reasoning, stream_options.include_usage, allow_fallbacks: false and require_parameters: true. inspectK9Stream and the K9 contract checks are unchanged. The localhost fixture is keyed on K9_REQUEST.model, so the comparison stays apples-to-apples with no src/ change.

The model's endpoints when pinned are deepinfra/fp8 ($0.28/M out), tenstorrent/fp8 and siliconflow/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 inspectK9Stream with every check it makes: model echo, exact reasoning_details (type: "reasoning.text", format: "unknown", index: 0), role: "assistant" with content: "" on reasoning deltas, no reasoning_content or tool_calls, no reasoning after the length terminal, usage after the terminal and not repeated, and a single [DONE]. A call counts only if all of those pass.

Model / endpoint Result
qwen/qwen3-32b deepinfra/fp8 40 / 40 passed every check, 5,285 to 5,360 B, completion_tokens 16 on all 40
deepseek/deepseek-r1-0528 deepinfra/fp4 20 / 20 bounded, but about 8x the cost
qwen/qwen3-14b deepinfra/fp8, qwen/qwen3.5-9b deepinfra/bf16, z-ai/glm-4.7-flash venice/fp8, nvidia/nemotron-3-nano nebius/fp8 2 / 2 OK (screening only)
deepseek/deepseek-v3.2-exp siliconflow/fp8 0 / 2, unbounded (rejected)

Budget 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 requires usage.completion_tokens <= max_tokens, through an explicit inspectK9Stream(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)) ignores max_tokens and reports 20 for the live 79-character reasoning. That is tracked separately, and this PR makes no src/ change.

RED (mutation): a local sensitivity check rewrites completion_tokens to 17 and expects the budget-enforcing path to throw. Without the assertion:

× OpenRouter K9 reasoning exhaustion > local wire preserves reasoning/details and clean length/usage/DONE semantics
  → expected [Function] to throw an error   (openrouter-chat.drift.ts:277)
  Tests  1 failed | 8 skipped (9)

With the assertion it passes (1 passed). If the enforceBudget branch is disabled (if (false && enforceBudget)), the same test fails again with expected [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" with OPENROUTER_API_KEY set:

run1 exit=0
 ✓ OpenRouter K9 reasoning exhaustion > paid live provider agrees with actual localhost K9  3668ms
      Tests  2 passed | 7 skipped (9)
live: status 200 completed True bytes 5435 provider DeepInfra completion_tokens 16
run2 exit=0
 ✓ OpenRouter K9 reasoning exhaustion > paid live provider agrees with actual localhost K9  607ms
      Tests  2 passed | 7 skipped (9)
live: status 200 completed True bytes 5285 provider DeepInfra completion_tokens 16

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:check and pnpm build all pass. pnpm test passes: 377 files, 14,073 passed and 3 skipped. Only the drift test file changes, so there is no public API or .d.ts change.

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.
@pkg-pr-new

pkg-pr-new Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@521

commit: 8f41182

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.
@jpr5

jpr5 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Merging with admin override over drift-live-pr (run 38097241624). Neither failure comes from this diff, which changes only openrouter-chat.drift.ts.

  • Attempt 1: the head leg failed OpenAI Responses K9 / Responses WS K9. Both have also failed on main since 2026-10-09 (runs 37893558052, 37994194206). The gate labelled them new-in-head only because the base and head live calls are separate.
  • Attempt 2: the base leg ran main's copy of the OpenRouter K9 test and hit the 256 KiB failure that this PR fixes.

All other checks pass, and the target test passed live twice locally (completion_tokens 16 both times).

@jpr5
jpr5 merged commit ef646a1 into main Oct 11, 2026
35 of 37 checks passed
@jpr5
jpr5 deleted the fix/drift-openrouter-chat-k9 branch October 11, 2026 00:24
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