Merge pull request #3677 from conroywhitney/fix/1897-session-status-time-hint

fix(system-prompt): hint session_status for date/time instead of embedding it
This commit is contained in:
Tak Hoffman
2026-01-31 20:22:41 -06:00
committed by GitHub
2 changed files with 42 additions and 4 deletions

View File

@@ -192,6 +192,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/openclaw",

View File

@@ -58,10 +58,13 @@ function buildUserIdentitySection(ownerLine: string | undefined, isMinimal: bool
}
function buildTimeSection(params: { userTimezone?: string }) {
if (!params.userTimezone) {
return [];
}
return ["## Current Date & Time", `Time zone: ${params.userTimezone}`, ""];
if (!params.userTimezone) return [];
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 buildSafetySection() {