Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
3.2 KiB
Python
76 lines
3.2 KiB
Python
"""I6 (tools and images review, 2026-10-22): a picture a tool returned, with an elastic image encoder that is not running,
|
|
used to write to a process that did not exist (AttributeError, then a 400 "malformed request" that every later turn of the
|
|
conversation repeated). It starts the encoder like a picture of the user does; when it cannot start, the picture becomes
|
|
an "[image omitted: why]" note.
|
|
|
|
python -m serve.test_vision_tool_image
|
|
"""
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
from pathlib import Path
|
|
|
|
from serve.frontend import ChatTemplate
|
|
from serve.server import ByteTokenizer, Service, Vision
|
|
from serve.test_vision_elastic import ElasticVision
|
|
from serve.test_vram import VramEngine
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def tool_turn():
|
|
return [{"role": "user", "content": "look at it"},
|
|
{"role": "tool", "tool_call_id": "t1", "content": [{"type": "image", "source": "x.png"}]}]
|
|
|
|
|
|
class FailingStart(ElasticVision):
|
|
def restart(self):
|
|
raise RuntimeError("the vision encoder did not start: it ended without saying anything (exit code 1)")
|
|
|
|
|
|
class ToolImage(unittest.TestCase):
|
|
def service(self, vision):
|
|
tok = ByteTokenizer()
|
|
engine = VramEngine(tok)
|
|
engine.loaded = True
|
|
return Service(engine, tok, ChatTemplate(ROOT / "serve/chat_template.jinja"), vision=vision)
|
|
|
|
def test_an_elastic_encoder_is_started_for_a_tool_picture(self):
|
|
vision = ElasticVision(tempfile.mkdtemp())
|
|
svc = self.service(vision)
|
|
messages = tool_turn()
|
|
svc._note_unreadable_tool_images(messages)
|
|
self.assertEqual(vision.starts, 1)
|
|
self.assertEqual(messages[1]["content"][0]["type"], "image") # kept: it was read
|
|
svc._note_unreadable_tool_images(messages) # the running encoder is used as it is
|
|
self.assertEqual(vision.starts, 1)
|
|
|
|
def test_an_encoder_that_cannot_start_leaves_a_note_not_a_400(self):
|
|
svc = self.service(FailingStart(tempfile.mkdtemp()))
|
|
messages = tool_turn()
|
|
svc._note_unreadable_tool_images(messages) # no exception
|
|
part = messages[1]["content"][0]
|
|
self.assertEqual(part["type"], "text")
|
|
self.assertIn("[image omitted:", part["text"])
|
|
self.assertIn("did not start", part["text"])
|
|
|
|
def test_prepare_survives_a_tool_picture_with_an_elastic_encoder(self):
|
|
vision = ElasticVision(tempfile.mkdtemp())
|
|
svc = self.service(vision)
|
|
self.addCleanup(lambda: getattr(svc.embeddings, "path", None) and svc.embeddings.path.unlink(missing_ok=True))
|
|
svc.prepare(tool_turn(), None, {})
|
|
self.assertEqual(vision.starts, 1)
|
|
|
|
def test_encode_without_a_running_reader_is_a_clear_value_error(self):
|
|
v = Vision.__new__(Vision)
|
|
v.dir, v.cache, v.proc = Path(tempfile.mkdtemp()), {}, None
|
|
import threading
|
|
v.lock = threading.Lock()
|
|
with mock.patch.object(Vision, "normalize", return_value=b"png"), self.assertRaises(ValueError) as cm:
|
|
v.encode(b"bytes")
|
|
self.assertIn("picture reader is not running", str(cm.exception))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|