fix: separate Current time from Reference UTC#42620
fix: separate Current time from Reference UTC#42620chencheng-li wants to merge 4 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR removes the UTC time suffix from the Key changes:
Potential concern:
Confidence Score: 4/5
Last reviewed commit: cb67ed0 |
src/agents/current-time.ts
Outdated
| 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})`; |
There was a problem hiding this 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:
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.cb67ed0 to
11be029
Compare
|
Adjusted this PR to preserve UTC as a secondary reference instead of removing it entirely.\n\nNew format:\n- |
11be029 to
ec98a69
Compare
|
Also fixed the failing audit in this branch: the repo already declared |
There was a problem hiding this comment.
💡 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}`; |
There was a problem hiding this comment.
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 👍 / 👎.
|
Closing and replacing with a clean follow-up PR rebased on latest main. |
Summary
Current time:anchored to the user-local timezoneReference UTC:lineWhy
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 UTCIn 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