Skip to content

fix: respond in user local timezone instead of UTC (#6214) - #6703

Merged
beastoin merged 2 commits into
BasedHardware:mainfrom
AasheeshLikePanner:fix/timezone-chat-responses
Apr 27, 2026
Merged

beastoin merged 2 commits into
BasedHardware:mainfrom
AasheeshLikePanner:fix/timezone-chat-responses

Conversation

@AasheeshLikePanner

Copy link
Copy Markdown
Contributor

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 locations
  • backend/utils/llm/conversation_processing.py - 2 locations
  • backend/utils/llm/external_integrations.py - 1 location

Testing

  • 98 unit tests passed
  • Logic verified: now responds in user's local timezone instead of UTC

Before (bug):

  • User in America/Sao_Paulo (UTC-3) asks: "What time did X happen?"
  • AI responds in UTC → Wrong time (3 hours ahead)

After (fix):

  • User in America/Sao_Paulo (UTC-3) asks: "What time did X happen?"
  • AI responds in local timezone → Correct time

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-apps

greptile-apps Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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 chat.py still computes the "today" date anchor as created_at.astimezone(timezone.utc).strftime('%Y-%m-%d') — a UTC date — while simultaneously instructing the model to respond in the user's local timezone, leaving the model without the correct local date when the two differ (e.g. near midnight UTC for UTC+X users).

  • backend/utils/llm/chat.py: all three prompt sites pass a UTC-only date string as the "today" anchor while asking for local-timezone responses — the model cannot derive the correct local date from this alone.

Confidence Score: 4/5

Safe 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

Filename Overview
backend/utils/llm/chat.py Three prompts updated to respond in local timezone, but all three still anchor "today" to the UTC date — users in UTC+X timezones can receive incorrect date context around midnight UTC.
backend/utils/llm/conversation_processing.py Two prompts changed from "convert to UTC, respond in UTC" to "respond in user local timezone"; timestamp anchor passes full ISO datetime with offset, giving the LLM enough info to compute local time.
backend/utils/llm/external_integrations.py Calendar-event extraction prompt updated to respond in user local timezone; full ISO timestamp with offset provided, so the LLM can compute local time correctly.

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (1): Last reviewed commit: "fix: respond in user local timezone inst..." | Re-trigger Greptile

Comment thread backend/utils/llm/chat.py Resolved
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)
@beastoin

Copy link
Copy Markdown
Collaborator

lgtm

@beastoin
beastoin merged commit 9915623 into BasedHardware:main Apr 27, 2026
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
… (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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants