Skip to content

fix: prevent deleted conversations from backlog resurrection - #21000

Merged
Git-on-my-level merged 17 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/deleted-conversation-tombstones
Oct 9, 2026
Merged

Git-on-my-level merged 17 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/deleted-conversation-tombstones

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

fix: prevent deleted conversations from backlog resurrection

A user-reported incident (May/June conversations re-appearing Oct 6–8) exposed a resurrection
path: the desktop client keeps un-uploaded sessions in a local outbox, and when a months-old
backlog drains (post-#19613 retry-budget removal), the from-segments create path re-derives the
same deterministic conversation id (uuid5(namespace, uid + "\0" + client_session_id)), finds
the doc absent (the user had deleted it), and re-creates the conversation — rerunning the full
pipeline including canonical memories. Fleet logs show ≥207 distinct users re-persisting
from-segments conversations since Oct 6; in one day's sample 103/955 persisted uploads were

30-day-old backlog (median age 114d, max 224d). Users who re-deleted during the drain hit
retryable 409s or had the delete undone by the next client re-post.

Design

  • database/conversation_tombstones.py: content-free deletion intent, stored at
    users/{uid}/deleted_conversations/{conversation_id} — identity fields only
    (conversation_id, deleted_at, bound from-segments client_session_id, created_at);
    never transcript, structured, or calendar data. create() is first-writer-wins so a
    retried delete preserves the original binding.
  • DELETE /v1/conversations/{id} and the developer-API conversation delete record the
    tombstone BEFORE any retraction/cleanup; a later failing step never removes it, so a
    delete that partially failed still suppresses future re-creation.
  • The shared from-segments create impl point-reads the tombstone before admission and
    acks retired identities with {id, status: "deleted", discarded: true} instead of
    creating — no processing, no memories, no vectors.
  • The live listen session runtime refuses to attach to a tombstoned conversation id.
  • Desktop: when an upload is acked as deleted, the local outbox row is deleted (pool-
    generation fenced so a stale owner cannot touch a newer owner's row); confirmed user
    deletes now also resolve matching local rows — including never-synced rows matched via
    the client-side mirror of the backend uuid5 identity (ConversationDeletionIdentity).
  • Account wipe (delete_user_data) already enumerates and removes the user's
    subcollections including deleted_conversations; doc comment updated.

Failure-Class

Failure-Class: new

New class FC-ingest-recreates-retired-identity ships in this PR (definition JSON +
scope hints + canonical prevention artifacts pointing at the tombstone module, its tests,
and the desktop retry tests). Existing classes cover adjacent-but-different mechanisms
(FC-content-derived-identity-retired-by-deletion: reissue a fresh identity on content
rewrite; FC-read-in-flight-across-delete-resurrects-row: client read fencing).

Testing

  • backend: pytest tests/unit/test_conversation_tombstones.py (tombstone content,
    owner scoping, ordering vs retraction/cleanup failures, developer-delete parity,
    listen-runtime rejection) + tests/unit/test_developer_from_segments_idempotency.py
    (tombstoned ack, idempotency hit preserved for live ids) + cascade/reprocess/
    client-processing/reminders suites — results in CI; known pre-existing main-side
    test-pollution pair documented below.
  • desktop: xcrun swift test --package-path Desktop (outbox ack resolution, deletion
    identity matching, pool-generation fencing) — results in CI.
  • e2e flow deleted-conversation-backlog.yaml covers delete → backlog re-post → ack →
    no resurrection.

Known pre-existing issue (not this PR)

tests/unit/test_developer_from_segments_idempotency.py performs import-time
sys.modules stubbing that leaks into files ordered after it in the same pytest worker;
combined with test_delete_conversation_cascade.py / test_reprocess_tombstone_guard.py
this reproduces 15 failures on pristine origin/main (verified on a clean main worktree).
CI's sharded execution order does not hit the pair. Left untouched here to keep this PR
scoped; worth a dedicated isolation fix.

Not in this PR

  • Mobile clients (iOS/Android): equivalent outbox/ack handling follows the same backend
    contract; separate change.
  • Tombstone TTL/cleanup cron: tombstones are tiny; deferred until volume data justifies it.
  • UI affordances for "this capture was deleted on another device".

Line-Count-Exception: backend/routers/conversations.py | 2284 -> 2288 | tombstone-first ordering: three-line intent commit plus one import at the delete entrypoint; logic lives in the new dedicated module
Line-Count-Exception: backend/routers/developer.py | 2603 -> 2645 | tombstone ack branch and pre-persist race re-check at the shared from-segments choke point plus intent commit on the developer delete route; no split that small is coherent

UI-Evidence: none -- pure behavior change (outbox ack resolution + tombstone guard); no visible UI element added, removed, or restyled; existing screens and flows render identically

Product invariants affected

  • INV-DATA-1: no .github/workflows/* files are touched by this diff.

View guided diff

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Review findings (grok, round 1):
- re-check tombstone before the final from-segments persist so a delete
  committing during processing still wins the admission race
- tombstone sync_merged_from source ids when the survivor delete purges
  them, or a backlog retry resurrects the merge donor
- create guard also matches a tombstone on the raw client session id
  (ws doc id / client_conversation_id alias), covering cross-device
  deletes of live conversations

Both regressions pinned in test_developer_from_segments_idempotency.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Review chain

Round 1 — cursor grok (grok-4.7-high, adversarial, read-only): APPROVE with 3 non-blocking findings, all verified at cited lines and fixed in 788e953:

  1. Pre-persist race — an in-flight from-segments create could still persist_processed_conversation after a concurrent delete committed. Fixed: tombstone re-check immediately before the final persist; a hit returns the deleted ack and never writes (from_segments_tombstoned_suppress).
  2. Merge-donor gap — delete_conversation_with_sync_sources hard-deleted sync_merged_from sources without recording deletion intent, so a backlog retry could resurrect a merge donor. Fixed: record_deletion per source before purge (same first-writer-wins binding).
  3. Cross-device identity gap — the create guard only matched the derived uuid5; a live conversation deleted on another device is tombstoned under its raw ws doc id (the client_conversation_id alias). Fixed: the guard now checks both identities.

Both race regressions pinned with new tests (test_deleted_ack_also_matches_raw_session_id_tombstone, test_pre_persist_tombstone_check_suppresses_delete_race_winner); suite green locally. Non-blocking perf note (narrow the outbox-candidate SQL on large libraries) accepted as-is: candidate set is bounded by per-user outbox size and the Swift matcher cannot over-match (verified: non-empty backendId must equal the deleted id; uuid5 fallback includes the local session id).

Review round 2 on the new head will be posted before merge.

- smart-merge flatten fixture binds conversation_tombstones.db to the
  fake store and the cascade fake document gains SDK create semantics
  (set-if-absent, AlreadyExists on replay) so merge-source intent
  writes resolve in-process instead of reaching real Firestore
- merge_validation import isolation stubs the new database module that
  merge_conversations now imports at module scope
Round-2 review BLOCK: a tombstone write that cannot reach Firestore
(unprovisioned project, blocked metadata endpoint) must not abort the
donor purge the user asked for. Log and continue; suppression still
holds through the survivor tombstone that the create guard re-checks
before recreating, and the pre-persist re-check covers in-flight work.
Same hermetic-import treatment as merge_validation: the fixture builds
a synthetic database package, so the new module-level import in
merge_conversations needs the stub entry to resolve.
Round-3 review BLOCK, both items:

- merge-source tombstone fixtures bind conversation_tombstones.db to
  the fake store (cascade x2, smart-merge audit now also asserts the
  donor intent record), so no cascade/audit test touches live
  Firestore and BlockedNetwork leaks are gone
- the pre-persist suppress branch checks BOTH identities (derived
  uuid5 + raw session id), purges the processing row it may have
  created/completed, and the race test now flips the tombstone only
  after process_conversation starts so it actually exercises this
  branch; admission create-if-absent is stubbed for hermeticity
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Review chain (complete)

  • Round 1 — grok APPROVE + 3 non-blocking → fixed in 788e953 (pre-persist race re-check, donor tombstones, raw-session-id guard).
  • Round 2 — grok BLOCK (donor purge not hermetic) → fixed in 8a2be89 (best-effort donor writes, logged) + 8d4aa47 / 57a6823 (fake-store binding, import-isolation stubs, SDK create() semantics on the cascade fake).
  • Round 3 — grok BLOCK (2 items: remaining unbound callers + suppress-path completeness) → fixed in 00feaa7 (audit-test tombstone stub + assertion tombstones == ['n']; suppress branch checks both identities AND purges the processing row; race test now flips the tombstone after process_conversation starts so it exercises the suppress branch; admission create stubbed hermetic).
  • Round 4 — grok APPROVE (0 blocking; 276 tests passed, zero BlockedNetwork escapes). Two new non-blocking notes on the suppress path's cleanup-failure and queued-vector-write edges recorded below as follow-up candidates — both require the delete that wrote the tombstone to have failed its own purge first, an order-of-failure edge beyond this PR's scope; tracked for the tombstone hardening follow-up.

CI: all checks green on head 00feaa7 (Backend shards, Desktop Swift, Dart, Android, Hygiene after body refresh). Reviewer chain: 4 rounds, every blocking finding verified at file:line, fixed, and re-reviewed on the exact new head.

@Git-on-my-level
Git-on-my-level merged commit 08afc66 into BasedHardware:main Oct 9, 2026
55 of 56 checks passed
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Merged

Squash-merged as 08afc66 on main. All required checks green on head 00feaa7 before merge (Backend unit shards, Desktop Swift, Dart, Android, Hygiene after the body declaration refresh to 2645). Dev auto-deploy (Backend to Development + pusher) in progress on this SHA; bake monitor watching:

  • from_segments_tombstoned_reject / from_segments_tombstoned_suppress log lines (guard firing)
  • from-segments idempotency persisted returned where session age > 30d (resurrection signature should stop growing)
  • delete-endpoint 409/5xx rates during the backlog drain

Git-on-my-level added a commit that referenced this pull request Oct 9, 2026
…rtion

RewindEvidenceCardTests asserted the old "unavailable locally" hint.
TranscriptionStorageRecoveryTests kept an assertion that the shell was
deleted after #21000 removed the delete from its setup; the
delete-survives-hydration case is covered by
testStaleServerHydrationCannotUndoConfirmedDelete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Oct 10, 2026
…ssertion

TasksStoreUnsyncedSyncTests hung on CI (327s/324s vs 300s budget, twice) before
any test case ran: the owner-transition fixture's finalization touches
RewindIndexer.shared, whose init resolved ClientDeviceService.shared.clientDeviceId
at actor-init time and could block on a Keychain SecItemCopyMatching IPC.
Resolve the device id on first frame write instead; the value is stable for the
process lifetime, so frame provenance is unchanged.

TranscriptionStorageRecoveryTests asserted hydrated.deleted in a test whose
setup delete was removed by the same PR that added the assertion (#21000);
no-resurrect coverage lives in testStaleServerHydrationCannotUndoConfirmedDelete
and the upsert tombstone early-return, so the stale line failed 3x on CI.
Git-on-my-level added a commit that referenced this pull request Oct 10, 2026
…ead (#21081)

* feat(desktop): ship a product guide the Mac chat agent can read

Chat had no local source for how this build of Omi works, so questions like enabling Only Meetings could not be answered from the UI the user actually has.

Co-authored-by: Cursor <[email protected]>

* chore(desktop): cover ProductKnowledgeBase in chat-hermetic e2e flow

The desktop-e2e-flow-coverage gate requires every changed desktop Swift source to be claimed by an e2e flow; the KB loader is exercised on the chat-hermetic path where the capability registry is already covered.

* test(pi-mono): list get_product_kb in the required-fields table

The exhaustive per-tool required-field assertion in pi-mono-extension must name every OMI tool; get_product_kb takes only optional params.

* fix(desktop): resolve Rewind device id lazily; drop stale hydration assertion

TasksStoreUnsyncedSyncTests hung on CI (327s/324s vs 300s budget, twice) before
any test case ran: the owner-transition fixture's finalization touches
RewindIndexer.shared, whose init resolved ClientDeviceService.shared.clientDeviceId
at actor-init time and could block on a Keychain SecItemCopyMatching IPC.
Resolve the device id on first frame write instead; the value is stable for the
process lifetime, so frame provenance is unchanged.

TranscriptionStorageRecoveryTests asserted hydrated.deleted in a test whose
setup delete was removed by the same PR that added the assertion (#21000);
no-resurrect coverage lives in testStaleServerHydrationCannotUndoConfirmedDelete
and the upsert tombstone early-return, so the stale line failed 3x on CI.

---------

Co-authored-by: Cursor <[email protected]>
kodjima33 pushed a commit that referenced this pull request Oct 13, 2026
…tion (#21329)

* fix(backend): restore the released 204 delete contract for conversation deletion

DELETE /v1/conversations/{conversation_id} shipped to released mobile clients
as 204 No Content. The 2026-07-04 response_model backfill (e22938a) turned
it into a 200 with a StatusResponse body, and the released app
(app/lib/backend/http/api/conversations.dart::deleteConversationServer) gates
delete success on exactly 204 — so every conversation delete there reads as a
failure: the optimistic tombstone is dropped immediately, the server-cursor
rebase and fetch-revision bookkeeping are skipped, and once the server delete
cannot complete (e.g. cascade retraction failing closed) the deleted
conversation resurfaces on the next refresh. This is the recurrence of

Restore status_code=204 with no body (the folders/mcp convention) and pin the
contract from both sides in backend/tests/unit/test_conversation_delete_wire_contract.py:
the router declaration and the regenerated app-client OpenAPI spec.

Verified: offline harness — cascade delete of a conversation with attributed
memories returned 503 before this change, 204 with an empty body after.

Failure-Class: FC-privacy-delete-fails-on-unprovisioned-derived-store
Amp-Thread-ID: https://ampcode.com/threads/T-01a0b590-2123-744a-9e4a-16706295c2d3
Co-authored-by: Max Carter <[email protected]>
(cherry picked from commit 21002a8)

* fix(checks): allow recorded released-status restorations in app-client contract gate

The gate treats the merge-base spec as the released-clients truth. That
baseline can itself carry a spec-only regression: e22938a (2026-07-04)
flipped DELETE /v1/conversations/{conversation_id} from the released 204
No Content to 200 + StatusResponse while every released mobile client
still gates delete success on exactly 204
(app/lib/backend/http/api/conversations.dart::deleteConversationServer,
#10446 recurrence: desktop delete errors, mobile re-adds on refresh).
With the baseline poisoned, the gate blocked restoring the actual
released contract, and the July regression shipped precisely because no
guard existed to catch it.

Add RELEASED_STATUS_RESTORES, patterned on DELIBERATELY_REMOVED_ENDPOINTS:
an explicit, evidence-cited (route, method, status) record whose
released-client contract predates the baseline regression, so restoring
that status is not flagged as a new success status. Entries are narrow —
an unrecorded operation cannot borrow the allowance — and both the
allow-and-refuse directions are unit-tested.

Evidence: app/lib/backend/http/api/conversations.dart:140 in the
released app source returns response.statusCode == 204 for this call.

Failure-Class: none
Amp-Thread-ID: https://ampcode.com/threads/T-01a0b76d-bb38-749d-a0da-1b0837aa8e2e
Co-authored-by: Max Carter <[email protected]>
(cherry picked from commit 11cc3c5)

* chore: regenerate TS/Swift OpenAPI clients for the restored 204 delete contract

Regenerated from the updated app-client spec with
backend/scripts/generate_ts_openapi_types.py and
generate_swift_openapi_types.py rather than cherry-picking 2fb1f42 from
#14691, whose generated files predate current main. Only the conversation
delete function changes: Swift returns Void, TypeScript returns without
parsing a body. No in-tree code calls either generated function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): expect no body from conversation delete under the 204 contract

test_conversation_tombstones.py (#21000) landed after the 200-with-body
regression and asserted the handler's {'status': 'Ok'} return. The route is
204 No Content again, the contract the released mobile client gates on
(app/lib/backend/http/api/conversations.dart::deleteConversationServer
returns statusCode == 204), so the handler returns None. The tests' subject,
tombstone ordering against retraction and cleanup, is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): assert conversation delete answers 204 with an empty body over HTTP

The wire-contract test pinned the route declaration and the published spec.
This adds the HTTP layer: the real route through FastAPI's TestClient, with
only storage side effects stubbed, for cascade=false and cascade=true. Against
main's route both requests answer 200 (assert 200 == 204), which the released
mobile client reads as a failed delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore(backend): keep the 204 delete rationale to one line

The full reasoning lives in test_conversation_delete_wire_contract.py; the
router stays at its line-count baseline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Amp <[email protected]>
Co-authored-by: Max Carter <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant