Skip to content

[Engine] Inkling 2: a tool call whose JSON holds <|end_message|> is still a call - #211

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/serve-fix-call-end-in-string
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/serve-fix-call-end-in-string

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 22, 2026 •

Copy link
Copy Markdown

Problem and result

InklingOutputParser ended a call block at the first <|end_message|>, also when it was inside a JSON string. The
model can write that text with ordinary tokens, for example in code:

<|message_model|>python<|content_invoke_tool_json|>{"name":"python","args":{"code":"print('<|end_message|>')"}}<|end_message|>

On main the client got this block as plain text and no call. With this PR it is the call
python({"code": "print('<|end_message|>')"}).

Related discussion

Split out of #200, as the maintainer asked there:
#200 (comment)
The bug was found by the Inkling 2 golden tests, which follow in a separate draft PR (port/serve-fixtures).

Approach

The call block now ends at the first tag outside the JSON's strings. If every tag seen so far is inside a string, the
parser waits for more text; at the end of the reply it falls back to the first tag, as before.

Validation

Passed:

  • cd terminal && ../.venv/bin/python -m unittest serve.test_inkling serve.test_server (CPU only): main 477 tests OK;
    this branch 478 tests OK.
  • Other serve and tokenizer suites (serve.test_family_parsers, test_lfm2, test_flint, test_gemma,
    test_prompt_encoder, test_stop_holdback, test_responses, test_tool_addition, test_tool_markup_retry,
    tools.test_strata_ornith122, tools.test_tokenizer_plain_spans, tools.test_setup_inkling,
    tools.test_hy4_tokenizer): 211 OK (1 skipped), the same on main and on this branch.
  • The new test, run against main's code, fails as expected.

Failed: On unchanged main d1f711e, serve.test_inkling + serve.test_server failed 1 of 477 once in 3 runs (the output didn't name the test; it is intermittent on main itself, not in this change). The branch runs passed every time.

Not run:

  • A check that llama.cpp 29b52d398b parses this reply as the same call: this rests on the golden fixture
    (port/serve-fixtures), not on a separate llama.cpp run.

Limits

  • With malformed JSON (an unbalanced quote) the rest of the reply is held until finish(): streaming stalls, but the
    final output is the same as on main.
  • Tag text inside text or thinking blocks is still cut, as on main. Fixing that needs token-level information.

Credits: VecSzn's InklingOutputParser on main.

🤖 Generated with Claude Code

…call

InklingOutputParser ended a call block at the first <|end_message|> (or
<|message_model|>), even inside a JSON string. A call such as
python({"code": "print('<|end_message|>')"}) - the model can write the tag's
text with ordinary tokens - was cut there, its JSON did not parse, and the
client got the raw block as text instead of the call. llama.cpp 29b52d398b
parses it as the call.

The block now ends at the first tag outside the JSON's strings. If every tag is
inside a string, the JSON has not closed: the parser waits for more, and at the
end of the reply it ends at the first tag as before (the block is then text).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo
okada-shogo marked this pull request as ready for review November 22, 2026 21:27
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
…holds <|end_message|> is still a call

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant