Skip to content

llamacpp adapter: her text turn renders and parses through the model's own chat handling (S2b slice 1) - #6145

Merged
joelteply merged 12 commits into
canaryfrom
fable/s2b-chat-turn
Nov 18, 2026
Merged

joelteply merged 12 commits into
canaryfrom
fable/s2b-chat-turn

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Serving S2b slice 1, stacked on #6144 (move-only). Design agreed with Codex on airc 2026-11-18 18:52Z.

A text turn on the in-process adapter now renders through the model's own chat handling (ChatTemplates, #6142) with her tools, and what she writes is parsed by the same ChatRender into content, reasoning and native tool calls.

Owners reused, nothing parallel:

  • request: request_body::wire_messages and request_body::openai_tools, which serving already sends and the trainer renders a lived turn from;
  • calls: the assembly inline in openai_adapter/stream.rs moves to inference::native_tool_calls::assemble, which both paths now call;
  • content blocks: native_tool_calls::content_blocks, which both paths now use.

Codex's conditions:

  • One ChatRender per request, from render to final parse.
  • ChatTemplates is Send, not Sync. It sits in a OnceLock<Result<Mutex<_>>> beside the model, and the lock is held for the render alone, released before decode.
  • No resident is routed here until slice 2 and the real tool/grammar proofs. There's no fallback launch and no second decode.
  • The persisted lived turn is unchanged: prompt capture records at the cognition layer (system, messages, offered tools, response), above any adapter. Open question for Codex: should the rendered prompt itself be recorded as well?

Refused rather than widened: a named tool_choice (ChatTurnError::SpecificToolChoice), because the model's own parser takes a mode.

Media turns keep the plain template until mtmd takes a chat render.

Slice 2 (separate PR): the render's grammar, lazy triggers, preserved tokens and extra stops go into the sampler. Then the four proofs: a streamed native tool call, a schema, a reasoning budget, and a resumed native prefix.

Measured

Not built locally (this machine serves), so CI is the first compile. Model-free tests:

  • her_turn_renders_the_wire_messages_and_tools_serving_sends
  • a_named_tool_choice_is_refused_not_widened
  • a_decode_that_reached_its_cap_ended_at_the_output_limit

The real-model checks are slice 2's four proofs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 5 commits November 18, 2026 12:49
…nged

