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(tracking): stop submitting Grok tasks while Cloro returns 500 for all of them (#734)
Gökhan Geyik2070ec9c77f2
diff --git a/server/src/workers/tracking-worker.js b/server/src/workers/tracking-worker.jsindex 8ecd5286d..f43802940 100644--- a/server/src/workers/tracking-worker.js+++ b/server/src/workers/tracking-worker.js@@ -19,6 +19,41 @@ function resolveModelPlatform(model) {return 'chatgpt';}+/**+ * Platforms Cloro cannot currently deliver, dropped before anything is+ * submitted.+ *+ * Grok started answering every task with a 500 on 2026-08-18. Leaving it in+ * the run would submit a paid task per prompt per region, hold the drain open+ * waiting for results that never arrive, and record nothing — so the platform+ * is removed up front rather than failing task by task.+ *+ * Deliberately a run-time filter and nothing else. Dropping Grok from the+ * engine picker would also drop it from `ALL_SCRAPERS`, which+ * `filterByPlan` and `alignPromptsToPlanForOrg` use as the allow-set when+ * writing prompts — so every prompt edit and every plan change would quietly+ * strip the stored id, and restoring Grok would need a data repair rather+ * than a revert. Empty this list when Cloro reports Grok healthy again and+ * every prompt that still lists it resumes on the next run.+ */+export const UNAVAILABLE_PLATFORMS = ['grok-web'];++/**+ * The platforms a prompt should actually be run against.+ *+ * Prompts keep whatever platform ids they were saved with, so the stored array+ * cannot be trusted at run time: a brand may have turned Shopping off since,+ * and a platform may be down. Both are filtered here rather than at the picker,+ * because every id that survives becomes a paid Cloro submission.+ */+export function runnablePlatforms(platforms, { shoppingEnabled } = {}) {+ return (platforms ?? []).filter(+ (platform) =>+ !UNAVAILABLE_PLATFORMS.includes(platform) &&+ (shoppingEnabled || platform !== 'chatgpt-shopping'),+ );+}+/*** PostgREST silently caps an un-paginated select at 1000 rows, so reading a* brand's pending tasks in one request under-reports any run that submitted@@ -210,17 +245,8 @@ export async function processTrackingJob({ brandId, promptId, promptIds, source,return allowedModels ? models.filter((m) => allowedModels.includes(m)) : models;};- // Shopping tracking is opt-in per brand: prompts can still carry the- // chatgpt-shopping platform from before the brand turned Shopping off (or- // from a picker that offered it regardless of the pref), so filter at run- // time instead of trusting the stored arrays — each skipped task is a paid- // Cloro scrape for data the brand can't even see.- const allowedPlatformsFor = (prompt) => {- const platforms = prompt.platforms && prompt.platforms.length > 0 ? prompt.platforms : [];- return brand.shopping_mode_enabled- ? platforms- : platforms.filter((p) => p !== 'chatgpt-shopping');- };+ const allowedPlatformsFor = (prompt) =>+ runnablePlatforms(prompt.platforms, { shoppingEnabled: brand.shopping_mode_enabled });// 4. Count total tasks: prompt × (models + scrapers) × regionslet totalTasks = 0;diff --git a/server/src/workers/tracking-worker.test.js b/server/src/workers/tracking-worker.test.jsindex a92a24b60..a5ee01aa9 100644--- a/server/src/workers/tracking-worker.test.js+++ b/server/src/workers/tracking-worker.test.js@@ -4,7 +4,13 @@ import { describe, expect, it, vi } from 'vitest';// SUPABASE_* env is absent (as in CI) — stub it before the import chain.vi.mock('../config/supabase.js', () => ({ default: {} }));-import { allTasksAreStale, drainBudgetExceeded, fetchAllPendingRows } from './tracking-worker.js';+import {+ allTasksAreStale,+ drainBudgetExceeded,+ fetchAllPendingRows,+ runnablePlatforms,+ UNAVAILABLE_PLATFORMS,+} from './tracking-worker.js';/*** Ghost detection for the Cloro drain loop (#687).@@ -204,3 +210,45 @@ describe('fetchAllPendingRows', () => {expect(error).toBeNull();});});++/**+ * What a run is allowed to submit (#731 follow-up).+ *+ * Every id that survives this filter becomes a paid Cloro task, so the two+ * reasons to drop one — the brand turned Shopping off, the platform is down —+ * both have to hold at run time, not at the moment the prompt was saved.+ */+describe('runnablePlatforms', () => {+ it('drops a platform that is currently unavailable', () => {+ expect(+ runnablePlatforms(['chatgpt-web', 'grok-web', 'perplexity-web'], { shoppingEnabled: true }),+ ).toEqual(['chatgpt-web', 'perplexity-web']);+ });++ it('drops shopping unless the brand has it enabled', () => {+ expect(+ runnablePlatforms(['chatgpt-web', 'chatgpt-shopping'], { shoppingEnabled: false }),+ ).toEqual(['chatgpt-web']);+ expect(+ runnablePlatforms(['chatgpt-web', 'chatgpt-shopping'], { shoppingEnabled: true }),+ ).toEqual(['chatgpt-web', 'chatgpt-shopping']);+ });++ it('applies both reasons at once', () => {+ expect(+ runnablePlatforms(['grok-web', 'chatgpt-shopping', 'gemini-web'], { shoppingEnabled: false }),+ ).toEqual(['gemini-web']);+ });++ it('returns an empty list for a prompt with no platforms', () => {+ expect(runnablePlatforms([], { shoppingEnabled: true })).toEqual([]);+ expect(runnablePlatforms(null, { shoppingEnabled: true })).toEqual([]);+ expect(runnablePlatforms(undefined, { shoppingEnabled: true })).toEqual([]);+ });++ // A prompt that lists only the unavailable platform must submit nothing at+ // all, rather than falling back to "no filter means run everything".+ it('leaves nothing to run when every platform is unavailable', () => {+ expect(runnablePlatforms([...UNAVAILABLE_PLATFORMS], { shoppingEnabled: true })).toEqual([]);+ });+});