From 034d4513d9bc57a36f9ff31126736b90c7cd6e2f Mon Sep 17 00:00:00 2001 From: Conroy Whitney Date: Wed, 28 Jan 2026 20:08:31 -0500 Subject: [PATCH] fix(system-prompt): hint session_status for date/time instead of embedding it The system prompt intentionally excludes the current date/time for cache stability (see 66eec295b). This leaves agents without date awareness, causing wrong day-of-week claims (#1897, #1928, #2108). Instead of reverting the cache optimization, add a one-line hint directing agents to use session_status when they need the current date/time. This keeps the prompt stable while teaching frontier models where to look. Also adds a negative test ensuring the date/time is NOT re-added to the system prompt, with comments explaining why and pointing to #3658 for the complementary gateway-level timestamp injection approach. Refs: #1897, #1928, #3658 --- src/agents/system-prompt.test.ts | 35 ++++++++++++++++++++++++++++++++ src/agents/system-prompt.ts | 7 ++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/agents/system-prompt.test.ts b/src/agents/system-prompt.test.ts index d915792af..aa4417079 100644 --- a/src/agents/system-prompt.test.ts +++ b/src/agents/system-prompt.test.ts @@ -171,6 +171,41 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("Time zone: America/Chicago"); }); + it("hints to use session_status for current date/time", () => { + const prompt = buildAgentSystemPrompt({ + workspaceDir: "/tmp/clawd", + userTimezone: "America/Chicago", + }); + + expect(prompt).toContain("session_status"); + expect(prompt).toContain("current date"); + }); + + // The system prompt intentionally does NOT include the current date/time. + // Only the timezone is included, to keep the prompt stable for caching. + // See: https://github.com/moltbot/moltbot/commit/66eec295b894bce8333886cfbca3b960c57c4946 + // Agents should use session_status or message timestamps to determine the date/time. + // Related: https://github.com/moltbot/moltbot/issues/1897 + // https://github.com/moltbot/moltbot/issues/3658 + it("does NOT include a date or time in the system prompt (cache stability)", () => { + const prompt = buildAgentSystemPrompt({ + workspaceDir: "/tmp/clawd", + userTimezone: "America/Chicago", + userTime: "Monday, January 5th, 2026 — 3:26 PM", + userTimeFormat: "12", + }); + + // The prompt should contain the timezone but NOT the formatted date/time string. + // This is intentional for prompt cache stability — the date/time was removed in + // commit 66eec295b. If you're here because you want to add it back, please see + // https://github.com/moltbot/moltbot/issues/3658 for the preferred approach: + // gateway-level timestamp injection into messages, not the system prompt. + expect(prompt).toContain("Time zone: America/Chicago"); + expect(prompt).not.toContain("Monday, January 5th, 2026"); + expect(prompt).not.toContain("3:26 PM"); + expect(prompt).not.toContain("15:26"); + }); + it("includes model alias guidance when aliases are provided", () => { const prompt = buildAgentSystemPrompt({ workspaceDir: "/tmp/clawd", diff --git a/src/agents/system-prompt.ts b/src/agents/system-prompt.ts index ed97fd539..3bb8caccc 100644 --- a/src/agents/system-prompt.ts +++ b/src/agents/system-prompt.ts @@ -51,7 +51,12 @@ function buildUserIdentitySection(ownerLine: string | undefined, isMinimal: bool function buildTimeSection(params: { userTimezone?: string }) { if (!params.userTimezone) return []; - return ["## Current Date & Time", `Time zone: ${params.userTimezone}`, ""]; + return [ + "## Current Date & Time", + `Time zone: ${params.userTimezone}`, + "If you need the current date, time, or day of week, use the session_status tool.", + "", + ]; } function buildReplyTagsSection(isMinimal: boolean) {