Skip to content

fix(desktop): keep deleted-lane tasks retired so they stop resurfacing as live - #11460

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
formed2forge:fix/desktop-deleted-task-retirement
Aug 13, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
formed2forge:fix/desktop-deleted-task-retirement

Conversation

@formed2forge

@formed2forge formed2forge commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Tasks deleted on another device came back as live tasks on a fresh machine, and the Removed list stayed empty:

TasksStore: Fetched 100 deleted tasks from API
TasksStore: Showing 0 deleted tasks from merged local cache

Cause

TaskActionItem.isRetired re-derives retirement from the response body (deleted == true, or a canonical status of cancelled/superseded). Its own doc comment records that list responses may omit legacy deleted and project retirement through canonical lifecycle status — and that status vocabulary is open, so any other value reads as live. ActionItemRecord.from(_:) persists deleted: item.isRetired, so a row arriving from the deleted lane without either marker was written to SQLite as live: absent from the .deleted scope query, present as a live task.

Fix

The lane is the authority on retirement, not a re-derivation from whichever fields a response happened to carry. fetchDeletedPage stamps retirement after both transports — live API and injected operations — so neither path can skip it, and both callers of that page (first load and auto-refresh) sync a correctly retired row.

Verification

macOS 27.0, Xcode 26.6 (stable, not the beta):

  • xcrun swift test --filter TasksStoreDeletedLaneRetirementTests → 2 passed
  • Reverting both production files to the parent commit → 2 failed, asserting the reported symptom: XCTAssertEqual failed: ("[]") is not equal to ("["deleted-on-phone"]")
  • All 87 tests matching TasksStore pass together, so nothing leaks through the TasksStore.shared singleton
  • swift-format lint --strict clean on all three files (linter confirmed live by checking it flags a deliberately malformed file)
  • desktop/macos/scripts/check-main-actor-xctest-hooks.py passes
  • Product-file line-count ratchet passes with the baseline raised 3688 → 3697

App-level: a combined build carrying this fix was run as the named bundle omi-combined-verify. The deleted lane now reports Fetched 100 deleted tasks / Showing 20 deleted tasks — Showing 0 against a non-zero fetch was the entire symptom, so this is the first run with a populated Removed list. The live list still sheds rows as the lane pages through (581 → 547 → 513 → 483, added=0), which is now the correct outcome: those rows land in the .deleted scope instead of vanishing.

Scope

Fixes retirement state, not refresh cadence — the deleted refresh still re-fetches and re-syncs a full page per tick. Tracked separately. Also corrects the write path only: rows already persisted as live by an affected build are reconciled by later refreshes, not rewritten.

Explicitly not a contributor to the desktop chat outage — that was measured to a missing index on conversation_turn_revisions(conversation_id, turn_id) and is fixed on its own branch.

Failure-Class: FC-split-mutation-authority

🤖 Generated with Claude Code

https://claude.ai/code/session_011qmdS9crg5qFhan7PCbWvZ

Review in cubic

…g as live

Tasks deleted on another device came back as live tasks on a fresh machine,
and the Removed list stayed empty:

  TasksStore: Fetched 100 deleted tasks from API
  TasksStore: Showing 0 deleted tasks from merged local cache

`TaskActionItem.isRetired` re-derives retirement from the response body
(`deleted == true`, or a canonical status of cancelled/superseded). Its own
doc comment records that list responses may omit legacy `deleted` and project
retirement through canonical lifecycle status — and that status vocabulary is
open, so any other value reads as live. `ActionItemRecord.from(_:)` persists
`deleted: item.isRetired`, so a row arriving from the deleted lane without
either marker was written to SQLite as live: it disappeared from the
`.deleted` scope query and reappeared as a live task.

The lane is the authority on retirement, not a re-derivation from whichever
fields a response happened to carry. `fetchDeletedPage` now stamps it after
both transports — live API and injected operations — so neither path can skip
it, and both callers of that page (first load and auto-refresh) sync a
correctly retired row.

Scope note: this fixes the retirement state, not the refresh cadence. The
deleted refresh still re-fetches and re-syncs a full page per tick whose
result `mergeWithoutAdding` may discard; that churn is tracked separately.

