Skip to content

server: split Inkling 2 replies into reasoning, text and tool calls - #4124

Open
ajensenwaud wants to merge 13 commits into
ashhart:mainfrom
ajensenwaud:ink-reply
Open

ajensenwaud wants to merge 13 commits into
ashhart:mainfrom
ajensenwaud:ink-reply

Conversation

@ajensenwaud

@ajensenwaud ajensenwaud commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Inkling 2 replies are typed blocks of reasoning, text and tool calls. The server now splits them by the state table of vLLM's Inkling parser, gives each tool call the request's keyed id, and holds a streamed block header back until the block names its kind.

Without the last two, agents looped: every call came back as call_0, and streamed tool names built up in the history until the model wrote them as prose. Only tokenizers with Inkling's markers take this path.

Checks on this head

  • Head c8f1556b1; lean checker 165 on the base, 165 on this head, 0 new.
  • zig build test-server-cpu -Dfixed-cpu: 1,804 of 1,819 tests, 15 skipped, on main 8ca30f3f9 with the same code as this head; zig build test: 9,802 of 9,882, 80 skipped.
  • zig fmt --check build.zig zig and git diff --check: clean. CI: pending.
  • The three route tests fail with the fix reverted and pass with it.

Receipt

n/a: no family on main serves Inkling 2. Kimi writes its own call ids, so it keeps the old path.

Served probe, two GB10s

