diff --git a/install-ornith-122b.sh b/install-ornith-122b.sh index 8e09cd56..3336dfc8 100755 --- a/install-ornith-122b.sh +++ b/install-ornith-122b.sh @@ -138,6 +138,7 @@ render_unit(){ # of its own (the proxy gives it one through enable_thinking), so those are its only fixes. Written again at every install and every switch, and left # as it is, mtime included, when nothing changed. TEMPLATE="$CONFIG_DIR/chat-template-ornith-122b.jinja" +# shellcheck disable=SC2054 # one argument: patch-template.py takes its fixes' names comma-separated TEMPLATE_FIXES=(--patches=system-reminder,tool-reference) lane_template(){ vlane_template "$TEMPLATE" "${TEMPLATE_FIXES[@]}"; } diff --git a/patch-template.py b/patch-template.py index d35730c0..7f295b72 100755 --- a/patch-template.py +++ b/patch-template.py @@ -129,11 +129,12 @@ TOOL_REF_PATCHED = ( " {{- raise_exception('Unexpected item type in content.') }}\n" ) TOOL_REF_MARKER = "item.type == 'tool_reference'" -# A template is left as it is only when it raises nothing at all: a guard on the name of the macro -# skipped the fix for a template that raises in a renamed macro or inline, and one on the error's words -# for a template that words it otherwise, and the install went on with every turn after a ToolSearch a -# 500 again (code reviews, 2026-10-26). One that raises anywhere the fix cannot reach stops the install. -TOOL_REF_RAISE = "raise_exception(" +# A template is left as it is only when it never names raise_exception: a guard on the name of the macro +# skipped the fix for a template that raises in a renamed macro or inline, one on the error's words for a +# template that words it otherwise, and one on "raise_exception(" for a space before the parenthesis or an +# alias of the function, and the install went on with every turn after a ToolSearch a 500 again (code +# reviews, 2026-10-26). One that can raise anywhere the fix cannot reach stops the install. +TOOL_REF_RAISE = "raise_exception" # The five fixes by name, in the order they are applied (--patches picks among them). diff --git a/tests/test_lean_level.py b/tests/test_lean_level.py index 68770444..075aa3ac 100644 --- a/tests/test_lean_level.py +++ b/tests/test_lean_level.py @@ -62,6 +62,17 @@ STOCK = ( "{%- elif reasoning_instructions %}\n" "{{- '<|im_start|>system\\n' + reasoning_instructions + '<|im_end|>\\n' }}\n" "{%- endif %}\n" + # the content loop the tool-reference fix anchors on, as the 27B's template has it: a template + # that raises where that fix cannot reach stops the install (code reviews, 2026-10-26). Defined + # and not called, it renders nothing. + "{%- macro render_content(content) %}\n" + " {%- for item in content %}\n" + " {%- if 'image' in item %}\n" + " {{- '' }}\n" + + pt.TOOL_REF_ANCHOR + + " {%- endif %}\n" + " {%- endfor %}\n" + "{%- endmacro %}\n" # SYSTEM_ANCHOR opens an if inside the message loop; the fixture closes both # so the result is a template jinja2 can actually compile and render. "{%- for message in messages %}\n" diff --git a/tests/test_patch_template.py b/tests/test_patch_template.py index 323f4589..53ee31e3 100755 --- a/tests/test_patch_template.py +++ b/tests/test_patch_template.py @@ -176,8 +176,12 @@ def main() -> None: "{{ raise_exception('Unexpected item type in content.') }}{%- endif %}{%- endfor %}", False), ("{%- for item in content %}{%- if item.type == 'text' %}{{ item.text }}{%- else %}" "{{ raise_exception('Unexpected content item type: ' ~ item.type) }}{%- endif %}{%- endfor %}", False), + ("{%- for item in content %}{%- if item.type == 'text' %}{{ item.text }}{%- else %}" + "{{ raise_exception ('Unknown item') }}{%- endif %}{%- endfor %}", False), + ("{%- set fail = raise_exception %}{%- for item in content %}{%- if item.type == 'text' %}" + "{{ item.text }}{%- else %}{{ fail('Unknown item') }}{%- endif %}{%- endfor %}", False), ("{%- for item in content %}{{ item.text }}{%- endfor %}", True))): - other_repo, other_sha = "org/next-checkpoint", "abf"[n] * 40 + other_repo, other_sha = "org/next-checkpoint", "abcdf"[n] * 40 make_fixture(base, other_repo, other_sha, body) other_out = os.path.join(base, f"next-{n}.jinja") r = subprocess.run([sys.executable, SCRIPT, "--patches=tool-reference", base, other_out, other_sha, diff --git a/tests/test_patch_template_default_kept.py b/tests/test_patch_template_default_kept.py index a6749423..15244a93 100644 --- a/tests/test_patch_template_default_kept.py +++ b/tests/test_patch_template_default_kept.py @@ -34,7 +34,8 @@ class TheDefaultIsKept(unittest.TestCase): snap = self.base / "hub" / "models--org--model" / "snapshots" / SHA snap.mkdir(parents=True) (snap / "chat_template.jinja").write_text( - "HEAD\n" + pt.EFFORT_ANCHOR + "\n" + pt.MSG_ANCHOR + "\nMID\n" + pt.LEAN_ANCHOR + pt.SYSTEM_ANCHOR + "\nTAIL\n") + "HEAD\n" + pt.EFFORT_ANCHOR + "\n" + pt.MSG_ANCHOR + "\nMID\n" + pt.LEAN_ANCHOR + pt.SYSTEM_ANCHOR + + "\n" + pt.TOOL_REF_ANCHOR + "\nTAIL\n") # the five anchors, as the 27B's template has them self.out = self.base / "out.jinja" def run_patch(self, lean_default=None):