Repository navigation
fix(backend): emit timezone-aware UTC timestamps from conversation search so chat shows correct times (#4643) - #8538
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
Positive signal from maintainer automation: this looks like a small, well-scoped backend correctness fix.
What I checked:
search_conversationsnow renders Typesense unix timestamps with an explicit UTC offset viadatetime.fromtimestamp(..., tz=timezone.utc).isoformat().- The conversion remains inside the existing per-hit malformed-record guard, so a bad timestamp still skips only that hit rather than failing the whole search.
- New unit coverage checks timezone awareness, the exact UTC instant, regression against naive ISO strings, and float timestamp handling; the test is wired into
backend/test.sh. - Current GitHub checks are passing.
Maintainer note: this is a narrow fix for conversation-search timestamp serialization. It does not by itself solve the broader timezone preference / local-time interpretation request in #4643, but it should make these search result timestamps safer for downstream chat/API consumers.
No blocking issues found from my review. Because this PR is coming through the maintainer automation guardrails, I’m leaving this as a positive signal rather than a formal approval.
kodjima33
left a comment
There was a problem hiding this comment.
Backend bug fix with regression test; CI green. Approving.
…tamps # Conflicts: # backend/test.sh
|
Merged latest main to clear a merge conflict. The only conflict was in |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Nice fix. Verified a couple of things on my side:
_utc_isousingdatetime.fromtimestamp(ts, tz=timezone.utc).isoformat()is the canonical replacement for the deprecatedutcfromtimestampand produces an explicit+00:00offset — correct.- The three call sites stay inside the existing per-record
try/except, which now also catchesOverflowError/OSErrorfor out-of-range timestamps — good hardening, and one bad indexed doc still just skips that hit rather than 500-ing the page. - Downstream is safe:
routers/conversations.py(the overlapping-calendar-event path) already normalizes naive datetimes to UTC, so it now receives an already-aware value and computes the same result.search_conversations_tooland the integration search endpoint don't re-parse these timestamps. - Scope is complete —
search.pywas the onlyutcfromtimestampsite inbackend/utils/conversations/.
The tests are well-aimed (timezone-awareness, correct instant, naive-string regression guard, float handling).
Flagging for maintainer review since this touches timestamps that feed the chat model and API clients, but the change itself looks correct and low-risk. Thanks for the contribution!
…tamps # Conflicts: # backend/test.sh
# Conflicts: # backend/test.sh
|
Positive signal (post-rebase re-check on ).\n\nIndependent verification of the change:\n- swaps the deprecated (removed in Python 3.12, and which emitted a naive ISO string with no offset) for . Same UTC instant, now with an explicit offset. This is the correct canonical fix.\n- The conversion stays inside the existing per-hit , so a single malformed indexed doc still skips just that hit rather than failing the whole search page.\n- New unit coverage checks timezone awareness, the exact UTC instant, a naive-string regression guard, and float timestamps; the suite is green.\n\nConsumer-safety check (the claim in the PR description):\n- The one downstream re-parser, (), already does followed by . Receiving an already-aware value lands in the same branch and produces the same result. No breakage.\n- reads only uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),105(lxd),988(docker), not timestamps. No other consumer found.\n\nScope note: the in the title references the timezone issue, not a parent PR; this is a sibling of the already-merged #8588 (screen activity) and #8575 (billing date) on the same theme, not a stacked branch sequence.\n\nThis is a small, well-scoped, well-tested correctness fix and the checks pass. Because of the label I'm leaving a positive signal rather than a formal approval. |
|
Positive signal (post-rebase re-check on 524a67c). Independent verification of the change:
Consumer-safety check (the claim in the PR description):
Scope note: the (#4643) in the title references the timezone issue, not a parent PR; this is a sibling of the already-merged #8588 (screen activity) and #8575 (billing date) on the same theme, not a stacked branch sequence. This is a small, well-scoped, well-tested correctness fix and the checks pass. Because of the needs-maintainer-review label I'm leaving a positive signal rather than a formal approval. |
|
Thanks for the thorough verification, David, especially tracing the one downstream re-parser in auto_link_calendar_event to confirm an already-aware +00:00 value lands in the same tzinfo branch and produces the same result. Agreed it is maintainer-gated. Nothing further from me. |
kodjima33
left a comment
There was a problem hiding this comment.
Backend bug fix, CI green, scoped — merging (confidence 4/5).
What
search_conversations(utils/conversations/search.py) renders each matched Typesense doc'screated_at,started_at, andfinished_atunix timestamps into ISO strings. It useddatetime.utcfromtimestamp(ts).isoformat(), which returns a naive datetime, so the string has no timezone offset (for example2023-11-14T22:13:20instead of2023-11-14T22:13:20+00:00).These timestamps go to the chat model (
search_conversations_toolis what the agent uses for "when did X happen?" event questions) and to API clients. A naive UTC string with no offset can be read as local time, so a conversation can be shown hours off depending on the reader's timezone. This is the same timezone-correctness class as the calendar rendering issue (#4643).How
_utc_iso(ts)helper that converts a unix timestamp to a timezone-aware UTC ISO 8601 string viadatetime.fromtimestamp(ts, tz=timezone.utc).isoformat(), so the offset is explicit.Safe for existing consumers: the one place that re-parses these strings (
routers/conversations.py, the overlapping-calendar-event path) already normalizes naive datetimes to UTC, so it now receives an already-aware value and produces the same result. The keyword-search id path does not read the timestamps at all.Testing
New pure unit test
tests/unit/test_search_conversations_utc_timestamps.py(registered in test.sh) covers the helper: the output is timezone-aware with an explicit+00:00offset, represents the correct UTC instant, is not a naive string (regression guard), and handles float timestamps. All 4 pass. The existing conversation search tests still pass. black and the async blocker lint are clean.