fix(session): move datetime from env block to user message - #35310
fix(session): move datetime from env block to user message#35310malventano wants to merge 1 commit into
Conversation
|
Equivalent plugin that does the same thing for those not wanting to rebuild Opencode with the PR: |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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