Repository navigation
Studio llama.cpp: the token-count memo renders again on a new day - #17090
Merged
Merged
Conversation
The memo key held everything the request sends to /apply-template but not the date, and llama.cpp renders date_string / strftime_now from its own clock (Llama 3.x templates print today's date), so a count memoised before midnight was returned after it. The local date is now part of the key.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
#16756 memoises Studio's llama.cpp chat token count, so a tool round that recounts the prompt it just fitted reuses one
/apply-template+/tokenizerender. The memo key covers the llama-server process, the model and every render input Studio sends, with an 8-entry LRU and no expiry.It does not cover the clock. llama.cpp builds
date_stringfrom the current time and gives Jinja templatesstrftime_now, and published templates print today's date (the Llama 3.2 template's "Today Date"). The same request rendered after midnight is a different prompt, possibly with a different token count, but the memo returns the old count for as long as the entry stays in the LRU. Reproduced with that template and a mocked server whose date moved from March 31 to April 1: the memo returned the March count (111 tokens) where a fresh render gives 112.Change
The memo key also holds the local date (
time.strftime("%Y-%m-%d"); llama-server is a local process on the same clock). Within a day, nothing changes: identical recounts still hit. On a new day the first count renders again.Cost: one
time.strftimecall per count, next to an HTTP round trip.Tests
test_a_new_day_renders_again: two identical counts on one day render once, the same count the next day renders again.test_llama_count_memo.pya174823)Not covered
strftime_now("%H:%M")) can still be off by its time string within one day. That spelling is not in the templates llama.cpp ships, and the count only sizes the context window.