Skip to content

Commit ffb1807

Browse files
codexAsh (Bug Lab)
authored andcommitted
fix(runtime): include day of week in system prompt date/time injection (#9899)
1 parent a9ec75f commit ffb1807

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/agents/system-prompt.test.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe("buildAgentSystemPrompt", () => {
350350
expect(prompt).toContain("Reminder: commit your changes in this workspace after edits.");
351351
});
352352

353-
it("shows timezone section for 12h, 24h, and timezone-only modes", () => {
353+
it("shows current date/time when available, with timezone-only fallback", () => {
354354
const cases = [
355355
{
356356
name: "12-hour",
@@ -360,6 +360,7 @@ describe("buildAgentSystemPrompt", () => {
360360
userTime: "Monday, January 5th, 2026 — 3:26 PM",
361361
userTimeFormat: "12" as const,
362362
},
363+
expectedLine: "Monday, January 5th, 2026 — 3:26 PM (America/Chicago)",
363364
},
364365
{
365366
name: "24-hour",
@@ -369,6 +370,7 @@ describe("buildAgentSystemPrompt", () => {
369370
userTime: "Monday, January 5th, 2026 — 15:26",
370371
userTimeFormat: "24" as const,
371372
},
373+
expectedLine: "Monday, January 5th, 2026 — 15:26 (America/Chicago)",
372374
},
373375
{
374376
name: "timezone-only",
@@ -377,13 +379,14 @@ describe("buildAgentSystemPrompt", () => {
377379
userTimezone: "America/Chicago",
378380
userTimeFormat: "24" as const,
379381
},
382+
expectedLine: "Time zone: America/Chicago",
380383
},
381384
] as const;
382385

383386
for (const testCase of cases) {
384387
const prompt = buildAgentSystemPrompt(testCase.params);
385388
expect(prompt, testCase.name).toContain("## Current Date & Time");
386-
expect(prompt, testCase.name).toContain("Time zone: America/Chicago");
389+
expect(prompt, testCase.name).toContain(testCase.expectedLine);
387390
}
388391
});
389392

@@ -397,29 +400,15 @@ describe("buildAgentSystemPrompt", () => {
397400
expect(prompt).toContain("current date");
398401
});
399402

400-
// The system prompt intentionally does NOT include the current date/time.
401-
// Only the timezone is included, to keep the prompt stable for caching.
402-
// See: https://github.com/moltbot/moltbot/commit/66eec295b894bce8333886cfbca3b960c57c4946
403-
// Agents should use session_status or message timestamps to determine the date/time.
404-
// Related: https://github.com/moltbot/moltbot/issues/1897
405-
// https://github.com/moltbot/moltbot/issues/3658
406-
it("does NOT include a date or time in the system prompt (cache stability)", () => {
403+
it("includes provided date/time in the system prompt", () => {
407404
const prompt = buildAgentSystemPrompt({
408405
workspaceDir: "/tmp/clawd",
409406
userTimezone: "America/Chicago",
410407
userTime: "Monday, January 5th, 2026 — 3:26 PM",
411408
userTimeFormat: "12",
412409
});
413410

414-
// The prompt should contain the timezone but NOT the formatted date/time string.
415-
// This is intentional for prompt cache stability — the date/time was removed in
416-
// commit 66eec295b. If you're here because you want to add it back, please see
417-
// https://github.com/moltbot/moltbot/issues/3658 for the preferred approach:
418-
// gateway-level timestamp injection into messages, not the system prompt.
419-
expect(prompt).toContain("Time zone: America/Chicago");
420-
expect(prompt).not.toContain("Monday, January 5th, 2026");
421-
expect(prompt).not.toContain("3:26 PM");
422-
expect(prompt).not.toContain("15:26");
411+
expect(prompt).toContain("Monday, January 5th, 2026 — 3:26 PM (America/Chicago)");
423412
});
424413

425414
it("includes model alias guidance when aliases are provided", () => {

src/agents/system-prompt.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,15 @@ function buildOwnerIdentityLine(
9393
return `Authorized senders: ${displayOwnerNumbers.join(", ")}. These senders are allowlisted; do not assume they are the owner.`;
9494
}
9595

96-
function buildTimeSection(params: { userTimezone?: string }) {
96+
function buildTimeSection(params: { userTimezone?: string; userTime?: string }) {
9797
if (!params.userTimezone) {
9898
return [];
9999
}
100-
return ["## Current Date & Time", `Time zone: ${params.userTimezone}`, ""];
100+
const formattedTime = params.userTime?.trim();
101+
const timeLine = formattedTime
102+
? `${formattedTime} (${params.userTimezone})`
103+
: `Time zone: ${params.userTimezone}`;
104+
return ["## Current Date & Time", timeLine, ""];
101105
}
102106

103107
function buildReplyTagsSection(isMinimal: boolean) {
@@ -361,6 +365,7 @@ export function buildAgentSystemPrompt(params: {
361365
: undefined;
362366
const reasoningLevel = params.reasoningLevel ?? "off";
363367
const userTimezone = params.userTimezone?.trim();
368+
const userTime = params.userTime?.trim();
364369
const skillsPrompt = params.skillsPrompt?.trim();
365370
const heartbeatPrompt = params.heartbeatPrompt?.trim();
366371
const heartbeatPromptLine = heartbeatPrompt
@@ -559,6 +564,7 @@ export function buildAgentSystemPrompt(params: {
559564
...buildUserIdentitySection(ownerLine, isMinimal),
560565
...buildTimeSection({
561566
userTimezone,
567+
userTime,
562568
}),
563569
"## Workspace Files (injected)",
564570
"These user-editable files are loaded by OpenClaw and included below in Project Context.",

0 commit comments

Comments
 (0)