Repository navigation
fix: respond in user local timezone instead of UTC (#6214) - #6703
Conversation
Fixes issue BasedHardware#6214 - Chat assistant gives wrong times due to timezone confusion Changed prompts to respond in user's local timezone instead of UTC to fix wrong timestamps in chat responses.
Greptile SummaryThis PR fixes timezone-aware LLM responses by changing six prompt instructions from "convert to UTC and respond in UTC" to "respond in user local timezone" across three backend files. The change is directionally correct, but
Confidence Score: 4/5Safe to merge for most users, but a latent off-by-one-day bug in chat.py remains for users in UTC+X timezones near midnight UTC. The conversation_processing.py and external_integrations.py changes are clean. The chat.py changes fix the primary complaint but introduce a secondary inconsistency: the UTC date anchor can differ from the local date for users east of UTC, so the LLM's "today" is still wrong in those edge cases. This is an active logic defect on the changed path, warranting a P1 and a 4/5 rather than 5/5. backend/utils/llm/chat.py — three prompt sites still derive "today" in UTC while instructing local-timezone responses. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Router
participant LLM Prompt (chat.py)
participant LLM Prompt (conv_processing.py)
participant LLM Prompt (external_integrations.py)
participant LLM
Client->>Router: request with uid + tz
Router->>LLM Prompt (chat.py): created_at (UTC date only) + tz
note over LLM Prompt (chat.py): today is {UTC date}...respond in local tz<br/>(UTC date != local date for UTC+X users near midnight)
LLM Prompt (chat.py)->>LLM: prompt with UTC anchor
LLM-->>Router: dates in local tz (but anchored to wrong day)
Router->>LLM Prompt (conv_processing.py): started_at.isoformat() + tz
note over LLM Prompt (conv_processing.py): full ISO timestamp with offset<br/>LLM can compute correct local time
LLM Prompt (conv_processing.py)->>LLM: prompt
LLM-->>Router: calendar events in local tz
Router->>LLM Prompt (external_integrations.py): started_at.isoformat() + tz
note over LLM Prompt (external_integrations.py): full ISO timestamp with offset
LLM Prompt (external_integrations.py)->>LLM: prompt
LLM-->>Router: structured events in local tz
Reviews (1): Last reviewed commit: "fix: respond in user local timezone inst..." | Re-trigger Greptile |
Fixes Greptile review feedback - the 'today' date was still computed in UTC
while asking for local timezone responses, causing wrong dates for users
in UTC+X timezones near midnight UTC.
Changed from:
today is {created_at.astimezone(timezone.utc).strftime('%Y-%m-%d')} in UTC
To:
today is {created_at.astimezone(ZoneInfo(tz)).strftime('%Y-%m-%d')} in {tz} (user's local timezone)
|
lgtm |
… (BasedHardware#6703) * fix: respond in user local timezone instead of UTC Fixes issue BasedHardware#6214 - Chat assistant gives wrong times due to timezone confusion Changed prompts to respond in user's local timezone instead of UTC to fix wrong timestamps in chat responses. * fix: use local timezone date anchor in chat prompts Fixes Greptile review feedback - the 'today' date was still computed in UTC while asking for local timezone responses, causing wrong dates for users in UTC+X timezones near midnight UTC. Changed from: today is {created_at.astimezone(timezone.utc).strftime('%Y-%m-%d')} in UTC To: today is {created_at.astimezone(ZoneInfo(tz)).strftime('%Y-%m-%d')} in {tz} (user's local timezone)
Summary
Fixes issue #6214 - Chat assistant gives wrong times due to timezone confusion.
When users asked about times/dates, the AI was responding in UTC instead of their local timezone, causing incorrect timestamps (e.g., user in UTC-3 would get times 3 hours off).
Changes
Changed LLM prompts to respond in user's local timezone instead of UTC:
backend/utils/llm/chat.py- 3 locationsbackend/utils/llm/conversation_processing.py- 2 locationsbackend/utils/llm/external_integrations.py- 1 locationTesting
Before (bug):
After (fix):