Repository navigation
fix(provider): reject unsupported Qwen3.8 reasoning effort as a client 400 - #1523
Conversation
…t 400 The Qwen3.8-27B chat template raises on any active reasoning effort other than low, medium or xhigh. The provider passed OpenAI-scale efforts such as `high` and `minimal` (raw `reasoning_effort` or typed `reasoning.effort`) straight into the template, so the request surfaced as a provider 500 `template_render` / `jinja_template` failure instead of a caller error. Flash-Next already validates the same template contract before rendering and returns a typed HTTP 400. Both concrete Qwen3.8-27B builds ship a byte-identical template with the same raise, so they now share that boundary via `hasRestrictedEffortTemplate`. Supported efforts, the default, disabled thinking and other models are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@javiech1 is attempting to deploy a commit to the EigenLabs Team on Vercel. A member of the Team first needs to authorize it. |
Threat model review — advisoryReviewed head Review not completed for this head. Previous findings are superseded, not confirmed resolved. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Coverage: 22/57 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.4391 reported, $0.0000 reserved with unknown cost; 5 paid request(s), 0 reused batch(es), 48132 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. |
…tests Drop the single-use hasRestrictedEffortTemplate helper in favour of the widened guard, restore the original comments with a one-line note, and fold the Qwen3.8 effort cases into one test. Behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CDrGQJwa1LC3j4TE6Dvgmo
Media requests build their prompt in vision preparation, which only ran
the reasoning-effort check for native-tool models. A Qwen3.8 image request
with an unsupported effort therefore reached the template raise, and the
preparation catch wrapped it as a retryable 503 requestRejected
("retry on another provider"), reported as capacity_busy on an idle
engine.
Run the effort check for every media request (it is a no-op outside the
restricted-effort templates) and let typed request errors from
preparation keep their own mapping, as the catch's comment already
intends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CDrGQJwa1LC3j4TE6Dvgmo
Brings #1528 (Nemotron Super video) and #1523 (Qwen3.8 reasoning effort 400). Conflicts: WeightHasher takes master's equivalent F_NOCACHE reader (internal, so the uncached parity test keeps calling it); the scheduler rethrows every engine error (master's, which includes GLM's capacity refusal); the load path keeps GLM's artifact ownership and Super's reload refusal; the fleet budget comment names both retained GLM memory and Super reservations.
Summary
The Qwen3.8-27B chat template raises on any active reasoning effort other than
low,mediumorxhigh. OpenAI-scale efforts that OpenRouter clients commonly send (high,minimal) reached the template unchanged, so the request failed as a provider 500template_render/jinja_template, the provider-fault class, instead of a caller error.Flash-Next already validates this exact template contract before rendering and returns the typed HTTP 400
unsupportedReasoningEffort(documented indocs/reference/qwen4-next-support.md: "rejected before template rendering with a typed HTTP 400, not coerced"). Both concrete Qwen3.8-27B builds ship a byte-identicalchat_template.jinjawith the same raise, so they now share that boundary by widening its guard. No effort is coerced; the default, supported efforts, disabled thinking and other models are unchanged.flowchart LR subgraph Before A1["Qwen3.8 request<br/>reasoning_effort=high"] --> B1[templateAdditionalContext] B1 --> C1["Jinja raise_exception<br/>Unexpected reasoning effort high"] C1 --> D1["500 template_render<br/>jinja_template (provider fault)"] end subgraph After A2["Qwen3.8 request<br/>reasoning_effort=high"] --> B2[templateAdditionalContext] B2 --> V2["validateReasoningContext<br/>(widened guard)"] V2 --> D2["400 invalid_request<br/>client_error, template not invoked"] endEvidence
Production provider (
EigenLabs/Qwen3.8-27B-4bit-mtp, v0.9.22, M5 Max) logged recurringinference failure code=template_render status=500 reason=jinja_templateon Qwen3.8 traffic (8 of ~450 requests on 2026-10-19, 3 more overnight). The log carries only the bounded reason, so I reproduced locally by feeding the real cached Qwen3.8 template throughProviderPromptContractPipeline.tokenizeProviderBodywithLocalTokenizerLoaderfor 31 OpenAI/OpenRouter request shapes (temporary probe, not committed):reasoning_effort: high/minimal/HighTemplateException"Unexpected reasoning effort …"client_errorreasoning: {effort: "high"}(typed)reasoning_effort: highnone,xhigh,reasoning.enabled,reasoning.max_tokens,high+enable_thinking:falsesystem,developer, tool loops, forcedtool_choice, odd tool arguments, content partssha256(chat_template.jinja)is identical forEigenLabs/Qwen3.8-27B-4bit(Hub) and the cached-mtpbuild (c3cf9e34…a81041).Media path (commit
9262bf1c5)Qwen3.8 is a VLM, and image requests build their prompt inside
EngineV2VisionPrefill.prepare.MediaIngest.buildUserInputran the effort check only for native-tool models (preserveTemplateFields), so a Qwen3.8 image request withhigh/minimalstill reached the template raise. The preparation catch then wrapped every non-media error asrequestRejected("engine_v2 media prefill construction failed … retry on another provider"). That is a retryable 503capacity_busyon an idle engine, and every Qwen3.8 provider fails the same request.The fix has two parts:
buildUserInputalways runsvalidateReasoningContext. It is a no-op outside the restricted-effort templates.MultiModelBatchSchedulerEngineErrors, so deterministic request errors keep their own mapping, as its comment already states.typedClientErrorKeepsItsMappingfails without the catch change; I checked this by reverting it locally.Context, not proof: on the production Mac, five
capacity_busyfailures arrived within five minutes overnight (02:16–02:21). Local 15 s concurrency snapshots for that window show at most 1 running of 8 slots, and at times a waiting request on an idle engine. The provider log carries only the bounded reason, so I cannot attribute those five to this path. It is the only Qwen3.8 text/media path I found that yieldscapacity_busyon an idle engine.Linked issue
Related to #1521 (Qwen3.8 share on OpenRouter). Provider 5xx counts against availability there; a deterministic caller error should not.
Test plan
swift build --build-testsswift test --skip-build --filter "Qwen4ReasoningEffortValidationTests|CachePromptParityTests|NativeMediaToolPreparationTests|ErrorMapping": 26 tests passswift test --skip-build --filter "Prompt|Template|Effort|Reasoning|ErrorMapping|InferenceFailure|ToolChoice|Qwen": 306 Swift Testing tests pass. The only XCTest failures are MiMo tests that requireMIMO_PROMPT_ARTIFACT_DIRECTORY(artifact not present locally), unrelated.nil/low/medium/xhighunchanged, rejecthigh/minimalwithout invoking the template, keep disabled-thinking precedence. The raw-bodyreasoning_effortpath is rejected at the same boundary. Otherqwen3_5IDs (Qwen3.5-9B, case-mismatched Qwen3.8 ID) stay untouched.NativeMediaToolPreparationTestscovers the Qwen3.8 build as production calls it (no preserved template fields, no native model type), andEngineV2VisionRoutingTests.typedClientErrorKeepsItsMappingcovers the catch. Vision/prompt/error subset: 713 tests pass.python3 scripts/changelog.py check,make docs-impact-check BASE=origin/master,scripts/docs-check.shComponents touched
Protocol / interface changes
Independent refactor pass
A separate subagent reviewed the diff against
AGENTS.md/docs/AGENTS.mdbefore commit and applied three small edits (all re-tested):validateReasoningContextcomment no longer claims anxhighdefault for every covered template ("accept only these exact spellings (Flash-Next defaults to xhigh)").docs/architecture/inference.mdwording now says known-rejected caller controls must be validated before rendering, instead of implying every such input already is.qwen38BuildsShareTheRestrictedEffortContractwas folded into one local helper; assertions are unchanged.Follow-up commit
411456719then removed what was not needed: the single-usehasRestrictedEffortTemplatehelper is inlined into the existing guard, the original comments are restored with a one-line note, and the Qwen3.8 cases are folded into one test (source diff now +4/−2). Considered and left:MediaIngest.swiftshares the predicate, so Qwen3.8 media requests with an unsupported effort also get the 400 before pixel decoding, as intended; no test or doc asserted the old message text; no shared prompt-contract vector uses a Qwen3.8 ID.Known limitations
jinja_templatereason, so the overnight failures are attributed to this cause by local reproduction with the real template, not by per-request evidence.Notes for reviewers
high → xhighandminimal → lowfor this template would be a small follow-up, but it is a product decision, so I did not make it here.fixtures/prompt-contract/v1/native_reasoning_vectors.jsonis shared with the platform prompt sidecar. No existing vector uses a Qwen3.8-27B ID, so nothing changes there. If the sidecar validates efforts independently, it may want the same predicate.system,system+assistant, or user turns that are entirely<tool_response>blocks) still hit the template's "No user query found in messages." and surface as a 500. That is also a caller error, but whether to reject it with a typed 400 for the whole Qwen 3.5/3.6/3.8 template family is a broader call, so I left it out.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.