An earlier draft of this note claimed that churn contributed to the desktop
chat outage via kernel-context contention. That was wrong, and it is corrected
here so the claim is not carried into the tree. The outage was measured on
2026-08-12 to a missing index: `buildContextSnapshot` joins `conversation_turns`
to `conversation_turn_revisions` on `turn_id`, which carried no index, so the
snapshot query took ~28s against the kernel's 15s `get_context_snapshot` budget.
A Node inspector CPU profile of the live kernel put 20.9% of samples under that
one query and journal replay at 0.1%, and the Swift app held 11-23% CPU while
the kernel saturated a core - so nothing on this path was starving chat. Adding
the index took that query to 0.03s and chat answers again. This deleted-lane
churn remains a real defect on its own merits, with no established link to
chat latency.

TasksStore.swift is on the BasedHardware#9838 oversized-product-file freeze, and stamping
retirement after both transports grows it 3688 -> 3697 lines, so the ratchet
baseline is raised by exactly that with a one-line justification. Splitting a
3,697-line store is the unreviewable migration a bug fix must not become; the
baseline records the debt instead of hiding it.

Failure-Class: FC-split-mutation-authority

Verification (macOS 27.0, Xcode 26.6 stable, Swift 6.3.3, 2026-08-11) — this
replaces the pre-amend "NOT RUN" block, which was accurate when authored in a
Linux container with no macOS toolchain:

  cd desktop/macos/Desktop
  xcrun swift test --force-resolved-versions --skip-update \
    --filter TasksStoreDeletedLaneRetirementTests
  => Executed 2 tests, with 0 failures

The test fails against the unfixed code, so it is coverage rather than
decoration. Both production files reverted to this commit's parent and rebuilt:

  => Executed 2 tests, with 2 failures
  XCTAssertEqual failed: ("[]") is not equal to ("["deleted-on-phone"]")
    - the retired row must show up in the deleted list instead of vanishing

That is the reported symptom reproduced. The passing run also inverts the log
signature from the bug report: "Fetched 1 deleted tasks from API / Showing 1
deleted tasks from merged local cache".

Isolation: each case passes alone, and all 85 tests matching `TasksStore` pass
together, so nothing leaks through the `TasksStore.shared` singleton.

Caveat on the second case: testAlreadyRetiredRowIsPassedThroughUnchanged also
fails against the unfixed code, so it is not the already-correct-path invariant
its name implies - both cases are sensitive to the stamping. The name oversells
what it isolates; the coverage itself is sound.

Also checked on macOS: desktop/macos/scripts/swift-format-wrapper.sh lint
--strict reports no diagnostics on all three files (verified the linter is live
by confirming it flags a deliberately malformed file);
desktop/macos/scripts/check-main-actor-xctest-hooks.py passes - note the
pre-amend message cited this as scripts/, which is the wrong path; no changed
line exceeds 120 columns, and the two >120 lines in TasksStore.swift are
pre-existing; Tests/ is the SPM test-target path, confirmed by 16 matching
symbols in the built "Omi ComputerPackageTests.xctest" bundle.

App-level verification (2026-08-12, after the above was first written): a
combined build carrying this fix and the chat context-snapshot index was run as
the named bundle `omi-combined-verify` on current upstream. The deleted lane now
reports what it was always failing to:

  TasksStore: Fetched 100 deleted tasks from API
  TasksStore: Showing 20 deleted tasks from merged local cache

`Showing 0` against a non-zero fetch was the whole symptom, so this is the first
run in which the Removed list is populated at all. The live list still sheds rows
as the lane pages through (581 -> 547 -> 513 -> 483, added=0), but that is now
the correct outcome rather than the defect: before, a deleted-lane row left the
live list and appeared nowhere, whereas those rows now land in the `.deleted`
scope, which is exactly why the count above is non-zero. The bundle had its own
fresh kernel database, so nothing here depends on repairing rows an earlier build
had already mis-stored as live.

Not run: the full desktop suite (only the filtered class and the 87 TasksStore
matches). This fix corrects the write path only — rows already persisted as live
by an affected build are reconciled by later refreshes, not rewritten.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CYhtePtn1bYg14Yjd2ZJUk
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011qmdS9crg5qFhan7PCbWvZ

@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.

2 issues found across 5 files

