Skip to content

server: give each Inkling 2 tool call its own id - #4124

Open
ajensenwaud wants to merge 1 commit into
ashhart:mainfrom
ajensenwaud:ink-reply
Open

ajensenwaud wants to merge 1 commit into
ashhart:mainfrom
ajensenwaud:ink-reply

Conversation

@ajensenwaud

@ajensenwaud ajensenwaud commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

When an agent calls tools through Inkling 2, every turn's tool call comes back with the same id, call_0. This is because main's Inkling 2 reply parser numbers calls within each reply, and the route passes those ids through unchanged. This PR fixes that.

What this changes

  • The parser no longer writes an id. The route gives each such call the request's keyed id, as it already does for parsed calls.

  • Kimi writes its own call ids, and the route keeps them.

  • This PR first carried a whole Inkling 2 reply parser. Main has since shipped its own, so the PR now carries only this fix on top of it.

  • Issue: Refs Inkling 2 Small on four DGX Sparks: a native CUDA family #3476.

  • Stacked on: main 9961ca492.

Checks on this head

  • Head fa5fae121. The lean checker reports 164 problems on main and 164 on this head.
  • zig build test-server-cpu -Dfixed-cpu passes 2,069 of 2,085 server tests, with 16 skipped.
  • test-server-inkling2-reply-host passes 97 of 98, with one skipped. Four route tests fail with the route change reverted, including a new two-turn test.
  • zig fmt --check and git diff --check are clean.

Receipt

n/a: no family on main serves Inkling 2 yet.

@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

@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

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @ajensenwaud. All six earlier requests are addressed in this parser. Main now has a native Inkling parser, so the remaining benefit should be carried onto that path.

Please preserve its token-identity grammar, UTF-8, stop and token-cap behavior. Decoded marker text and argument arrays behave differently in this older parser. The added ID loop also skips main's existing call_0 IDs, so it does not yet give native calls distinct request IDs. A focused change with whole/streamed and distinct-turn fixtures would address that without replacing the shipped parser. We can handle the main overlap.

  • Synthena

The Inkling 2 reply parser numbered calls within each reply, so every
turn's first call came back as call_0 and agent clients could not tell
one turn's call from the next. The parser now writes no id, and the
route gives native calls without one the request's keyed id, as it does
for parsed calls. Kimi's model-written ids are kept.
@ajensenwaud ajensenwaud changed the title server: split Inkling 2 replies into reasoning, text and tool calls server: give each Inkling 2 tool call its own id Nov 25, 2026
@ajensenwaud

Copy link
Copy Markdown
Contributor Author

Thanks, Ash, and thanks @AIFlowML. I took the focused route: the PR now carries only the id fix, on main's native parser.

  • Ids. The parser no longer writes call_0. The route gives each native call without a model-written id the request's keyed id, as it does for parsed calls, and Kimi keeps its own ids.
  • Fixtures. A new route test sends a turn that returns a tool call, then a second turn that carries the call and its result. Each turn's call gets its own id, and whole and streamed replies agree on both.
  • Behaviour. Token-identity splitting, UTF-8, stops and the token cap stay main's code, untouched. The older parser is gone, so its marker text and argument handling no longer apply.

@ashhart

ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thank you, @ajensenwaud. The focused shape is right: the native parser keeps its token-identity grammar, UTF-8, stop and token-cap behavior, and the old parser is gone. Native marker calls now take the request-keyed ID, Kimi's own IDs remain untouched, and the new whole/stream two-turn fixture checks the intended distinction.

One supported path still keeps the repeated ID. Bare grammar calls go through bareCalls in zig/src/server/chat_inkling2.zig. Its ID loop at lines 165-166 still writes call_0, so the new missing-ID handling in openai_calls.zig leaves that ID in place. The existing bare-call fixtures check names and arguments but not IDs, so they do not catch this.

Please remove that obsolete comment and ID loop. Bare calls will then use the same request-keyed missing-ID path as native marker calls. Add the same whole/stream, distinct-turn assertions for a bare call; on the current head, both turns still return call_0.

The supplied host results are credited. I did not rerun them in this static review.

  • Synthena

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