Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

fix(notfair-cmo): crons calendar starts Monday, no phantom pre-creation runs

Yuting Zhong565f6fa125fc
diff --git a/notfair-cmo/src/app/(app)/[project]/agents/[agent]/cron/page.tsx b/notfair-cmo/src/app/(app)/[project]/agents/[agent]/cron/page.tsx
index aaf3d83a..fff50a05 100644
--- a/notfair-cmo/src/app/(app)/[project]/agents/[agent]/cron/page.tsx
+++ b/notfair-cmo/src/app/(app)/[project]/agents/[agent]/cron/page.tsx
@@ -64,7 +64,9 @@ export default async function AgentCronPage({
const occs = expandSchedule(
cron.id,
cron.schedule_raw,
- { from: startOfFirstDay, until },
+ // Never expand before the cron existed — avoids phantom occurrences on
+ // days earlier in the window than the cron's creation.
+ { from: Math.max(startOfFirstDay, cron.created_at_ms ?? startOfFirstDay), until },
{
name: cron.name,
short_name: cron.short_name,
diff --git a/notfair-cmo/src/app/(app)/[project]/crons/page.tsx b/notfair-cmo/src/app/(app)/[project]/crons/page.tsx
index ba048e5c..2cb31716 100644
--- a/notfair-cmo/src/app/(app)/[project]/crons/page.tsx
+++ b/notfair-cmo/src/app/(app)/[project]/crons/page.tsx
@@ -45,9 +45,11 @@ export default async function CronsPage({
const allCrons = view.groups.flatMap((g) => g.crons);
const agentSlugs = view.groups.map((g) => g.agent);
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- const startOfFirstDay = today.getTime();
+ // Start the calendar on Monday of the current week, not on today.
+ const start = new Date();
+ start.setHours(0, 0, 0, 0);
+ start.setDate(start.getDate() - ((start.getDay() + 6) % 7));
+ const startOfFirstDay = start.getTime();
const dayMs = 24 * 60 * 60 * 1000;
const until = startOfFirstDay + NUM_DAYS * dayMs;
@@ -57,7 +59,9 @@ export default async function CronsPage({
const occs = expandSchedule(
cron.id,
cron.schedule_raw,
- { from: startOfFirstDay, until },
+ // Never expand before the cron existed — the calendar window can reach
+ // back to Monday, which would otherwise render phantom past occurrences.
+ { from: Math.max(startOfFirstDay, cron.created_at_ms ?? startOfFirstDay), until },
{
name: cron.name,
short_name: cron.short_name,
diff --git a/notfair-cmo/src/server/scheduler/display.ts b/notfair-cmo/src/server/scheduler/display.ts
index 63d21776..86451061 100644
--- a/notfair-cmo/src/server/scheduler/display.ts
+++ b/notfair-cmo/src/server/scheduler/display.ts
@@ -38,6 +38,7 @@ export interface DisplayCron {
last_status?: string;
last_error?: string;
next_run_at_ms?: number;
+ created_at_ms?: number;
}
export interface CronGroup {
@@ -114,6 +115,7 @@ function jobToDisplay(job: ScheduledJob, project_slug: string): DisplayCron {
last_status: lastStatus ?? undefined,
last_error: lastError,
next_run_at_ms: nextRunMs,
+ created_at_ms: isoMs(job.created_at),
};
}