Repository navigation
fix(backend): render chat tool timestamps in the user's timezone (#6214) - #9719
Conversation
The chat/agent tool results that still emitted bare UTC made the model state the wrong time of day. `get_action_items_text` (the `/v1/tools/*` service behind the desktop, web, and MCP agent clients) rendered `Due: 2026-06-26 22:00:00` with no timezone, so the model read that wall clock as local — "tonight" for what was actually 19:00 for a UTC-3 user. `search_memories_text` and `search_memories_tool` rendered a bare UTC date, which is a day late for anyone west of Greenwich in the evening. Every timestamp handed to the model now carries an explicit timezone label, which is what the agentic action-item tool already did (#4643); its sibling REST service and both memory paths were the stragglers. A timezone lookup failure falls back to labelled UTC rather than aborting retrieval. The formatting itself now has one owner: `_format_local` is promoted out of action_item_tools into `utils/conversations/render.py` as `format_local_time`, alongside a new `format_local_date`, so a third copy of the same conversion is not added. fixes #6214
tianmind-studio
left a comment
There was a problem hiding this comment.
I found two integration gaps on d1dc6b11 that should be addressed before merge.
First, the default-memory path still bypasses the new timezone conversion. Both search_memories_text and search_memories_tool compute display_tz, but when search_memory_default_chat_memories_vector_decision_text returns USE_MEMORY, they immediately return its preformatted text. That adapter still formats updated_at with a raw strftime('%Y-%m-%d') in utils/memory/chat_memory_adapter.py, so a 2026-06-27T01:30:00Z memory is still rendered as 2026-06-27 for America/Sao_Paulo. I reproduced this through both public functions; each returned date: 2026-06-27. Please thread the display timezone (or a date formatter) into that adapter path and cover the USE_MEMORY branch in the regression tests.
Second, the new test file is not order-safe with the existing suite. On Windows, pytest tests/unit/test_action_item_date_validation.py tests/unit/test_tool_services_timezone.py -q fails during collection with AttributeError: module 'google.auth' has no attribute 'credentials'. test_action_item_date_validation.py snapshots sys.modules before its real google.auth imports, then restores the package while leaving imported children such as google.auth.credentials cached. Moving _SYS_MODULES_SNAPSHOT = snapshot_sys_modules(...) below the three importable_mod_name imports fixes the leak; the same two-file run then passes all 41 tests. Please include that isolation fix (or an equivalent hermetic approach) so the test can coexist in a single pytest process.
What
Chat/agent tool results that still emitted bare UTC timestamps now render in the user's configured timezone, with an explicit timezone label.
Three surfaces were leaking UTC:
get_action_items_text(/v1/tools/action-items— desktop, web, MCP agent clients)Due: 2026-06-26 22:00:00Due: 2026-06-26 19:00:00 America/Sao_Paulosearch_memories_text(same REST surface)date: 2026-06-27date: 2026-06-26search_memories_tool(agentic chat)date: 2026-06-27date: 2026-06-26Why
From #6214:
The conversations half of this was fixed in #7736 (
conversations_to_stringlocalizes), but the action-item and memory tool results were never converted — so the issue's "always" is still not true today, and the reporter's exact symptom survives on the surfaces above.The failure mode is specifically the missing timezone label: an unlabelled UTC wall clock reads as local time to the model, so it says "tonight" for a due date that is actually mid-afternoon for the user. Memory dates are worse in a quieter way — the UTC calendar date rolls over at a different instant than the user's, so a memory captured at 21:00 in São Paulo is reported a day late.
Root cause / bug class
The agentic action-item tool already fixed exactly this in #4643, but the fix was applied at one call site rather than the shared boundary. Its REST sibling (
tool_services/action_items.py) and both memory paths kept formatting rawstrftimeoutput.To close the class rather than patch one more site, the formatting now has one owner:
_format_localis promoted out ofaction_item_tools.pyintoutils/conversations/render.pyasformat_local_time(next to the existingresolve_display_tz), plus a newformat_local_datefor the date-only case. Both treat a naive timestamp as UTC defensively, so no path can hand the model an unlabelled wall clock.A timezone lookup failure falls back to labelled UTC and never aborts retrieval.
Verified
Backend env synced with
./scripts/sync-python-deps.sh;ENCRYPTION_SECRET/OPENAI_API_KEYpertest.sh.1. Regression tests fail without the fix. New
backend/tests/unit/test_tool_services_timezone.py(15 tests) imports the real modules and swaps collaborators withmonkeypatch, so it exercises the production formatters. Reverting only the three production files and re-running:2. Real rendered tool output (the string the model actually receives), user tz
America/Sao_Paulo, storeddue_at = 2026-06-26T22:00:00Z:That is the reporter's 3-hour skew, gone.
3. Full backend suite —
bash test.sh: no collection errors, no regressions. The single failure,test_vad_gate.py::test_concurrent_sessions_no_deadlock, is a pre-existing flake unrelated to this change (it touches none of the changed modules); A/B'd against pristineorigin/main, where it fails 3/3 runs in isolation while this branch passes 2/3.4.
make preflight—PR preflight passed: 8 checks.Covered: conversion correctness, naive-timestamp handling, the label on every emitted timestamp, unset-timezone fallback, and timezone-lookup failure.
Not covered
MemoryDB.get_memories_as_strstill renders... UTC— it is explicitly labelled, so the model can convert it correctly and it is not the mislabelling bug; threading a timezone into that shared model method is a wider change and is left out deliberately.fixes #6214
Auto-generated from issue feedback by the mini issues-improver. Review before merge.