Repository navigation
fix(backend): cancel task reminders when a conversation and its tasks are deleted - #15041
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verified this fix statically against the head tree — it's correct, and nicely minimal. Thank you for the clear write-up and the focused tests.
backend/routers/conversations.py — the cascade branch now snapshots the conversation's tasks with get_action_items_by_conversation before delete_action_items_for_conversation and sends sync_action_item_reminder(..., completed=True, due_at=None) for each open task with a due date. I checked this against the existing single-task delete path:
DELETE /v1/action-items/{id}sendssend_action_item_deletion_messageafter deleting, andsync_action_item_reminderwithcompleted=True/due_at=Noneroutes to exactly that function (utils/notifications.py). So the fix reuses the sameaction_item_deleteFCM message the app already treats as "cancel the scheduled local notification by id" — true parity, no new client contract.- The
due_at and not completedfilter matches the client's arming condition (reminders are only armed for open dated tasks persync_action_item_reminder's contract), so skipping completed/undated tasks avoids needless FCM round-trips. - The read is uid-scoped and happens before the delete, so no cross-tenant exposure and no lost snapshot.
_send_to_userswallows FCM send errors (logs and returns 0), so a push failure can't break the delete path. - Local import matches the router's existing convention.
backend/tests/unit/test_delete_conversation_cancels_task_reminders.py — good behavioral coverage: drives the real delete_conversation through stubbed seams and asserts the exact cancel kwargs across the open-dated / completed / undated matrix, plus the no-tasks case. The fake utils.notifications module keeps it hermetic.
Two non-blocking notes for maintainers (fine as follow-ups, not asking to expand this PR):
- The same orphaned-reminder gap still exists in the other two
delete_action_items_for_conversationcallers:utils/conversations/merge_conversations.py(~line 661) andutils/conversations/process_conversation.py(~line 1868). Worth a follow-up so a merge or reprocess can't leave the same stale reminder behind. - Single-task delete/update routes call
_wake_task_changes(proactive-enginetask_changedwake); the cascade path still doesn't. May be intentional, but it's an inconsistency worth a conscious decision.
CI is green on this head (backend merge gate, unit suite, hermetic E2E, formatting, hygiene). Leaving for human maintainer review before merge — notification fan-out on a user-data deletion surface deserves a maintainer sign-off, and the two notes above are easier to rule on with fresh eyes.
🤖 Automated review on behalf of the maintainers.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Verified on current main (1ef3b91). Cascade delete (the app always sends ?cascade=true) calls delete_action_items_for_conversation and never cancels reminders. Tasks API delete sends action_item_delete; this path does not. Snapshotting with get_action_items_by_conversation and sync_action_item_reminder(..., completed=True) for open dated tasks is the same cancel. Tests cover open/completed/undated and the no-tasks case. I am not merging. |
Fixes #15040
A cascade delete (what the app always sends) removed the conversation's tasks with
delete_action_items_for_conversationbut never cancelled their local reminders, so a reminder could still fire for a task that no longer existed.delete_conversationnow reads the conversation's tasks before deleting them and callssync_action_item_reminder(..., completed=True)for each open task with a due date, which sends the cancel the Tasks API already sends on delete. Tasks without a due date, or already completed, have no reminder and are skipped. The import is local, like the other local imports in this router.tests/unit/test_delete_conversation_cancels_task_reminders.pydeletes a conversation with an open dated task, a completed dated task and an undated task. On main no cancel is sent (assert [] == [...]). With the fix only the open dated task is cancelled, and a conversation without tasks sends nothing. The existing cascade tests still pass.Line-Count-Exception: backend/routers/conversations.py | 2249 -> 2257 | cancel reminders of the tasks a cascade delete removes
Failure-Class: none