Serving S2b routes a resident's turn through the model's own chat handling (ChatRender, #6142):
render with tools and reasoning, parse native tool calls. That work lands in generate_text, a
392-line body inside the 853-line adapter file, which would cross the 1,000-line rule. This is the
move only: LlamaCppAdapter::generate in llamacpp_adapter/generate.rs (404 lines), the trait method
delegates. No line of the body changes; llamacpp_adapter.rs is 463 lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
The streamed OpenAI-compatible path assembled a model's native tool calls inline in
openai_adapter/stream.rs (name filter, UnparsedArguments::parse with the generation end, the
unparseable-arguments probe, ToolCall). The in-process engine reads the same calls from the
model's own chat parser (S2b), so the assembly moves to inference::native_tool_calls::assemble and
both call it: a call's fate reads the same whichever engine served her turn. Behavior unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…s own chat handling (S2b slice 1)

A text turn now renders through ChatTemplates (llama.cpp common/chat, #6142) with her tools, from
the same wire_messages and openai_tools serving sends, and what she writes is parsed by that same
ChatRender into content, reasoning and native tool calls. The calls are assembled by
native_tool_calls::assemble, the owner the streamed path uses; content blocks come from
native_tool_calls::content_blocks, which the streamed path now uses too.

- LlamaCppBackend::render_chat_turn: templates load once beside the model (OnceLock, Mutex: the
  templates are Send, not Sync); the lock is held for the render alone, released before decode.
- One ChatRender per request, from render to final parse.
- A named tool_choice is refused (ChatTurnError::SpecificToolChoice): the model's own tool-choice
  parser takes a mode, and widening a name to any tool would be a silent change.
- Media turns keep the plain template until mtmd takes a chat render.

Not in this slice (slice 2): the render's grammar, lazy triggers, preserved tokens and extra stops
into the sampler, then the four proofs. No resident is routed here until then.

Tests: her_turn_renders_the_wire_messages_and_tools_serving_sends,
a_named_tool_choice_is_refused_not_widened, a_decode_that_reached_its_cap_ended_at_the_output_limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…d (stringly_errors ratchet)

f556a46 moved generate_text's body into an inherent LlamaCppAdapter::generate, which added a
second Result<_, String> signature beside the trait's (stringly_errors 4245 -> 4246). The move is now
the whole AIProviderAdapter impl into llamacpp_adapter/provider.rs, the way openai_adapter/provider.rs
holds that adapter's: no new signature, generate.rs is gone. Verified byte-exact: provider.rs after
its header equals canary's llamacpp_adapter.rs lines 188-853; llamacpp_adapter.rs equals lines
1-187 plus 'mod provider;'. 853 -> 188 + 673 lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…o S2b slice 1

Git carried slice 1's edits through the generate.rs -> provider.rs rename: the chat render, parse
and response fields now sit inside AIProviderAdapter::generate_text in provider.rs (704 lines).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ngth, only media turns build the plain-template messages (Codex on #6145)

- The registry template is the chat render's override only for a model without its own; with
  one, common/chat loads the GGUF's templates (its named tool_use one among them), which an
  explicit override suppresses (common/chat.cpp:761-776).
- finish_reason(end, called): the output limit first, so a turn the cap cut (even mid-call)
  reads Length, never ToolUse/Stop.
- carries_media decides the path before anything is built: a text turn no longer clones every
  message into ChatMsg to discard it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@github-actions github-actions Bot added size: XL and removed size: L labels Nov 18, 2026
joelteply and others added 5 commits November 18, 2026 13:09
…'s default OR named tool_use template (Codex on #6145)

A GGUF carrying only tokenizer.chat_template.tool_use read as having no template (chat_template()
queries the default only), so the registry template masked the model's own. Now the one-time
ChatTemplates init asks Model::has_chat_template (pointer check, no copy) for the default or the
named tool_use template, and asks for the registry template only when both are absent. The
registry lookup is a closure: a text turn copies no template string; the media path resolves its
plain template where it renders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…fusal carries the choice, assemble takes the calls as they come

Pays back the three ratchets bb0a6f2 raised:
- string_identities (+3): prompt_of and parse_turn deserialize Described / ParsedMessage /
  ParsedCall instead of reading .get("prompt"|"tool_calls"|"id") by name.
- stringly_errors (+1): ChatTurnError::SpecificToolChoice carries the ToolChoice, not its name.
- contract_shape (+1): native_tool_calls::assemble takes impl IntoIterator<Item = StreamToolAccum>
  (it consumes them); parse_turn feeds its calls straight in, no intermediate Vec.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Base automatically changed from fable/adapter-generate-split to canary November 18, 2026 19:56
@joelteply
joelteply marked this pull request as ready for review November 18, 2026 20:26
# Conflicts:
#	core/continuum-engine/src/inference/llamacpp_adapter/provider.rs
@joelteply
joelteply merged commit 3336b95 into canary Nov 18, 2026
33 checks passed
@joelteply
joelteply deleted the fable/s2b-chat-turn branch November 18, 2026 20:47
joelteply added a commit that referenced this pull request Nov 19, 2026
…'s ChatRender), the residents' contract ported onto it

Canary's serving S2a/S2b (#6142, #6145) and this branch's 75cea66 built the same capability twice
(chat_boundary.cpp + ChatRender + chat_turn.rs, and chat_template.cpp + chat_template.rs +
native_chat.rs); both defined continuum_chat_free, so they could not link together. Canary's stays
the owner (agreed with Codex, 06:07Z). Ported onto it, the three things residents need that it lacked:

- the think budget: chat_boundary's continuum_chat_reasoning_budget (llama.cpp's
  common_reasoning_budget, what llama-server ran) as llama::SamplerChainBuilder::reasoning_budget,
  bounded by the render's own thinking tags (chat_turn::Described::think_bound); a stated zero
  budget renders with enable_thinking off (chat_turn::thinking_request);
- the template's extra stops (Described::additional_stops) into the decode's stops;
- her view's end (chat_turn::view_text: her view rendered by the same templates, generation prompt
  off; describe now returns generation_prompt), passed as TurnPrompt.stable_prefix so the engine
  checkpoints her there (CONTINUUM-ENGINE 4.15).

Deleted: core/llama/chat_template.cpp, src/safe/chat_template.rs, llamacpp_adapter/native_chat.rs,
LlamaCppBackend::chat_templates and its second `chat` field, the inline AIProviderAdapter impl (it
lives in provider.rs on canary), and the llama crate's serde deps. The fork pin moves to 2869b164a7
(fable/persona-files merged with 51c7089eec, so it carries canary's 74be098b5 and #6156's pooled
graph).

Checked with serving down (06:08-06:13Z): cargo check of continuum-core, continuum-engine --tests,
the persona crates and the metal example; llama chat tests 3/3; persona-engine 21/21.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant