Skip to content

fix: honor request reasoning effort and typed Qwen tool parameters - #28

Closed
chris247474 wants to merge 1 commit into
ashhart:mainfrom
chris247474:fix/opencode-reasoning-and-tool-types
Closed

chris247474 wants to merge 1 commit into
ashhart:mainfrom
chris247474:fix/opencode-reasoning-and-tool-types

Conversation

@chris247474

Copy link
Copy Markdown
Contributor

Summary

Qwen XML tool calls currently serialize every parameter as a string. An array-valued parameter such as OpenCode's questions therefore fails client schema validation with “Expected array, got string”. Decode explicitly typed parameters using the offered tool schema in both the final parser and incremental streamer, while preserving string values and whitespace. Typed streamed values are buffered until their closing tag; malformed or mismatched values remain strings for client validation.

Chat requests also currently ignore reasoning_effort. Honor per-request none, low, medium, high, and xhigh without mutating server defaults; map high to Qwen's xhigh, and preserve explicit chat_template_kwargs.enable_thinking precedence. Apply the request effort consistently to prompt, history, and system-prefix rendering, and report the effective setting in runtime metadata.

Includes regression tests and README documentation. Changes target the MLX server; union/reference schema resolution and a separate reasoning-token budget are outside this change.

Validation

  • Full upstream-documented pytest suite on an Apple M5: 401 passed, 2 skipped.
  • Skips: missing Vontra tokenizer fixture and an unsupported quantization group-size case.
  • New-file Ruff checks and git diff --check passed.
  • Package wheel built successfully with pip wheel --no-deps.
  • Before porting to current main, live Qwen model calls verified correctly typed nested question arrays through streaming and non-streaming HTTP responses. Desktop question rendering was not separately verified.
  • NVIDIA GPU execution was not tested; the repository has no GitHub Actions workflows.

Based on upstream main bb4b4a35863af562fc4ccb2586300d8f94b5d6de.

@ashhart ashhart added the bug Something isn't working label Sep 27, 2026
@ashhart

ashhart commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Thanks @chris247474 for the reasoning-effort and typed-parameter fixes. They're in 0.3.5, which ships tonight, as a commit authored by you. This PR closes when the release is published.

@chris247474

Copy link
Copy Markdown
Contributor Author

Thanks @chris247474 for the reasoning-effort and typed-parameter fixes. They're in 0.3.5, which ships tonight, as a commit authored by you. This PR closes when the release is published.

Thanks for including this little contribution @ashhart and for all the work on this! Roughly doubled the decode speed on my M5 Pro 48GB RAM machine.

@ashhart

ashhart commented Sep 27, 2026

Copy link
Copy Markdown
Owner

@ashhart ashhart closed this Sep 27, 2026
ashhart pushed a commit that referenced this pull request Sep 29, 2026
The Mac server has decoded Qwen `<parameter=k>` values by the tool's JSON
schema since 0.3.5 (#28); the CUDA server's parser still returned every
value as a string, so an array parameter reached the client as
"[\"a\", \"b\"]" instead of ["a", "b"] and strict clients rejected the call.

cuda/reply_text.parse_tool_calls now runs each value through the same
tool_parameters.decode_parameter the Mac server uses: array, object,
boolean, integer, number and null parameters decode when the text is valid
JSON of that type, anything else keeps its exact text.
@ashhart ashhart added the landed Landed on main by the maintainers; the commits keep the contributor's authorship label Oct 28, 2026
kelchm pushed a commit to kelchm/TensorFold that referenced this pull request Nov 7, 2026
The grammar was built inside Stream.init's argument list, and only a started job frees it, so a Stream.init that failed
after the build leaked it. It is now built first and freed on that failure. Only out-of-memory reaches this path.

Adapted to this engine by Mia's AI Lab from the second half of SvangenStudios' 0039 on
https://github.com/MiaAI-Lab/DeepSeek-V4.1-Flash-1017-4x-DGX-Sparks-TensorFold (PR ashhart#28); the use-after-free that PR's
first half fixes is not present here.

Origin: MiaAI-Lab/GLM-5.3-Flash-DGX-Sparks-1104@13f2464 patches/engine 0093-lanes-a-reply-grammar-is-freed-when-its-stream-cannot-start.patch sha256:636b0a5eef48c67654448f2c346f8dbe57d824789126d6175393111642896a95
Maxrio9 added a commit to Maxrio9/TensorFold that referenced this pull request Nov 25, 2026
…ning_effort compatibility

Ports MiaAI-Lab's Inkling-2-Mini-DGX-Spark-TensorFold patches 0013 (structured
output and tool_choice on CUDA, xgrammar 0.2.8 cache bypass), 0017 (reply
grammar freed on stream-start failure, opt-in tool-call guard; from
SvangenStudios PR ashhart#28) and 0010 (vLLM-compatible reasoning_effort and reasoning
field) to the EXL3 Mini engine with DSpark and shared forward. RTX PRO 4500,
3.3bpw: required, named and json_schema replies 10/10 valid each at 1 and 2
parallel requests with and without drafts; plain decode unchanged.

Co-authored-by: MiaAI Lab <[email protected]>
Co-authored-by: ajensenwaud <[email protected]>
kelchm added a commit to kelchm/TensorFold that referenced this pull request Nov 26, 2026
lane_stream.open constructed the reply grammar inline inside lanes.Stream.init's argument struct, and LaneHost.finish only frees Stream.grammar when job.started is true. If lanes.Stream.init failed with error.OutOfMemory after h.constraint succeeded, both the Constraint allocation and its underlying grammar matcher leaked.

Build the reply grammar before calling lanes.Stream.init and call deinit(h.gpa) in the Stream.init catch path, matching freeProposer and recalls.release. Add a deterministic failing-allocator host regression test in lane_host_grammar_test.zig proving both the matcher and Constraint leak before the fix and clean deallocation after it.

Originally authored by SvangenStudios in MiaAI-Lab/DeepSeek-V4.1-Flash-1017-4x-DGX-Sparks-TensorFold (PR ashhart#28, Apache-2.0) and adapted via MiaAI-Lab/GLM-5.3-Flash-DGX-Sparks-1104 (Apache-2.0) patch 0007.

Co-authored-by: SvangenStudios <[email protected]>
Co-authored-by: MiaAI-Lab <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants