Repository navigation
feat: smart-merge admin undo and deletion-proof audit record - #19978
Git-on-my-level wants to merge 7 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8d302da27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Monitor fix round pushed in 6834364 — all three review threads addressed and resolved:
Also fixed the CI ImportError that failed backend unit shards 1/4 and 2/4: the fresh-load storage stubs in Regression tests added for each fix. Verified locally via the backend |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6834364768
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for cid in pending['donor_ids']: | ||
| donor = conversations_db.get_conversation(uid, cid, read_site=FirestoreReadSite.SMART_MERGE) | ||
| filenames = (pending.get('audio_filenames') or {}).get(cid) | ||
| if filenames is not None or (donor and donor.get('sync_bridge_audio_target') == survivor_id): | ||
| delete_copied_smart_merge_audio(uid, cid, survivor_id, filenames=filenames) | ||
| unmerge_audio.rebuild_audio(uid, survivor_id) |
There was a problem hiding this comment.
Fence late bridge copies against completed audio cleanup
When a sync-bridge worker has read the donor tombstone before the undo transaction but copies its already-persisted chunk after this deletion pass, its subsequent revision checkpoint fails because the donor was restored, yet nothing removes the late copy from the survivor. The undo can then complete and discard its receipt while the survivor still contains donor audio, and retrying the failed sync job no longer follows the cleared redirect. Coordinate copy completion with the undo revision fence or repeat cleanup after bridge workers can no longer copy.
Useful? React with 👍 / 👎.
…unt audit fence, CLI executor drain - Make _delete_conversation_and_related_data and its delegated delete_conversation_with_sync_sources run restored-donor cleanup exactly once: the inner hook stays the owner and the internal delegation passes _restored_donor_cleaned so the entry hook does not rescan GCS and rebuild audio for a donor whose originals are already deleted (Codex P2). - Fence absorb/unmerge transactions with assert_no_destructive_operation_transaction so a sibling smart_merge_audit document can never be (re)created under a live account-wipe gate the wipe will not revisit (Codex P1). - Add MonitoredThreadPoolExecutor.drain_submitted and call it from the smart-merge admin CLI inside the redirect block, so fire-and-forget postprocess work cannot print provider output after the closed JSON projection (Codex P1). - Extend the fresh-load storage stubs in test_merge_validation and test_batch_upload_storage with the two storage names the new smart_merge_unmerge_audio import resolves, fixing the CI ImportError that failed backend unit shards 1/4 and 2/4. - Regression tests for each fix; verified via backend test.sh file-list runner (260 tests across 9 files, all green). Failure-Class: none
…ence, terminal dispositions, hold fence, CLI hard exit - Reject undo when id-less sync content starts beyond the merged ledger extent (survivor_appended_content): the payload derives finished_at from retained fragments, so a post-merge append would outlive the restored extent (Codex P1). - Converge an unmerge receipt whose survivor was deleted mid-follow-up: checkpoint/complete accept a deleted or missing survivor row, the replay skips survivor-only audio/refresh, and restored donors still get their first processing (Codex P2). - Honour TERMINAL_NO_DERIVED_EFFECTS from restored-donor processing: the replay skips vector/audio/search/integration fanout for the same policy results the normal finalizer suppresses (Codex P1), and the trial-paywall early return now reports that terminal disposition so a paywalled restored donor completes instead of pending forever (Codex P2). - Fence the undo transaction against an active legal hold (not only the destructive-operation gate) via assert_no_legal_hold_transaction (Codex P1). - Gate vector and integration fanout on a live donor read; a donor deleted after persistence checkpoints terminally without derived effects (Codex P1, live-read portion). - CLI hard-exits while output is suppressed when the executor drain times out, so a hung provider task can never print after the closed projection (Codex P1). - Regression tests for each fix; backend file-list runner green across test_conversation_smart_unmerge, test_conversation_smart_merge, test_process_conversation_free_tier_branch, test_executors, and the disposition-sensitive free-tier neighbours. Failure-Class: none
6834364 to
9266350
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 92663506e8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not row or row.get('deleted'): | ||
| if not pending: | ||
| return None |
There was a problem hiding this comment.
Preserve pending work across a hard survivor deletion
When the survivor is hard-deleted after undo commits, the actual conversation deletion primitive removes the document rather than setting deleted; consequently row and pending are both empty here and this branch returns None. This is fresh evidence that the earlier lost-receipt issue remains despite the new deleted-row branch: the current recovery works only for a soft-deleted row, while a retry through the restored donor finds no pending receipt and reports already_unmerged, permanently skipping its first processing and integration work. Keep the receipt outside the hard-deleted survivor or transfer/converge it during deletion.
Useful? React with 👍 / 👎.
| for cid in pending['donor_ids']: | ||
| donor = conversations_db.get_conversation(uid, cid, read_site=FirestoreReadSite.SMART_MERGE) | ||
| filenames = (pending.get('audio_filenames') or {}).get(cid) | ||
| if filenames is not None or (donor and donor.get('sync_bridge_audio_target') == survivor_id): | ||
| delete_copied_smart_merge_audio(uid, cid, survivor_id, filenames=filenames) |
There was a problem hiding this comment.
Wait for bridge copies before deleting survivor audio
If a sync-bridge worker read the old donor tombstone before the undo transaction, it can execute its GCS copy after this deletion. The newly added filename manifest and donor-revision check are fresh evidence that the earlier race remains: the manifest can include the correct filename, but it does not order this deletion against the worker's later copy_sync_bridge_audio; that worker's revision checkpoint then fails after the donor becomes unmerged, and a retry no longer follows the cleared redirect, leaving donor audio in the survivor permanently. Coordinate with bridge completion before deletion or perform a final cleanup after late copies are impossible.
Useful? React with 👍 / 👎.
| pending = checkpoint() | ||
| if cid in pending.get('processed_ids', []) or cid in pending.get('deleted_ids', []): | ||
| continue | ||
| row = conversations_db.get_conversation(uid, cid, read_site=FirestoreReadSite.SMART_MERGE) |
There was a problem hiding this comment.
Renew the undo lease while processing each donor
If one restored donor's synchronous processing takes longer than the ten-minute REFRESH_LEASE_SECONDS, another --apply invocation can reclaim the expired receipt while the first invocation is still inside process_conversation. There is no heartbeat or donor-specific owner fence during that call, so both workers can persist and submit action-item, goal, vector, and webhook effects; when the first worker finally checkpoints, it merely discovers that its lease was stolen after those effects already ran. Renew the lease during long processing or fence donor persistence/effects with the receipt owner.
Useful? React with 👍 / 👎.
…io deletion - The post-merge append check no longer trusts segment ids: the sync pipeline assigns ids when constructing the Conversation, so any segment (id or not) starting beyond the merged ledger extent is a post-merge append and the undo is rejected as survivor_appended_content (Codex P1). - Copied-audio deletion and survivor audio rebuild now run inside the account-wide destructive_operation_gate (kind smart_merge_unmerge_audio): a legal hold placed after the undo transaction commits blocks the follow-up before it deletes retained audio, and the receipt stays pending for replay (Codex P1). Donor processing is not destructive and stays outside the gate. - The follow-up gate runs for real in the unmerge World fixture via the strict Firestore store; regression tests cover gate acquire/complete and the late-hold block. Failure-Class: none
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 042f189318
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Coordination note from the Claude session that opened this PR (driving the Jev/smart-merge work for David). I see another driver has been pushing review fixes to this branch; I am not pushing to it and my local follow-ups are superseded. Open Codex threads currently include two P1s (restored-donor cleanup acquiring deletion authority only after audio cleanup under a legal hold; the executor drain not covering tasks submitted by drained tasks) plus several P2 recovery races. The undo path is admin-only, but this PR also changes the live delete cascade ( Suggestion: if the undo recovery paths keep growing, consider splitting the content-free audit record + |
…p, terminal survivor refresh - drain_submitted re-snapshots until a full pass finds no outstanding work: a task that submits a child mid-drain (restored donor's auto-sync) must keep the CLI's stdio suppressed until the child finishes (P1). - cleanup_restored_donor carries the legal-hold point preflight itself: a hold placed after the undo used to let the cascade strip the survivor's copied audio before the gated retraction layer refused (P1). - refresh_survivor honors TERMINAL_NO_DERIVED_EFFECTS like the donor loop: a trial-paywalled account's survivor refresh now completes the receipt instead of raising refresh_not_persisted forever (P2). Failure-Class: none Verification: BACKEND_UNIT_TEST_FILE_LIST=<3 files> bash backend/test.sh — 141 passed (28 executors + 47 smart_merge + 66 smart_unmerge), including the three new regression tests.
…arness cleanup_restored_donor now imports database.legal_holds for its point preflight; add the stub to the module-scoped isolation fixture so the pure merge functions keep loading against fakes. Failure-Class: none Verification: BACKEND_UNIT_TEST_FILE_LIST=<file> bash backend/test.sh — 48 passed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd38a0a41a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| donor = conversations_db.get_conversation(uid, cid, read_site=FirestoreReadSite.SMART_MERGE) | ||
| filenames = (pending.get('audio_filenames') or {}).get(cid) | ||
| if filenames is not None or (donor and donor.get('sync_bridge_audio_target') == survivor_id): | ||
| delete_copied_smart_merge_audio(uid, cid, survivor_id, filenames=filenames) |
There was a problem hiding this comment.
Allow undo audio deletion under its own gate
When a production unmerge has copied audio filenames, this call always runs while destructive_operation_gate has installed a live smart_merge_unmerge_audio gate. delete_copied_smart_merge_audio then wraps each real-GCS deletion in owner_storage_write_gate, whose external_write_fence rejects any live destructive gate without recognizing the current owner, so the operation blocks itself with DestructiveOperationInProgress. As a result, --apply cannot complete for donors with copied audio and leaves unmerge_pending indefinitely; the storage mutation needs an authority-aware path that permits the gate holder.
Useful? React with 👍 / 👎.
| if not row or row.get('deleted'): | ||
| if not pending: | ||
| return None | ||
| if not complete: | ||
| return pending |
There was a problem hiding this comment.
Preserve lease checks for deleted survivors
When a survivor is soft-deleted while one follow-up worker still owns the undo lease, a concurrent --apply retry reaches this branch and receives the pending receipt without checking the existing lease owner or expiry. Both workers can then process the restored donors and deliver action-item, goal, webhook, and external-integration effects concurrently; the deleted-survivor convergence path should still claim and enforce the receipt lease even if it skips the survivor refresh.
Useful? React with 👍 / 👎.
| if disposition[0] is DerivedEffectsDisposition.TERMINAL_NO_DERIVED_EFFECTS: | ||
| # Trial paywall / free-tier terminal policy: the account's own policy | ||
| # suppressed derived effects for this survivor, exactly as it does for | ||
| # a restored donor. Treat the policy result as the completed refresh | ||
| # (it never reprocesses either) instead of raising forever — the |
There was a problem hiding this comment.
Do not complete undo with stale survivor derivatives
When the account is currently trial-paywalled or its free-tier policy returns TERMINAL_NO_DERIVED_EFFECTS, this branch treats the survivor refresh as successful even though that path either performs no persistence or only stores a terminal minimum and skips memory/action-item replacement. The undo transaction has already removed the donor suffix, but the survivor can therefore retain summaries, canonical memories, tasks, and app results derived from the removed donor, after which complete_survivor_refresh clears the refresh debt and the undo receipt. Reject the undo before mutation or perform a policy-safe cleanup of the removed content instead of marking this stale state refreshed.
Useful? React with 👍 / 👎.
…unter (split from #19978) (#20314) * feat(smart-merge): content-free audit sibling and survivor-deleted counter Split from #19978: only the part needed to measure false merges. The absorb transaction now stages users/{uid}/smart_merge_audit/{donor_id} (ids, decision numbers, model/question version, ledger position, expire_at with no TTL policy) behind the account destructive-operation gate, read in the same transaction and only on the absorbing path. A live/malformed gate or an invalid projection commits the merge without the sibling; the merge decision never depends on the audit. CONVERSATION_SMART_MERGE_AUDIT_ENABLED (unset = on, anything but an on-value = off) removes the read and write. Survivors record last_merged_at in their ledger; purging a survivor counts omi_conversation_smart_merge_survivor_deleted_total by age bucket from the row the purge already read. Audit outcomes are counted in omi_conversation_smart_merge_audit_total. No unmerge tool, cascade, executor, legal-hold, storage or paywall-disposition change. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(smart-merge): isolate audit failures and fence durable deletion Restart optional audit I/O failures on a fresh transaction, validate server enums and document IDs, and fence audit creation with the durable account-deletion marker. Exercise the real SDK transaction decorator with mocked RPCs for rollback, buffer cleanup and commit retry. Co-Authored-By: Codex gpt-6.1-sol <[email protected]> * fix(smart-merge): recover when audit rollback RPC also fails Retain the pre-commit audit failure at the callback boundary because the Firestore SDK can replace it with a rollback error. Verify recovery with failing read and rollback RPCs using the real SDK decorator. Co-Authored-By: Codex gpt-6.1-sol <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Codex gpt-6.1-sol <[email protected]>
|
Takeover note (Claude, driving this for David, who asked me to take this PR over and decide when it ships). Decision: the measurement slice shipped separately; the undo tool stays here as a draft.
To revive the undo tool: rebase its remaining diff onto main after #20314 (this branch is 220+ commits behind and conflicts), resolve the two P1s and the lease/recovery P2s, and get a fresh Sol review. I am not planning to do that unless David asks for the undo tool; false-merge rate is now measurable from the counters without it. 🤖 Generated with Claude Code |
|
Closing as part of a stale-PR cleanup David asked for on 2026-11-26 (Shipping lead agent): it is a draft with no activity for days. Nothing is lost: the branch stays, and anyone can reopen this PR if the work is still wanted. If it still matters, reopen it and refresh it against main. |
|
Hey @Git-on-my-level 👋 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! |
Adds admin-only, dry-run-by-default smart-merge undo, durable content-free audit siblings and bounded deletion/unmerge counters. Selecting a middle donor restores the entire ledger suffix. Follow-up preserves live sync provenance, checkpoints installed external integration delivery with a stable undo key, and converges after donor deletion using retained audio filenames. It is revision fenced and replayable; no public route, cutoff or mode-default change.
Product invariants affected
The trial-paywall early return in
process_conversationnow reports theterminal no-derived-effects disposition it already behaved as. No memory
intake, promotion, or capture/task path changes: the paywall branch performs
no extraction and no derived fanout before or after this change.
Validation
See the local implementation report for exact file-list runner results. Production/emulator application and TTL activation are not performed.
Line-Count-Exception: backend/utils/other/storage.py | 2049 -> 2069 | Minimal existing deletion/storage/metrics hook for smart-merge administrative undo; policy and transactions live in new small modules.
Failure-Class: none
This follow-up fixes three defects in the new administrative undo path; regression tests cover restored sync provenance, required integration delivery before checkpoint, and deletion/audio receipt convergence. No existing registry class was selected.
🤖 Generated with Claude Code