Skip to content

fix: qwen-chat-template models ignore declared reasoning efforts - #148397

Merged
steipete merged 25 commits into
openclaw:mainfrom
areslp:fix/qwen-chat-template-reasoning-effort
Oct 14, 2026
Merged

steipete merged 25 commits into
openclaw:mainfrom
areslp:fix/qwen-chat-template-reasoning-effort

Conversation

@areslp

@areslp areslp commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Related: #131213

What Problem This Solves

Fixes selected reasoning strength being dropped by Qwen chat-template models that declare compat.supportedReasoningEfforts.

User Impact

A selected turn, saved session preference, configured default, or inherited explicit choice sends the mapped chat_template_kwargs.reasoning_effort. Unselected calls omit effort and preserve the backend default; the logical fallback stays medium. Off disables thinking without sending effort. Undeclared templates retain binary controls.

New native children retain explicit/configured thinking preferences without saving automatic parent tiers as explicit child choices. Existing saved levels still count as selections because historical records have no selection provenance. No session schema, public plugin option, dependency declaration, or config knob is added.

Why This Change Was Made

The shared direct/managed Chat Completions owner now serializes selected effort. A bounded private selection bit carries intent through the existing reply, queue, CLI, cron, session, fallback, and child owners, and is stripped from public harness handoffs.

This refresh preserves the contributor's commits, removes vLLM changes superseded by #150149, and deletes the old forwarding-only tests and helper paths. Thanks @areslp for the original repair and @hippoley for the selection-provenance analysis.

Evidence

Before the main refresh, on macOS, an isolated real Gateway used sessions.create and chat.send through a recording proxy forwarding bodies unchanged to Ollama 0.40.3 qwen3:4b. The original main dropped effort for /think high; the candidate sends it. Every real-model case completed with a terminal model answer.

Gateway case Nested effort after fix Before / after wall time
Unselected omitted 45.736 / 42.403 s
Inline /think high high 30.933 / 29.513 s
Ordinary turn after inline selection omitted — / 6.169 s
Explicit saved session choice (sessions.patch) high — / 7.483 s
/think off omitted; thinking disabled 95.389 / 39.083 s

A deterministic Gateway fixture independently returns backend-default, high, backend-default, high, and off for those five cases. An inline directive is turn-scoped; the next turn is unselected unless a session choice was saved.

The HTTP regression produced 16 failures when only the original serializer was restored, then passed all 60 cases with the fix (340.948 / 414.853 s wall). Child persistence, CLI HTTP, logical default, subagent-tool planning, and queue-state checks pass. Public-harness projection checks also pass. The existing cancellation suite now includes the private selection field in its two expected result objects (3 failures before, all 4 cases passing after; 289.72 / 209.46 s wall). CLI HTTP checks cover unselected, selected, mapped configured default, off, and absence of the private flag on the wire.

Core types, all 28 selected test type graphs, targeted lint/format, diff checks, required baseline ratchets, config docs, plugin inventory, and the final qaRuntime build pass. Local extension-wide typing was limited by an existing unlinked QA/Crabbox dependency in the Gateway-only setup; the dependency install waited on a shared package-store operation and was cancelled without bypassing that lock. The pre-refresh CI run on 56b53fe9e57eaaff3354f1e9b7b5290a372e3bd2 subsequently passed production and selected test type lanes, covering that local dependency limitation. Isolated Codex review of the full behavior change is clean at P0–P2. Subsequent changes remove unused imports, clarify a comment, shrink an assertion allowance, and update two cancellation expectations; production behavior is unchanged. The isolated follow-up review is also clean at P0–P2 on 56b53fe9e57eaaff3354f1e9b7b5290a372e3bd2.

The child fixture initially timed out during its shared loader before assertions; an unchanged replay passed. One CLI attempt was invalidated by a comment edit during compiler snapshot preparation; the frozen-head replay passed. No timeout or assertion was weakened. Shared-host compilation and artifact-lock waits dominate local wall time; the CLI integration itself took 85.289 s to exercise the real command/config/session path (549.11 s total wall).

Production: +231/−136 (net +95); tests/support: +578/−20. The production growth carries bounded selection intent through existing owners after removing obsolete original-PR paths. No model-facing prompt text changed.