Confidence score: 4/5

  • In desktop/macos/Desktop/Sources/TaskActionItem.swift, retired() can leave deleted nil/false for rows marked only with status = "cancelled"/"superseded", so fallback or direct consumers may misclassify deleted lanes as active and show incorrect actions/state — normalize the legacy deleted flag for every lane row when deriving retired items.
  • In desktop/macos/Desktop/Sources/TaskActionItem.swift, lane stamping currently sets only deleted and can leave deletedBy, deletedAt, and deletedReason unset/stale when the server omits fields, which risks inconsistent deletion metadata in UI/logging flows — populate or explicitly clear the related deleted-* fields alongside deleted during normalization.
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/TaskActionItem.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/TaskActionItem.swift:101">
P2: When a deleted-lane row has only `status = "cancelled"` or `"superseded"`, `retired()` leaves `deleted` nil/false. Normalize the legacy `deleted` marker for every lane row so fallback and direct consumers cannot treat the row as live.</violation>

<violation number="2" location="desktop/macos/Desktop/Sources/TaskActionItem.swift:103">
P2: The only field the lane stamps is `deleted`; `deletedBy`, `deletedAt`, and `deletedReason` are left as whatever the server omitted. When a deleted-lane response omits the legacy `deleted` field (the exact case this fix targets), it can omit `deletedBy` too, so rows synced to the cache land with `deleted = true` but no provenance. TasksPage partitions the Removed lane with `removedByMe` (`deletedBy == "user"`) vs `removedByAI` (`deletedBy != "user"`), and `ActionItemStorage.getRecentDeletedTasks(..., deletedBy:)` / `TaskAssistant` (line 1588) query user-deletions by that column, so a user-deleted task whose provenance is dropped shows up as AI-removed and drops out of user-deletion flows.</violation>
</file>

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

Re-trigger cubic

