Skip to content

fix(app): clear a task section with one batch delete, not one request per task - #24653

Merged
Git-on-my-level merged 5 commits into
mainfrom
fix/app-section-clear-batch-delete
Nov 5, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
fix/app-section-clear-batch-delete

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Problem

Clearing a whole task section on mobile (_confirmClearCompleted, and the unused clearCompletedItems) sent one DELETE /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 with ValueError: Failed to commit transaction in 5 attempts. The user saw rows reappear with an error.

Prod backend stderr, 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 on backend-c94c934 (contains 43085bb). #24583 reduced these failures but didn't remove them.

Change

  • POST /v1/action-items/batch-delete already settles many ids as one route mutation, and multi-select delete (deleteSelectedItems) already uses it. Section clear and clearCompletedItems now use the same path through a shared _deleteItemsInBulk helper.
  • Rollback behaviour is unchanged. If the request fails, every row goes back to its original position. If the server deletes only some rows, only the rejected rows come back. If the session changed mid-request, nothing is restored. Apple Reminders mirroring still fans out per item on the client, as before.
  • Locked (paid-plan) tasks are left out of a section batch. The batch endpoint refuses the whole request (402) if any id is locked, where a per-task delete refused only that task, so this keeps the old outcome: the rest is deleted, locked tasks stay, and the same failure notice shows.
  • Requests are sequential chunks of at most 450 ids. The server commits a batch delete in 499-document Firestore batches, so a larger request could fail half done and the client would restore rows the server had already deleted. Each chunk is now all-or-nothing, and a failed chunk restores only its own rows and the unsent rest (Luna R1 P2). A 1,000-task section is 3 requests, still 3 route mutations instead of 2,000 transactions.
  • Apple Reminders are deleted only for ids the server confirmed. Before, they were deleted before the request, so a rejected batch (including a 402 from a task that became locked after the list loaded) left rows back on screen with their reminders gone (Luna R1 P2). This also applies to multi-select delete, which shares the helper.
  • Known limit: a task that becomes locked on the server after the list loaded still makes its chunk return 402. The rows come back with the failure notice, and a refresh picks up the lock so the next clear succeeds.
  • macOS already uses batch-delete for 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_settle worse. 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 new action_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 analyze on 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 attempts on delete_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

Git-on-my-level and others added 2 commits November 5, 2026 07:45
… 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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T01:53:24.168800Z 25dc2f5 New commits
ℹ️ 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" or "@codex security review".

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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 4 files

Confidence score: 4/5

  • In action_items_page.dart, a session change makes deleteActionItems return 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.json overstates 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.dart doesn’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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
"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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Git-on-my-level and others added 2 commits November 5, 2026 08:03
…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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +1455 to +1456
final deleted = result.deleted;
if (deleted == null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit dd762d1 into main Nov 5, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/app-section-clear-batch-delete branch November 5, 2026 02:18
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