fix: freeze memory metadata timestamps in system prompt head - #20
Open
Ghilteras wants to merge 1 commit into
Open
fix: freeze memory metadata timestamps in system prompt head#20Ghilteras wants to merge 1 commit into
Ghilteras wants to merge 1 commit into
Conversation
renderMemoryMetadata() emitted new Date().toISOString() on every request, spliced at index 1 of the system prompt. Provider prompt caching requires a byte-identical prefix: the millisecond timestamp made the cache never match past the injection point, so the full conversation was re-sent as fresh input on every turn (measured: cache hit 94% -> 15%, ~10x cost). Fixes #8, closes the issue raised in #14.
Ghilteras
force-pushed
the
fix/freeze-metadata-timestamp
branch
from
August 3, 2026 06:14
90ebe80 to
8faac95
Compare
Author
|
@joshuadavidthomas can we unblock this |
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
renderMemoryMetadata() emits
new Date().toISOString()(millisecond precision) on every request. The system.transform hook splices it at index 1 of the system prompt. Provider prompt caching is prefix-based: a changing byte near the top means the cache never matches past it — the entire conversation re-sends as fresh input every turn.Measured impact
In production (opencode + DeepSeek): cache hit ratio collapsed from ~94% to ~15%, daily cost ~13x. Fingerprint: cache_read pinned to the static base prompt size for every message.
Fix
Freeze the metadata block — no dynamic timestamps. opencode already injects the current date in the env block, so this loses no information. Memory blocks themselves still appear in the prompt and change when written (memory_set/replace), which is the intended cache-busting event; the per-request timestamp was not.
Test
Replaced the timestamp-asserting test with a stability regression test (two render calls → identical output). All tests + typecheck pass.
Fixes #8. Related: #14.