Skip to content

fix(processing-attention): coerce timestamps to UTC and guard null retry maps - #23170

Closed
huynhnhatquandongnai-source wants to merge 1 commit into
BasedHardware:mainfrom
huynhnhatquandongnai-source:fix/processing-attention-timestamp-guards
Closed

huynhnhatquandongnai-source wants to merge 1 commit into
BasedHardware:mainfrom
huynhnhatquandongnai-source:fix/processing-attention-timestamp-guards

Conversation

@huynhnhatquandongnai-source

@huynhnhatquandongnai-source huynhnhatquandongnai-source commented Oct 22, 2026 •

Copy link
Copy Markdown

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:

  • �ackend/database/processing_attention.py:
    • Added _coerce_utc_datetime(value) to normalize naive datetime, aware datetime, and ISO-8601 string timestamps to UTC.
    • Updated iming(row) to normalize start and end before (end_dt - start_dt).total_seconds().
    • Updated lease_live(operation, now) to normalize lease_expires_at, created_at, and
      ow to UTC before comparing expires > now_dt.
    • Guarded item.get('retry') with isinstance(..., dict) in list_items and claim_in_transaction, and used .get('state') / .get('operation_id') on operation in list_items.
  • �ackend/tests/unit/test_processing_attention_timestamp_guards.py:
    • Added unit regression tests for mixed naive/aware and ISO-8601 timestamps in iming() and lease_live(), plus explicit {'retry': None} handling in list_items() and claim_in_transaction().

Verification

  • pytest backend/tests/unit/test_processing_attention_timestamp_guards.py (3 passed)

Failure-Class: none

Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94

View guided diff

Bounty Payout Coordinates

  • PayPal: [email protected]
  • Base Mainnet USDC: 0xb9f3765aeb1974c27a193463f655a1a57b3aec94

…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 Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_datetime correctly handles naive datetimes (assumed UTC, matching the module's own now_utc() writes), aware datetimes (astimezone), and ISO-8601 strings; the explicit Z → +00:00 rewrite keeps fromisoformat safe on older Pythons, and unparseable input returns None instead of raising. I reproduced the old-code failures locally (TypeError on naive/aware subtraction in timing(), TypeError on naive/aware comparison in lease_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"] in list_items() and claim_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: in list_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 — the database._client stub before import makes the test self-isolating; coverage spans mixed naive/aware timestamps, ISO strings, lease fallback to created_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.

@omiagent

omiagent Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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.

@omiagent omiagent Bot closed this Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] fix(processing-attention): coerce timestamps to UTC and guard null retry maps ($50 proposed)

2 participants