Repository navigation
fix(backend): call get_firestore_client() in typesense dual-write resolver - #15107
Merged
Git-on-my-level merged 2 commits intoSep 20, 2026
Merged
Git-on-my-level merged 2 commits into
Git-on-my-level merged 2 commits into
Conversation
Git-on-my-level
marked this pull request as ready for review
September 20, 2026 14:42
Member
Author
|
Coordinator: rebasing onto latest main after 'base branch was modified' on merge. |
Git-on-my-level
added a commit
that referenced
this pull request
Sep 21, 2026
## Root cause Prod first-party Typesense dual-write (`typesense_index.py`) started running after #15107, then fail-opened on every upsert whose `structured` blob still carried Firestore `DatetimeWithNanoseconds` (`Object of type DatetimeWithNanoseconds is not JSON serializable`). 37 of those in 2h on serving `16fc207`. Search stayed on the Firebase extension. ## Failure class (fixes) Failure-Class: none ## Fix Sanitize `structured` (and nested lists/dicts) to JSON-safe values before upsert: datetimes → unix seconds, GeoPoints → `[lat, lng]`. Top-level timestamps were already epoch-coerced; nested `structured.events.*.created_at` was not. ## Test `pytest tests/unit/test_conversation_typesense_index.py::TestDocumentShape` — 8 passed, including `test_structured_firestore_datetime_is_json_serializable` (`json.dumps` of a DatetimeWithNanoseconds subclass). ## Rollout Does not uninstall the Typesense extension. After merge+prod deploy, re-run the C018 coverage gate; remove the Eventarc trigger only if that PASSes. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/15328?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. -->
This was referenced Sep 24, 2026
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
[Bounty proposal] docs(python-cli): Azerbaijani (az) AI agent quickstart guide ($25 proposed)
#15427
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
This was referenced Sep 24, 2026
Closed
Closed
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
_resolve_firestore_client()inbackend/utils/conversations/typesense_index.pyimported the memoized factoryget_firestore_clientand returned the function itself instead of calling it. Every first-party Typesense dual-write that reached the projection read then died with'function' object has no attribute 'collection', which the module's fail-open contract swallowed — visible in production as 500+omi_fallback_event … to=fail_openentries per 24h in backend logs (serving SHA7d8a0093e0f7, still onorigin/main). A live read-only coverage gate over 30 users / 173 conversations confirmed the consequence: 171 conversations were matched in the index via the Firebase Typesense extension only, and 2 were missing entirely — the first-party writer contributed nothing.Failure class (fixes)
Failure-Class: none
Fix
One line (plus a comment): call the factory.
Sibling check:
_resolve_firestore_clienthas exactly one caller —_fetch_index_projection, which immediately doesclient.collection(...)— and no other module imports the resolver, so the one-liner is sufficient. The sibling_resolve_default_db_clientreturnsdata_plane_db, which is already a lazy proxy object (not a factory), so it is correct as-is and untouched. The fail-open contract is deliberately unchanged here; making sync failures louder than a swallowed fallback deserves its own design pass (follow-up), since it trades search freshness signal against write-path availability.Tests
Extends the module's existing suite
backend/tests/unit/test_conversation_typesense_index.py(existing tests always injectedfirestore_client, which is why the broken default seam stayed green):test_resolver_calls_the_factory_and_returns_its_client— monkeypatchesdatabase._client.get_firestore_clientwith a sentinel-returning fake; asserts the sentinel is returned (i.e. the factory is actually called, once).test_default_path_sync_reads_firestore_through_the_factory— end-to-end default-path regression: syncs with no injectedfirestore_client; asserts the document is upserted. On the unfixed resolver this test fails (False is True), reproducing the swallowed production failure.test_typesense_outage_does_not_raise_out_of_write_pathsnow also fakes the projection-read client, matching the test's other I/O seams: pre-fix, its sync died at the broken resolver before ever reaching the Typesense outage, so this very bug had silently narrowed that test's coverage; post-fix it exercises the real outage path.Both new tests were verified to fail against the pre-fix resolver and pass after the fix. Full file via
backend/test.sh(file-isolated, duration guard on): 55 passed.Rollout note
This unblocks the Typesense extension retirement: after merge + deploy, re-run the saved coverage gate (30 users / 173 conversations) and confirm first-party writes close the gap before removing the Eventarc trigger. Rollback = revert this PR.