Skip to content

fix(provider): reject unsupported Qwen3.8 reasoning effort as a client 400 - #1523

Merged
Gajesh2007 merged 4 commits into
Layr-Labs:masterfrom
javiech1:fix/qwen38-reasoning-effort
Oct 22, 2026
Merged

Gajesh2007 merged 4 commits into
Layr-Labs:masterfrom
javiech1:fix/qwen38-reasoning-effort

Conversation

@javiech1

@javiech1 javiech1 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Qwen3.8-27B chat template raises on any active reasoning effort other than low, medium or xhigh. OpenAI-scale efforts that OpenRouter clients commonly send (high, minimal) reached the template unchanged, so the request failed as a provider 500 template_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 in docs/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-identical chat_template.jinja with 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"]
  end
Loading

Evidence

Production provider (EigenLabs/Qwen3.8-27B-4bit-mtp, v0.9.22, M5 Max) logged recurring inference failure code=template_render status=500 reason=jinja_template on 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 through ProviderPromptContractPipeline.tokenizeProviderBody with LocalTokenizerLoader for 31 OpenAI/OpenRouter request shapes (temporary probe, not committed):

Shape Before After
reasoning_effort: high / minimal / High 500 TemplateException "Unexpected reasoning effort …" 400 client_error
reasoning: {effort: "high"} (typed) 500 400
tools + reasoning_effort: high 500 400
none, xhigh, reasoning.enabled, reasoning.max_tokens, high + enable_thinking:false OK OK (unchanged)
mid-conversation system, developer, tool loops, forced tool_choice, odd tool arguments, content parts OK OK (unchanged)

sha256(chat_template.jinja) is identical for EigenLabs/Qwen3.8-27B-4bit (Hub) and the cached -mtp build (c3cf9e34…a81041).

Media path (commit 9262bf1c5)

Qwen3.8 is a VLM, and image requests build their prompt inside EngineV2VisionPrefill.prepare. MediaIngest.buildUserInput ran the effort check only for native-tool models (preserveTemplateFields), so a Qwen3.8 image request with high/minimal still reached the template raise. The preparation catch then wrapped every non-media error as requestRejected("engine_v2 media prefill construction failed … retry on another provider"). That is a retryable 503 capacity_busy on an idle engine, and every Qwen3.8 provider fails the same request.

The fix has two parts:

  • buildUserInput always runs validateReasoningContext. It is a no-op outside the restricted-effort templates.
  • The vision catch rethrows typed MultiModelBatchSchedulerEngineErrors, so deterministic request errors keep their own mapping, as its comment already states.

typedClientErrorKeepsItsMapping fails without the catch change; I checked this by reverting it locally.

Context, not proof: on the production Mac, five capacity_busy failures 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 yields capacity_busy on 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-tests
  • swift test --skip-build --filter "Qwen4ReasoningEffortValidationTests|CachePromptParityTests|NativeMediaToolPreparationTests|ErrorMapping": 26 tests pass
  • swift 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 require MIMO_PROMPT_ARTIFACT_DIRECTORY (artifact not present locally), unrelated.
  • New cases: both Qwen3.8 IDs accept nil/low/medium/xhigh unchanged, reject high/minimal without invoking the template, keep disabled-thinking precedence. The raw-body reasoning_effort path is rejected at the same boundary. Other qwen3_5 IDs (Qwen3.5-9B, case-mismatched Qwen3.8 ID) stay untouched.
  • Real-template probe above (local, not committed)
  • Media path: NativeMediaToolPreparationTests covers the Qwen3.8 build as production calls it (no preserved template fields, no native model type), and EngineV2VisionRoutingTests.typedClientErrorKeepsItsMapping covers the catch. Vision/prompt/error subset: 713 tests pass.
  • python3 scripts/changelog.py check, make docs-impact-check BASE=origin/master, scripts/docs-check.sh

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. The existing typed error and wire classification are reused; its human-readable message is now model-neutral ("This model supports reasoning effort low, medium, or xhigh when thinking is enabled").

Independent refactor pass

A separate subagent reviewed the diff against AGENTS.md/docs/AGENTS.md before commit and applied three small edits (all re-tested):

  • The validateReasoningContext comment no longer claims an xhigh default for every covered template ("accept only these exact spellings (Flash-Next defaults to xhigh)").
  • The docs/architecture/inference.md wording now says known-rejected caller controls must be validated before rendering, instead of implying every such input already is.
  • The duplicated request construction in qwen38BuildsShareTheRestrictedEffortContract was folded into one local helper; assertions are unchanged.

Follow-up commit 411456719 then removed what was not needed: the single-use hasRestrictedEffortTemplate helper 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.swift shares 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

  • Unsupported efforts are rejected, not served. This removes a provider-fault 500 but does not turn those requests into completed work (see the coercion note below).
  • Production logs carry only the bounded jinja_template reason, so the overnight failures are attributed to this cause by local reproduction with the real template, not by per-request evidence.
  • The "No user query found" template 500 is still open (see below).
  • Unit and real-template render checks only; no live end-to-end serving run was needed or claimed for this change.

Notes for reviewers

  • Coercion vs rejection. This follows the existing Flash-Next policy (reject, don't alias). If you would rather serve these requests, mapping high → xhigh and minimal → low for this template would be a small follow-up, but it is a product decision, so I did not make it here.
  • Prompt sidecar parity. fixtures/prompt-contract/v1/native_reasoning_vectors.json is 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.
  • Remaining Qwen3.8 template 500 (not changed here). Histories with no real user turn (only 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


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…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>
@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

@javiech1 is attempting to deploy a commit to the EigenLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 96899114206b against base 701452c6cd60.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Review in progress; coverage is not complete

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.

javiech1 and others added 3 commits October 20, 2026 17:10
…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
@Gajesh2007
Gajesh2007 merged commit 4957ad2 into Layr-Labs:master Oct 22, 2026
2 of 7 checks passed
jonathan308 added a commit that referenced this pull request Oct 22, 2026
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.
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.

3 participants