Skip to content

fix(backend): cancel task reminders when a conversation and its tasks are deleted - #15041

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/backend-conversation-delete-cancels-task-reminders
Sep 20, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/backend-conversation-delete-cancels-task-reminders

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15040

A cascade delete (what the app always sends) removed the conversation's tasks with delete_action_items_for_conversation but never cancelled their local reminders, so a reminder could still fire for a task that no longer existed.

delete_conversation now reads the conversation's tasks before deleting them and calls sync_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.py deletes 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.

cd backend
python -m pytest tests/unit/test_delete_conversation_cancels_task_reminders.py tests/unit/test_delete_conversation_cascade.py tests/unit/test_delete_conversation_cascade_retraction_fence.py -q   # 10 passed
BACKEND_UNIT_TEST_FILE_LIST=<those three files> bash test.sh                                                                                                                  # passed

Line-Count-Exception: backend/routers/conversations.py | 2249 -> 2257 | cancel reminders of the tasks a cascade delete removes

Failure-Class: none

Review in cubic

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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} sends send_action_item_deletion_message after deleting, and sync_action_item_reminder with completed=True/due_at=None routes to exactly that function (utils/notifications.py). So the fix reuses the same action_item_delete FCM message the app already treats as "cancel the scheduled local notification by id" — true parity, no new client contract.
  • The due_at and not completed filter matches the client's arming condition (reminders are only armed for open dated tasks per sync_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_user swallows 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):

  1. The same orphaned-reminder gap still exists in the other two delete_action_items_for_conversation callers: utils/conversations/merge_conversations.py (~line 661) and utils/conversations/process_conversation.py (~line 1868). Worth a follow-up so a merge or reprocess can't leave the same stale reminder behind.
  2. Single-task delete/update routes call _wake_task_changes (proactive-engine task_changed wake); 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.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Sep 19, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

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.

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

5/5: fixes #15040, clear root cause, regression test added, CI green (all backend shards pass).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] fix(backend): deleting a conversation leaves its tasks' reminders armed ($25 proposed)

4 participants