Skip to content

fix: improve bulk rules progress tracking#990

Merged
elie222 merged 2 commits intomainfrom
fix/show-processed-bulk
Nov 19, 2025
Merged

fix: improve bulk rules progress tracking#990
elie222 merged 2 commits intomainfrom
fix/show-processed-bulk

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Nov 19, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Date range changes now properly reset the run state and progress indicators.
  • New Features

    • Enhanced progress tracking for bulk rule runs with clearer in-progress and success messages.
    • Reports queued thread counts during runs and handles cancellations gracefully.
    • Added explicit notification when no unread emails are found in the selected date range.
  • Chores

    • App version bumped to v2.20.10

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
inbox-zero Ready Ready Preview Nov 19, 2025 8:37pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replaces numeric thread counting with a Set of processed thread IDs, adds a runResult state for run outcomes, changes onRun to report queued thread IDs and completion status/count, updates pagination to call onThreadsQueued and onComplete, and adjusts UI to show progress and a zero-result message.

Changes

Cohort / File(s) Summary
BulkRunRules component refactor
apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx
Replaced totalThreads with processedThreadIds: Set<string>; added runResult state; compute remaining and completed from set/queue membership; progress label derives from these values; start/end date changes clear run state and processed IDs; show progress/success UI only when processed IDs exist; display zero-count message "No unread emails found in the selected date range."
Run callback & pagination changes
apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx
Changed onRun signature: now accepts onThreadsQueued(threadIds) and onComplete(status, count); during pagination, report queued thread IDs via onThreadsQueued, update totalProcessed, and invoke onComplete with "success" or "cancelled" and the processed count.
Version bump
version.txt
Updated version from v2.20.9 to v2.20.10.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BulkRunRules
    participant Parent

    User->>BulkRunRules: Click "Start Run"
    BulkRunRules->>BulkRunRules: Clear runResult & processedThreadIds
    BulkRunRules->>BulkRunRules: Fetch first page of threads

    loop For each page
        BulkRunRules->>Parent: onThreadsQueued(threadIds)
        Parent->>Parent: Queue threads for processing
        BulkRunRules->>BulkRunRules: Add threadIds to processedThreadIds / increment totalProcessed
        BulkRunRules->>BulkRunRules: Fetch next page (or stop)
    end

    alt Completed normally
        BulkRunRules->>Parent: onComplete("success", totalProcessed)
    else Aborted
        BulkRunRules->>Parent: onComplete("cancelled", totalProcessed)
    end

    Parent->>BulkRunRules: (ack) update UI
    BulkRunRules->>User: Show progress or "No unread emails found..." if count === 0
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify Set-based deduplication and lifecycle handling of processedThreadIds
  • Validate new onRun signature usage and that onThreadsQueued receives correct IDs each page
  • Confirm onComplete status/count semantics, including cancelled flows
  • Check UI conditions for progress/success/zero-count messages and date-picker reset behavior

Possibly related PRs

Poem

🐰 Threads in a neat Set, one by one they hop,

Queued and counted till the paging stops,
If none arrive I pause and say,
"No unread emails found today."
Hooray for runs that finish with a hop!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving bulk rules progress tracking through refactored state management from totalThreads to processedThreadIds and enhanced progress reporting.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/show-processed-bulk

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79020b6 and e574ec2.

📒 Files selected for processing (1)
  • apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx (10 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx (3)

31-33: Set-based tracking is solid; remaining computation could be lighter-weight

Using Set<string> for processedThreadIds and deriving remaining via intersection with the AI queue is a good way to avoid double-counting and to gate progress on actual queue state. The only nit is that remaining allocates a new Set every render:

const remaining = new Set(
  [...processedThreadIds].filter((id) => queue.has(id)),
).size;

For large runs you could instead just count matches in a loop (or via reduce) and/or wrap the computation in a useMemo keyed on processedThreadIds and queue to avoid extra allocations. Not urgent, but would slightly simplify and optimize this hot-path calculation.

Also applies to: 45-47, 51-55


116-149: Guard against running getting stuck true if onRun throws

setRunning(false) is only invoked in the onComplete callback:

(count) => {
  setRunning(false);
  if (count === 0) {
    setRunResult({ count });
  }
}

and onComplete(totalProcessed) is called at the end of run(). If fetchWithAccount, runAiRules, or JSON parsing ever throw synchronously (rather than returning a non‑OK response), run() will reject and onComplete will never be called, leaving running stuck true and the cancel button visible.

Consider wrapping the body of run() in try/finally to guarantee that onComplete (or at least a “done/error” callback that clears running) is invoked exactly once even on unexpected exceptions:

async function run() {
  try {
    // existing loop, fetch, queue, sleep, etc.
  } finally {
    onComplete(totalProcessed);
  }
}

You can extend this later to pass an optional error or status flag if you want the caller to distinguish success vs failure.

Also applies to: 184-201, 262-265


76-82: Progress messaging semantics are good; slight UX edge cases

Using processedThreadIds.size as the total and processedThreadIds.size - remaining as “completed” gives a meaningful progress indicator tied to actual queue membership:

  • While some of this run’s threads are still in the AI queue, you show Progress: completed/total emails completed.
  • Once none of this run’s IDs are in the queue, you flip to Success: Processed total emails.

This is a nice improvement over pure counting. One minor UX quirk to be aware of: if the queue drains between pages and then new pages get queued, the banner may briefly show “Success” before reverting to a “Progress” state for the newly queued IDs. That’s acceptable, but if it ever feels jumpy you could gate the “Success” message on receiving the final onComplete as well.

Also applies to: 247-249, 259-260

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c7cf27 and 79020b6.

📒 Files selected for processing (2)
  • apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx (10 hunks)
  • version.txt (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx (1)
apps/web/components/Typography.tsx (1)
  • SectionDescription (127-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: test
🔇 Additional comments (2)
version.txt (1)

1-1: Version bump matches scope of changes

Version increment to v2.20.10 is appropriate for this behavioral/UI tweak to bulk rules.

apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx (1)

90-94: Date changes correctly reset run state

Clearing runResult and processedThreadIds when start/end dates change avoids showing stale progress or “no unread” messages for a different date range. This wiring looks correct and keeps the UI state consistent with the selected filters.

Also applies to: 100-104

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx">

<violation number="1" location="apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx:146">
`runResult` is set whenever the run completes with `count === 0`, but `onRun` calls `onComplete(totalProcessed)` even after errors or user cancellation. This causes the UI to claim “No unread emails found…” when the run was actually aborted or failed, misleading the user.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

},
(count) => {
setRunning(false);
if (count === 0) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 19, 2025

Choose a reason for hiding this comment

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

runResult is set whenever the run completes with count === 0, but onRun calls onComplete(totalProcessed) even after errors or user cancellation. This causes the UI to claim “No unread emails found…” when the run was actually aborted or failed, misleading the user.

Prompt for AI agents
Address the following comment on apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx at line 146:

<comment>`runResult` is set whenever the run completes with `count === 0`, but `onRun` calls `onComplete(totalProcessed)` even after errors or user cancellation. This causes the UI to claim “No unread emails found…” when the run was actually aborted or failed, misleading the user.</comment>

<file context>
@@ -111,9 +132,21 @@ export function BulkRunRules() {
+                            },
+                            (count) =&gt; {
+                              setRunning(false);
+                              if (count === 0) {
+                                setRunResult({ count });
+                              }
</file context>

✅ Addressed in e574ec2

@elie222 elie222 merged commit 6e31e8a into main Nov 19, 2025
13 of 14 checks passed
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (reviewed changes from recent commits).

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx">

<violation number="1" location="apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx:269">
The `runAiRules` function, which is called by this component, does not handle errors within its queued jobs. This can lead to a permanent inconsistency between the AI processing queue state and the UI, causing progress indicators to freeze on an error, even though this component reports that the queuing was successful.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

}

onComplete();
onComplete("success", totalProcessed);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 19, 2025

Choose a reason for hiding this comment

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

The runAiRules function, which is called by this component, does not handle errors within its queued jobs. This can lead to a permanent inconsistency between the AI processing queue state and the UI, causing progress indicators to freeze on an error, even though this component reports that the queuing was successful.

Prompt for AI agents
Address the following comment on apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx at line 269:

<comment>The `runAiRules` function, which is called by this component, does not handle errors within its queued jobs. This can lead to a permanent inconsistency between the AI processing queue state and the UI, causing progress indicators to freeze on an error, even though this component reports that the queuing was successful.</comment>

<file context>
@@ -249,14 +254,19 @@ async function onRun(
     }
 
-    onComplete(totalProcessed);
+    onComplete(&quot;success&quot;, totalProcessed);
   }
 
</file context>
Fix with Cubic

@elie222 elie222 deleted the fix/show-processed-bulk branch December 18, 2025 23:07
@coderabbitai coderabbitai bot mentioned this pull request Dec 19, 2025
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