Repository navigation
fix: restore conversation deletion - #11727
undivisible wants to merge 4 commits into
Conversation
Conversation deletion now preserves backend errors for the list and detail surfaces. Memory deletion restores the row and presents recovery guidance when the backend delete fails. Verification: Swift formatting and test-quality checks passed. The focused direct XCTest run passed 7 tests: deletion recovery guidance and failed memory delete restoration. Failure-Class: none
Failure-Class: none
Failure-Class: none Tests: backend tests/unit/test_ws_j_delete_privacy.py; backend tests/unit/test_memory_apply_store.py; backend/scripts/scan_async_blockers.py; backend/scripts/typecheck.sh
…+ converge cascade-retract CAS (#11684, #11726) (#11731) ## What changed and why Two production 5xx classes from the 2026-08-17 incident window (watchdog `75afe342f6f8`, serving SHA `6316415` = merged #11627), fixed in two independent commits: 1. **Missing opposite-direction Firestore list-scan indexes → 503 (#11684).** Serving queries order `updated_at DESC, __name__ ASC` (`read_canonical_scan_page`, plus the historical dual-stream scans and the review-queue status scan). Firestore automatic single-field indexes only cover `field+__name__` in the *same* direction, so these need real composites — but `_query_spec_index_requirements()` dropped every spec with ≤1 non-`__name__` field. Prod answered `FailedPrecondition: The query requires an index`, mapped to 503 `Canonical memory unavailable` / `Historical memory unavailable` on `GET /v3/memories` and the cascade-delete skip-guard scan. Fix: the predicate now declares exactly the opposite-direction pairs and regenerates the manifest with the four missing indexes (`memory_items` `updated_at DESC`+`__name__ ASC`; `memories` `updated_at DESC`+`__name__ ASC`; `memories` `created_at DESC`+`__name__ ASC`; `memory_review_queue` `status ASC`+`__name__ DESC`). Same-direction singles and array-contains pairs stay out (deploy rejects those as redundant). 2. **Cascade-retract CAS exhaustion → 500 (#11726).** Concurrent same-uid canonical writes all bump the one account-global `memory_state/apply_control` document. `replace_conversation_sourced_memories`' three *immediate* CAS attempts exhausted under that contention and raised an unhandled `RuntimeError` → `DELETE /v1/conversations/{id}?cascade=true` returned 500 while the Flutter client retried one conversation up to 12× and kept the storm fed. A repeat delete whose committed receipt went stale (another conversation's replacement advanced `source_generation`) livelocked on `source replacement operation already exists` the same way. Fix on the retract entry only (cascade delete + merge; the extraction replace path keeps its existing contract): bounded backoff retry (5 rounds, 0.05→0.5s), and after each conflict an epoch-guarded empty-cohort check — the same double-read control fence the replacement loop uses — returns the committed-empty result when a peer already retracted the source. Exhaustion raises typed `ConversationReplacementConflictError` (a `RuntimeError` subclass, so existing callers are unchanged), which `delete_conversation` maps to a retryable **503** *before anything is deleted*: the #11627 never-orphan-live-memories fence holds, and a retried delete is idempotent (receipt replay / already-retracted short-circuit). Closes #11684 Closes #11726 ## Relationship to open work - **Supersedes #11687** (aryanorastar's index fix). That branch conflicts with current main — main refactored the predicate into `_query_spec_index_requirements()` — so this PR re-expresses the same semantic change there, ports its test fix verbatim (`test_firestore_config_does_not_declare_same_direction_single_field_composites` + the four-tuple declaration test), and regenerates the manifest through the generator rather than hand-patched JSON hunks. Credit for the measured predicate direction belongs to #11684/#11687. - **Does not replace #11727** (draft: zero-write retraction while intake is paused). That PR targets the fenced-intake path; this PR converges the open-intake CAS path. Whichever lands second will need a small rebase; the touched regions barely overlap. - Out of scope, per #11726: #11685/#11688 extract abort, MEMORY_MODE/cohort/control-schema redesign, client-only backoff. ## Merge sequencing (required) `firestore_readiness` runs `reconcile_firestore_indexes.py --check-only` on backend deploys and **fails closed until every manifest index is READY**. Merge only after a human runs `Reconcile Firestore Indexes` → `prod` → `APPLY_FIRESTORE_INDEXES` (dev first is fine) — that APPLY alone stops the 503s even before this PR merges. Split-merging (declaration after APPLY lands separately) is a later human decision; nobody should run APPLY from this PR. ## How it was verified - `pytest tests/unit/test_firestore_index_config.py tests/unit/test_firestore_indexes.py tests/unit/test_reconcile_firestore_indexes.py tests/unit/test_firestore_query_contract.py` → **62 passed** (was 61 on the wrong predicate; the renamed same-direction test no longer codifies the bug and the new opposite-direction declaration test pins all four indexes). - `python3 backend/scripts/generate_firestore_indexes.py --write` then read-mode → `firestore.indexes.json matches the Firestore index registry`; diff adds exactly the 4 entries (+56 lines, same shape as #11687). - `python3 backend/scripts/firestore_query_coverage.py --check-ratchet` → exit 0 (coverage keys on query signatures; QUERY_SPECS unchanged → no baseline drift). - `pytest tests/unit/test_cascade_retract_convergence.py tests/unit/test_delete_conversation_cascade_retraction_fence.py` → **7 passed**: injected `ConversationSourceReplacementConflict` rounds converge with bounded backoff; repeat retract with a stale receipt returns already-retracted instead of livelocking; exhausted conflicts with live items still raise (conversation + memories intact, #11627 fence); route maps the typed conflict to 503 before any delete. - Affected memory suites: `pytest tests/unit/test_ws_i_hardening.py tests/unit/test_ws_j_delete_privacy.py tests/unit/test_memory_apply_store.py tests/unit/test_memory_replace_policy.py tests/unit/test_merge_conversations_canonical_delete.py tests/unit/test_merge_skips_retraction_without_canonical_memories.py tests/unit/test_universal_memory_service.py tests/unit/test_atomicity_lifecycle_regressions.py` → **173 passed**. - Scan-read/fake-contract: `pytest tests/unit/test_bounded_firestore_list_reads.py tests/unit/test_firestore_fake_contract.py` → **12 passed**. - `scripts/pr-preflight --suggest` → INV-MEM-1 required; failure-class protocol honored below. Not verified here: live Firestore behavior (no APPLY, no prod/dev writes — the four indexes must be provisioned by a human via the workflow above). ## Tests - Index half regression: `backend/tests/unit/test_firestore_index_config.py::test_firestore_config_declares_opposite_direction_universal_list_scans` (fails on main's manifest) and the renamed same-direction test (fails if the predicate over-declares). - CAS half regression: `backend/tests/unit/test_cascade_retract_convergence.py` (three behavioral tests: convergence under injected conflicts, stale-receipt idempotency, fail-closed exhaustion) + `test_delete_conversation_cascade_retraction_fence.py::test_exhausted_replacement_conflict_maps_to_retryable_503_before_any_delete`. ## Product invariants affected INV-MEM-1 ## Failure class (fixes) Failure-Class: FC-undeclared-serving-query-index (That class covers the index half exactly — a serving query's composite index missing from the registry manifest. The CAS half has no existing class in the registry; it is a candidate for a new class — "account-global CAS exhaustion surfaced as an unhandled 500 on a retryable, idempotent operation" — to be registered separately per the transition-narrative protocol, not inline in this fix PR.) Line-Count-Exception: backend/routers/conversations.py | 1515 -> 1527 | retryable-503 mapping for the cascade-retract conflict (#11726) is a few lines inside the existing delete route; splitting the router is out of scope for an incident fix Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py | 2388 -> 2491 | retract convergence loop + epoch-guarded completion check + typed conflict error live with the CAS loop they wrap (#11726); extraction into a new module would split the replace/retract boundary mid-incident ## Residual risk - The 503-after-exhaustion path is still a 5xx by design — but only after 5 backoff rounds *and* a proven-non-empty source, with nothing deleted and a safe client retry; the incident's unbounded 12×-retry 500 loop is gone (converges or fails closed). - The already-retracted short-circuit trusts the same double-read fence the replacement loop uses; it cannot skip a retract that still has live items (live items → keep retrying → raise). - Multi-instance Cloud Run: the backoff converges cross-instance via the control CAS itself; there is no cross-instance lock (deliberately — the smallest shape #11726 sanctioned). <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/11731?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. -->
Failure-Class: none
|
Status check-in: this branch has drifted behind Options:
Say the word (or react 👍 on this comment for option 1) and I'll schedule the rebase. Not auto-rebasing now because each one is a multi-hour, conflict-heavy job and these have been quiet long enough that confirming intent first avoids wasted work. |
|
Closing as stale. ~2,400 commits behind The core bug this PR fixes (deletion blocked by the canonical intake fence) — if it still reproduces on current main, it deserves a fresh minimal PR against today's |
|
Hey @undivisible 👋 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! |
Summary
Root cause
The deletion path used the same intake fence as canonical memory creation, so conversations with existing canonical memory could not be deleted while intake was paused.
Validation
backend/.venv/bin/pytest backend/tests/unit/test_ws_j_delete_privacy.py backend/tests/unit/test_memory_apply_store.py -qbackend/.venv/bin/python backend/scripts/scan_async_blockers.pybackend/scripts/typecheck.shbash app/test.shmake preflightProduct invariant
INV-MEM-1: preserves the canonical memory collection and existing tier policy while allowing only zero-write retractions.Failure-Class: none
Line-Count-Exception: backend/database/memory_apply_store.py | 1932 -> 1961 | A dedicated transaction preserves the paused-intake boundary for ordinary writes while allowing only zero-write retraction.
Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py | 2388 -> 2406 | The adapter selects the dedicated zero-write retraction path without changing normal canonical replacement behavior.
Line-Count-Exception: desktop/macos/Desktop/Sources/MainWindow/Pages/MemoriesPage.swift | 3468 -> 3482 | The existing page owns optimistic deletion state, restoration, and its user-visible failure alert.