Skip to content

fix(inkling2): end a block only at end_message - #227

Open
kalomaze wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
kalomaze:fix/inkling2-block-boundaries-min
Open

kalomaze wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
kalomaze:fix/inkling2-block-boundaries-min

Conversation

@kalomaze

@kalomaze kalomaze commented Nov 27, 2026 •

Copy link
Copy Markdown

Inkling2ToolParser._split splits a completion into blocks at <|message_model|> and starts a new block at every content marker. tml_renderers.renderers.Inkling2 (0.4.2, as pinned in CI) ends a block only at <|end_message|>. A leading <|message_model|> is optional, and a later one, like a second content marker, is body text.

So when a text block lacks its <|end_message|>, a tool call after it comes back as an OK call, where the reference keeps it as text. A tool-call marker inside a text or thinking block does the same. A caller runs a call that the reference parser never produces, and in RL the environment executes and rewards it with nothing marking it as malformed. In the other direction, a block after <|end_message|> without <|message_model|> is dropped, where the reference parses it.

Fix

Split blocks at <|end_message|> and read one content kind per block, from its first marker. A well-formed completion parses as before.

Reproducer:

import tml_renderers as tml
from renderers import create_renderer
from renderers.base import load_tokenizer

tok = load_tokenizer("thinkingmachines/Inkling-2-Mini")
renderer = create_renderer(tok)
# The text block has no <|end_message|> before the next <|message_model|>.
sampled = (
    "<|message_model|><|content_text|>Deleting the build directory."
    "<|message_model|>bash<|content_invoke_tool_json|>"
    '{"name": "bash", "args": {"cmd": "rm -rf build"}}'
    "<|end_message|><|content_model_end_sampling|>"
)
ids = tok.encode(sampled, add_special_tokens=False)

parsed = renderer.parse_response(ids)
print("renderers:", repr(parsed.content), [(c.name, c.arguments, c.status.value) for c in parsed.tool_calls])

_, parser = tml.renderers.Inkling2(effort=0.9).render_for_completion(
    tml.chat.MessageList.from_openai_chat_dicts([{"role": "user", "content": "Clean up."}])
)
(ref,) = tml.chat.MessageList(parser.parse_tokens(ids).messages).to_openai_chat_dicts()
print("tml_renderers:", repr(ref["content"]), ref.get("tool_calls", []))
content tool calls
tml_renderers 'Deleting the build directory.<|message_model|>bash<|content_invoke_tool_json|>{…}' none
before 'Deleting the build directory.' bash {"cmd": "rm -rf build"}, ok
after same as tml_renderers none

Tests

  • New test_block_framing_matches_tml in tests/test_inkling_reference.py checks content and tool calls against tml_renderers for both Inkling 2 checkpoints, in three cases: <|message_model|> inside an open text block, a tool-call marker inside a text block, and a block after <|end_message|> without <|message_model|>.
  • test_tool_call_inside_thinking_block in tests/test_inkling2.py now expects the reference result: the marker and body stay in reasoning_content and there is no tool call.
  • All of these fail on main and pass with the change.
  • -m "not model": 212 passed, 1 skipped. -m model -k inkling: 1,342 passed, 18 skipped. tests/test_inkling2.py, tests/test_inkling_reference.py and tests/test_parsers.py: 100 passed, 6 skipped (the framing cases on the original Inkling checkpoints).
  • ruff check and format (0.15.12) pass. ty check renderers reports the same 62 diagnostics as main, none in parsers.py.

Tool-call validation is unchanged.

Note

Fix Inkling2ToolParser._split to end blocks only at end-message tokens

  • Changes Inkling 2 block segmentation in renderers/parsers.py so blocks are split only on end-message tokens; a leading model token is still skipped
  • Later model tokens and content-kind markers stay in the current block's content or reasoning. The first content-kind marker sets the block kind, and each block yields at most one tool call
  • Updates tests in tests/test_inkling2.py and adds reference-parser framing cases in tests/test_inkling_reference.py
  • Behavioral Change: a tool-JSON marker after a thinking marker now appears as reasoning text with no tool call parsed

Macroscope summarized 9d52011.


Note

Medium Risk
Changes Inkling 2 parsing semantics for RL/training callers that relied on the old block splits; well-formed completions should be unchanged, but malformed samples will parse differently and may stop executing phantom tool calls.

Overview
Aligns Inkling 2 completion parsing with tml_renderers: Inkling2ToolParser._split now segments on <|end_message|> only, not on repeated <|message_model|> or extra content-kind markers. A block’s type comes from its first marker; any later <|message_model|> or tool/thinking tokens inside the same block stay in text or reasoning, and at most one tool call is emitted per closed block.

Behavior change: malformed or nested markers (e.g. <|content_invoke_tool_json|> inside an open thinking block, or a second <|message_model|> before <|end_message|>) no longer produce spurious OK tool calls. Blocks after <|end_message|> without a leading model token are no longer dropped.

Tests are updated: test_tool_call_inside_thinking_block expects reference reasoning text with no tool call; new test_block_framing_matches_tml cases assert content and tool calls match the reference parser.

Reviewed by Cursor Bugbot for commit 9d52011. Bugbot is set up for automated code reviews on this repo. Configure here.

Inkling2ToolParser._split splits a completion into blocks at
<|message_model|> and starts a new block at every content marker.
tml_renderers.renderers.Inkling2 ends a block only at <|end_message|>: a
leading <|message_model|> is optional, and a later one, like a second content
marker, is body text.

A tool call that followed a text block without its <|end_message|>, or a
tool-call marker inside a text or thinking block, came back as an OK call,
where the reference keeps it as text. A block after <|end_message|> without
<|message_model|> was dropped, where the reference parses it.

Split blocks at <|end_message|> and read one content kind per block, from its
first marker.
@kalomaze
kalomaze marked this pull request as ready for review November 27, 2026 00:58

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.

1 participant