Skip to content

fix(desktop): keep user-deletion provenance so "Removed by me" is not empty (#11517) - #11559

Closed
kodjima33 wants to merge 1 commit into
mainfrom
watchdog/issue-11517-deleted-by-user-provenance
Closed

kodjima33 wants to merge 1 commit into
mainfrom
watchdog/issue-11517-deleted-by-user-provenance

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Bug (#11517)

Desktop "Removed by me" is structurally empty, and task extraction never learns which tasks the user deleted.

TasksStore.deleteTask tombstones a synced task with deletedBy = "user" — and then the acknowledgement path hard-deleted the row (deleteActionItemByBackendId, whose deletedBy: argument was accepted and never read). The Removed lane re-fetches deleted tasks from the backend, and the backend has no deleted_by field, so the row came back with deletedBy: nil. TasksPage partitions the lane on exactly that column:

case .removedByAI: return task.deleted == true && task.deletedBy != "user"
case .removedByMe: return task.deleted == true && task.deletedBy == "user"

so every user deletion landed under "Removed by AI". The same NULL empties getRecentDeletedTasks(deletedBy: "user") (SQL = ? never matches NULL) — the list TaskAssistant feeds the extraction model as "don't re-extract these" — so the model kept re-suggesting tasks the user had explicitly removed.

Second clobber on the same column: ActionItemRecord.updateFrom(_ item: TaskActionItem) copied the server's (always nil) deleted_by over the local value, so hydration erased the attribution even inside the pending window.

Fix

  • ActionItemStorage.markActionItemDeletionAcknowledged(backendId:) — the ack now clears the pending flag and keeps the tombstone (deleted = 1, deletedBy intact) instead of purging the row. The retirement is already durable server-side; the local row is the only place the provenance exists. Used by both ack callers (deleteTask after a 2xx, and the pending-deletion flush).
  • updateFrom(_:) keeps local provenance when the server omits deleted_by, and clears it only when the server reports the task live again (nothing left to attribute).
  • Dropped the never-read deletedBy: parameter from deleteActionItemByBackendId and documented its two genuine hard-delete callers (a local-only task the server never saw; the undo purge before a restore re-inserts).

Every live-lane query in ActionItemStorage already pairs completed with deleted == false (audited all 17), so a retained tombstone stays invisible — asserted in the test.

Tested

swift test --filter ActionItemDeletionSyncTests — 5 passed, 0 failures (3 new/updated: the ack keeps deleted = 1 + deletedBy = "user" and stays out of the live lane; the deleted-page hydration keeps that attribution and the row shows up in getRecentDeletedTasks(deletedBy: "user"); a server row that comes back live clears the stale provenance).

The regression test provably catches the bug. Reverting only the updateFrom hunk and re-running:

ActionItemDeletionSyncTests.swift:126: XCTAssertEqual failed: ("nil") is not equal to ("Optional("user")")
  - hydration must not re-attribute a user deletion to the AI
ActionItemDeletionSyncTests.swift:131: XCTAssertTrue failed
  - task extraction reads this list to stop re-suggesting what the user removed
Executed 5 tests, with 2 failures

Adjacent suites green after the change: ActionItemLocalIdentityMutationTests (6), TasksStoreOwnerBoundaryTests (29, including the static mutation-authority guard the new function is registered in), LocalMutationAuthorizationTests (5), ActionItemStorageVisibilityReconciliationTests (2). swift build --build-tests clean.

Not verified through the running app: exercising the lane end-to-end needs a signed-in desktop build against the real backend. The lane predicate is a direct read of the column this PR fixes (task.deleted == true && task.deletedBy == "user"), and the storage-level assertions cover the write and both hydration directions.

Line-Count-Exception: desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift | 1795 -> 1830 | adds the acknowledgement path next to the tombstone write it pairs with; splitting this file is out of scope for a bug fix

Known gap (tracked, not this PR)

Bulk delete (Select All → Delete → ActionItemStorage.deleteActionItemsByBackendIds) still hard-deletes its rows, so bulk deletions remain unattributed. Same failure class, different function; noted on #11517 rather than widened into this fix.

Failure-Class: none

🤖 automated by hourly watchdog — tested and merged

Review in cubic

… empty

deleteTask tombstones a synced task with deletedBy = "user", but the ack path
hard-deleted the row (deleteActionItemByBackendId accepted a deletedBy argument
and never read it). The Removed lane refetches deleted tasks from the backend,
which has no deleted_by field, so the row came back with deletedBy nil and
TasksPage filed every user deletion under "Removed by AI". The same NULL emptied
getRecentDeletedTasks(deletedBy: "user") — the list TaskAssistant feeds the
extraction model as "don't re-extract these" — so it kept re-suggesting tasks the
user had explicitly deleted. Hydration clobbered the column a second way:
updateFrom copied the server's nil over the local value.

- markActionItemDeletionAcknowledged: the ack clears backendSynced = 0 and keeps
  the tombstone instead of purging the row. The retirement is already durable
  server-side; the local row is the only place the provenance exists.
- updateFrom keeps local provenance when the server omits deleted_by, and clears
  it only when the server reports the task live again.
- Drop the never-read deletedBy parameter from deleteActionItemByBackendId; its
  two remaining callers are genuine hard deletes (local-only task, undo purge).

Every live-lane query in ActionItemStorage already pairs completed with
deleted == false, so a retained tombstone stays invisible.

Verified: swift test --filter ActionItemDeletionSyncTests — 5 passed. Reverting
just the updateFrom hunk fails testDeletedPageHydrationKeepsUserProvenance with
("nil") is not equal to ("Optional("user")"), so the regression test catches the
bug it was written for. Adjacent suites green: ActionItemLocalIdentityMutation
(6), TasksStoreOwnerBoundary (29), LocalMutationAuthorization (5),
ActionItemStorageVisibilityReconciliation (2).

Failure-Class: none

Fixes #11517

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 8 files

Confidence score: 2/5

  • In desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift (markActionItemDeletionAcknowledged), an undo that lands before the delete ack can match the restored live row and re-mark it deleted, creating a concrete undo regression for users — gate acknowledgement to rows that are still tombstones (deleted && !backendSynced).
  • desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift now keeps tombstones after ack, but desktop/macos/Desktop/Sources/Stores/TasksStore.swift (purgeAllSoftDeletedItems) still removes synced deleted rows, so the new retention behavior can be wiped on next full sync — align purge criteria with the new tombstone lifecycle.
  • desktop/macos/Desktop/Sources/Rewind/Core/ActionItemModels.swift (updateFrom) and reconcileDashboardVisibilityFields in ActionItemStorage.swift apply deletedBy differently, which can overwrite preserved local retirement metadata and cause inconsistent visibility/audit state — make reconciliation follow the same omit-preserve rule.
  • In desktop/macos/Desktop/Sources/Stores/TasksStore.swift, nearby docs no longer match the ack behavior (row preserved vs removed), which increases maintenance and future regression risk — update the comments to reflect the current deletion-ack flow.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/macos/Desktop/Sources/Stores/TasksStore.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/Stores/TasksStore.swift:2520">
P3: The ack no longer removes the local row: markActionItemDeletionAcknowledged preserves the tombstone (deleted=1, backendSynced=1), which is the whole point of this PR. The docs right above this call still say the server's confirmation "purges" the tombstone and "removes the local row", and the comment above the deleteTask ack still says an acknowledgement "clears the local tombstone". Update these comments to describe the retained-tombstone behavior so future readers don't expect the row to disappear.</violation>
</file>

<file name="desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift:1254">
P1: When undo runs before the delete response returns, this method can find the restored live row and mark it deleted again. Require the row to still be a pending tombstone (`deleted && !backendSynced`) before acknowledging it.</violation>

<violation number="2" location="desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift:1255">
P2: markActionItemDeletionAcknowledged now keeps the tombstone but sets backendSynced = true. The next full sync runs purgeAllSoftDeletedItems (TasksStore.swift ~2230), which deletes every row with deleted = 1 except pending tombstones (backendSynced = 0 AND backendId IS NOT NULL). Acknowledged tombstones have backendSynced = 1, so they are purged on the next full sync and the user-deletion provenance the PR set out to keep is discarded — "Removed by me" empties and extraction re-suggests the task again. The PR claims the row is kept 'durable' with no purging of the tombstone, but testFullSyncPurgeKeepsPendingTombstones only guards pending tombstones and even documents that acknowledged soft-deletes are purged. Either exclude acknowledged tombstones from that purge or drop the durability claim, otherwise the fix only holds until the next full sync.</violation>
</file>

<file name="desktop/macos/Desktop/Sources/Rewind/Core/ActionItemModels.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/Rewind/Core/ActionItemModels.swift:381">
P2: updateFrom now preserves local deletedBy when the server omits it and the row is still retired, but reconcileDashboardVisibilityFields (ActionItemStorage.swift ~727) still does `record.deletedBy = item.deletedBy` when the retirement status changes, and `record.deletedBy = item.deletedBy` again when incomingDeleted and the values differ. Because the backend never sends deleted_by (nil), any dashboard visibility refresh of a user-deleted task overwrites the preserved "user" provenance back to nil, re-filing it under "Removed by AI" on the other hydration path this PR is meant to fix. The reconcile path needs the same provenance-preserving rule as updateFrom or the two code paths disagree.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

try await db.write { database in
try authorization.require()
if var record = try Self.fetchRecord(database, surfacedId: backendId) {
record.deleted = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: When undo runs before the delete response returns, this method can find the restored live row and mark it deleted again. Require the row to still be a pending tombstone (deleted && !backendSynced) before acknowledging it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift, line 1254:

<comment>When undo runs before the delete response returns, this method can find the restored live row and mark it deleted again. Require the row to still be a pending tombstone (`deleted && !backendSynced`) before acknowledging it.</comment>

<file context>
@@ -1232,6 +1231,39 @@ actor ActionItemStorage {
+      try await db.write { database in
+        try authorization.require()
+        if var record = try Self.fetchRecord(database, surfacedId: backendId) {
+          record.deleted = true
+          record.backendSynced = true
+          record.updatedAt = Date()
</file context>

try authorization.require()
if var record = try Self.fetchRecord(database, surfacedId: backendId) {
record.deleted = true
record.backendSynced = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: markActionItemDeletionAcknowledged now keeps the tombstone but sets backendSynced = true. The next full sync runs purgeAllSoftDeletedItems (TasksStore.swift ~2230), which deletes every row with deleted = 1 except pending tombstones (backendSynced = 0 AND backendId IS NOT NULL). Acknowledged tombstones have backendSynced = 1, so they are purged on the next full sync and the user-deletion provenance the PR set out to keep is discarded — "Removed by me" empties and extraction re-suggests the task again. The PR claims the row is kept 'durable' with no purging of the tombstone, but testFullSyncPurgeKeepsPendingTombstones only guards pending tombstones and even documents that acknowledged soft-deletes are purged. Either exclude acknowledged tombstones from that purge or drop the durability claim, otherwise the fix only holds until the next full sync.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Rewind/Core/ActionItemStorage.swift, line 1255:

<comment>markActionItemDeletionAcknowledged now keeps the tombstone but sets backendSynced = true. The next full sync runs purgeAllSoftDeletedItems (TasksStore.swift ~2230), which deletes every row with deleted = 1 except pending tombstones (backendSynced = 0 AND backendId IS NOT NULL). Acknowledged tombstones have backendSynced = 1, so they are purged on the next full sync and the user-deletion provenance the PR set out to keep is discarded — "Removed by me" empties and extraction re-suggests the task again. The PR claims the row is kept 'durable' with no purging of the tombstone, but testFullSyncPurgeKeepsPendingTombstones only guards pending tombstones and even documents that acknowledged soft-deletes are purged. Either exclude acknowledged tombstones from that purge or drop the durability claim, otherwise the fix only holds until the next full sync.</comment>

<file context>
@@ -1232,6 +1231,39 @@ actor ActionItemStorage {
+        try authorization.require()
+        if var record = try Self.fetchRecord(database, surfacedId: backendId) {
+          record.deleted = true
+          record.backendSynced = true
+          record.updatedAt = Date()
+          try record.update(database)
</file context>

// Retirement provenance ("user" / "ai_dedup" / "staged") is local-only state: taking
// the server's nil re-attributed every user deletion to the AI on the next hydration.
// A task the server reports as live has no retirement left to attribute.
if let itemDeletedBy = item.deletedBy {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: updateFrom now preserves local deletedBy when the server omits it and the row is still retired, but reconcileDashboardVisibilityFields (ActionItemStorage.swift ~727) still does record.deletedBy = item.deletedBy when the retirement status changes, and record.deletedBy = item.deletedBy again when incomingDeleted and the values differ. Because the backend never sends deleted_by (nil), any dashboard visibility refresh of a user-deleted task overwrites the preserved "user" provenance back to nil, re-filing it under "Removed by AI" on the other hydration path this PR is meant to fix. The reconcile path needs the same provenance-preserving rule as updateFrom or the two code paths disagree.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Rewind/Core/ActionItemModels.swift, line 381:

<comment>updateFrom now preserves local deletedBy when the server omits it and the row is still retired, but reconcileDashboardVisibilityFields (ActionItemStorage.swift ~727) still does `record.deletedBy = item.deletedBy` when the retirement status changes, and `record.deletedBy = item.deletedBy` again when incomingDeleted and the values differ. Because the backend never sends deleted_by (nil), any dashboard visibility refresh of a user-deleted task overwrites the preserved "user" provenance back to nil, re-filing it under "Removed by AI" on the other hydration path this PR is meant to fix. The reconcile path needs the same provenance-preserving rule as updateFrom or the two code paths disagree.</comment>

<file context>
@@ -374,7 +374,15 @@ extension ActionItemRecord {
+    // Retirement provenance ("user" / "ai_dedup" / "staged") is local-only state: taking
+    // the server's nil re-attributed every user deletion to the AI on the next hydration.
+    // A task the server reports as live has no retirement left to attribute.
+    if let itemDeletedBy = item.deletedBy {
+      self.deletedBy = itemDeletedBy
+    } else if !self.deleted {
</file context>

try? await ActionItemStorage.shared.deleteActionItemByBackendId(
id,
deletedBy: "user",
try? await ActionItemStorage.shared.markActionItemDeletionAcknowledged(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The ack no longer removes the local row: markActionItemDeletionAcknowledged preserves the tombstone (deleted=1, backendSynced=1), which is the whole point of this PR. The docs right above this call still say the server's confirmation "purges" the tombstone and "removes the local row", and the comment above the deleteTask ack still says an acknowledgement "clears the local tombstone". Update these comments to describe the retained-tombstone behavior so future readers don't expect the row to disappear.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Stores/TasksStore.swift, line 2520:

<comment>The ack no longer removes the local row: markActionItemDeletionAcknowledged preserves the tombstone (deleted=1, backendSynced=1), which is the whole point of this PR. The docs right above this call still say the server's confirmation "purges" the tombstone and "removes the local row", and the comment above the deleteTask ack still says an acknowledgement "clears the local tombstone". Update these comments to describe the retained-tombstone behavior so future readers don't expect the row to disappear.</comment>

<file context>
@@ -2517,9 +2517,8 @@ class TasksStore: ObservableObject {
-      try? await ActionItemStorage.shared.deleteActionItemByBackendId(
-        id,
-        deletedBy: "user",
+      try? await ActionItemStorage.shared.markActionItemDeletionAcknowledged(
+        backendId: id,
         authorization: Self.localMutationAuthorization(snapshot: lease.authorizationSnapshot)
</file context>

@kodjima33

Copy link
Copy Markdown
Collaborator Author

Closing this rather than leaving it open: the merge gate I run under requires green CI, and `Desktop Swift Static & Test Contracts` cannot go green on any branch right now — it is red on unmodified `main` (77 failures across 3 suites) and equally red on #11553. Filed as #11563 with the root cause of the largest suite (15a51fb added .background(InkGlassHitRegionReporter()) to the modal scrim's host-sized barrier; reverting that one line takes ShellModalScrimTests from 74 failures to 0).

The fix itself is finished and independently verified — make preflight 20/20, ActionItemDeletionSyncTests 5/5, and reverting only the updateFrom hunk makes the new regression test fail, so it does catch the bug. Nothing about it is in question; only the lane is.

The branch is kept, unrebased, at watchdog/issue-11517-deleted-by-user-provenance (fa3aa51). Once #11563 is fixed, reopen this PR — no rebase should be needed. Issue #11517 stays open.

@kodjima33 kodjima33 closed this Aug 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @kodjima33 👋

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:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

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!

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