Skip to content

fix(runtime): include day of week in system prompt date/time injection (#9899)#32586

Open
BlueBirdBack wants to merge 1 commit intoopenclaw:mainfrom
BlueBirdBack:fix/issue-9899
Open

fix(runtime): include day of week in system prompt date/time injection (#9899)#32586
BlueBirdBack wants to merge 1 commit intoopenclaw:mainfrom
BlueBirdBack:fix/issue-9899

Conversation

@BlueBirdBack
Copy link
Copy Markdown
Contributor

Summary

Fixes #9899 — The system prompt now includes the full formatted date/time with day of week when userTime is available, instead of just the timezone.

Changes

  • src/agents/system-prompt.ts: Updated buildTimeSection() to accept and render userTime parameter. When available, outputs Thursday, 2026-02-05 16:01 EST (America/New_York) instead of just Time zone: America/New_York
  • src/agents/system-prompt.test.ts: Updated tests to verify both formats (with and without userTime)

Why

Agents frequently get the day of week wrong when doing calendar/schedule lookups. The userTime was already being computed by buildSystemPromptParams via formatUserTime but was not being threaded into the system prompt output.

Minimal change — 2 files, 15 insertions, 20 deletions.

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Mar 3, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR fixes a long-standing issue where agents would guess the day of week incorrectly by threading the already-computed userTime value into the system prompt's buildTimeSection. When userTime is available the agent now sees a complete formatted line (e.g. Monday, January 5th, 2026 — 3:26 PM (America/Chicago)) instead of just the raw timezone.

Key changes:

  • buildTimeSection now accepts an optional userTime param and conditionally emits the full formatted line or falls back to Time zone: <tz>.
  • buildAgentSystemPrompt trims and passes userTime through to buildTimeSection.
  • Tests are updated to assert format-specific expected output and drop the now-incorrect cache-stability assertion.

One issue found:

  • The session_status guidance hint at line 507-509 ("If you need the current date, time, or day of week, run session_status") is still emitted unconditionally whenever userTimezone is set, even when userTime is already injected into the prompt. This creates a misleading instruction — the prompt simultaneously provides the date/time and tells the model to make a tool call to get it. The condition should be userTimezone && !userTime to suppress the hint when it is no longer needed.

Confidence Score: 4/5

  • This PR is safe to merge with a minor fix — one stale guidance line should be gated on the absence of userTime.
  • The core change is small, correct, and well-tested. The only issue is that the session_status hint (line 507-509) is left unconditional, creating a redundant/contradictory instruction when userTime is present. It does not break functionality but could confuse the model into making unnecessary tool calls. All other logic is sound.
  • src/agents/system-prompt.ts — lines 507-509 (session_status hint needs to be gated on !userTime)

Last reviewed commit: ffb1807

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Additional Comments (1)

src/agents/system-prompt.ts
Stale session_status hint when userTime is already injected

After this PR, when userTime is provided the system prompt now contains the formatted current date, time, and day of week directly. However, the guidance line at this location still unconditionally tells the agent "If you need the current date, time, or day of week, run session_status" whenever userTimezone is set — even when the answer is already present in the prompt header.

This creates a contradiction: the prompt simultaneously supplies the date/time and instructs the model to make a tool call to retrieve it. At best this is confusing to the model; at worst it triggers unnecessary session_status calls.

The condition should be narrowed so the hint only appears in the timezone-only fallback case (i.e. userTimezone is set but userTime is not):

    userTimezone && !userTime
      ? "If you need the current date, time, or day of week, run session_status (📊 session_status)."
      : "",
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/system-prompt.ts
Line: 507-509

Comment:
**Stale `session_status` hint when `userTime` is already injected**

After this PR, when `userTime` is provided the system prompt now contains the formatted current date, time, and day of week directly. However, the guidance line at this location still unconditionally tells the agent _"If you need the current date, time, or day of week, run session_status"_ whenever `userTimezone` is set — even when the answer is already present in the prompt header.

This creates a contradiction: the prompt simultaneously supplies the date/time and instructs the model to make a tool call to retrieve it. At best this is confusing to the model; at worst it triggers unnecessary `session_status` calls.

The condition should be narrowed so the hint only appears in the **timezone-only fallback** case (i.e. `userTimezone` is set but `userTime` is not):

```suggestion
    userTimezone && !userTime
      ? "If you need the current date, time, or day of week, run session_status (📊 session_status)."
      : "",
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ffb1807647

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +101 to +103
const timeLine = formattedTime
? `${formattedTime} (${params.userTimezone})`
: `Time zone: ${params.userTimezone}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep system prompt stable for provider prefix caching

Including userTime directly in the system prompt makes the prompt content change on every run (the value is generated from new Date() in src/agents/system-prompt-params.ts), which defeats prefix/system-prompt caching and increases latency/cost for cached providers (for example, src/agents/pi-embedded-runner/extra-params.ts explicitly adds cache_control to cache the system message). This regresses the existing cache-hit strategy and will impact all sessions that rebuild prompts frequently.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include day of week in system prompt date/time injection

2 participants