Repository navigation
fix(tasks): stop spurious not-found overlay on tag removal - #294
Conversation
Removing a tag from a task association could throw a "not found" BusinessException if the association was already removed (e.g. by a racing/duplicate removal request), even though the desired end state was already achieved. This surfaced as an error overlay notification alongside a successful removal. - RemoveTaskTagCommandHandler now treats a missing/already-deleted association as an idempotent no-op instead of throwing. - TaskDetailsController guards processTagChanges against concurrent invocations and removes tags from the local cache optimistically so a stale diff can't re-target an association already being removed. - Update remove_task_tag_command_test.dart to assert the new successful no-op behavior.
There was a problem hiding this comment.
Code Review
This pull request makes the task tag removal command idempotent by returning a successful no-op instead of throwing an exception when a tag is already deleted or not found. It also introduces concurrency guards and optimistic state updates in the TaskDetailsController to prevent race conditions during batch tag updates. The reviewer suggested optimizing the batch processing loop by passing a flag to prevent redundant network requests and UI rebuilds on individual tag operations.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| for (final tagOption in tagOptionsToAdd) { | ||
| if (!context.mounted) return; | ||
| await addTag(tagOption.value, context); | ||
| } | ||
|
|
||
| for (final taskTag in tagsToRemove) { | ||
| if (!context.mounted) return; | ||
| await removeTag(taskTag.id, context); | ||
| } | ||
| for (final taskTag in tagsToRemove) { | ||
| if (!context.mounted) return; | ||
| await removeTag(taskTag.id, context); | ||
| } |
There was a problem hiding this comment.
Pass reloadAndNotify: false to addTag and removeTag to prevent redundant network requests and UI rebuilds for each individual tag change. The final reload and notification at the end of processTagChanges will handle updating the state once for all changes.
| for (final tagOption in tagOptionsToAdd) { | |
| if (!context.mounted) return; | |
| await addTag(tagOption.value, context); | |
| } | |
| for (final taskTag in tagsToRemove) { | |
| if (!context.mounted) return; | |
| await removeTag(taskTag.id, context); | |
| } | |
| for (final taskTag in tagsToRemove) { | |
| if (!context.mounted) return; | |
| await removeTag(taskTag.id, context); | |
| } | |
| for (final tagOption in tagOptionsToAdd) { | |
| if (!context.mounted) return; | |
| await addTag(tagOption.value, context, reloadAndNotify: false); | |
| } | |
| for (final taskTag in tagsToRemove) { | |
| if (!context.mounted) return; | |
| await removeTag(taskTag.id, context, reloadAndNotify: false); | |
| } |
Summary
Removing a tag from a task succeeded, but an unrelated "task tag not found" error overlay also appeared, per the report:
Root cause:
TaskDetailsController.processTagChangesdiffs the cached_taskTagssnapshot to compute which tags to remove, then sequentially awaitsremoveTag()per tag; the cache is only refreshed after a successful removal vialoadTaskTags(). Nothing preventedprocessTagChanges/onTagsSelectedfrom being re-invoked while a previous removal was still in flight, so a second call could diff against the stale snapshot and re-sendRemoveTaskTagCommandfor an association the first call had already soft-deleted.RemoveTaskTagCommandHandlerthen threwBusinessException('Task tag not found', ...)for the duplicate, whichAsyncErrorHandler/ErrorHelpersurfaced as an overlay — alongside the first call's successful removal.Fix
RemoveTaskTagCommandHandler: treat "association not found" and "already deleted" as an idempotent successful no-op instead of throwing. The caller's desired end state (tag not on task) is already achieved, so this isn't a real error.TaskDetailsController: guardprocessTagChangesagainst concurrent/re-entrant calls, and remove tags from the local_taskTagscache optimistically before awaiting the remove command, so a racing diff can't re-target an association already being removed.remove_task_tag_command_test.dartto assert the new no-op behavior for "not found" / "already deleted" / empty-id cases.Scope note
The same "throw not-found on duplicate remove" pattern exists in
RemoveHabitTagCommand,RemoveTagTagCommand,RemoveNoteTagCommand, andRemoveAppUsageTagCommand. Only the reported task-tag path is fixed here to keep the change minimal; worth a follow-up if the same overlay is seen elsewhere.Test plan
fvm flutter test test/core/application/features/tasks/commands/remove_task_tag_command_test.dart— 8/8 passimport_tasks_command_test.dart/task_group_creation/save_task_commanddefault-estimated-time tests exist on this checkout independent of this change)