diff --git a/tests/chat_test.cpp b/tests/chat_test.cpp
index 32c04564..7bdb06bc 100644
--- a/tests/chat_test.cpp
+++ b/tests/chat_test.cpp
@@ -1016,6 +1016,33 @@ TEST(the_capability_probe_reads_what_the_template_actually_does) {
CHECK(c.system_role);
}
+/* jinja2 reads `obj.0` as `obj[0]`, and GLM-5's template tests a tool result with
+ * `m.content.0.type`. The engine threw on it, and the probe, which swallows a throw, reported a
+ * template that renders tools as one that cannot: every request with `tools` was refused. */
+TEST(a_dotted_integer_is_an_index_as_in_jinja2) {
+ ChatTemplate glm;
+ CHECK_OK(glm.load(
+ "{%- if tools %}{% for t in tools %}{{ t.function.name }};{% endfor %}{% endif %}"
+ "{%- for m in messages %}"
+ "{%- if m.role == 'tool' and m.content is not mapping and m.content.0.type == 'tool_reference' %}"
+ "{%- else %}<{{ m.role }}>{{ m.content }}"
+ "{%- if m.tool_calls %}{% for c in m.tool_calls %}{{ c.function.name }}{% endfor %}{% endif %}"
+ "{{ m.role }}>{%- endif %}"
+ "{%- endfor %}"
+ "{%- if add_generation_prompt %}{% endif %}", "", ""));
+ CHECK(glm.caps().tools);
+ CHECK(glm.caps().tool_calls);
+
+ ChatTemplate first;
+ CHECK_OK(first.load("{{ messages.0.content }}|{{ messages.1.role }}", "", ""));
+ json msgs = json::array();
+ msgs.push_back({{"role", "user"}, {"content", "hi"}});
+ msgs.push_back({{"role", "assistant"}, {"content", "hello"}});
+ ChatPrompt p;
+ CHECK_OK(first.apply(msgs, json(), ChatOptions{}, &p));
+ CHECK_EQ(p.prompt, std::string("hi|assistant"));
+}
+
/* Unparseable Jinja (common in hand-built containers) is reported at load time as an error value;
* a throw would cross the bringup path. */
TEST(a_template_that_does_not_parse_is_a_value_and_not_a_throw) {
diff --git a/vendor/UPSTREAM b/vendor/UPSTREAM
index a2fcf8ef..12b439eb 100644
--- a/vendor/UPSTREAM
+++ b/vendor/UPSTREAM
@@ -64,6 +64,7 @@ vendor/llama/common/jinja/ <- llama.cpp common/jinja/
llama.h, no common.h -- which is why it lifts cleanly and chat.cpp did not.
LOCAL CHANGES: patches/0015-jinja-print-a-list-or-a-dict-as-its-repr.patch
+ patches/0021-jinja-a-dotted-integer-is-an-index.patch
vendor/llama/common/chat.{h,cpp}
vendor/llama/common/chat-auto-parser.h
@@ -554,3 +555,12 @@ PATCH SERIES
\u form of a character it leaves out (\u0009 for \t), and a positive class admits \t \n
\r \f \b only in their short form. gbnf_test covers each escape in and out of a class, quantified, and negated, and the
refusals.
+
+ patches/0021-jinja-a-dotted-integer-is-an-index.patch
+
+ llama.cpp's ae9afff8 ("jinja : support dot property integer literals (#28817)"), after the
+ lifted commit; drop it on the next refresh. jinja2 reads `obj.0` as `obj[0]`; the engine
+ threw "Static member property must be an identifier". GLM-5's template tests a tool result
+ with `m.content.0.type`, and since the probe swallows the throw the template came back as
+ tools=0 tool_calls=0, as 0006 describes: every request with `tools` was refused.
+ tests/chat_test.cpp (a_dotted_integer_is_an_index_as_in_jinja2).
diff --git a/vendor/llama/common/jinja/runtime.cpp b/vendor/llama/common/jinja/runtime.cpp
index f81d98d9..5a089d3d 100644
--- a/vendor/llama/common/jinja/runtime.cpp
+++ b/vendor/llama/common/jinja/runtime.cpp
@@ -779,6 +779,12 @@ value member_expression::execute_impl(context & ctx) {
} else {
property = this->property->execute(ctx);
}
+ } else if (is_stmt(this->property)) {
+ // syntax: obj.index
+ property = mk_val(cast_stmt(this->property)->val);
+ if (property->as_int() < 0) {
+ throw std::runtime_error("Static member property cannot be negative");
+ }
} else {
// syntax: obj.prop
if (!is_stmt(this->property)) {
diff --git a/vendor/patches/0021-jinja-a-dotted-integer-is-an-index.patch b/vendor/patches/0021-jinja-a-dotted-integer-is-an-index.patch
new file mode 100644
index 00000000..435443f3
--- /dev/null
+++ b/vendor/patches/0021-jinja-a-dotted-integer-is-an-index.patch
@@ -0,0 +1,17 @@
+diff --git a/common/jinja/runtime.cpp b/common/jinja/runtime.cpp
+index f81d98d..5a089d3 100644
+--- a/common/jinja/runtime.cpp
++++ b/common/jinja/runtime.cpp
+@@ -779,6 +779,12 @@ value member_expression::execute_impl(context & ctx) {
+ } else {
+ property = this->property->execute(ctx);
+ }
++ } else if (is_stmt(this->property)) {
++ // syntax: obj.index
++ property = mk_val(cast_stmt(this->property)->val);
++ if (property->as_int() < 0) {
++ throw std::runtime_error("Static member property cannot be negative");
++ }
+ } else {
+ // syntax: obj.prop
+ if (!is_stmt(this->property)) {