A two-turn agent chat with one shell tool, served by the family stack with this parser on 19 November:

  • The whole and streamed replies return the same call, id call_3841ff1feb3b791e5b054bbb, and no content.
  • The second turn returns a new id, call_04810c8943136edb2aebd90b.
  • Before the fix, every turn returned call_0 and the stream sent run_shell as text.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @ajensenwaud for the Inkling 2 series (#4124 to #4128). Before we review it, one housekeeping ask that applies to all five: the commits' authors use your GitHub noreply address, but their committer is a personal email address. Our landing checks only accept noreply identities in a commit's history, so please rewrite the committer on each branch, for example with git rebase --exec 'git commit --amend --no-edit --reset-author' origin/main after setting user.email to your noreply address, then force-push. Nothing else needs to change; we will start the reviews as soon as the heads move.

  • Synthena

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Done: all five heads are rewritten with the noreply address as committer and force-pushed. The kernel PRs also now use the common CUDA helpers, which fixes the cuda_common_check failure; the SASS is unchanged.

@ajensenwaud
ajensenwaud force-pushed the ink-reply branch 2 times, most recently from 883d011 to 5f93ca1 Compare November 20, 2026 09:45
@ajensenwaud

Copy link
Copy Markdown
Contributor Author

The Windows benchmark-clients failure is test_a_healthy_server_proves_both, added in 7e4d988; this PR touches only zig/src/server, and #4075 fails the same way.

@AIFlowML

Copy link
Copy Markdown
Contributor

@ajensenwaud @ashhart I checked the three Inkling route regressions from a clean checkout of 5f93ca1b5. The PR describes the assertions, and the first thing I would add to the receipt is the smaller command that runs them without a model or GPU:

  • macOS arm64, Zig 0.17.0: zig build test-server-cpu -Dcpu=apple_m1 -j6 --summary all — 1,676 passed, 15 skipped.
  • Linux x86-64, Zig 0.17.0: zig build test-server-cpu -Dfixed-cpu -j6 --summary all — 1,681 passed, 15 skipped.

The suite includes whole and streamed call parsing, suppression of the tool block header as text, and the request-specific call IDs. The fixture supplies scripted tokens and checks the route output. My test merge against 675ec00cc reported a conflict only in CHANGELOG.md. The affected server paths merged cleanly.

Igor Lessio - AIFLOW LABS

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up on the new public head f97e7f88. The trial merge with main 46c6ee22 is clean, including the CHANGELOG. On M5 Max with Zig 0.17.0, zig build test-server-cpu -Dcpu=apple_m1 -j4 --summary all passed 1,722 tests with 15 skips.

I also applied the filters "an Inkling 2" and "inkling2 reply:" to the same server test module in a scratch build step. That passed 33/33, covering the parser and the whole/streamed route fixtures. These run without a checkpoint.

Rechecked the rebase at e65393047 in a clean trial merge with 37fa51d23. The same M5 Max server CPU command passed again with 1,722 tests and 15 skips. This run used the checkpoint-free server fixtures.

I checked the committer requirement on the four still-open Inkling heads, #4124 and #4126 through #4128. Every commit ahead of main on these branches now uses a GitHub noreply committer. #4125 has already landed.

Igor Lessio - AIFLOW LABS

@jschmied

Copy link
Copy Markdown
Contributor

Shared-core review at e653930472 against main fa13df5dd1. I read the code only and did not build or run it. Inkling 2 Mini (#4274) will serve through this path.

Copies of server code

  1. JSON scanner: server/inkling_reply.zig:100 member, :122 stringEnd and :130 valueSpan are a second hand-written JSON value scanner. They duplicate server/tool_json_cut.zig:24 stringEnd, :35 valueEnd and :62 members.
    • Fix: export one scanner, from tool_json_cut or a small json_span.zig, and use it in both places.
  2. Delta emission: chat_inkling.zig:41-55 copies the reasoning and content delta emission from chat_kimi.zig:27-38 line for line. It also hard-codes stability to false.
    • Fix: share one emitDeltas(g, sink, result, stable).

Behaviour

  • Missing guards: chat_inkling.zig:15-38 splits the reply whether or not g.chat is set. It also keeps tool calls after a stop string matched. Kimi guards both cases (chat_kimi.zig:8, :11-14).
    • I expect a raw /v1/completions request comes back split; I inferred this and didn't run it.
    • Fix: mirror the two guards, with a route test for each.
  • Reasoning tokens: usage always reports reasoning_tokens = 0 (chat_inkling.zig:36). chat_generation.zig:437 takes the native count, so the thinking-block tokens should be counted there.
  • Quadratic streaming: each stream step decodes and re-splits the whole reply (chat_inkling.zig:43 → read → :16). The cost grows quadratically with reply length, which matters for long reasoning. I haven't measured it.
    • Kimi's kimi_reply.zig Stream is incremental.
    • Fix: keep the split state across steps and decode only the new ids.

Nit

  • Dispatch: chat_inkling.zig:10 is() detects Inkling by looking up marker tokens (two token_id lookups per step). Kimi dispatches on vtable.format == .kimi at the same sites (chat_generation.zig:153,299). An .inkling tokenizer format would match that.

@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks @ajensenwaud. Splitting Inkling 2 replies into reasoning, text and tool calls is the right shape, and it follows main's other reply parsers. Before it lands, it needs to match what those parsers already do in six places:

  1. Streaming: each new delta reparses the whole reply so far, so work grows with the square of the reply length. Keep the parser state in Generation and consume only the new tokens, as zig/src/server/kimi_reply.zig's incremental Stream does: keep partial UTF-8 and block state between rounds.
  2. Offered tools and tool_choice: a call is emitted even when its name isn't among the request's tools, or isn't the one tool_choice names. Resolve each name against the offered tools with the same spelling rules as callName in zig/src/server/tool_parse.zig, treat unoffered names as content, and use the offered tool's spelling.
  3. Stop strings: when a stop string matches, the reply should carry no tool calls, as chat_kimi.zig does. Cover a stop string that ends a block, whole and streamed.
  4. Argument scanning: the member scanner can take a string value for a key and cut the wrong span. Use a JSON member scanner that tracks key position, decodes escaped keys, accepts all JSON whitespace and returns the value's exact span (main's tool_parse.zig has one).
  5. Malformed tool JSON becomes a call with an empty name and {} arguments. Return no call there, and keep the block as content.
  6. Raw completions (not chat) should come back as the decoded text, with no reasoning split and no calls, as chat_kimi.zig does.

A host test for each would be ideal. We'll rebase it onto main for you afterwards if main has moved.

  • Synthena

@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Thanks, Ash, and thanks @jschmied for the earlier read. Both reviews are answered in c8f1556b1, on main cc645a54b.

  1. Streaming. The split keeps its state in Generation and reads only the new text from the server's incremental decode, which keeps partial UTF-8 between rounds. A partial block marker is held back until it completes. A test feeds a reply one byte at a time, splitting multi-byte characters, and checks every prefix against the whole split.
  2. Offered tools. Each call is resolved against the request's tools, already narrowed by tool_choice, with callName's spelling rules, and takes the offered spelling. A call to any other name stays in the content.
  3. Stop strings. A stop-string match leaves the reply with no calls. A test covers a stop string that ends a block, whole and streamed.
  4. Argument scanning. The reply reads arguments with main's member scanner in tool_json_cut.zig, which tracks key position, decodes escaped keys, accepts all JSON whitespace and returns the value's exact span. A test covers a string value equal to a key, an escaped key, and tabs and newlines.
  5. Malformed JSON. A tool block whose JSON does not parse, or that names no tool, stays in the content as written.
  6. Raw completions. A /v1/completions reply comes back as the decoded text, with no split and no calls.

From @jschmied's review, Kimi and Inkling now share one emitDeltas, usage counts the thinking-block tokens, and the server detects Inkling once, as a tokenizer format.

zig build test passes 9,802 of 9,882 tests, with 80 skipped, on the same commits over main 8ca30f3f9.

@jschmied

Copy link
Copy Markdown
Contributor

@ajensenwaud, I checked c8f1556b1 on main cc645a54b. Ash's six points and ours are settled.

  • Tests: zig build test-server-cpu -Dfixed-cpu (the server module, which imports inkling_reply.zig and inkling_route_test.zig) passes 5/5 steps, 1,804 of 1,819 tests. The 15 skipped tests are the env-gated tokenizer and Clef ones; no Inkling test skips. That run includes:
    • the byte-at-a-time stream (inkling_reply.zig:294, and the route test at inkling_route_test.zig:302);
    • stop strings, whole and at a block's end (:230, :271);
    • offered tools with tool_choice: none (:254);
    • non-JSON blocks (:288);
    • raw completions (:216).
  • Streaming: Stream.feed reads only past fed (inkling_reply.zig:77-99), on the server's append-only incremental decode (chat_inkling.zig:37-46).
  • Offered tools: names resolve through tool_parse.knownNames and callName over the tools that tool_specs.active already narrowed (inkling_reply.zig:180-181).
  • Arguments: they come from tool_json_cut.members and find (:182), so the second scanner is gone. A failed parse keeps the block as content (:102-104).
  • Our four points:
    • Kimi and Inkling share emitDeltas (chat_kimi.zig:34).
    • Raw completions and stop strings are guarded (chat_inkling.zig:12,15).
    • Usage counts the thinking-block ids (:32, test inkling_reply.zig:283).
    • Dispatch is on the .inkling format (model_text.zig:154, hf_text.zig:145, chat_generation.zig:153,312).

@AIFlowML

Copy link
Copy Markdown
Contributor

I tested c8f1556b1 together with the current #4128 head a5a75d697 on main 3a02038db. The parser trial applies cleanly by itself. In the combined trial the only overlap was in THIRD_PARTY_NOTICES.md. I kept all three Inkling notices for the reply parser, expert and vision kernels, and DSpark drafter. No code resolution was needed.

On M5 Max with Zig 0.17.0, the combined tree passed 1,870 tests with 19 skips and compiled the native Linux ARM64 CUDA target.

zig build test-server-cpu test-inkling2-host test-inkling2-cuda-host \
  test-gradient-serving check-native-cuda-host \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all

This checks the server parser, family code and serving pins together. GPU inference and the release checkpoint were outside the run.

Igor Lessio - AIFLOW LABS

…eplies

Inkling replies now read a call's args and a cut call's name through the member scanner in tool_json_cut.zig, so the server keeps one copy of that code.
Kimi's stream now hands its reasoning and content to one emitDeltas function, and the Inkling stream calls the same function.
…stop

Raw /v1/completions replies on an Inkling 2 tokenizer now come back as the model wrote them, markers included. A reply that a stop string ended keeps no tool calls, as Kimi's does. A route test covers each case.
Usage now reports the tokens inside thinking blocks as reasoning tokens, read from the marker token ids. It reported 0 before.
Each stream step now feeds only the newly decoded text to a split kept across steps, instead of decoding and splitting the whole reply again. A test feeds a reply one byte at a time and checks every prefix against the whole split.
The tokenizer is checked once for Inkling 2's markers when it opens, so
each step reads the format instead of looking up two tokens, as Kimi
replies already do.
A tool block whose JSON does not parse, or that names no tool, used to
become a call with an empty name. It now stays in the reply's content.
A call is resolved against the request's tools, which tool_choice has
already narrowed, with the spelling rules tool_parse.zig uses. A call
to any other name stays in the reply's content.
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Nov 23, 2026
… does to them

- A reply puts the raw string in content as well and reasoning_tokens is 0; ashhart#4124 merged into this branch fixes both.
@AIFlowML

Copy link
Copy Markdown
Contributor

I rechecked the new 55c307b760dbb8cd2a8089a9123331705ada115a head against main 4c79cfe346d3c239ff7dfd7aa694df799755bafa. Main now routes Inkling replies through chat_inkling2.zig and inkling2_reply.zig from #4387 and its follow-ups. The trial merge stops in THIRD_PARTY_NOTICES.md, chat_generation.zig and hf_text.zig where the two implementations meet.

On that exact main SHA, zig build test-server-cpu -Dfixed-cpu --summary all passed with 2,073 passes and 16 skips. I also ported the new UTF-8 assertion into the existing upstream Inkling route fixture in a scratch checkout. Both the two-byte accents and four-byte emoji arrived intact in reasoning and content, with the full reply and streamed token strides 1, 2, 3 and 256. The focused host run passed 102 with one skip.

One behavior from this PR still differs: main's native Inkling route test expects call_0, and the native branch in openai_calls.attach returns the parser's IDs, while the generic path assigns the request-keyed IDs. If the distinct-per-turn ID is still needed, that is the focused follow-up I would carry onto the shipped parser. The split/UTF-8 result above used the scripted host route, without a live checkpoint.

Igor Lessio - AIFLOW LABS

This branch has not been deployed

No deployments
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.

4 participants