Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions apps/web/app/(app)/[emailAccountId]/assistant/BulkRunRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ThreadsQuery } from "@/app/api/threads/validation";
import { LoadingContent } from "@/components/LoadingContent";
import { runAiRules } from "@/utils/queue/email-actions";
import { sleep } from "@/utils/sleep";
import { toastError } from "@/components/Toast";
import { PremiumAlertWithData, usePremium } from "@/components/PremiumAlert";
import { SetDateDropdown } from "@/app/(app)/[emailAccountId]/assistant/SetDateDropdown";
import { useThreads } from "@/hooks/useThreads";
Expand Down Expand Up @@ -93,10 +94,22 @@ export function BulkRunRules() {

<Button
type="button"
disabled={running || !startDate}
disabled={running || !startDate || !emailAccountId}
loading={running}
onClick={async () => {
if (!startDate) return;
if (!startDate) {
toastError({
description: "Please select a start date",
});
return;
}
if (!emailAccountId) {
toastError({
description:
"Email account ID is missing. Please refresh the page.",
});
return;
}
setRunning(true);
abortRef.current = await onRun(
emailAccountId,
Expand Down Expand Up @@ -164,21 +177,42 @@ async function onRun(
for (let i = 0; i < 100; i++) {
const query: ThreadsQuery = {
type: "inbox",
nextPageToken,
limit: LIMIT,
after: startDate,
before: endDate || undefined,
before: endDate,
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Nov 2, 2025

Choose a reason for hiding this comment

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

Setting before to the raw endDate causes before=undefined to be sent when no end date is chosen, which fails validation and breaks bulk processing. Restore the guard so before is omitted when endDate is undefined.

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

<comment>Setting `before` to the raw `endDate` causes `before=undefined` to be sent when no end date is chosen, which fails validation and breaks bulk processing. Restore the guard so `before` is omitted when `endDate` is undefined.</comment>

<file context>
@@ -164,21 +177,42 @@ async function onRun(
         limit: LIMIT,
         after: startDate,
-        before: endDate || undefined,
+        before: endDate,
         isUnread: true,
+        nextPageToken: nextPageToken || undefined,
</file context>
Fix with Cubic

isUnread: true,
nextPageToken: nextPageToken || undefined,
};

const res = await fetchWithAccount({
url: `/api/threads?${
// biome-ignore lint/suspicious/noExplicitAny: simplest
new URLSearchParams(query as any).toString()
}`,
emailAccountId,
});

if (!res.ok) {
const errorData = await res.json().catch(() => ({}));
console.error("Failed to fetch threads:", res.status, errorData);
toastError({
title: "Failed to fetch emails",
description: errorData.error || `Error: ${res.status}`,
});
break;
}
Comment thread
elie222 marked this conversation as resolved.

const data: ThreadsResponse = await res.json();

if (!data.threads) {
console.error("Invalid response: missing threads", data);
toastError({
title: "Invalid response",
description: "Failed to process emails. Please try again.",
});
break;
}
Comment thread
elie222 marked this conversation as resolved.

nextPageToken = data.nextPageToken || "";

const threadsWithoutPlan = data.threads.filter((t) => !t.plan);
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.17.22
v2.17.23
Loading