Skip to content

fix: separate Current time from Reference UTC#42620

Closed
chencheng-li wants to merge 4 commits intoopenclaw:mainfrom
chencheng-li:fix/local-only-current-time
Closed

fix: separate Current time from Reference UTC#42620
chencheng-li wants to merge 4 commits intoopenclaw:mainfrom
chencheng-li:fix/local-only-current-time

Conversation

@chencheng-li
Copy link
Copy Markdown

@chencheng-li chencheng-li commented Mar 11, 2026

Summary

  • keep Current time: anchored to the user-local timezone
  • move UTC onto a separate Reference UTC: line
  • avoid putting two competing calendar dates on the same primary time line

Why

The current format can present two competing calendar dates on the same line, for example:

Current time: Tuesday, March 10th, 2026 — 5:49 PM (America/Los_Angeles) / 2026-03-11 00:49 UTC

In evening hours for US timezones, models can latch onto the UTC date and treat it as "today", even though the user-facing local date is still March 10. This is especially risky for session startup and reset flows where the date anchor influences which daily memory files the agent reads.

This PR keeps UTC available for log reconciliation, but demotes it to a clearly secondary line so the local-time anchor remains unambiguous.

New format

Current time: Tuesday, March 10th, 2026 — 5:49 PM (America/Los_Angeles)
Reference UTC: 2026-03-11 00:49 UTC

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR removes the UTC time suffix from the Current time: prompt line in resolveCronStyleNow, keeping only the user's local timezone timestamp. The motivation is sound: showing both local and UTC times on the same line can confuse LLM models into anchoring on the UTC date when users are in evening timezones where local and UTC calendar dates differ.

Key changes:

  • Deleted the utcTime local variable and the / ${utcTime} suffix from timeLine
  • timeLine now reads Current time: <formatted local time> (<timezone>)

Potential concern:

  • The fallback when formatUserTime returns undefined still uses new Date(nowMs).toISOString(), which is a UTC string. In that edge case the prompt would show a UTC date labeled with a local timezone — the exact ambiguity the PR aims to avoid. This is a pre-existing issue but worth addressing as a follow-up.

Confidence Score: 4/5

  • This PR is safe to merge — it makes a focused, low-risk removal of the UTC suffix from a prompt string.
  • The change is a two-line deletion with no logic changes or new dependencies. The fix correctly addresses the stated cross-day ambiguity. The only concern is the pre-existing toISOString() fallback which could reintroduce the UTC date in rare failure scenarios, but this does not block the PR.
  • No files require special attention beyond the noted fallback behavior in src/agents/current-time.ts.

Last reviewed commit: cb67ed0

Comment on lines +26 to +28
const formattedTime =
formatUserTime(new Date(nowMs), userTimezone, userTimeFormat) ?? new Date(nowMs).toISOString();
const utcTime = new Date(nowMs).toISOString().replace("T", " ").slice(0, 16) + " UTC";
const timeLine = `Current time: ${formattedTime} (${userTimezone}) / ${utcTime}`;
const timeLine = `Current time: ${formattedTime} (${userTimezone})`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

UTC ISO fallback still leaks UTC date

When formatUserTime returns undefined (e.g. if Intl.DateTimeFormat throws or yields incomplete parts), the line falls back to new Date(nowMs).toISOString(), which produces a UTC timestamp like 2026-03-11T00:49:00.000Z. The resulting timeLine would then look like:

Current time: 2026-03-11T00:49:00.000Z (America/Los_Angeles)

This is exactly the cross-day ambiguity the PR is trying to eliminate — a UTC date displayed alongside a local timezone label. While this edge case is rare, it directly undermines the stated goal of keeping the prompt local-only.

Consider falling back to a locale-aware alternative, for example using Intl.DateTimeFormat with timeZoneName: "short" directly, or returning a clearly labeled fallback string instead of the raw ISO timestamp:

const formattedTime =
  formatUserTime(new Date(nowMs), userTimezone, userTimeFormat) ??
  new Intl.DateTimeFormat("en-US", { timeZone: userTimezone, dateStyle: "full", timeStyle: "short" }).format(new Date(nowMs));
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/current-time.ts
Line: 26-28

Comment:
**UTC ISO fallback still leaks UTC date**

When `formatUserTime` returns `undefined` (e.g. if `Intl.DateTimeFormat` throws or yields incomplete parts), the line falls back to `new Date(nowMs).toISOString()`, which produces a UTC timestamp like `2026-03-11T00:49:00.000Z`. The resulting `timeLine` would then look like:

```
Current time: 2026-03-11T00:49:00.000Z (America/Los_Angeles)
```

This is exactly the cross-day ambiguity the PR is trying to eliminate — a UTC date displayed alongside a local timezone label. While this edge case is rare, it directly undermines the stated goal of keeping the prompt local-only.

Consider falling back to a locale-aware alternative, for example using `Intl.DateTimeFormat` with `timeZoneName: "short"` directly, or returning a clearly labeled fallback string instead of the raw ISO timestamp:

```ts
const formattedTime =
  formatUserTime(new Date(nowMs), userTimezone, userTimeFormat) ??
  new Intl.DateTimeFormat("en-US", { timeZone: userTimezone, dateStyle: "full", timeStyle: "short" }).format(new Date(nowMs));
```

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

@chencheng-li chencheng-li force-pushed the fix/local-only-current-time branch from cb67ed0 to 11be029 Compare March 11, 2026 01:14
@chencheng-li chencheng-li changed the title fix: keep Current time prompt local-only fix: separate Current time from Reference UTC Mar 11, 2026
@chencheng-li
Copy link
Copy Markdown
Author

Adjusted this PR to preserve UTC as a secondary reference instead of removing it entirely.\n\nNew format:\n- Current time: <local time> (<timezone>)\n- Reference UTC: <utc time>\n\nThat keeps UTC available for timestamp/log reconciliation without making it compete with the primary local-time date anchor.

@chencheng-li chencheng-li force-pushed the fix/local-only-current-time branch from 11be029 to ec98a69 Compare March 11, 2026 01:16
@chencheng-li
Copy link
Copy Markdown
Author

Also fixed the failing audit in this branch: the repo already declared tar 7.5.11 in dependencies, but pnpm.overrides.tar was still pinned to 7.5.10, which forced the vulnerable version back into the lockfile and dependency tree.\n\nThis update bumps the override to 7.5.11 and refreshes pnpm-lock.yaml accordingly.

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: 9ec093faf9

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

formatUserTime(new Date(nowMs), userTimezone, userTimeFormat) ?? new Date(nowMs).toISOString();
const utcTime = new Date(nowMs).toISOString().replace("T", " ").slice(0, 16) + " UTC";
const timeLine = `Current time: ${formattedTime} (${userTimezone}) / ${utcTime}`;
const timeLine = `Current time: ${formattedTime} (${userTimezone})\nReference UTC: ${utcTime}`;
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 Update all call-site assertions for split UTC time format

Changing resolveCronStyleNow to emit Current time and Reference UTC on separate lines is valid, but only one test was adjusted; several existing assertions still hardcode the old single-line ... / ... UTC format (for example in session-reset-prompt, post-compaction-context, and memory-flush tests), so this commit will cause deterministic test failures in the standard suite and block CI until those expectations are updated.

Useful? React with 👍 / 👎.

@chencheng-li
Copy link
Copy Markdown
Author

Closing and replacing with a clean follow-up PR rebased on latest main.

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.

1 participant