[BUG]: Default `{datetime}` in system prompt breaks prefix cache reuse across minute boundaries
What happened?
#6016 (addressing #6014) added this sentence to the default system prompt:
The current date and time is {datetime}.
{datetime} expands to moment().format("LLLL"), which changes at every minute boundary. The expansion runs on every request in both the chat and agent system-prompt paths.
Prompt caching is prefix-based (Anthropic cache_control, OpenAI automatic prefix caching, KV-cache reuse in llama.cpp / vLLM / Ollama). Because the timestamp sits near the beginning of the system prompt — the first content of every request — a minute change invalidates the cached prefix from that position onward: the rest of the system prompt, RAG context, memories, and the entire chat history. Consecutive turns rarely land in the same minute, so in practice every turn is a miss for every workspace on the default prompt. With ANTHROPIC_CACHE_CONTROL enabled, each turn additionally pays the cache-write premium with effectively no hits.
#6014 noted that "the small amount of tokens should have very little impact". That holds for token count; the problem is their position.
Relevant code:
server/models/systemSettings.js—saneDefaultSystemPromptserver/models/systemPromptVariables.js—{datetime}expansionserver/utils/chats/index.js—chatPrompt()(chat path)server/utils/agents/aibitat/providers/ai-provider.js—Provider.systemPrompt()(agent path)
Steps to reproduce
- Use a workspace on the default system prompt.
- Build its system prompt with
chatPrompt(workspace)(orProvider.systemPrompt({ workspace })for the agent path). - Advance the clock across a minute boundary and build it again.
- Compare: the two strings differ near the beginning, even though the workspace configuration is unchanged.
This demonstrates the changing prefix; actual cache behavior can be confirmed with provider-side cache metrics.
Expected behavior
Everything before the latest user message stays byte-identical between turns, while the model still receives the current date and time.
One way to achieve this is to append the current datetime to the latest user message instead of embedding it in the system prompt — the last user message is new on every turn anyway.
Affected workspaces
- Workspaces whose
openAiPromptisnulland resolve to the default at runtime. - Workspaces created since #6016 without a custom prompt:
Workspace.new()persists the default text intoopenAiPrompt(server/models/workspace.js), so changing the default constant alone does not fix existing records.
Custom prompts that explicitly use {datetime} or other time variables are out of scope: that is an opt-in the user made, and #6016 did not change it.
Source: Mintplex-Labs/anything-llm