The previous CI run, on 56b53fe9e57eaaff3354f1e9b7b5290a372e3bd2, passed all selected lanes except an inherited release-test inventory mismatch and an X publication composition timeout. Exact-base source/tree evidence established the inventory mismatch. The maintainer classified the X timeout as unrelated main E2E slowness: this PR changes no X publication or authority files, and the exact main base itself used 93.833 seconds of the 120-second local test budget. No further X investigation or timeout change is included.

Current main bde739923e22902f6d8a8d875e6fda68f472e9aa was merged normally, preserving contributor history, in 3f31828eec9891d4a5f447fb56626e0f70aea9b8. The four overlapping files merged without conflicts. The Qwen serializer, queue behavior, and private harness projection are unchanged by the merge. Fresh isolated Codex review is scoped-clean at P0–P2; core types, the three selected test type graphs, scoped lint, and formatting pass. All three requested suites passed on the merge commit: HTTP contract (60) plus queue state (15), 478.28 s Vitest wall; harness projection (7), 306.37 s Vitest wall. The complete wrapper exited 0 in 1181.350 s including compilation, input verification, and cleanup. Scoped checks passed in 439.617 s total (core types 76.886 s; three selected test type graphs 247.578 s; lint 107.484 s; format/diff 7.669 s). All nine CI ratchet/config checks passed in 783.047 s. No source repair or baseline expansion was needed after the merge.

CI run 38541345995 on head 3f31828eec9891d4a5f447fb56626e0f70aea9b8 failed the awaited-bundle timing case at attempt.tool-search-catalog-abort.test.ts:400. Full-file local replays establish this failure is inherited from CI's exact main base 0b54949a41012201ca310a583810c46d4c15dc41: both the PR head and that base produce 1 failed / 9 passed with TypeError: Cannot convert undefined or null to object, kind: "failed", and source: "prompt". The test and shared fixture are unchanged between those revisions. GitHub confirms synthetic merge 2e95f5c52a194c8de6b798d69eaf5f263c15641c has those exact base/head parents.

Both replays used node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt.tool-search-catalog-abort.test.ts --maxWorkers=1 on macOS with isolated temporary state and independent compiler caches. Head: 473.916 s total wall / 255.86 s Vitest; exact base: 434.220 s total wall / 204.10 s Vitest. No source, mock, assertion, or timeout change was needed to reproduce either result. This attributes the red check; it does not repair the underlying main-base defect.

ClawSweeper reviewed the pre-refresh head 56b53fe9e57eaaff3354f1e9b7b5290a372e3bd2 with no actionable code findings. Per maintainer direction, this refresh stops after confirming fresh exact-head CI starts; it does not wait for CI or another bot review. Latest-stable upgrade and live persisted native-child proof remain unrun; those proof-only holds are left to maintainer review. Live proof covers the configured Qwen template over Ollama's OpenAI-compatible endpoint on macOS. It establishes wire controls and completed answers, not reasoning-depth performance, LM Studio, native Ollama /api/chat, or upgrade validation.

Map enabled thinking levels to chat_template_kwargs.reasoning_effort with the Qwen 3.8 template tiers (minimal/low -> low, medium -> medium, high/xhigh/max -> xhigh) in both Chat Completions builders. The bundled vLLM plugin keeps its binary /think profile at the template default effort.
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: vllm extensions: qwen size: S labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR forwards selected Qwen chat-template reasoning effort while preserving backend defaults and preventing automatic parent tiers from becoming saved child preferences.

Example: A Qwen chat-template model declares low, medium, and xhigh efforts with high mapped to xhigh, and the user selects /think high.

  • Before: The request enables thinking but omits chat_template_kwargs.reasoning_effort.
  • After: The request sends chat_template_kwargs.reasoning_effort as xhigh; an unselected turn still omits it.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and source-correct, with meaningful Gateway proof but incomplete coverage of the changed persistence and upgrade behavior.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A selected reasoning level appears available but does not reach the configured Qwen chat-template backend.
Reason: The repair makes existing declared controls effective while preserving unselected backend defaults and keeping automatic levels out of durable child preferences.

Merge readiness

⛔ Blocked before merge - 2 items remain

This PR fixes a current reasoning-control bug through the shared request owner; no actionable code findings remain.

