From 5ca1b96988b617c92f9aa8bfe8d0e647920a816f Mon Sep 17 00:00:00 2001 From: Conroy Whitney Date: Wed, 28 Jan 2026 22:28:48 -0500 Subject: [PATCH] feat: add "Current Date:" label to timestamp prefix Changes [Wed 2026-01-28 20:30 EST] to [Current Date: Wed 2026-01-28 20:30 EST]. Tested with qwen3-1.7B: even with DOW in the timestamp, the model ignored it and tried to compute the day using Zeller's Congruence. The "Current Date:" semantic label is widely present in training data and gives small models the best chance of recognizing the timestamp as authoritative context rather than metadata to parse. Cost: ~18 tokens per message. Prevents hallucination spirals that burn hundreds or thousands of tokens on date derivation. --- .../server-methods/agent-timestamp.test.ts | 20 +++++++++---------- src/gateway/server-methods/agent-timestamp.ts | 7 ++++--- src/gateway/server-methods/agent.test.ts | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/gateway/server-methods/agent-timestamp.test.ts b/src/gateway/server-methods/agent-timestamp.test.ts index 9ac3f7d13..7aece7a31 100644 --- a/src/gateway/server-methods/agent-timestamp.test.ts +++ b/src/gateway/server-methods/agent-timestamp.test.ts @@ -18,7 +18,7 @@ describe("injectTimestamp", () => { timezone: "America/New_York", }); - expect(result).toMatch(/^\[Wed 2026-01-28 20:30 EST\] Is it the weekend\?$/); + expect(result).toMatch(/^\[Current Date: Wed 2026-01-28 20:30 EST\] Is it the weekend\?$/); }); it("uses channel envelope format with DOW prefix", () => { @@ -28,7 +28,7 @@ describe("injectTimestamp", () => { const result = injectTimestamp("hello", { timezone: "America/New_York" }); // DOW prefix + formatZonedTimestamp format - expect(result).toBe(`[Wed ${expected}] hello`); + expect(result).toBe(`[Current Date: Wed ${expected}] hello`); }); it("always uses 24-hour format", () => { @@ -43,14 +43,14 @@ describe("injectTimestamp", () => { const result = injectTimestamp("hello", { timezone: "America/Chicago" }); // 8:30 PM EST = 7:30 PM CST = 19:30 - expect(result).toMatch(/^\[Wed 2026-01-28 19:30 CST\]/); + expect(result).toMatch(/^\[Current Date: Wed 2026-01-28 19:30 CST\]/); }); it("defaults to UTC when no timezone specified", () => { const result = injectTimestamp("hello", {}); // 2026-01-29T01:30:00Z - expect(result).toMatch(/^\[Thu 2026-01-29 01:30/); + expect(result).toMatch(/^\[Current Date: Thu 2026-01-29 01:30/); }); it("returns empty/whitespace messages unchanged", () => { @@ -66,7 +66,7 @@ describe("injectTimestamp", () => { }); it("does NOT double-stamp messages already injected by us", () => { - const alreadyStamped = "[Wed 2026-01-28 20:30 EST] hello there"; + const alreadyStamped = "[Current Date: Wed 2026-01-28 20:30 EST] hello there"; const result = injectTimestamp(alreadyStamped, { timezone: "America/New_York" }); expect(result).toBe(alreadyStamped); @@ -85,7 +85,7 @@ describe("injectTimestamp", () => { const result = injectTimestamp("hello", { timezone: "America/New_York" }); - expect(result).toMatch(/^\[Sun 2026-02-01 00:00 EST\]/); + expect(result).toMatch(/^\[Current Date: Sun 2026-02-01 00:00 EST\]/); }); it("handles date boundaries (just before midnight)", () => { @@ -93,19 +93,19 @@ describe("injectTimestamp", () => { const result = injectTimestamp("hello", { timezone: "America/New_York" }); - expect(result).toMatch(/^\[Sat 2026-01-31 23:59 EST\]/); + expect(result).toMatch(/^\[Current Date: Sat 2026-01-31 23:59 EST\]/); }); it("handles DST correctly (same UTC hour, different local time)", () => { // EST (winter): UTC-5 → 2026-01-15T05:00Z = midnight Jan 15 vi.setSystemTime(new Date("2026-01-15T05:00:00.000Z")); const winter = injectTimestamp("winter", { timezone: "America/New_York" }); - expect(winter).toMatch(/^\[Thu 2026-01-15 00:00 EST\]/); + expect(winter).toMatch(/^\[Current Date: Thu 2026-01-15 00:00 EST\]/); // EDT (summer): UTC-4 → 2026-07-15T04:00Z = midnight Jul 15 vi.setSystemTime(new Date("2026-07-15T04:00:00.000Z")); const summer = injectTimestamp("summer", { timezone: "America/New_York" }); - expect(summer).toMatch(/^\[Wed 2026-07-15 00:00 EDT\]/); + expect(summer).toMatch(/^\[Current Date: Wed 2026-07-15 00:00 EDT\]/); }); it("accepts a custom now date", () => { @@ -116,7 +116,7 @@ describe("injectTimestamp", () => { now: customDate, }); - expect(result).toMatch(/^\[Fri 2025-07-04 12:00 EDT\]/); + expect(result).toMatch(/^\[Current Date: Fri 2025-07-04 12:00 EDT\]/); }); }); diff --git a/src/gateway/server-methods/agent-timestamp.ts b/src/gateway/server-methods/agent-timestamp.ts index 6cd24b797..0b09d34e7 100644 --- a/src/gateway/server-methods/agent-timestamp.ts +++ b/src/gateway/server-methods/agent-timestamp.ts @@ -53,13 +53,14 @@ export function injectTimestamp(message: string, opts?: TimestampInjectionOption const formatted = formatZonedTimestamp(now, timezone); if (!formatted) return message; - // Add 3-letter day-of-week for smaller models that can't derive DOW - // from a date. Costs ~1 token, cheap insurance. + // "Current Date:" label is unambiguous even for tiny models (1.7B+). + // 3-letter DOW included because small models can't derive it from a date. + // Total cost: ~18 tokens — saves thousands when it prevents hallucination. const dow = new Intl.DateTimeFormat("en-US", { timeZone: timezone, weekday: "short" }).format( now, ); - return `[${dow} ${formatted}] ${message}`; + return `[Current Date: ${dow} ${formatted}] ${message}`; } /** diff --git a/src/gateway/server-methods/agent.test.ts b/src/gateway/server-methods/agent.test.ts index 669a8aa07..e572d2abc 100644 --- a/src/gateway/server-methods/agent.test.ts +++ b/src/gateway/server-methods/agent.test.ts @@ -163,7 +163,7 @@ describe("gateway agent handler", () => { await vi.waitFor(() => expect(mocks.agentCommand).toHaveBeenCalled()); const callArgs = mocks.agentCommand.mock.calls[0][0]; - expect(callArgs.message).toBe("[Wed 2026-01-28 20:30 EST] Is it the weekend?"); + expect(callArgs.message).toBe("[Current Date: Wed 2026-01-28 20:30 EST] Is it the weekend?"); mocks.loadConfigReturn = {}; vi.useRealTimers();