chat: read a function name that ends at whitespace (Ling 3.0)

Ling-3.0-flash's template writes a call as the opener, the function name, a
newline, and only then the argument tags:

    <tool_call>read
    <arg_key>path</arg_key>
    <arg_value>/a</arg_value>
    </tool_call>

The differential analysis names the function between the opener and the first
argument tag, so its end is the bare newline and name_suffix comes out as
whitespace alone. chat_format_check refused that, so every request carrying
tools answered 501 with "this model's tool calls cannot be read back:
name_suffix must end the function name with something besides whitespace" --
the whole tool-calling surface, for every Ling-3.0 checkpoint.

A suffix with no core of its own is the suffixless ending written out: the
name stops at the whitespace. The reader now takes it that way (name_open keys
on the trimmed core, so the name runs to the first arg_prefix or call_end,
whitespace trimmed), while the grammar still writes the template's newline.
The object family has no such terminator -- its brace ends the name -- and
keeps the refusal, as does the wrapped format whose bare name_prefix would
otherwise read as a call.

Adds the real template as a fixture and a regression test that derives the
format, builds the grammar, and reads a two-call reply built from the derived
fields; a second test pins the object family's refusal.
This commit is contained in:
Victor Ionescu authored and StillDeadcode committed 2026-11-16 18:03:16 +01:00
1 parent bd3fa646bc
commit b988378e70
8 files changed
+275 -21

No files matched your search

+12 -3
View File
@@ -2213,11 +2213,11 @@ int Engine::collect_step(const RadBatch* b, StepOut& so) {
* drive the KV rollback, the conv cursor and the emitted text) say how far the step
* really got. */
acc = accept_cut_at_eog(out, acc,
[&](int32_t t) { return vocab_ && vocab_->is_eog(t); });
[&](int32_t t) { return is_eog(t); });
so.accepted[i] = acc;
so.token[i] = out[acc];
so.eos[i] = vocab_ && vocab_->is_eog(so.token[i]) ? 1 : 0;
so.eos[i] = is_eog(so.token[i]) ? 1 : 0;
if (tree) {
if (so.path.empty()) so.path.assign(plan.e.size() * RAD_SCHED_MAX_SPEC, 0);
for (int32_t t = 0; t < acc; ++t) so.path[i * RAD_SCHED_MAX_SPEC + t] = path[t];
@@ -2254,7 +2254,7 @@ int Engine::collect_step(const RadBatch* b, StepOut& so) {
continue;
}
so.token[i] = so.rows[(size_t)so.first_row[i]];
so.eos[i] = vocab_ && vocab_->is_eog(so.token[i]) ? 1 : 0;
so.eos[i] = is_eog(so.token[i]) ? 1 : 0;
if (e.req && e.req->sp.n_probs >= 0)
RAD_TRY(row_logprobs(so, so.first_row[i], so.token[i]));
/* Advance the grammar on every rank: each builds the mask for its own vocabulary shard from
@@ -3392,6 +3392,15 @@ int Engine::run_server() {
const bool have_tpl = !gen_ && vocab_ && !vocab_->chat_template().empty() &&
chat_bridge.init(*vocab_, declared_format, plugins_.arch_plugin) >= 0 &&
chat_bridge.ready();
/* A token this format writes as one of its own call delimiters is a call boundary, not a
* turn's: a reply that closes a call with it must be able to write the next one, and text
* after it. A container that also declares it end-of-generation would cut every tool-calling
* turn there, so the id leaves the decoder's stop set. */
eog_demoted_ = chat_bridge.eog_call_markers();
for (int32_t id : eog_demoted_)
RAD_WARN("vocab: token %d \"%s\" is end-of-generation and one of this model's "
"tool-call delimiters; a turn no longer ends on it", id,
vocab_->text(id).c_str());
if (embedding_) {
/* No chat endpoint: the model's template, when it has one, renders a `messages` input. */
if (have_tpl) embed_info.tpl = &chat_bridge;