Priority: P2
Reviewed head: 3f31828eec9891d4a5f447fb56626e0f70aea9b8

Before merge

  • Add real behavior proof - The recorded macOS Gateway run through an unchanged-body proxy to Ollama qwen3:4b covers selected and saved effort, unselected omission, Off, and completed answers; the serializer is unchanged from the previously proven head. Native-child persistence remains mock-supported without real creation and durable readback after restart. Attach redacted logs or terminal output covering that path, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted real native-child creation and restart readback for automatic and explicit/configured inheritance, plus a latest-stable upgrade transcript preserving existing settings and data.
Agent review details

How this fits together

Gateway replies, commands, cron jobs, and native subagents resolve thinking choices before the shared Chat Completions serializer turns them into provider request fields.

flowchart LR
 A[Turn and saved preferences] --> B[Thinking selection owners]
 B --> C[Run and queue context]
 C --> D[Session transport]
 D --> E[Shared completions serializer]
 E --> F[Qwen backend]
 C --> G[Native child planning]
Loading

Technical review

Best possible solution:

Land the shared selected-effort repair with transient provenance and preserved existing saved choices once the remaining validation gates are satisfied.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically omits nested effort for declared Qwen chat-template models, and the supplied Gateway comparison corroborates that path; this review ran no target code.

Is this the best way to solve the issue?

The patch fixes serialization at the shared owner and carries selection intent from existing resolution owners, avoiding a new default, public option, or durable provenance field.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b3d5dbae8512.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +95, Tests +558, Docs +5, Other 0. Total +658 across 46 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 31 231 136 +95
Tests 10 578 20 +558
Docs 4 9 4 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 46 819 161 +658

Review metrics

