Repository navigation
fix(processing-attention): coerce timestamps to UTC and guard null retry maps - #23170
Conversation
…try maps
- Add _coerce_utc_datetime in backend/database/processing_attention.py so
timing() and lease_live() do not raise TypeError when started_at, created_at,
finished_at, or lease_expires_at mix naive and aware datetimes or ISO-8601
strings.
- Guard explicit null {'retry': None} fields in list_items() and
claim_in_transaction() to prevent AttributeError when checking retry state.
- Add unit tests in backend/tests/unit/test_processing_attention_timestamp_guards.py.
Failure-Class: none
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verdict: the production change is correct and nicely scoped — no blocking issues; leaving formal approval to a human maintainer since this touches the processing-attention data path.
What I verified:
backend/database/processing_attention.py—_coerce_utc_datetimecorrectly handles naive datetimes (assumed UTC, matching the module's ownnow_utc()writes), aware datetimes (astimezone), and ISO-8601 strings; the explicitZ→+00:00rewrite keepsfromisoformatsafe on older Pythons, and unparseable input returns None instead of raising. I reproduced the old-code failures locally (TypeError on naive/aware subtraction intiming(), TypeError on naive/aware comparison inlease_live(), AttributeError on an explicit{"retry": None}via.get("retry", {})returning None) — the bugs this fixes are real.- The isinstance-dict guards on
item["retry"]inlist_items()andclaim_in_transaction()are the right minimal fix; using.get("state")/.get("operation_id")on the claim operation doc removes the KeyError path. One intentional behavior change to be aware of: inlist_items(),item["retry"]is now only overwritten when the claim doc actually has a state — previously it was overwritten unconditionally. backend/tests/unit/test_processing_attention_timestamp_guards.py— thedatabase._clientstub before import makes the test self-isolating; coverage spans mixed naive/aware timestamps, ISO strings, lease fallback tocreated_at, and null retry maps. I ran the file in an isolated copy: 3 passed.
Blast radius: limited to the owner-scoped attention ledger read/claim path; every changed branch turns a crash into a graceful fallback, so legacy documents with string or naive timestamps stop breaking reads.
USER IMPACT: users with older or partially-written conversation records stop seeing failed attention/retry items (previously those reads could crash); no visible behavior change otherwise.
Still wanted as a reviewer (non-blocking): a one-line comment on _coerce_utc_datetime noting the naive-means-UTC assumption, so future readers know it mirrors how this module writes timestamps.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Thanks for this fix, @huynhnhatquandongnai-source! Your commits are being carried forward in #25896 (cherry-picked with your original authorship intact) so they can land with the current CI and repo conventions. Closing this in favor of that branch — your contribution is credited there and in the git history. |
|
Hey @huynhnhatquandongnai-source 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Fixes #23169
Summary
Prevents unhandled TypeError and AttributeError crashes in �ackend/database/processing_attention.py when conversation or retry-claim documents contain naive datetime / ISO-8601 string timestamps or explicit None
etry maps:
ow to UTC before comparing expires > now_dt.
Verification
Failure-Class: none
Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
Bounty Payout Coordinates
[email protected]0xb9f3765aeb1974c27a193463f655a1a57b3aec94