Skip to content

fix(backend): cancel the source tasks' reminders when conversations are merged - #15177

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
kduailabs:fix/merge-cancels-source-task-reminders
Sep 21, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
kduailabs:fix/merge-cancels-source-task-reminders

Conversation

@kduailabs

@kduailabs kduailabs commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

_delete_conversation_and_related_data (used by the conversation-merge cleanup) deletes every source conversation's action items but never tells the client, so each open dated source task keeps its scheduled reminder on the phone after the merge.

Impact

Merging conversations creates a new conversation, processes it (which schedules fresh reminders for its tasks), and then deletes every source. The deleted source rows still own local notifications the mobile client scheduled from the reminder data message; the client cancels them only on the deletion data message (app/lib/services/notifications/action_item_notification_handler.dart → handleDeletionMessage), so after a merge the user gets duplicate reminders for the same commitments, and reminders for tasks the merged extraction dropped altogether.

Same class as the sibling paths fixed in #15041 (conversation cascade delete), #15043 (developer API delete), #14983/#14984 (checking a task off inside a conversation) and #15028/#15029 (MCP task writes).

Fix

Read the source's stored tasks before deleting them, then send sync_action_item_reminder(..., completed=True, due_at=None) for each open dated row (the gating #15041 uses on the conversation-delete path). 16 lines in one function; the reminder import stays local like the other lazy imports in this module, and the delete itself still happens before the cancel is attempted.

Tests

backend/tests/unit/test_merge_source_delete_cancels_task_reminders.py (new, hermetic, reusing the merge suite's import-isolation harness):

  • a source with an open dated task, a completed dated task and an undated task cancels only the open dated one
  • a source without open dated tasks sends nothing

Verification

cd backend
python -m pytest tests/unit/test_merge_source_delete_cancels_task_reminders.py -q        # 2 passed
python -m pytest tests/unit/test_merge_skips_retraction_without_canonical_memories.py -q  # 29 passed
python -m pytest tests/unit/test_merge_conversations_canonical_delete.py tests/unit/test_merge_validation.py tests/unit/test_merge_conversation_photos.py tests/unit/test_merge_deleted_source_race.py -q  # 52 passed
python -m black --check utils/conversations/merge_conversations.py tests/unit/test_merge_source_delete_cancels_task_reminders.py  # clean

Against origin/main merge_conversations.py the new positive test fails (sync_action_item_reminder called 0 times).

Failure-Class: none

Review in cubic

@kduailabs

Copy link
Copy Markdown
Contributor Author

Bounty proposal for this fix: #15178 ($25 proposed).

@kduailabs
kduailabs force-pushed the fix/merge-cancels-source-task-reminders branch from 6d17f3a to 794a934 Compare September 20, 2026 16:05

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

Verified on 794a93427461.

Merge cleanup deletes each source's action items and never tells the client, so open dated source tasks keep their reminders next to the merged conversation's new ones. This head reads the source rows first and sends sync_action_item_reminder(..., completed=True, due_at=None) inside the existing try. Complementary to #15175 (swipe-delete) and #15180 (reprocess), not the same hole.

Units, hygiene, and hermetic E2E are green on this SHA. I am not merging.

@Git-on-my-level Git-on-my-level added the backend Backend Task (python) label Sep 20, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the fix end to end against the head — it closes a real gap in the merge cleanup and mirrors the conversation-delete semantics correctly. Noting the specifics:

backend/utils/conversations/merge_conversations.py — _delete_conversation_and_related_data now reads the source's action items before delete_action_items_for_conversation and sends sync_action_item_reminder(..., completed=True, due_at=None) for each open dated row. Checked the semantics chain: completed=True maps to send_action_item_deletion_message (utils/notifications.py), whose action_item_delete FCM data message the app handles in ActionItemNotificationHandler.handleDeletionMessage → cancelNotification(id). The due_at and not completed gate is the exact inverse of the client's arming condition (the handler won't schedule when due_at is null), so only rows that could own an armed reminder get a cancel. Ordering is also safe: sources are deleted only after the merged conversation is processed, and merged processing mints new action-item ids, so these cancels can't collide with the merged tasks' fresh reminders. Failure isolation is right — the new sends sit inside the existing try/except that logs and continues, so a failed cancel can't abort the rest of source deletion.

backend/tests/unit/test_merge_source_delete_cancels_task_reminders.py — hermetic via the merge suite's import-isolation harness; covers the gating precisely (open dated task cancels with the exact kwargs, completed dated and undated tasks don't, a source with no open dated tasks sends nothing). The explicit restore of patched module attrs and the drop of the freshly imported merge modules in teardown is appreciated — that fixture hygiene keeps the unit suite order-independent.

One non-blocking thought for a possible follow-up (not this PR): utils.notifications already has send_action_items_batch_deletion_message, so a source with many open dated tasks could cancel in one chunked payload instead of N per-item FCM sends. The per-item call here matches the sibling delete paths, so consistency is fine — just worth considering if merge cleanup ever shows up in FCM quota.

Checks are green on this head (backend unit suite, hermetic merge gate, sync cloud tasks gauntlet, hermetic e2e) and @aryanorastar's approval is already recorded. Good, narrow fix with the right tests.

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

@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 confidence: real bug (merging conversations deletes each source's dated tasks without cancelling their client-scheduled reminders, causing duplicate/stale reminders), same class as merged siblings (#15041/#15043/#14983/#15028), scoped with new regression tests that fail against origin/main, all CI green.

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

Labels

backend Backend Task (python)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants