Repository navigation
fix(app): clear a task section with one batch delete, not one request per task - #24653
Conversation
… per task Clearing completed tasks sent one DELETE per task at once. Every one of those requests writes the same per-owner Pinecone route document on the server (begin and finish of each vector mutation), so a section clear contended on one document across instances and some deletes failed with "Failed to commit transaction in 5 attempts" (prod 11-04: bursts of 27, 41 and, after #24583, 16). The batch-delete endpoint already settles many ids as one route mutation, and multi-select delete already used it. Section clear and clearCompletedItems now use the same path through a shared _deleteItemsInBulk helper, keeping the existing rollback: a failed request puts every row back in place, a partial result restores only the rejected rows. A larger server-side retry budget was tried and dropped: under the real Firestore emulator's 3-process burst proof it made settlement worse (main 2/2 pass, longer budget 1/5), because extra retries add lock pressure on the same document. Older app versions keep the server-side behaviour from #24583. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The batch endpoint refuses the whole request (402) if any task is locked, where a per-task delete refused only that task. Sending only unlocked tasks keeps the old outcome: the rest of the section is deleted, locked tasks stay, and the user sees the same failure notice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
3 issues found across 4 files
Confidence score: 4/5
- In
action_items_page.dart, a session change makesdeleteActionItemsreturn false without restoring the rows, so this path can leave the items absent while showing a deletion error. Handle this path without assuming the rows were restored. - The note in
20261105-clear-completed-tasks-reliably.jsonoverstates the change: partial failures can still restore rejected rows, and older app versions still use the server retry path. Reword it to match the behavior that changed. action_items_section_clear_test.dartdoesn’t cover a session change while the bulk request is pending, leaving the no-restore path unverified. Add a test for that case.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/changelog/unreleased/20261105-clear-completed-tasks-reliably.json">
<violation number="1" location="app/changelog/unreleased/20261105-clear-completed-tasks-reliably.json:2">
P3: This note promises that bulk completed-task deletes no longer fail partway, but the PR still restores rejected rows on partial failure and keeps the server retry path for older app versions. Reword it to describe the improvement, e.g. "Deleting completed tasks at once is less likely to fail partway and bring some back."</violation>
</file>
<file name="app/test/providers/action_items_section_clear_test.dart">
<violation number="1" location="app/test/providers/action_items_section_clear_test.dart:75">
P3: No test covers the session-changed path, where `deleteActionItems` must return false without restoring rows. Add a case that calls `ensureLoaded` or the session reset while the bulk request is pending, then assert the rows stay removed.</violation>
</file>
<file name="app/lib/pages/action_items/action_items_page.dart">
<violation number="1" location="app/lib/pages/action_items/action_items_page.dart:381">
P2: On a session change, `deleteActionItems` returns false and this shows the 'failed to delete' error. The provider does not restore rows in that case, so the comment's claim that rejected rows are already back is wrong here. Have the provider report stale separately, or skip the error when the session changed.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| // One batch request, not one delete per task: concurrent single deletes for one owner | ||
| // contend on the same server route document and fail. | ||
| final deleted = await provider.deleteActionItems(items); | ||
| if (!mounted || deleted) return; |
There was a problem hiding this comment.
P2: On a session change, deleteActionItems returns false and this shows the 'failed to delete' error. The provider does not restore rows in that case, so the comment's claim that rejected rows are already back is wrong here. Have the provider report stale separately, or skip the error when the session changed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At app/lib/pages/action_items/action_items_page.dart, line 381:
<comment>On a session change, `deleteActionItems` returns false and this shows the 'failed to delete' error. The provider does not restore rows in that case, so the comment's claim that rejected rows are already back is wrong here. Have the provider report stale separately, or skip the error when the session changed.</comment>
<file context>
@@ -375,8 +375,10 @@ class _ActionItemsPageState extends State<ActionItemsPage> with AutomaticKeepAli
+ // One batch request, not one delete per task: concurrent single deletes for one owner
+ // contend on the same server route document and fail.
+ final deleted = await provider.deleteActionItems(items);
+ if (!mounted || deleted) return;
// The provider has already put each rejected row back; say so, as a single delete does
// (task_delete_undo.dart), instead of letting the rows reappear in silence.
</file context>
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "change": "Deleting all completed tasks at once no longer fails partway and brings some of them back." | |||
There was a problem hiding this comment.
P3: This note promises that bulk completed-task deletes no longer fail partway, but the PR still restores rejected rows on partial failure and keeps the server retry path for older app versions. Reword it to describe the improvement, e.g. "Deleting completed tasks at once is less likely to fail partway and bring some back."
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At app/changelog/unreleased/20261105-clear-completed-tasks-reliably.json, line 2:
<comment>This note promises that bulk completed-task deletes no longer fail partway, but the PR still restores rejected rows on partial failure and keeps the server retry path for older app versions. Reword it to describe the improvement, e.g. "Deleting completed tasks at once is less likely to fail partway and bring some back."</comment>
<file context>
@@ -0,0 +1,3 @@
+{
+ "change": "Deleting all completed tasks at once no longer fails partway and brings some of them back."
+}
</file context>
| "change": "Deleting all completed tasks at once no longer fails partway and brings some of them back." | |
| "change": "Deleting completed tasks at once is much less likely to fail partway and bring some of them back." |
| expect(p.actionItems.map((item) => item.id), ['c']); | ||
| }); | ||
|
|
||
| test('a failed batch puts every row back in place and reports failure', () async { |
There was a problem hiding this comment.
P3: No test covers the session-changed path, where deleteActionItems must return false without restoring rows. Add a case that calls ensureLoaded or the session reset while the bulk request is pending, then assert the rows stay removed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At app/test/providers/action_items_section_clear_test.dart, line 75:
<comment>No test covers the session-changed path, where `deleteActionItems` must return false without restoring rows. Add a case that calls `ensureLoaded` or the session reset while the bulk request is pending, then assert the rows stay removed.</comment>
<file context>
@@ -0,0 +1,101 @@
+ expect(p.actionItems.map((item) => item.id), ['c']);
+ });
+
+ test('a failed batch puts every row back in place and reports failure', () async {
+ final p = await provider([_item('a', completed: true), _item('b'), _item('c', completed: true)], bulk: (_) => null);
+ final before = p.actionItems.map((item) => item.id).toList();
</file context>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a718ebeb59
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!mounted || deleted.every((ok) => ok)) return; | ||
| // One batch request, not one delete per task: concurrent single deletes for one owner | ||
| // contend on the same server route document and fail. | ||
| final deleted = await provider.deleteActionItems(items); |
There was a problem hiding this comment.
Snapshot section rows by ID before bulk deletion
If a task refresh finishes while the confirmation dialog is open, items still contains the old DTO instances while _applyFetchedActionItems has replaced the provider's rows. The new bulk helper snapshots positions using _actionItems.indexOf(item), but these DTOs have identity equality, so the positions become -1 and collapse into one map entry. The rows are still removed by ID, but on a failed or partial batch _restoreDeletedItem skips index -1, leaving rejected tasks missing locally instead of restoring them. The previous single-delete path located rows by ID. Resolve the current rows and their positions by ID before taking the bulk rollback snapshot.
Useful? React with 👍 / 👎.
…minders after confirm Luna R1 on #24653: the server commits a batch delete in 499-document batches, so one large request could fail after deleting part of it and the client would restore rows that were already gone. Requests are now sequential chunks of at most 450 ids, each a single atomic commit; a failed chunk restores only its own and later rows. Apple Reminders are removed only for server-confirmed ids, so a rejected batch no longer strips reminders from rows that come back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The section clear now uses the batch-delete endpoint. The widget test only faked per-task deletes, so its accepted case hit the dead loopback base URL; the rejected case passed by accident. The fake server now serves batch-delete too, and both cases assert one batch request and no single deletes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25dc2f508d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| final deleted = result.deleted; | ||
| if (deleted == null) { |
There was a problem hiding this comment.
Report failures after a successful bulk-delete chunk
When multi-select deletion spans more than 450 tasks and a later chunk fails, _deleteItemsInBulk returns a non-null list of previously confirmed IDs, so this condition skips the failure notification and selection restoration. The rejected and unsent tasks reappear silently, and task_selection_action_bar.dart's _handleDelete ignores the returned boolean, so nothing else reports the failure. Previously, a failed bulk request restored the selection and displayed bulkDeleteFailed. Preserve an explicit failure indicator across the helper result, notify the user, and restore selection for the rejected tasks even when earlier chunks succeeded.
Useful? React with 👍 / 👎.
Problem
Clearing a whole task section on mobile (
_confirmClearCompleted, and the unusedclearCompletedItems) sent oneDELETE /v1/action-items/{id}per task, all at once. Each request does a Pinecone vector mutation whose begin and finish both write the owner's single route document (pinecone_partition_state.py). A 40-task clear became about 80 Firestore transactions on one document across Cloud Run instances, and some failed withValueError: Failed to commit transaction in 5 attempts. The user saw rows reappear with an error.Prod
backendstderr, counts only (ro-prod), 11-04: bursts of 27 (06–09Z) and 41 (15–18Z). After #24583 went live there was a single burst of 16 at 23:45Z onbackend-c94c934(contains 43085bb). #24583 reduced these failures but didn't remove them.Change
POST /v1/action-items/batch-deletealready settles many ids as one route mutation, and multi-select delete (deleteSelectedItems) already uses it. Section clear andclearCompletedItemsnow use the same path through a shared_deleteItemsInBulkhelper.batch-deletefor bulk deletes (TasksStore+BulkSelection.swift). The web app has no bulk fan-out.Tried and dropped
A larger server-side contention budget (8 fresh transactions inside 20 s) made the real-Firestore-emulator burst proof
test_real_firestore_cross_process_same_owner_deletes_settleworse. Main passed 2/2 runs; the larger budget passed 1/5. Extra retries add lock pressure on the same document. The structural backend fix for older app versions is to move pending-op bookkeeping off the route document, which is a separate, larger change.Verification
flutter test test/providers/plus the page tests: 1,452 passed, including the newaction_items_section_clear_test.dart, which covers one batch call and zero single deletes, full rollback, partial restore, locked tasks left out, an all-locked section sending nothing, 450-id chunking (1,000 tasks becomes 450/450/100), a failed second chunk restoring only its rows, and the empty no-op. Reminder ordering isn't covered by a unit test because reminder deletion is Apple-platform-only.flutter analyzeon the changed files: no issues. Formatting uses the pinned Flutter 3.44.5.Rollout
App-only, no flag. Old app versions keep today's per-item behaviour. The prod signal to watch after this release reaches users is backend stderr
Failed to commit transaction in 5 attemptsondelete_action_item.Failure-class transition narrative
Failure-Class: FC-pinecone-route-document-contention
This is a recurrence after #24583. Its bounded retries cut a burst from 27–41 failures to 16, but a client that sends one delete per task still produces one route-document transaction pair per task. The prevention moves upstream: a section delete is one batch mutation, so the burst never forms. The server-side bound from #24583 stays as it is for older app versions.
UI-Evidence: none -- no visual change; the confirm dialog, row removal and error toast are the same, only the request behind them changes (covered by provider tests)
Line-Count-Exception: app/lib/providers/action_items_provider.dart | 1507 -> 1555 | the two delete paths now share one rollback helper instead of the section path fanning out; splitting the provider is out of scope for this fix
🤖 Generated with Claude Code