diff --git a/hindsight-integrations/openclaw/src/index.test.ts b/hindsight-integrations/openclaw/src/index.test.ts index b88fa0a39f..56090702e8 100644 --- a/hindsight-integrations/openclaw/src/index.test.ts +++ b/hindsight-integrations/openclaw/src/index.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect } from "vitest"; import { stripMemoryTags, extractRecallQuery, + formatCurrentTimeForRecall, formatMemories, prepareRetentionTranscript, countUserTurns, @@ -249,6 +250,22 @@ describe("formatMemories", () => { }); }); +// --------------------------------------------------------------------------- +// formatCurrentTimeForRecall — UTC label (#1789, mirrors #1568) +// --------------------------------------------------------------------------- + +describe("formatCurrentTimeForRecall", () => { + it("renders the UTC suffix so the LLM doesn't misread it as local time", () => { + const fixed = new Date(Date.UTC(2026, 4, 27, 16, 25, 0)); // 2026-05-27 16:25 UTC + expect(formatCurrentTimeForRecall(fixed)).toBe("2026-05-27 16:25 UTC"); + }); + + it("zero-pads month / day / hours / minutes", () => { + const fixed = new Date(Date.UTC(2026, 0, 3, 4, 5, 0)); + expect(formatCurrentTimeForRecall(fixed)).toBe("2026-01-03 04:05 UTC"); + }); +}); + // --------------------------------------------------------------------------- // retention helpers // --------------------------------------------------------------------------- diff --git a/hindsight-integrations/openclaw/src/index.ts b/hindsight-integrations/openclaw/src/index.ts index e6d8717fc3..8c88fd4163 100644 --- a/hindsight-integrations/openclaw/src/index.ts +++ b/hindsight-integrations/openclaw/src/index.ts @@ -316,13 +316,16 @@ async function flushRetainQueue(): Promise { const DEFAULT_RECALL_PROMPT_PREAMBLE = "Relevant memories from past conversations (prioritize recent when conflicting). Only use memories that are directly useful to continue this conversation; ignore the rest:"; -function formatCurrentTimeForRecall(date = new Date()): string { +export function formatCurrentTimeForRecall(date = new Date()): string { const year = date.getUTCFullYear(); const month = String(date.getUTCMonth() + 1).padStart(2, "0"); const day = String(date.getUTCDate()).padStart(2, "0"); const hours = String(date.getUTCHours()).padStart(2, "0"); const minutes = String(date.getUTCMinutes()).padStart(2, "0"); - return `${year}-${month}-${day} ${hours}:${minutes}`; + // Suffix with " UTC" so the LLM doesn't misread the timestamp as local + // time and make wrong recency judgments. Mirrors the fix landed for the + // Claude Code integration in #1568. (#1789) + return `${year}-${month}-${day} ${hours}:${minutes} UTC`; } /**