Skip to content

fix(backend): cancel action item reminder on completion (#5085) - #7695

Merged
kodjima33 merged 10 commits into
BasedHardware:mainfrom
ZachL111:fix/action-item-reminder-cancel-on-complete
Jun 9, 2026
Merged

kodjima33 merged 10 commits into
BasedHardware:mainfrom
ZachL111:fix/action-item-reminder-cancel-on-complete

Conversation

@ZachL111

@ZachL111 ZachL111 commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5085

Summary

Completing an action item never cancelled its scheduled reminder, so users kept getting reminder notifications for tasks they'd already finished. Worse, the general update endpoint actively re-armed the reminder on a completed item. This cancels the reminder on completion and reschedules it only for open tasks with a due date.

Root cause

Action-item reminders are scheduled client-side from a data FCM message; the client cancels a scheduled reminder when it receives action_item_delete and (re)schedules on action_item_update. On the backend, the cancel message was sent only on the delete paths. None of the completion paths sent it:

  • toggle_action_item_completion (routers/action_items.py) marked the item complete and returned with no cancel.
  • update_action_item re-sent send_action_item_update_message whenever due_at was present, even when the same request set completed=true, re-arming the reminder.
  • The agentic tools (utils/retrieval/tools/action_item_tools.py, utils/retrieval/tool_services/action_items.py) and the Developer API update (routers/developer.py) had the same gap.

Fix

Centralize the decision in one helper, utils/notifications.sync_action_item_reminder(...):

  • task completed, or no due date → send send_action_item_deletion_message (cancel the scheduled reminder).
  • open task with a due date → send send_action_item_update_message (reschedule).

Reusing the deletion message as the cancel signal is intentional and needs no app change: the client handler treats action_item_delete as "cancel the scheduled local notification by id", not as a task deletion.

The helper is called with the final item state from every create/update/complete path:

  • toggle_action_item_completion, cancel on complete; reschedule when un-completing an item that still has a future due date.
  • update_action_item, reconcile when completed or due_at changed (replaces the old unconditional re-arm); a cleared due date now cancels.
  • both agentic update tools and the Developer API update.
  • create_action_item no longer arms a reminder for an item created already-completed.

Edge cases

  • Completing → cancel only (never re-arm). Un-completing with a future due date → reschedule.
  • due_at cleared → cancel any stale reminder.
  • Updates that don't touch completed/due_at (e.g. description, sort order) send no reminder traffic (no regression / no extra FCM).
  • Re-completing an already-completed item → cancel is idempotent.

Testing

New backend/tests/unit/test_action_item_reminder_cancel_on_complete.py (registered in test.sh). It imports the real sync_action_item_reminder (under a stub finder, since utils.notifications pulls in firebase/db) and asserts: completed → cancel; open+due → reschedule with the ISO due date; open/no-due → cancel; completed/no-due → cancel. Plus source-inspection tests that every create/update/complete path stays wired to the helper and that the old "re-arm whenever due_at present" block is gone. Verified red→green: the whole suite fails on current main and passes with this change. scripts/lint_async_blockers.py is clean.

PR status check

gh pr search for 5085 is empty (open and all states); searches for send_action_item_deletion_message / completion-reminder PRs return nothing; git log -S on the notification helpers shows the scheduling/dedup/batch-delete history but no prior completion-cancel fix merged or reverted. No open PR touches these paths for this bug.

ZachL111 added 7 commits June 7, 2026 18:37
…edule reminders

Centralizes the client reminder-lifecycle decision: cancel the scheduled
reminder when a task is completed or has no due date, and (re)schedule only
for an open task with a due date. Reuses the action_item_delete message, which
the client treats as "cancel the scheduled local notification". (BasedHardware#5085)
…ng on update (BasedHardware#5085)

toggle_action_item_completion now cancels the scheduled reminder (and reschedules
when un-completing an item with a due date); update_action_item reconciles via the
final state instead of unconditionally re-sending the reschedule whenever due_at is
present; create no longer arms a reminder for an already-completed item.
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where completing an action item never cancelled its client-scheduled reminder, and the general update endpoint actively re-armed the reminder even on already-completed items. The fix introduces a sync_action_item_reminder helper in utils/notifications.py that centralizes the cancel-vs-reschedule decision and wires it into every create/update/complete path across the router, developer API, and both agentic tool layers.

  • utils/notifications.py: New sync_action_item_reminder helper — sends a deletion message (cancel) when the task is completed or has no due date, and an update message (reschedule) only for open tasks with a due date.
  • routers/action_items.py: create_action_item now skips arming a reminder for pre-completed items; update_action_item replaces the old unconditional re-arm; toggle_action_item_completion gains a cancel-on-complete call.
  • routers/developer.py, tool_services/action_items.py, action_item_tools.py: All wired to the new helper, eliminating the same gap in the developer API and agentic update paths.

Confidence Score: 4/5

The change is safe to merge — it only adds FCM cancel/reschedule calls and never touches persistence logic, so the worst-case regression is a spurious or missing reminder notification rather than data loss.

The core fix is correct and well-reasoned across all five call sites. The due_at parameter in the new helper is untyped, and tool_services/action_items.py uses a different (pre-update) state-resolution strategy than the other call sites — both are benign in practice but represent small inconsistencies worth cleaning up before this pattern is extended further.

backend/utils/notifications.py for the missing Union type annotation, and backend/utils/retrieval/tool_services/action_items.py for the inconsistent pre-update existing fallback vs. the post-write DB re-fetch used elsewhere.

Important Files Changed

Filename Overview
backend/utils/notifications.py Adds sync_action_item_reminder helper that centralizes cancel/reschedule logic; due_at parameter lacks a type annotation.
backend/routers/action_items.py Fixes create_action_item (skip reminder for pre-completed items), update_action_item (replace unconditional re-arm with sync_action_item_reminder), and toggle_action_item_completion (add cancel-on-complete call); all use fresh DB reads for state.
backend/routers/developer.py Replaces the unconditional send_action_item_data_message with sync_action_item_reminder; correctly synthesizes final state from update_data + action_item fallback without an extra DB round-trip.
backend/utils/retrieval/tool_services/action_items.py Wires sync_action_item_reminder into update_action_item_text; unlike action_item_tools.py, uses pre-update existing as fallback for due_at rather than a fresh DB read, creating a minor inconsistency.
backend/utils/retrieval/tools/action_item_tools.py Adds reminder sync block after DB write using fresh updated_item read; consistent with router approach.
backend/tests/unit/test_action_item_reminder_cancel_on_complete.py New unit tests covering the four main reminder-sync scenarios; source-inspection guards for call-site wiring are present but rely on string search and could give false positives after refactoring.
backend/test.sh Registers the new test file in the test runner; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Action Item create / update / toggle] --> B{completed or due_at changed?}
    B -- No --> Z[No FCM reminder traffic]
    B -- Yes --> C[sync_action_item_reminder]
    C --> D{completed == true OR due_at is None?}
    D -- Yes --> E[send_action_item_deletion_message - Client cancels scheduled notification]
    D -- No --> F[send_action_item_update_message - Client reschedules notification]
Loading

Reviews (1): Last reviewed commit: "test(backend): register action item remi..." | Re-trigger Greptile

Comment thread backend/utils/notifications.py Resolved
ZachL111 added 3 commits June 7, 2026 20:06
… service

Re-fetch the action item after the write so the cancel/reschedule decision uses
the authoritative value, matching update_action_item_tool, instead of the
pre-update snapshot.

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

backend bug fix (cancel action item reminder on completion, fixes #5085) — approve only per policy

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.

BUG: Receiving Notifications for Already-Completed Tasks

2 participants