8000 fix(tasks): stop spurious not-found overlay on tag removal by ahmet-cetinkaya · Pull Request #294 · ahmet-cetinkaya/whph · GitHub
[go: up one dir, main page]

Skip to content

fix(tasks): stop spurious not-found overlay on tag removal - #294

Merged
ahmet-cetinkaya merged 1 commit into
mainfrom
fix/task-tag-remove-not-found-notification
Jul 4, 2026
Merged

ahmet-cetinkaya merged 1 commit into
mainfrom
fix/task-tag-remove-not-found-notification

Conversation

@ahmet-cetinkaya
Copy link
Copy Markdown
Owner

Summary

Removing a tag from a task succeeded, but an unrelated "task tag not found" error overlay also appeared, per the report:

Bir tasktan etiket kaldırılırken başarılı bir şekilde kaldırıyor fakat aynı zamanda bulunamadı hatası overlay notification olarak görüyorum.

Root cause: TaskDetailsController.processTagChanges diffs the cached _taskTags snapshot to compute which tags to remove, then sequentially awaits removeTag() per tag; the cache is only refreshed after a successful removal via loadTaskTags(). Nothing prevented processTagChanges/onTagsSelected from being re-invoked while a previous removal was still in flight, so a second call could diff against the stale snapshot and re-send RemoveTaskTagCommand for an association the first call had already soft-deleted. RemoveTaskTagCommandHandler then threw BusinessException('Task tag not found', ...) for the duplicate, which AsyncErrorHandler/ErrorHelper surfaced 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: guard processTagChanges against concurrent/re-entrant calls, and remove tags from the local _taskTags cache optimistically before awaiting the remove command, so a racing diff can't re-target an association already being removed.
  • Updated remove_task_tag_command_test.dart to 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, and RemoveAppUsageTagCommand. 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 pass
  • Confirmed no test regressions introduced by this diff (pre-existing unrelated failures in import_tasks_command_test.dart / task_group_creation / save_task_command default-estimated-time tests exist on this checkout independent of this change)
  • Manual: open a task, add 2+ tags, remove one tag then immediately remove another before the first completes — confirm no "not found" overlay and both removals persist

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.
@ahmet-cetinkaya ahmet-cetinkaya self-assigned this Jul 4, 2026
@ahmet-cetinkaya
ahmet-cetinkaya merged commit 6709e07 into main Jul 4, 2026
3 checks passed
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +458 to +466
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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);
}

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.

1 participant

0