Repository navigation
Conversation
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 5/5
- In
backend/utils/conversations/merge_conversations.py,_photo_sort_keyreimplements datetime coercion instead of using_coerce_dt, which creates a small long-term risk of the two paths drifting and producing inconsistent photo ordering in edge cases; before merging, switch_photo_sort_keyto call_coerce_dtso timestamp normalization stays under one contract.
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…imestamp contract
|
Hi @ZachL111 — thank you for finding and writing up this retrieval/output semantic correctness issue. We consolidated this group into a smaller aggregate PR with shared semantic models/helpers and focused tests: #8366. Your original discovery, reproduction details, and candidate fix are credited in the new PR body and commit metadata. I’m closing this individual PR as superseded by #8366, not because the issue is invalid. Thanks again for surfacing it. |
|
Hey @ZachL111 👋 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:
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! 💜 |
## Summary Supersedes #8290, #8291, #8306, #8310, #8311, #8313, #8319, #8320. Original issue discovery, reproductions, and candidate fixes by @ZachL111. This aggregates the retrieval/output semantic correctness fixes into one focused backend PR: - adds shared conversation metadata keys/model and uses them for vector metadata production + reranking - fixes metadata entity extraction so entities no longer copy topics - refactors RAG chunking through a pure `build_conversation_context(...) -> str | None` path so short conversations are included consistently - separates calendar deletion successes from failures before building user-visible output - normalizes merge/photo timestamps through a UTC-aware helper and keeps malformed/missing photo dates with a structured warning - makes proactive-notification cache setters keyword-only for `app_id` to prevent passing an `App` object as the cache key - validates daily-summary LLM JSON with a Pydantic payload, falls back only on JSON/model-validation failures, and stops logging raw LLM output - safely handles Google contacts with absent names while preserving email extraction ## Included Zach PRs Included/redesigned in this aggregate: #8290, #8291, #8306, #8310, #8311, #8313, #8319, #8320. Deferred from this aggregate: none. ## Tests - `cd backend && ./scripts/sync-python-deps.sh` - `cd backend && source .venv/bin/activate && pytest tests/unit/test_retrieval_semantics.py tests/unit/test_daily_summary_regenerate.py tests/unit/test_daily_summary_race_condition.py tests/unit/test_conversations_to_string.py` - `cd backend && source .venv/bin/activate && python -m py_compile models/conversation_metadata.py models/calendar_mutation.py models/daily_summary_payload.py utils/conversations/datetime_utils.py utils/conversations/merge_conversations.py utils/retrieval/rag.py utils/llm/chat.py utils/llm/external_integrations.py utils/retrieval/tools/calendar_tools.py database/mem_db.py database/redis_db.py database/vector_db.py tests/unit/test_retrieval_semantics.py` - `cd backend && bash testing/e2e/run.sh` — 73 passed, 6 skipped Also ran `python backend/scripts/scan_async_blockers.py` from repo root; it exits 0 and reports existing async-blocker findings unrelated to this PR. Running it from `backend/` currently fails with `Error: backend/routers not found`, so root invocation was used. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/8366?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Supersedes BasedHardware#8290, BasedHardware#8291, BasedHardware#8306, BasedHardware#8310, BasedHardware#8311, BasedHardware#8313, BasedHardware#8319, BasedHardware#8320. Co-authored-by: ZachL111 <[email protected]>
Summary
_collect_all_photosin the conversation merge path sorts the combined photo list bycreated_at, using a naivedatetime.minas the fallback for photos that are missing the field. Firestore photocreated_atvalues are tz-aware, so the moment one photo lackscreated_at(and gets the naive fallback) while another carries a tz-aware value, the sort comparison raisesTypeError: can't compare offset-naive and offset-aware datetimes. That exception propagates up toperform_merge_async, whose outertry/exceptonly logs it, so the whole merge silently aborts for that user and the merged conversation is never created. This change coerces every sort key to a uniform tz-aware UTC datetime so the sort never raises and the merge completes.Root cause
In
backend/utils/conversations/merge_conversations.py,_collect_all_photosbuildsall_photosfrom every source conversation and then sorts them:datetime.minis offset-naive. Firestore deserializes photocreated_atto an offset-awaredatetime. Python refuses to order naive against aware values, so as soon as the list mixes a real (aware)created_atwith a fallback (naive) one,list.sortraisesTypeError: can't compare offset-naive and offset-aware datetimes._collect_all_photosis called at the top ofperform_merge_async(merged_photos = _collect_all_photos(uid, sorted_convs)), and that function wraps its whole body inexcept Exception as e: logger.error(...). The TypeError is swallowed there, so the user gets no merged conversation and no error surfaced, just a logged failure. The same file already solves the identical naive-vs-aware problem for conversation-level timestamps with the_coerce_dthelper, but the photo sort key was never given the same treatment.Fix
Replace the bare
datetime.minkey with a helper that normalizes each key to a tz-aware UTC datetime: a tz-aware epoch sentinel for the missing case, ISO-string coercion for older write paths that persistedcreated_atas a string, and a tz attach for any naive datetime that slips through.datetimeandtimezoneare already imported at module top, so no new import is needed. For the normal case where every photo has a tz-awarecreated_at, the ordering is unchanged. Photos missing the field sort first under the epoch sentinel, which matches the previous intent ofdatetime.min.Testing
Added
backend/tests/unit/test_merge_photos_naive_datetime.py, registered inbackend/test.sh.merge_conversationsinitializes Firestore and GCS at import time, so the test mirrorstest_merge_validation.py: it installs the database modules under a stub finder, stubsutils.other.storageand themodels.*chain, then imports the realmerge_conversationsfrom source and calls_collect_all_photosdirectly withget_conversation_photosmocked. Cases covered: a photo with nocreated_atmixed with tz-aware photos does not raise and orders correctly, an ISO-stringcreated_atmixed with tz-aware datetimes coerces and sorts, an all tz-aware list sorts ascending, and dedup-by-id still holds with the new key. Verified red to green: the test fails on current main and passes with this change.PR status check
No open PR changes this logic. The photo sort key in
_collect_all_photosdoes not appear anywhere in this file's history, so this is not a previously reverted fix being resubmitted. No filed GitHub issue matches.