fix(session): move datetime from env block to user message#35310
Open
malventano wants to merge 1 commit into
Open
fix(session): move datetime from env block to user message#35310malventano wants to merge 1 commit into
malventano wants to merge 1 commit into
Conversation
Author
|
Equivalent plugin that does the same thing for those not wanting to rebuild Opencode with the PR: |
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.
Issue for this PR
Closes #29672, #32622
Type of change
What does this PR do?
The env block's
Today's dateis the only dynamic field in an otherwise static system prompt. It changes at midnight, invalidating the KV cache for every active session, subagent, and background task that continues into the next day. The cost impact ranges from 10x (Anthropic) to 120x (DeepSeek) cache miss premium per session, and self-hosted users take a TTFT stall from full re-prefill on every resumed session.This removes the date from env and moves it to a
<system-reminder>tag on the last user message, usinginfo.time.created(DB-persisted message creation timestamp), upgrading from date-only to full datetime (toString()) so the model gets time and timezone context for elapsed-time reasoning across tool call chains. The env block is now fully static; the stamp lives after the cache boundary, re-derived from immutable metadata each step.Cost impact
When the cached prefix changes, providers reprocess the full system prompt at the uncached rate:
For a 100K-token session crossing midnight, avoidable cost is $0.27 (Sonnet) to $0.45 (Opus) per session. A real-user report measured ~$0.50/session spike at midnight (#31266). Multiplied by every concurrent session, subagent, and background task across all users crossing midnight simultaneously.
Performance impact
For self-hosted users (vLLM, TGI, Ollama, llama.cpp), a midnight boundary forces a full re-prefill on every session continuing into the next day. For a 100K-token prompt, prefill can take tens of seconds to minutes, the user feels this as a TTFT stall on the first prompt after midnight, on every session resumed the next day. With a static env block, the KV cache persists across days and session resumptions, so prefill runs once and is reused indefinitely.
References: #31266, #31363, measured DeepSeek cost data
Supersedes #32677, #33246.
How did you verify your code works?
Built locally. Confirmed the env block no longer contains the date string, and the last user message receives a
<system-reminder>with the full datetime stamp including timezone. The stamp is re-derived frominfo.time.createdeach step, so it persists across the conversation without DB writes.Screenshots / recordings
N/A -- terminal behavior
Checklist