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

+31 -6
View File
@@ -526,12 +526,7 @@ public:
* derive it from the template. A declaration the parser cannot run is refused at startup. */
int init(const Vocab& v, const RadChatFormat* declared = nullptr,
const std::string& plugin = std::string()) {
/* The spellings, resolved once. See ReplyOptions::terminators. */
terminators_.clear();
for (int32_t id : v.eog()) {
const std::string s = v.text(id);
if (!s.empty()) terminators_.push_back(s);
}
eog_call_markers_.clear();
const int st = t_.load_from_vocab(v);
if (st < 0) return st;
@@ -569,9 +564,38 @@ public:
RAD_INFO("chat: reply format %s", chat_format_describe(f).c_str());
if (t_.caps().tools && !tool_refusal_.empty())
RAD_WARN("chat: tool calls are refused for this model: %s", tool_refusal_.c_str());
/* A container can name a token end-of-generation that this format writes as one of its
* own call delimiters (a converted checkpoint that lists its tool-call close). A turn
* ending there loses a second call and anything after it, and a reply that quotes the tag
* is cut mid-sentence; the engine drops these ids from the decoder's set
* (Vocab::drop_eog). */
eog_call_markers_.clear();
if (f.has_tools())
for (const std::string& m : chat_format_markers(f))
for (int32_t id : v.eog())
if (v.text(id) == m &&
std::find(eog_call_markers_.begin(), eog_call_markers_.end(), id) ==
eog_call_markers_.end())
eog_call_markers_.push_back(id);
/* The spellings, resolved once. See ReplyOptions::terminators. A call delimiter the
* container also declares terminal is left out here too: the parser must read it as the
* call boundary it is, not as the end of the reply. */
terminators_.clear();
for (int32_t id : v.eog()) {
if (std::find(eog_call_markers_.begin(), eog_call_markers_.end(), id) !=
eog_call_markers_.end())
continue;
const std::string s = v.text(id);
if (!s.empty()) terminators_.push_back(s);
}
return RAD_OK;
}
/* End-of-generation ids whose spelling is one of the format's call delimiters: a call
* boundary the container also declares a turn boundary. Empty for a model without tools. */
const std::vector<int32_t>& eog_call_markers() const { return eog_call_markers_; }
bool ready() const { return t_.ready() && fmt_ != nullptr; }
bool supports_tools() const override { return t_.caps().tools; }
std::string tools_probe_error() const override { return t_.caps().probe_error; }
@@ -752,6 +776,7 @@ private:
ChatTemplate t_;
std::vector<std::string> terminators_;
std::vector<int32_t> eog_call_markers_;
std::shared_ptr<const ReplyFormat> fmt_;
bool declared_ = false;
std::string tool_refusal_;