Skip to content

fix: preserve GLM string arguments and stream Inkling tool calls - #3653

Merged
inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/3629-glm-inkling
Dec 1, 2026
Merged

inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/3629-glm-inkling

Conversation

@Jaeyeong-CHOI

@Jaeyeong-CHOI Jaeyeong-CHOI commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3629.

GLM-4.7 and LongCat now preserve indentation and trailing newlines for string arguments. Padded numbers and other JSON values still coerce, and quoted JSON strings decode normally. The shell-style fallback is unchanged.

Chat Completions and Anthropic Messages buffer tool fragments until the non-streaming parser confirms the call. Valid Inkling calls retain argument deltas; malformed or length-truncated calls emit no tool frame. Responses still streams tentative items and marks unfinished ones incomplete without replaying them as completed calls. Private frame offsets keep same-name siblings distinct without changing public Rust struct literals.

Both published Inkling 2 Mini and Small declare an empty join for repeated content and reasoning. With two explicit text messages, mlxcel classified the first as prompt-opened reasoning and dropped it. The parser now keeps both without adding a separator.

Verification: CPU-only, Metal disabled. Compared the GLM parser with the upstream Python implementation and Inkling with Neywa-Labs/mlx-vlm#2810 and the published response templates. Ran the filtered library suite, wire-event tests, independent regression review, cargo fmt --check and make verify-used-by. The Metal-enabled make verify-test gate and a real GLM-4.7 checkpoint generation were not run locally.

The follow-up passed 910 filtered library tests (4 ignored), including route, wire-event and public struct-literal regressions, with Metal disabled and a 32 MiB test-thread stack.

@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Dec 1, 2026
Jaeyeong-CHOI and others added 3 commits December 2, 2026 08:43
Restrict Chat Completions EOF buffering in `ChatToolCallStream` to the Inkling family so Hermes, Qwen3-Coder, Mistral, Llama 3, and DeepSeek-V4 DSML retain live incremental streaming (lablup#2396), and restore the DSML live-streaming route test.

Preserve wire spelling in `plan_buffered` when semantically identical Inkling JSON arguments differ only in formatting (such as `{"city": "Paris"}`), preventing spurious reconciliation warnings and single-chunk fallback on Chat Completions and Anthropic Messages.

Validated with 599 `tool_calls`/`tool_call_stream`/`streaming_anthropic` unit tests, `cargo fmt --check`, and a real Metal `mlxcel-server` check on `models/glm-4.7-flash-4bit` preserving `'    return x\n'` in a `write_file` tool call.

Refs lablup#3629, lablup#3653
@inureyes

inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Implementation Hardening Summary

Audited PR #3653 against issue #3629 across src/server/tool_calls/ and the Chat, Responses, and Anthropic streaming routes.

Findings & Fixes

  • Rebase onto main: Resolved conflicts in src/server/routes/chat.rs against shape_tool_chat_reply and snapshot_calls.
  • Correctness (HIGH): plan_buffered passed preserve_wire_spelling = false, which caused spaced Inkling JSON arguments ({"city": "Paris"}) to fail the strip_prefix check against the compactly re-serialized final parse, logging a spurious WARN and collapsing multi-delta streaming to a single chunk on both Chat Completions and Anthropic Messages. Enabled wire-spelling preservation for semantically identical Inkling JSON and added spaced-JSON regression tests in tool_call_stream.rs and streaming_anthropic.rs.
  • Correctness / Scope (HIGH): ChatToolCallStream buffered all tool-call formats until EOF, regressing live incremental streaming (feat: Stream tool-call arguments incrementally on Chat and Responses #2396) for Hermes, Qwen3-Coder, Mistral, Llama 3, and DSML. Scoped EOF buffering in ChatToolCallStream to Family::Inkling via IncrementalToolCallStreamer::is_inkling() and restored the original live-streaming DSML test in tool_call_stream_route_tests.rs.
  • Security & Performance: Verified UTF-8 char-boundary safety, bounded recipient/held buffers (MAX_RECIPIENT_BYTES, MAX_HELD_BYTES), panic containment in IncrementalToolCallStreamer, and linear scanning.

Validation

  • cargo test --profile test-fast --lib -- tool_calls tool_call_stream streaming_anthropic: 599 passed, 0 failed.
  • cargo fmt --check: passed.
  • Real-model Metal check (models/glm-4.7-flash-4bit via mlxcel-server /v1/chat/completions, Apple M1 Ultra): write_file tool call preserved leading indentation and trailing newline (content: ' return x\n').

@inureyes
inureyes force-pushed the fix/3629-glm-inkling branch from d07f256 to 789c38a Compare December 1, 2026 23:56
@inureyes
inureyes merged commit 550c3df into lablup:main Dec 1, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:review Under review type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Keep GLM-4.7 string argument whitespace, stream Inkling calls

2 participants