Skip to content

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

fix(notfair-cmo): boot the cron scheduler + capture run summaries (0.4.4)

Yuting Zhong97606693178e
diff --git a/notfair-cmo/CHANGELOG.md b/notfair-cmo/CHANGELOG.md
index b7248ed6..e9bfae68 100644
--- a/notfair-cmo/CHANGELOG.md
+++ b/notfair-cmo/CHANGELOG.md
@@ -1,5 +1,15 @@
# notfair-cmo
+## 0.4.4 — 2026-06-03
+
+**Cron jobs actually run now.** The Crons calendar was rendering future occurrences from the cron expression and creating `scheduled_jobs` rows, but the tick loop that actually dispatches due jobs was never starting. `ensureSchedulerRunning()` was defined in `src/server/scheduler/tick.ts` and imported from nowhere — no layout, no instrumentation, no CLI. Net effect: clicking a past occurrence on the calendar showed no status badge and the Result section had nothing to render, because `scheduled_job_runs` stayed empty forever.
+
+New `src/instrumentation.ts` registers a `nodejs`-runtime hook that calls `ensureSchedulerRunning()` once per server boot. Verified live: a test cron inserted at 16:45 UTC fired ~25s later, Codex returned a short reply, the green-check badge appeared on the calendar chip, and the detail dialog rendered the captured summary with duration (7.6s).
+
+**Run summaries are captured and shown.** `loadCronRuns()` used to hardcode `summary: ""` even though the Result section in the detail dialog rendered from that field — so every completed run, no matter what the adapter produced, displayed "Run finished with no summary." `dispatchJob` now accumulates the adapter's final-text event (or concatenated delta chunks, capped at 4000 chars) and `finishJobRun` persists it to a new `summary` column on `scheduled_job_runs` (migration 014). The calendar's detail dialog now shows what the agent actually said.
+
+**Failed-run badge fix.** The calendar's status glyph maps "ok" → green check and "error" → red badge, but `loadCronRuns` was returning `"failed"` for failed runs — they rendered as a neutral gray dot. `normalizeRunStatus` now maps `done → ok` and `failed → error` at the read boundary so the destructive badge fires correctly. Same helper applies to `jobToDisplay`'s `last_status` so the per-cron summary row matches.
+
## 0.4.3 — 2026-06-02
**Humanized tool-call rendering in the chat transcript.** The chat used to show every shell call as the raw command — long `/bin/zsh -lc "rg --files ..."` lines splatted right under the assistant's reasoning, with both the tool group's `name` and `label` rendering the same incantation. Visually noisy and didn't tell the user anything they couldn't infer from the prose above it.
diff --git a/notfair-cmo/package.json b/notfair-cmo/package.json
index 332d295c..99cc4142 100644
--- a/notfair-cmo/package.json
+++ b/notfair-cmo/package.json
@@ -1,6 +1,6 @@
{
"name": "notfair-cmo",
- "version": "0.4.3",
+ "version": "0.4.4",
"description": "Open-source AI marketing CMO portal. Run locally; orchestrates marketing agents (Google Ads, SEO, and more) on top of Claude Code, Codex, or other local AI coding agents.",
"license": "MIT",
"bin": {
diff --git a/notfair-cmo/src/instrumentation.ts b/notfair-cmo/src/instrumentation.ts
new file mode 100644
index 00000000..a2b3960a
--- /dev/null
+++ b/notfair-cmo/src/instrumentation.ts
@@ -0,0 +1,9 @@
+// Next.js boots this once per server process via the instrumentation hook.
+// We use it to start the cron tick loop — without this call, scheduled jobs
+// fire never, the calendar shows no run history, and the detail dialog has
+// nothing to render in its Result section.
+export async function register(): Promise<void> {
+ if (process.env.NEXT_RUNTIME !== "nodejs") return;
+ const { ensureSchedulerRunning } = await import("@/server/scheduler/tick");
+ ensureSchedulerRunning();
+}
diff --git a/notfair-cmo/src/server/db/migrations.ts b/notfair-cmo/src/server/db/migrations.ts
index 8f429f9d..12c82bac 100644
--- a/notfair-cmo/src/server/db/migrations.ts
+++ b/notfair-cmo/src/server/db/migrations.ts
@@ -542,6 +542,16 @@ ALTER TABLE projects
ALTER TABLE mcp_tokens ADD COLUMN token_endpoint TEXT;
ALTER TABLE mcp_tokens ADD COLUMN client_id TEXT;
ALTER TABLE mcp_tokens ADD COLUMN client_secret TEXT;
+`,
+ },
+ {
+ name: "014_scheduled_job_run_summary.sql",
+ sql: `
+-- Migration 014: capture a short summary on every cron run so the calendar
+-- detail dialog can show what actually happened. dispatchJob accumulates the
+-- adapter's final/delta text and writes it on finishJobRun.
+
+ALTER TABLE scheduled_job_runs ADD COLUMN summary TEXT;
`,
},
];
diff --git a/notfair-cmo/src/server/db/migrations/014_scheduled_job_run_summary.sql b/notfair-cmo/src/server/db/migrations/014_scheduled_job_run_summary.sql
new file mode 100644
index 00000000..dbaa8ed6
--- /dev/null
+++ b/notfair-cmo/src/server/db/migrations/014_scheduled_job_run_summary.sql
@@ -0,0 +1,5 @@
+-- Migration 014: capture a short summary on every cron run so the calendar
+-- detail dialog can show what actually happened. dispatchJob accumulates the
+-- adapter's final/delta text and writes it on finishJobRun.
+
+ALTER TABLE scheduled_job_runs ADD COLUMN summary TEXT;
diff --git a/notfair-cmo/src/server/scheduler/display.ts b/notfair-cmo/src/server/scheduler/display.ts
index 9aeb8dc6..63d21776 100644
--- a/notfair-cmo/src/server/scheduler/display.ts
+++ b/notfair-cmo/src/server/scheduler/display.ts
@@ -81,10 +81,17 @@ function formatRelativeMs(ms: number | undefined): string {
return delta > 0 ? `in ${days}d` : `${days}d ago`;
}
+function normalizeRunStatus(s: string | undefined): string | undefined {
+ if (!s) return undefined;
+ if (s === "done") return "ok";
+ if (s === "failed") return "error";
+ return s;
+}
+
function jobToDisplay(job: ScheduledJob, project_slug: string): DisplayCron {
// Most recent run gives us the last_status / last_error fields the UI surfaces.
const recent = listJobRuns(job.id, 1)[0];
- const lastStatus = recent?.status === "done" ? "ok" : recent?.status;
+ const lastStatus = normalizeRunStatus(recent?.status);
const lastError = recent?.error_message ?? undefined;
const lastRunMs = isoMs(job.last_run_at) ?? (recent ? Date.parse(recent.started_at) : undefined);
const nextRunMs = isoMs(job.next_run_at);
@@ -153,8 +160,8 @@ export function loadCronRuns(cron_id: string, limit = 100): CronRun[] {
return {
run_at_ms: startedMs,
finished_at_ms: finishedMs,
- status: r.status === "done" ? "ok" : r.status,
- summary: "",
+ status: normalizeRunStatus(r.status) ?? r.status,
+ summary: r.summary ?? "",
error: r.error_message ?? undefined,
duration_ms: Number.isFinite(finishedMs - startedMs) ? finishedMs - startedMs : undefined,
};
diff --git a/notfair-cmo/src/server/scheduler/index.ts b/notfair-cmo/src/server/scheduler/index.ts
index 0ff2fbcd..23ac32ac 100644
--- a/notfair-cmo/src/server/scheduler/index.ts
+++ b/notfair-cmo/src/server/scheduler/index.ts
@@ -141,13 +141,14 @@ export interface ScheduledJobRun {
finished_at: string | null;
status: "running" | "done" | "failed";
error_message: string | null;
+ summary: string | null;
}
export function startJobRun(scheduled_job_id: string): string {
const id = randomUUID();
getDb()
.prepare(
- "INSERT INTO scheduled_job_runs (id, scheduled_job_id, started_at, finished_at, status, error_message) VALUES (?, ?, ?, NULL, 'running', NULL)",
+ "INSERT INTO scheduled_job_runs (id, scheduled_job_id, started_at, finished_at, status, error_message, summary) VALUES (?, ?, ?, NULL, 'running', NULL, NULL)",
)
.run(id, scheduled_job_id, new Date().toISOString());
return id;
@@ -157,12 +158,13 @@ export function finishJobRun(
run_id: string,
status: "done" | "failed",
error_message: string | null = null,
+ summary: string | null = null,
): void {
getDb()
.prepare(
- "UPDATE scheduled_job_runs SET finished_at = ?, status = ?, error_message = ? WHERE id = ?",
+ "UPDATE scheduled_job_runs SET finished_at = ?, status = ?, error_message = ?, summary = ? WHERE id = ?",
)
- .run(new Date().toISOString(), status, error_message, run_id);
+ .run(new Date().toISOString(), status, error_message, summary, run_id);
}
export function listJobRuns(scheduled_job_id: string, limit = 50): ScheduledJobRun[] {
diff --git a/notfair-cmo/src/server/scheduler/tick.ts b/notfair-cmo/src/server/scheduler/tick.ts
index 9fd0d3cd..f578199e 100644
--- a/notfair-cmo/src/server/scheduler/tick.ts
+++ b/notfair-cmo/src/server/scheduler/tick.ts
@@ -47,8 +47,8 @@ async function runTickSafe(): Promise<void> {
markJobRun(job.id);
const runId = startJobRun(job.id);
try {
- await dispatchJob(job);
- finishJobRun(runId, "done");
+ const summary = await dispatchJob(job);
+ finishJobRun(runId, "done", null, summary);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
console.error(`[scheduler] job ${job.id} failed:`, err);
@@ -62,7 +62,7 @@ function workspaceDirFor(agentId: string): string {
return join(dataDir, "agents", agentId);
}
-async function dispatchJob(job: ScheduledJob): Promise<void> {
+async function dispatchJob(job: ScheduledJob): Promise<string | null> {
const project = getProject(job.project_slug);
if (!project) {
throw new Error(`project not found: ${job.project_slug}`);
@@ -76,6 +76,13 @@ async function dispatchJob(job: ScheduledJob): Promise<void> {
});
appendTranscriptEvent(session.id, "user", { text: job.message, source: "cron" });
+ // Prefer the adapter's explicit `final` event for the summary; fall back to
+ // concatenated `delta` chunks if the adapter only streams text. Truncate so
+ // we never bloat the DB with a multi-MB run row.
+ let finalText: string | null = null;
+ let deltaBuffer = "";
+ const MAX_SUMMARY = 4000;
+
for await (const evt of adapter.execute({
projectSlug: project.slug,
agentId: job.agent_id,
@@ -89,9 +96,17 @@ async function dispatchJob(job: ScheduledJob): Promise<void> {
continue;
}
appendTranscriptEvent(session.id, evt.kind, evt);
- if (evt.kind === "error") {
+ if (evt.kind === "final") {
+ finalText = evt.text;
+ } else if (evt.kind === "delta" && deltaBuffer.length < MAX_SUMMARY) {
+ deltaBuffer += evt.text;
+ } else if (evt.kind === "error") {
throw new Error(evt.message);
}
}
touchSession(session.id);
+
+ const raw = (finalText ?? deltaBuffer).trim();
+ if (!raw) return null;
+ return raw.length > MAX_SUMMARY ? `${raw.slice(0, MAX_SUMMARY)}…` : raw;
}