Repository navigation
Supersedes #23170: fix(processing-attention): coerce timestamps to UTC and guard null retry maps - #25896
Supersedes #23170: fix(processing-attention): coerce timestamps to UTC and guard null retry maps#25896omiagent[bot] wants to merge 1 commit into
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 defensive fix itself is correct and well-tested, but this head fails required CI on a pyright error introduced by the diff — a one-line change before merge.
Blocking: Backend unit shard 1/8 fails at the pyright step with reportOptionalMemberAccess at backend/database/processing_attention.py:210:52. In list_items you wrote:
item_retry = item.get('retry') if isinstance(item.get('retry'), dict) else {}
The condition calls item.get('retry') a second time, so pyright cannot apply isinstance narrowing and infers item_retry as dict | None, making item_retry.get('state') an optional-member access. Bind once instead:
raw_retry = item.get('retry')
item_retry = raw_retry if isinstance(raw_retry, dict) else {}
The same double-call pattern appears in claim_in_transaction (~line 309); pyright only flagged 210 this run, but I'd fix both identically. Note pyright runs before pytest in the shard, so CI never executed your new tests on this head either.
The substance is good:
- _coerce_utc_datetime (~97-113): correct normalization — naive treated as UTC, 'Z' normalized for fromisoformat on older Pythons, unparseable values return None and fall back to today's behavior (duration 0 / lease fallback). Well-formed records are unchanged.
- lease_live (~237-244): previously an ISO-string lease_expires_at silently fell through to created_at + RETRY_LEASE_SECONDS, misjudging lease expiry; now parsed correctly. Behavior changes only for malformed records, in the safe direction.
- list_items op_state guard: no more KeyError on claim docs missing 'state', and item['retry'] is no longer overwritten with {'state': None}.
- backend/tests/unit/test_processing_attention_timestamp_guards.py: I ran the three tests against this head locally (3 passed, plus 101 passing in adjacent processing_attention suites) since CI's pytest step never reached them.
Security: no new data flows or dependencies; this narrows crash paths in transactional conversation creation and the Home pending read. Blast radius: processing-attention ledger reads and retry claims for records with malformed timestamps or explicit retry: null.
USER IMPACT: conversations stop getting stuck in the processing/failed lane and the retry button keeps working when a stored record has mixed-format timestamps or an explicit retry: null.
Action items: (1) apply the local-binding fix at line 209 (and the twin in claim_in_transaction), (2) push so CI re-runs and the new tests actually execute.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
What this does, in plain terms
Conversation processing keeps a per-user "attention ledger" — the list of items Home shows as processing, failed, or retryable, plus the retry-claim leases behind the retry button. This change makes that ledger tolerant of three kinds of malformed data that occasionally end up in stored documents (older app versions, backup restores, racy writes):
TypeError: can't subtract offset-naive and offset-aware datetimesinside transactional conversation creation and the Home pending read.2026-04-21T10:00:00Z) stored where datetime objects were expected made lease-expiry checks misjudge retry-claim leases, breaking retries for those items.retry: null(instead of a missing field) crashed retry-state inspection withAttributeError: 'NoneType' object has no attribute 'get'.For users this means conversations no longer get stuck in the processing/failed lane and the retry button keeps working after an abnormal write. The fix is purely defensive: well-formed records behave exactly as before, and every new code path falls back to today's behavior. Rollback risk is minimal.
Provenance and credit
Authored by @huynhnhatquandongnai-source in #23170 (opened 2026-10-22). This branch cherry-picks the original commit with the author's authorship intact in git history (committer: omiagent bot).
Carry-forward notes (rebase onto current main):
list_items()gained non-retryable expiry handling since the original PR; the author's guarded retry-map write is layered onto main's current block with no behavior change to expiry.firestore_client=instead of module-attribute monkeypatching); the three test scenarios are the author's, unchanged in intent.retryable =expression now that the guard variable shortens the line — formatting only.Product invariants affected
none
Verification
backend/tests/unit/test_processing_attention_timestamp_guards.py: 3 passed (junitxml tests=3 failures=0 errors=0 skipped=0), Python 3.11, backend venv.test_pending_work.py,test_dead_letter_visible_row_title.py,test_strict_firestore_transaction.py,test_phase_shadow_readers.py,test_restore_recording_obligation.py): 185 passed, 0 failed (junitxml counts).bash scripts/backend-python-format --checkclean on both changed files (pinned black 26.5.1).bash scripts/pr-preflight --pr-body-file— result recorded below.Failure class
Failure-Class: none