Repository navigation
fix(backend): read naive timestamps as UTC when creating a developer conversation from text - #22900
Conversation
…conversation from text POST /v1/dev/user/conversations compared finished_at with started_at. A timestamp without an offset next to one with an offset (or next to the aware "now" default for started_at) made that comparison raise TypeError, so the request failed with HTTP 500. The CLI sends naive values for date-only flags, so `omi conversation create --finished-at 2026-10-20` hit it. Read a naive started_at/finished_at as UTC. Two naive timestamps were already accepted and are still accepted; the request schema is unchanged.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verdict: correct fix, nicely scoped, no blocking issues.
- backend/routers/developer.py:1157 — the
read_naive_timestamp_as_utcvalidator fixes a real 500:finished_at < started_atat developer.py:1761 raises TypeError whenever one supplied timestamp is offset-naive and the other aware, or a naivefinished_atmeets the tz-awaredatetime.now(timezone.utc)default at line 1757. Coercing naive to UTC at the model boundary resolves every mixed case, and both-naive bodies keep succeeding exactly as before (naive-vs-naive always compared fine). - Reading naive values as UTC instead of the 422 the from-segments routes use (
require_timezone_offset, developer.py:1291) is the right call here — this route has always accepted two naive timestamps, so rejecting would break currently-working requests (e.g. the CLI's date-only flags). Worth knowing: naive values now persist as tz-aware UTC rather than naive datetimes; strictly safer downstream, but a small storage behavior change. - Blast radius confined:
CreateConversationRequestis used only byPOST /v1/dev/user/conversations(developer.py:1722), and the generated JSON schema is unchanged. - backend/tests/unit/test_dev_api_conversations_poison.py:286 — the parametrized test covers all three naive/aware combinations plus naive
finished_atagainst the aware now-default; the companion tests pin both-naive acceptance and the inverted-range 422. Good coverage.
USER IMPACT: developers creating a conversation from text with a timestamp that lacks a timezone offset no longer get a 500 error — it is read as UTC and the request succeeds.
Non-blocking nit: the body claims the JSON schema is byte-for-byte unchanged — a tiny test asserting that would pin it.
Leaving for routine maintainer merge.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Verdict: the production change is correct and nicely scoped; leaving a comment rather than a formal approval, which is reserved for maintainer sign-off here.
USER IMPACT: developers creating a conversation from text with timezone-less timestamps (e.g. the CLI's date-only flags) now get a successful request with the timestamp read as UTC, instead of an HTTP 500. Nothing blocking from my side. Optional nicety: a brief note in the endpoint docs that offset-less timestamps are interpreted as UTC. Leaving for human maintainer review before merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Thanks! On the storage note: Firestore already stores a naive datetime as UTC, so the saved timestamp is the same instant before and after (checked with google.api_core.datetime_helpers.to_microseconds). This route's response returns only the id and status flags, not the timestamps, so no client sees a new offset. I left the endpoint docs as they are so the generated schema and clients stay unchanged. |
kodjima33
left a comment
There was a problem hiding this comment.
Scoped bug fix (naive-timestamp TypeError -> 500 on /v1/dev/user/conversations), stated root cause, 5 new tests reproducing the crash and passing after the fix, CI green. Mirrors existing from-segments guard. Merging.
What's wrong
POST /v1/dev/user/conversations(create a conversation from text) checks the timestamps like this:When one timestamp has a UTC offset and the other doesn't, or a
finished_atwithout an offset meets the aware "now" default forstarted_at, Python can't compare them and raisesTypeError. The request fails with HTTP 500 instead of a usable answer.The CLI sends values without an offset for date-only and plain
YYYY-MM-DDTHH:MM:SSflags, soomi conversation create --text ... --finished-at 2099-01-01hits it.The sibling route,
from-segments, got a guard for the same comparison in #13511 (#13505). This route didn't.text)finished_at: "2099-01-01T00:10:00"started_at: "2026-01-01T00:00:00",finished_at: "2026-01-01T00:10:00Z"started_at: "2026-01-01T00:00:00Z",finished_at: "2026-01-01T00:10:00"started_at: "2026-01-01T00:10:00",finished_at: "2026-01-01T00:00:00Z"(finish before start)finished_at must be after started_atChange
CreateConversationRequestgets astarted_at/finished_atvalidator that reads a timestamp without an offset as UTC.I didn't copy the
from-segments422. Two offset-less timestamps have always been accepted on this route, and the CLI sends them for date-only flags. Rejecting them would break requests that work today. Reading them as UTC matches how they were already stored.The request's JSON schema is byte-for-byte the same before and after (validation and serialization modes), so the OpenAPI contract doesn't change.
Tests
backend/tests/unit/test_dev_api_conversations_poison.py(the existing developer-conversations harness) has 5 new cases through the real route withTestClient:finished_atpassed to processing.All 5 fail on main (four return 500, and the naive pair reaches processing without an offset) and pass with the change.
All 32 files picked by
scripts/select_backend_unit_tests.py --changed-filesfor this diff pass, each run in its own process.Failure-Class: none
Line-Count-Exception: backend/routers/developer.py | 2814 -> 2821 | the request-model validator belongs next to CreateConversationRequest, like its from-segments sibling
UI-Evidence: none -- backend-only request validation change, no UI.