-
-
Notifications
You must be signed in to change notification settings - Fork 39.7k
Description
Bug Description
The pre-compaction memory flush instructs the AI agent to write to memory/YYYY-MM-DD.md, but the agent writes files with the wrong year (e.g., 2025-06-27.md instead of 2026-02-15.md). This happens because the agent has no reliable way to determine the current date during memory flush — the system prompt only includes the timezone, not the actual date.
Root Cause (two issues)
1. buildTimeSection() drops the computed userTime
File: dist/agents/system-prompt.js, line 37-41
function buildTimeSection(params) {
if (!params.userTimezone) return [];
return ["## Current Date & Time", `Time zone: ${params.userTimezone}`, ""];
}userTime (e.g., "Saturday, February 15th, 2026 — 6:37 PM") is correctly computed by formatUserTime() in date-time.js and passed through the entire call chain (compact.js:236 → system-prompt.js:25 → buildAgentSystemPrompt()), but buildTimeSection() only renders the timezone string and silently ignores the actual date/time value.
The agent's system prompt ends up with:
## Current Date & Time
Time zone: America/New_York
...instead of including the formatted date.
2. Memory flush prompt uses literal YYYY-MM-DD placeholder
File: dist/auto-reply/reply/memory-flush.js, line 6-9
export const DEFAULT_MEMORY_FLUSH_PROMPT = [
"Pre-compaction memory flush.",
"Store durable memories now (use memory/YYYY-MM-DD.md; create memory/ if needed).",
// ...
].join(" ");YYYY-MM-DD is passed as a literal string to the AI model. Without the actual date in the system prompt, the model must guess the year from its training data cutoff, which produces incorrect filenames.
Note: Cron jobs are unaffected because cron/isolated-agent/run.js (lines 170-172) correctly injects the date into the command body:
const formattedTime = formatUserTime(new Date(now), userTimezone, userTimeFormat);
const timeLine = `Current time: ${formattedTime} (${userTimezone})`;
commandBody = `${base}\n${timeLine}`.trim();Impact
On my system, 12 memory files were created with wrong filenames over the course of a single day. The model hallucinated dates ranging from 2025-01-30 to 2025-09-21 for content that was actually written on 2026-02-15. The month/day also varies randomly because the model invents plausible dates from its training data.
Suggested Fix
Fix 1: Include userTime in the system prompt
function buildTimeSection(params) {
if (!params.userTimezone) return [];
const lines = ["## Current Date & Time"];
if (params.userTime) lines.push(`Current time: ${params.userTime}`);
lines.push(`Time zone: ${params.userTimezone}`, "");
return lines;
}Fix 2: Substitute YYYY-MM-DD before sending to the agent
In agent-runner-memory.js, resolve the placeholder before passing it as the prompt:
const today = new Date().toISOString().split("T")[0];
const resolvedPrompt = memoryFlushSettings.prompt.replaceAll("YYYY-MM-DD", today);Both fixes are two-line changes. Fix 1 is the more general correctness fix; Fix 2 is the belt-and-suspenders defense for memory flush specifically.
Environment
- OpenClaw version:
2026.2.14 - OS: Windows 11
- Node.js: v22.22.0
- Primary model:
anthropic/claude-opus-4-5
Workaround
Override the memoryFlush.prompt in openclaw.json to force the agent to run a system command for the date:
"memoryFlush": {
"prompt": "Write any lasting notes to a dated file in memory/. CRITICAL: First run this command to get today's date: powershell -Command \"Get-Date -Format yyyy-MM-dd\" — then use THAT exact output as the filename. Do NOT guess or assume the date or year. Reply with NO_REPLY if nothing to store.",
"systemPrompt": "Pre-compaction memory flush. You MUST verify today's date via a system command before writing any memory file. Never assume the year."
}