Metric Value Why it matters
Production versus test growth Production +231/−136; tests/support +578/−20 Production growth carries bounded selection intent through existing owners; HTTP and command coverage exercise request behavior rather than adding a competing implementation.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Declared Qwen chat-template effort selections are silently ignored, with limited impact on custom compatible-model configurations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (32 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-08T19:36:33.797Z sha 6f88b58 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-09T10:48:35.579Z sha 7f91c1d :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-09T12:33:49.063Z sha 708ff47 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-09T12:59:28.383Z sha 708ff47 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-14T05:23:54.005Z sha fa0b836 :: needs real behavior proof before merge. :: [P2] Update cancellation expectations for the added provenance field
  • reviewed 2026-10-14T06:44:17.784Z sha 56b53fe :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-14T08:55:31.749Z sha 56b53fe :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-14T09:26:54.525Z sha 3f31828 :: needs real behavior proof before merge. :: none

Reviewed October 14, 2026, 6:24 AM ET / 10:24 UTC (Revision 33).

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
Default qwen-chat-template models without a provider thinking profile to high, which maps to the Qwen 3.8 template's xhigh default, so forwarding thinking levels does not lower reasoning depth for setups that never selected a level.
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 15, 2026
areslp and others added 2 commits September 16, 2026 14:22
Resolve against main's shared reasoning resolver: map Qwen chat-template tiers from the resolved thinking level, which binary and chat-template formats carry independently of scalar reasoning_effort support.
Keep the new `level` field that carries the resolved thinking level to the
chat-template and binary controls, alongside main's updated ChatGPT none
support comment.

Co-Authored-By: Claude Opus 5 <[email protected]>
areslp and others added 2 commits September 23, 2026 04:01
Keep the high default for qwen-chat-template models in the model thinking
profile, and adopt main's three-argument catalog level helper now that Ultra
is added by the harness-level resolveThinkingProfile wrapper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep main's removal of the older vLLM chat-template cases, and keep this
branch's regression for dropping reasoning_effort from binary chat-template
thinking. That case seeds the transport payload, so the capture helper keeps
its initialPayload option.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 27, 2026
Qwen chat-template tiers were applied to every model with that thinking
format, although tier vocabularies differ between templates. Send
chat_template_kwargs.reasoning_effort only when the model declares
compat.supportedReasoningEfforts, resolved like reasoning_effort for other
OpenAI-compatible models, and default only those models to high. Undeclared
models keep binary thinking and the previous request shape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@areslp areslp changed the title fix: qwen-chat-template models ignore /think effort levels fix: qwen-chat-template models ignore declared reasoning efforts Sep 27, 2026
@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Sep 27, 2026
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Oct 8, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 8, 2026
areslp added 4 commits October 8, 2026 05:43
Preserve thinking selection provenance in the queue run options after
main moved the shared run fields into a RunEmbeddedAgentParams Pick.
Integrate upstream removal of two unused Control UI exports reported by
the changed checks. The Qwen proposal remains patch-identical relative
to the new main, with no fixture repair or default-policy change.
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 14, 2026
@steipete
steipete merged commit 218baa9 into openclaw:main Oct 14, 2026
163 of 166 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…nclaw#148397)

* fix: qwen-chat-template models ignore /think effort levels

Map enabled thinking levels to chat_template_kwargs.reasoning_effort with the Qwen 3.8 template tiers (minimal/low -> low, medium -> medium, high/xhigh/max -> xhigh) in both Chat Completions builders. The bundled vLLM plugin keeps its binary /think profile at the template default effort.

* fix: keep default depth for unconfigured qwen-chat-template models

Default qwen-chat-template models without a provider thinking profile to high, which maps to the Qwen 3.8 template's xhigh default, so forwarding thinking levels does not lower reasoning depth for setups that never selected a level.

* fix: send qwen chat-template effort only for declared efforts

Qwen chat-template tiers were applied to every model with that thinking
format, although tier vocabularies differ between templates. Send
chat_template_kwargs.reasoning_effort only when the model declares
compat.supportedReasoningEfforts, resolved like reasoning_effort for other
OpenAI-compatible models, and default only those models to high. Undeclared
models keep binary thinking and the previous request shape.

* fix: require an explicit effort list for chat-template tiers

The chat-template guard read efforts through the model contract resolver,
which infers lists for GPT-family ids. A qwen-chat-template model served
under such an alias without compat.supportedReasoningEfforts therefore sent
reasoning_effort. Read only the declared compat list, and cover an
undeclared GPT-family alias over managed and direct HTTP.

* docs: note the default effort for declared chat-template models

Declaring supportedReasoningEfforts on a qwen-chat-template model makes
OpenClaw send the resolved effort on every enabled turn, including high when
no level is selected. Say so, and point to params.thinking for templates
whose own default differs.

* fix: preserve Qwen template defaults with private thinking provenance

* fix(qwen): distinguish cron candidate thinking selector

* refactor: keep thinking provenance within bounded owners

* chore: finish Qwen effort validation cleanup

* test: include thinking provenance in cancellation expectations

---------

Co-authored-by: Peter Steinberger <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
…off 400 (#172580)

* fix(agents): preserve custom provider thinking defaults

Do not infer thinking-off support from an OpenAI-compatible endpoint's wire format. Preserve explicit compatibility settings and effort mappings, and warn once per model per minute when conversation-label generation fails without logging provider errors or source content.

Fixes #171068. Utility thinking-off requests were introduced in 380c115.

* fix(agents): limit inferred thinking-off exception to Z.AI

Keep the custom endpoint omission limited to inferred zai while retaining the existing OpenAI proxy off-effort policy. Restore inferred DeepSeek and Together off controls and cover Qwen controls through the simple-completion HTTP path.

Preserve the Z.AI/bigmodel title regression and conversation-label warnings. Initialize the shared transport host before timed HTTP cases.

Follow-up to #171068.

* fix(ai): preserve explicit Z.AI off controls

Carry the inferred custom Z.AI off-control exception in resolved compatibility instead of treating any unresolved thinking intent as undeclared support. Preserve explicit binary controls and managed scalar-off contracts while retaining inferred Z.AI omission and DeepSeek/Together controls.

* fix(ai): honor declared inferred Z.AI off controls

Use canonical reasoning support and mapping resolvers before treating custom inferred Z.AI off controls as undeclared. Preserve supported none/off efforts, normalized declarations, and off mappings while retaining undeclared omission and other provider controls. Clarify the title-generation contract in the model docs.

Release adaptation: stable's completions request builder does not carry the thinkingExplicit flag added on main by #148397, so derive it from the request's reasoning/reasoningEffort options and pass it to applyCompletionsReasoningAndRouting. Ported only the conversation-label warning test; the neighbouring main-only runtime-selection tests were dropped.

(cherry picked from commit 20299f8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation extensions: qwen gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants