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): order the candidate queue by what each action covers (#866)
Gökhan Geyik67b7dce5feb6
diff --git a/server/src/config/action-engine.js b/server/src/config/action-engine.jsindex 6f6645c20..ffa5aab52 100644--- a/server/src/config/action-engine.js+++ b/server/src/config/action-engine.js@@ -328,9 +328,16 @@ export const ENGINE_THRESHOLDS = Object.freeze({impactHigh: 200,impactMedium: 65,impactLow: 30,- /** Per linked signal, up to `evidenceCap` signals: at most 15. */- evidencePerSignal: 1.5,- evidenceCap: 10,+ /**+ * Per doubling of the targets the action covers, up to `evidenceMax`.+ * Targets rather than signals: the library folds a group of prompts into+ * one signal and keeps at most five signals a kind, so counting signals+ * scored nearly every candidate the same. Logarithmic, so fifty prompts+ * outrank five and five outrank one, but breadth never buys a grade.+ * 1 target → 2.5, 5 → 6.5, 11 → 9, 50 → 14.2.+ */+ evidencePerDoubling: 2.5,+ evidenceMax: 15,/** Per day waited, up to `ageCapDays` days: at most 42. */agePerDay: 3,ageCapDays: 14,diff --git a/server/src/lib/action-center/candidates.js b/server/src/lib/action-center/candidates.jsindex a062528f8..303248290 100644--- a/server/src/lib/action-center/candidates.js+++ b/server/src/lib/action-center/candidates.js@@ -47,10 +47,14 @@ const IMPACT_SCORE = {* opportunity outrank a visibility collapse is not a priority order, it is a* vote.*- * @param {{ impact: string, signalCount: number, firstSeenAt?: string|Date }} candidate+ * Evidence is the action's reach — how many prompts, pages, sources or+ * topics it covers (`payload.targetCount`) — and falls back to the signal+ * count for a definition whose payload does not name its targets.+ *+ * @param {{ impact: string, signalCount: number, reach?: number, firstSeenAt?: string|Date }} candidate* @param {Date} now*/-export function scoreCandidate({ impact, signalCount, firstSeenAt }, now = new Date()) {+export function scoreCandidate({ impact, signalCount, reach, firstSeenAt }, now = new Date()) {const base = IMPACT_SCORE[impact] ?? IMPACT_SCORE.low;// Defensive rather than trusting: a caller that forgets to pass the count@@ -58,7 +62,11 @@ export function scoreCandidate({ impact, signalCount, firstSeenAt }, now = new D// the whole queue to alphabetical order. A scoring bug that still promotes// something every night, just the wrong thing, is not one anybody notices.const count = Number.isFinite(signalCount) ? Math.max(signalCount, 0) : 0;- const evidence = Math.min(count, priority.evidenceCap) * priority.evidencePerSignal;+ const breadth = Number.isFinite(reach) && reach > 0 ? reach : count;+ const evidence = Math.min(+ Math.log2(1 + breadth) * priority.evidencePerDoubling,+ priority.evidenceMax,+ );const seen = firstSeenAt ? new Date(firstSeenAt).getTime() : now.getTime();const waitedDays = Math.max(0, Math.floor((now.getTime() - seen) / DAY_MS));diff --git a/server/src/lib/action-center/candidates.test.js b/server/src/lib/action-center/candidates.test.jsindex 213b9f17d..db76921cb 100644--- a/server/src/lib/action-center/candidates.test.js+++ b/server/src/lib/action-center/candidates.test.js@@ -47,8 +47,38 @@ describe('scoreCandidate', () => {});it('stops paying for evidence past the cap', () => {- const capped = scoreCandidate(candidate({ signalCount: priority.evidenceCap }), NOW);- expect(scoreCandidate(candidate({ signalCount: 500 }), NOW)).toBe(capped);+ const base = scoreCandidate(candidate({ signalCount: 0 }), NOW);+ expect(scoreCandidate(candidate({ reach: 100_000 }), NOW)).toBe(base + priority.evidenceMax);+ });++ /**+ * What the queue sorted on before: signals. The library folds fifty prompts+ * into one signal and keeps five signals a kind, so nearly every candidate+ * scored the same and the queue promoted in id order. Reach is what tells+ * fifty prompts from two topics.+ */+ it('ranks by how much the action covers, not how many signals carry it', () => {+ const wide = scoreCandidate(candidate({ signalCount: 1, reach: 50 }), NOW);+ const narrow = scoreCandidate(candidate({ signalCount: 5, reach: 2 }), NOW);+ expect(wide).toBeGreaterThan(narrow);+ });++ it('separates five targets from one, and fifty from five', () => {+ const score = (reach) => scoreCandidate(candidate({ reach }), NOW);+ expect(score(5)).toBeGreaterThan(score(1));+ expect(score(50)).toBeGreaterThan(score(5));+ });++ it('falls back to the signal count when the payload names no targets', () => {+ expect(scoreCandidate(candidate({ signalCount: 4, reach: undefined }), NOW)).toBe(+ scoreCandidate(candidate({ signalCount: 1, reach: 4 }), NOW),+ );+ });++ /** Breadth moves a candidate within its grade, never across one. */+ it('never lets breadth alone cross a grade', () => {+ const widest = scoreCandidate(candidate({ impact: 'medium', reach: 100_000 }), NOW);+ expect(widest).toBeLessThan(scoreCandidate(candidate({ impact: 'high', reach: 1 }), NOW));});/**diff --git a/server/src/lib/action-center/generate.js b/server/src/lib/action-center/generate.jsindex c3488d693..a9e45537f 100644--- a/server/src/lib/action-center/generate.js+++ b/server/src/lib/action-center/generate.js@@ -271,7 +271,11 @@ export async function generateActionsForBrand(brandId, { now = new Date(), sourcconst existing = waiting.get(definition.id);const firstSeenAt = existing?.first_seen_at ?? nowIso;- const score = scoreCandidate({ impact, signalCount: unclaimed.length, firstSeenAt }, now);+ const reach = payload.targetCount;+ const score = scoreCandidate(+ { impact, signalCount: unclaimed.length, reach, firstSeenAt },+ now,+ );const row = {brand_id: brandId,definition_id: definition.id,@@ -330,6 +334,7 @@ export async function generateActionsForBrand(brandId, { now = new Date(), sourc// the scorer so the same shape can be scored straight out of the// database, where the signals themselves are just ids.signalCount: unclaimed.length,+ reach,payload,firstSeenAt,});