/// `deleted = false` and comes back as a live task on any machine whose
/// cache was built from that lane.
func retired() -> TaskActionItem {
guard !isRetired else { return self }

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: When a deleted-lane row has only status = "cancelled" or "superseded", retired() leaves deleted nil/false. Normalize the legacy deleted marker for every lane row so fallback and direct consumers cannot treat the row as live.

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

<comment>When a deleted-lane row has only `status = "cancelled"` or `"superseded"`, `retired()` leaves `deleted` nil/false. Normalize the legacy `deleted` marker for every lane row so fallback and direct consumers cannot treat the row as live.</comment>

<file context>
@@ -86,6 +86,24 @@ struct TaskActionItem: Codable, Identifiable, Equatable {
+  /// `deleted = false` and comes back as a live task on any machine whose
+  /// cache was built from that lane.
+  func retired() -> TaskActionItem {
+    guard !isRetired else { return self }
+    var copy = self
+    copy.deleted = true
</file context>

func retired() -> TaskActionItem {
guard !isRetired else { return self }
var copy = self
copy.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.

P2: The only field the lane stamps is deleted; deletedBy, deletedAt, and deletedReason are left as whatever the server omitted. When a deleted-lane response omits the legacy deleted field (the exact case this fix targets), it can omit deletedBy too, so rows synced to the cache land with deleted = true but no provenance. TasksPage partitions the Removed lane with removedByMe (deletedBy == "user") vs removedByAI (deletedBy != "user"), and ActionItemStorage.getRecentDeletedTasks(..., deletedBy:) / TaskAssistant (line 1588) query user-deletions by that column, so a user-deleted task whose provenance is dropped shows up as AI-removed and drops out of user-deletion flows.

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

<comment>The only field the lane stamps is `deleted`; `deletedBy`, `deletedAt`, and `deletedReason` are left as whatever the server omitted. When a deleted-lane response omits the legacy `deleted` field (the exact case this fix targets), it can omit `deletedBy` too, so rows synced to the cache land with `deleted = true` but no provenance. TasksPage partitions the Removed lane with `removedByMe` (`deletedBy == "user"`) vs `removedByAI` (`deletedBy != "user"`), and `ActionItemStorage.getRecentDeletedTasks(..., deletedBy:)` / `TaskAssistant` (line 1588) query user-deletions by that column, so a user-deleted task whose provenance is dropped shows up as AI-removed and drops out of user-deletion flows.</comment>

<file context>
@@ -86,6 +86,24 @@ struct TaskActionItem: Codable, Identifiable, Equatable {
+  func retired() -> TaskActionItem {
+    guard !isRetired else { return self }
+    var copy = self
+    copy.deleted = true
+    return copy
+  }
</file context>

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deleted-lane rows persisted as live because retirement was re-derived from an open status vocabulary; stamping retirement at the lane is the right authority. Root cause + regression test + revert-proof verification.

@formed2forge

Copy link
Copy Markdown
Contributor Author

Both review findings were investigated against current code. Neither requires a change to this PR, and no code was changed. Evidence below, plus two genuine defects found in passing that are filed separately.

Finding 1 — retired() leaves deleted nil for status-only rows: harmless

True that the guard !isRetired else { return self } returns early, leaving deleted nil when a lane row is retired only via taskStatus. It cannot produce the stated consequence, for two independent reasons.

Every writer that persists a TaskActionItem derives the stored column from isRetired, never from item.deleted:

Rewind/Core/ActionItemModels.swift:323    deleted: item.isRetired,
Rewind/Core/ActionItemModels.swift:376    self.deleted = item.isRetired
Rewind/Core/ActionItemModels.swift:750    deleted: item.isRetired,
Rewind/Core/ActionItemStorage.swift:744   let incomingDeleted = item.isRetired

The early return fires only when isRetired is already true — i.e. precisely the cases those writers already resolve to true. ActionItemRecord.deleted is non-optional Bool, so such rows land in SQLite as deleted = 1. taskStatus also survives the round-trip (RewindDatabase.swift:2535 column; written ActionItemModels.swift:335/:387, read :489), so a cached row satisfies both projections.

The one un-stamped in-memory object is contained. It reaches published state only via the sync-failure fallback deletedTasks = response.items (Stores/TasksStore.swift:2093), and deletedTasks is read only inside TasksStore.swift. TasksPage's in-memory sources are completedTasks/incompleteTasks (TasksPage.swift:2223-2225); its Removed lanes are SQLite-backed.

I did try the suggested normalisation — dropping the guard so the lane always stamps — and reverted it: testAlreadyRetiredRowIsPassedThroughUnchanged asserts "an already-retired row must round-trip untouched", and the custom == compares .deleted (TaskActionItem.swift:113). Making the change would mean rewriting an existing guard with no external source for the new expected value, to fix nothing observable.

Finding 2 — lane stamps only deleted, provenance left nil: mechanism correct, attributed harm does not exist

The mechanism is verified exactly as described: TasksPage.swift:200-201 partitions on deletedBy == "user" (nil ⇒ removedByAI); ActionItemStorage.swift:1420-1432 filters AND deletedBy = ? (never matches NULL); TaskAssistant.swift:1588 queries deletedBy: "user" — note that file is under TaskExtraction/, not TaskAgent/.

But the harm cannot occur, because nothing in the macOS target ever writes deletedBy = "user". ActionItemStorage.deleteActionItemByBackendId accepts a deletedBy argument, never reads it, and hard-deletes the row (ActionItemStorage.swift:1186-1207). So removedByMe is structurally empty and that query structurally returns [] — with or without this PR. No task can lose provenance it never had.

Three further corrections:

  • retired() does not drop provenance. var copy = self carries deletedBy through unchanged; nil-ness originates at decode, upstream of the lane.
  • deletedAt and deletedReason are never persisted for action items at all — hardcoded nil at ActionItemModels.swift:481-482. Two of the three named fields are structurally unpersistable, independent of this PR.
  • Nil-provenance rows in Removed are pre-existing: rows carrying cancelled/superseded were already isRetired before this fix, already landed in Removed, already had NULL provenance. The only newly-reachable population is rows with neither marker — and the sole in-tree server retirement path (retire_action_items_for_conversation) is genuinely system-side, so "Removed by AI" is the correct bucket for them.

Stamping provenance in the lane would fabricate a value the server never sent, and would require changing three let declarations to var to do it. Not done.

One limit stated plainly: whether the deployed server omits deleted_by could not be proven from this repo — the in-tree ActionItemResponse (backend/models/action_item.py:188-219, extra='ignore') cannot carry it and the backend never writes it, but the deployed backend is ahead of this tree (it honours a deleted query param this tree lacks). The conclusion does not depend on that, since it rests on the missing client-side writer.

Filed separately

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.

3 participants