Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(action-center): mark a task tried before its check reads anything, cap each brand's night, and check after the task writer (#1682)
Cihan87202b840b91
diff --git a/docs/guides/action-center.mdx b/docs/guides/action-center.mdxindex 6cfe75fb4..557937338 100644--- a/docs/guides/action-center.mdx+++ b/docs/guides/action-center.mdx@@ -83,7 +83,7 @@ Click a row to open the action. Under its title you set **Status**, **Assignee**Each action comes with tasks: concrete steps such as "Refresh content for these prompts" or "Add structured data to these pages". Open a task to see its details: **What**, **URL** (the exact page), **Where**, **Why**, **Change** (the text before and after, or the text to add), **How** (one step per line), **Done when**, **How we check** (Automatic: we fetch the page again; Re-run: the prompts run again; Manual: you confirm it), **Type** (Content, On-page, Technical, Outreach, PR or Product), **Effort** and **Role**. Click **Edit** to change any of them. A task from the Action Center's own plan comes with its **Done when**, with **How we check** for most of them (not for a task measured over a GA4 or Search Console window), and with its **URL** when it changes a page and the action is about one page.-A task checked **Automatic** is checked on its page, fetched again (up to 200 tasks a night, and when you click **Check now**), by what it changes:+A task checked **Automatic** is checked on its page, fetched again (up to 200 tasks a night, at most 20 of one brand's, the least recently tried first, and when you click **Check now**), by what it changes:- **A broken page:** the page answers again.- **Publishing:** the page answers where it wasn't before. A page already live at the first check passes once it changes.diff --git a/server/src/lib/action-center/task-checks.js b/server/src/lib/action-center/task-checks.jsindex 893f4482f..e82ab7ab6 100644--- a/server/src/lib/action-center/task-checks.js+++ b/server/src/lib/action-center/task-checks.js@@ -58,6 +58,11 @@ export const CHECKS = Object.freeze({/** The most open tasks one nightly sweep checks: pages are fetched one at a time. */export const SWEEP_LIMIT = 200;+/** The most of one brand's tasks a night's sweep checks: a brand with many new tasks doesn't hold the others back. */+export const SWEEP_PER_BRAND = 20;+/** Rows the sweep reads a page at a time to fill a night past the brands' caps, and pages at most. */+const SWEEP_PAGE = 1000;+const SWEEP_PAGES = 5;/** A task tried this recently isn't tried again by the sweep. */const RECHECK_AFTER_MS = 20 * 60 * 60 * 1000;const FETCH_TIMEOUT_MS = 10_000;@@ -554,27 +559,28 @@ async function checkShoppingTask(task, action, { fetch, now }) {* status: string, details: object|null, updated_at?: string }} task* @param {{ brand_id: string }} action*/-export async function runTaskCheck(task, action, { fetch = fetchPage, now = new Date() } = {}) {- const kind = checkKind(task);+export async function runTaskCheck(read, action, { fetch = fetchPage, now = new Date() } = {}) {+ const kind = checkKind(read);if (!kind) return { reason: 'not_checkable' };- if (!OPEN.includes(task.status)) return { reason: 'not_open' };- if (kind === 'shoppingLinks') return checkShoppingTask(task, action, { fetch, now });- const d = task.details ?? {};+ if (!OPEN.includes(read.status)) return { reason: 'not_open' };+ if (kind === 'shoppingLinks') return checkShoppingTask(read, action, { fetch, now });+ const d = read.details ?? {};+ const previous = d.autoCheck ?? null;+ // Tried now, before anything is read: a task that can't be checked here+ // (no address, a read that throws) leaves the head of the sweep's queue,+ // and a second run that read the task before this one isn't let check it too.+ const claim = { ...d, autoCheck: { ...(previous ?? {}), triedAt: now.toISOString() } };+ if (!(await writeCheck(read, claim, { now }))) return { reason: 'changed' };+ const task = { ...read, details: claim, updated_at: now.toISOString() };const domains = await brandDomains(action.brand_id);const url = pageAddress(d.url, storedHost(domains[0]));if (!url) return { reason: 'not_checkable' };- const previous = d.autoCheck ?? null;let auditChecks = [];if (kind === 'structuredData' || kind === 'crawlers') {auditChecks = await auditChecksFor(task.action_id, url);// Raised from the bot logs (a cited page crawlers never read): robots.txt- // can't say it's fixed. Its try is kept, so the sweep goes on to others.+ // can't say it's fixed. Its try is kept (the claim), so the sweep goes on to others.if (kind === 'crawlers' && !auditChecks.includes('ai-bot-access')) {- await writeCheck(- task,- { ...d, autoCheck: { ...(previous ?? {}), triedAt: now.toISOString() } },- { now },- );return { reason: 'not_checkable' };}}@@ -645,7 +651,7 @@ export async function runTaskCheck(task, action, { fetch = fetchPage, now = new* library task with a check, or a written one with its new text) and have a* page, of open actions, not held (reopened after they passed), the least* recently tried first, none tried in the last day, one page at a time, at- * most SWEEP_LIMIT. A failure on one task+ * most SWEEP_LIMIT and SWEEP_PER_BRAND of one brand's. A failure on one task* is logged and the rest go on.** @returns {Promise<{ checked: number, passed: number }>}@@ -655,35 +661,43 @@ export async function sweepTaskChecks({fetch = fetchPage,now = new Date(),} = {}) {- const { data: rows, error } = await supabaseAdmin- .from('action_tasks')- .select(- 'id, action_id, task_key, title, status, details, updated_at, actions!inner(brand_id, status, deleted_at)',- )- .in('status', OPEN)- .eq('details->>check', 'auto')- .not('details->>url', 'is', null)- .or(- `task_key.in.(${Object.keys(CHECKS).join(',')}),and(task_key.is.null,details->change->>after.not.is.null)`,- )- // A task reopened after it passed is the person's call: Check now still reads it.- .is('details->autoCheck->>held', null)- .is('actions.deleted_at', null)- .not('actions.status', 'in', '(completed,dismissed)')- .order('details->autoCheck->>triedAt', { ascending: true, nullsFirst: true })- .limit(limit);- if (error) throw new Error(error.message);-const since = now.getTime() - RECHECK_AFTER_MS;- // A shopping links task is checked after each catalog sync, not here.- const due = (rows ?? []).filter((row) => {- const kind = checkKind(row);- return (- kind &&- kind !== 'shoppingLinks' &&- !(Date.parse(row.details?.autoCheck?.triedAt ?? '') >= since)- );- });+ const due = [];+ const perBrand = new Map();+ for (let page = 0; page < SWEEP_PAGES && due.length < limit; page += 1) {+ const { data: rows, error } = await supabaseAdmin+ .from('action_tasks')+ .select(+ 'id, action_id, task_key, title, status, details, updated_at, actions!inner(brand_id, status, deleted_at)',+ )+ .in('status', OPEN)+ .eq('details->>check', 'auto')+ .not('details->>url', 'is', null)+ .or(+ `task_key.in.(${Object.keys(CHECKS).join(',')}),and(task_key.is.null,details->change->>after.not.is.null)`,+ )+ // A task reopened after it passed is the person's call: Check now still reads it.+ .is('details->autoCheck->>held', null)+ .is('actions.deleted_at', null)+ .not('actions.status', 'in', '(completed,dismissed)')+ .order('details->autoCheck->>triedAt', { ascending: true, nullsFirst: true })+ .order('id')+ .range(page * SWEEP_PAGE, (page + 1) * SWEEP_PAGE - 1);+ if (error) throw new Error(error.message);+ for (const row of rows ?? []) {+ if (due.length >= limit) break;+ const kind = checkKind(row);+ // A shopping links task is checked after each catalog sync, not here.+ if (!kind || kind === 'shoppingLinks') continue;+ if (Date.parse(row.details?.autoCheck?.triedAt ?? '') >= since) continue;+ const action = Array.isArray(row.actions) ? row.actions[0] : row.actions;+ const taken = perBrand.get(action?.brand_id) ?? 0;+ if (taken >= SWEEP_PER_BRAND) continue;+ perBrand.set(action?.brand_id, taken + 1);+ due.push(row);+ }+ if ((rows ?? []).length < SWEEP_PAGE) break;+ }let checked = 0;let passed = 0;for (const row of due) {diff --git a/server/src/lib/action-center/task-checks.test.js b/server/src/lib/action-center/task-checks.test.jsindex 32b3a7b50..358b8416e 100644--- a/server/src/lib/action-center/task-checks.test.js+++ b/server/src/lib/action-center/task-checks.test.js@@ -34,6 +34,7 @@ function table(name) {or: filter('or'),order: filter('order'),limit: () => chain,+ range: filter('range'),maybeSingle: async () => {reads.push({ table: name, filters: q.filters });const row = db[name];@@ -55,6 +56,7 @@ vi.mock('../shopping-check.js', () => ({ checkShoppingDraft }));const {CHANGED_BELOW,MIN_CHANGED_RUNS,+ SWEEP_PER_BRAND,changedRuns,checkKind,checkPage,@@ -468,6 +470,8 @@ describe('runTaskCheck', () => {});const now = new Date('2026-10-27T03:00:00Z');const at = now.toISOString();+ /** The task's last write: what the check found (the first is its claim, triedAt alone). */+ const lastWrite = () => ops.filter((op) => op.table === 'action_tasks').at(-1);it('completes a task that passes, keeps the check on it and tells History', async () => {const fetch = fetchOf({ [PAGE]: html('x') });@@ -477,15 +481,19 @@ describe('runTaskCheck', () => {});// A page read up to 512 KB.expect(fetch.mock.calls[0][1]).toMatchObject({ maxBytes: 512 * 1024, truncate: true });- const update = ops.find((op) => op.table === 'action_tasks');+ const update = lastWrite();expect(update.payload).toMatchObject({status: 'completed',// The template's mark stays: a check is no one's edit.details: { source: 'template', autoCheck: { passed: true } },});- // Only if no one moved or edited it meanwhile.+ // Only if no one moved or edited it meanwhile: the claim on the task as+ // read, the result on the claim.+ const [claim] = ops.filter((op) => op.table === 'action_tasks');+ expect(claim.payload.details.autoCheck).toEqual({ triedAt: at });+ expect(claim.filters).toContainEqual(['updated_at', '2026-10-26T10:00:00Z']);expect(update.filters).toContainEqual(['status', 'todo']);- expect(update.filters).toContainEqual(['updated_at', '2026-10-26T10:00:00Z']);+ expect(update.filters).toContainEqual(['updated_at', at]);expect(ops.find((op) => op.table === 'action_events').payload).toMatchObject({action_id: 'a1',event: 'task_checked',@@ -517,7 +525,7 @@ describe('runTaskCheck', () => {now,});expect(result.autoCheck).toMatchObject({ passed: true, url: PAGE, held: true });- expect(ops.find((op) => op.table === 'action_tasks').payload).not.toHaveProperty('status');+ expect(lastWrite().payload).not.toHaveProperty('status');expect(ops.some((op) => op.table === 'action_events')).toBe(false);// A check that fails meanwhile keeps it held; one that passes again doesn't close it.ops = [];@@ -534,7 +542,7 @@ describe('runTaskCheck', () => {{ fetch: fetchOf({ [PAGE]: html('x') }), now },);expect(again.autoCheck).toMatchObject({ passed: true, held: true });- expect(ops.find((op) => op.table === 'action_tasks').payload).not.toHaveProperty('status');+ expect(lastWrite().payload).not.toHaveProperty('status');// Its URL edited since: a new page, checked as one.ops = [];await runTaskCheck(@@ -542,7 +550,42 @@ describe('runTaskCheck', () => {action,{ fetch: fetchOf({ 'https://acme.example/plans': html('x') }), now },);- expect(ops.find((op) => op.table === 'action_tasks').payload.status).toBe('completed');+ expect(lastWrite().payload.status).toBe('completed');+ });++ it('marks a task tried before reading anything, so one it can’t check leaves the queue (#1565 C6)', async () => {+ // No address can be made: still tried.+ const typed = task({ details: { check: 'auto', url: 'not an address' } });+ const fetch = fetchOf({});+ expect(await runTaskCheck(typed, action, { fetch, now })).toEqual({ reason: 'not_checkable' });+ expect(lastWrite().payload.details.autoCheck).toEqual({ triedAt: at });+ expect(fetch).not.toHaveBeenCalled();+ // Claimed by another run meanwhile (the task changed since it was read): left to it.+ ops = [];+ db.moved = true;+ expect(await runTaskCheck(task(), action, { fetch, now })).toEqual({ reason: 'changed' });+ expect(fetch).not.toHaveBeenCalled();+ db.moved = false;+ });++ it('a read that throws still writes triedAt', async () => {+ // The page comes back, then reading it throws: the claim already marked the task tried.+ const fetch = vi.fn(async (url) => ({+ url,+ status: 200,+ get html() {+ throw new Error('unreadable');+ },+ }));+ const written = task({+ task_key: null,+ details: { check: 'auto', url: '/pricing', change: { after: 'Plans from $9' } },+ });+ await expect(runTaskCheck(written, action, { fetch, now })).rejects.toThrow('unreadable');+ expect(fetch).toHaveBeenCalled();+ const writes = ops.filter((op) => op.table === 'action_tasks');+ expect(writes).toHaveLength(1);+ expect(writes[0].payload.details.autoCheck).toEqual({ triedAt: at });});it('reads only the brand’s own pages', async () => {@@ -634,7 +677,7 @@ describe('runTaskCheck', () => {reason: 'not_checkable',});expect(fetch).not.toHaveBeenCalled();- expect(ops.find((op) => op.table === 'action_tasks').payload.details.autoCheck).toEqual({+ expect(lastWrite().payload.details.autoCheck).toEqual({triedAt: at,});db.actions = { targets: [{ id: PAGE, checks: ['ai-bot-access'] }] };@@ -669,7 +712,7 @@ describe('runTaskCheck', () => {missing: ['page_error'],sketch: { hashes: ['aa'], runs: 1 },});- const update = ops.find((op) => op.table === 'action_tasks');+ const update = lastWrite();expect(update.payload).not.toHaveProperty('status');expect(ops.some((op) => op.table === 'action_events')).toBe(false);// Another page's first look isn't kept for this one.@@ -696,7 +739,7 @@ describe('runTaskCheck', () => {expect(await runTaskCheck(tried, action, { fetch: fetchOf({}), now })).toEqual({reason: 'no_answer',});- expect(ops.find((op) => op.table === 'action_tasks').payload.details.autoCheck).toEqual({+ expect(lastWrite().payload.details.autoCheck).toEqual({at: 'x',passed: false,missing: ['page_error'],@@ -842,6 +885,21 @@ describe('sweepTaskChecks', () => {expect(filters).toContainEqual(['is', 'details->autoCheck->>held', null]);});+ it('checks at most SWEEP_PER_BRAND of one brand’s tasks a night, the others’ too', async () => {+ const other = { brand_id: 'b2', status: 'new', deleted_at: null };+ db.action_tasks = [+ ...Array.from({ length: 25 }, (_, i) => row(`a${i}`)),+ ...Array.from({ length: 3 }, (_, i) => row(`b${i}`, { actions: other })),+ ];+ const fetch = fetchOf({ [PAGE]: html('x') });+ expect(await sweepTaskChecks({ fetch, now })).toEqual({ checked: 23, passed: 23 });+ expect(SWEEP_PER_BRAND).toBe(20);+ // Read a page at a time, in a steady order.+ const filters = reads.find((r) => r.table === 'action_tasks').filters;+ expect(filters).toContainEqual(['range', 0, 999]);+ expect(filters).toContainEqual(['order', 'id']);+ });+it('checks the open tasks not tried in the last day, one at a time', async () => {db.action_tasks = [row('t1'),diff --git a/server/src/server.js b/server/src/server.jsindex 00b0ea7f4..70c7db6ab 100644--- a/server/src/server.js+++ b/server/src/server.js@@ -180,16 +180,19 @@ async function runDailyTracking() {// Write the tasks of recent actions whose writing a pass missed (AC-004):// the budget was spent, the model failed, or the process restarted.// Bounded per sweep; a no-op unless ACTION_TASKS_AI is on.- sweepActionTasks().catch((err) => {- logger.error({ err }, '[task-writer] daily sweep crashed');- });-- // Check the open tasks checked `auto` on their pages (AC-010): a page+ //+ // Then check the open tasks checked `auto` on their pages (AC-010): a page// fetched again with the free reader, one at a time, bounded per night. A- // task that passes is completed. Fire-and-forget like the rest.- sweepTaskChecks().catch((err) => {- logger.error({ err }, '[task-checks] daily sweep crashed');- });+ // task that passes is completed. Once the writer's sweep settles, as it+ // can delete a task a check just completed. Fire-and-forget like the rest.+ sweepActionTasks()+ .catch((err) => {+ logger.error({ err }, '[task-writer] daily sweep crashed');+ })+ .then(() => sweepTaskChecks())+ .catch((err) => {+ logger.error({ err }, '[task-checks] daily sweep crashed');+ });// Insights rollup backstop (00066). Re-refreshes the trailing days for// every brand, so days whose run never stamped (partial, crashed) and