Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio llama.cpp: the token-count memo renders again on a new day (#17090)

Daniel Hanf54a4710b2c7
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 5d8bfddfa6d..91c4f16394d 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -8202,6 +8202,8 @@ def _count_memo_key(backend, *parts) -> Optional[bytes]:
getattr(backend, "_model_identifier", None),
id(process),
getattr(process, "pid", None),
+ # llama.cpp renders date_string / strftime_now from its clock (Llama 3.x templates print the date)
+ time.strftime("%Y-%m-%d"),
*parts,
],
sort_keys = True,
diff --git a/studio/backend/tests/test_llama_count_memo.py b/studio/backend/tests/test_llama_count_memo.py
index 11a83d4d6ae..32a05c26f90 100644
--- a/studio/backend/tests/test_llama_count_memo.py
+++ b/studio/backend/tests/test_llama_count_memo.py
@@ -89,6 +89,19 @@ def test_anything_the_render_sees_misses(monkeypatch, change):
assert paths.count("/tokenize") == before + 1
+def test_a_new_day_renders_again(monkeypatch):
+ from core.inference import llama_cpp
+
+ backend, paths = _setup(monkeypatch)
+ day = ["2026-03-31"]
+ monkeypatch.setattr(llama_cpp.time, "strftime", lambda fmt, *a: day[0])
+ backend.count_chat_tokens(_MESSAGES, None, _TOOLS, strict = True)
+ backend.count_chat_tokens(_MESSAGES, None, _TOOLS, strict = True)
+ day[0] = "2026-04-01"
+ backend.count_chat_tokens(_MESSAGES, None, _TOOLS, strict = True)
+ assert paths == ["/apply-template", "/tokenize"] * 2
+
+
def test_a_failed_render_is_not_remembered(monkeypatch):
backend, paths = _setup(monkeypatch, status = 503)
with pytest.raises(RuntimeError):