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
feat(action-center): keep what became of an action's signals with its measured result (#1687)
Cihan3e543b38f1b7
diff --git a/docs/guides/action-center.mdx b/docs/guides/action-center.mdxindex 46e4e9a1e..06aafc3e9 100644--- a/docs/guides/action-center.mdx+++ b/docs/guides/action-center.mdx@@ -191,7 +191,7 @@ The **History** tab lists actions once they are In Progress, On Hold, CompletedClick an action to see **What was the goal?**, **What happened?** (the signals it was built from), its affected items and tasks, and the **Result**:-- When a completed action's week after closing is over, Ansvisor compares its metrics over the 7 days before it was raised with the 7 days after it closed. The result reads **Improved**, **No meaningful change** or **Declined**. It is measured after the action, not proven to be caused by it.+- When a completed action's week after closing is over, Ansvisor compares its metrics over the 7 days before it was raised with the 7 days after it closed. The result reads **Improved**, **No meaningful change** or **Declined**. It is measured after the action, not proven to be caused by it. The History drawer also says what became of the signals that raised it by then: how many ended, turned into another, were dismissed, or are still open.- A dismissed action is **Not measurable**, and so is one with no metric to read.- An action sent from a prompt's Improve tab reports on how many platforms its position improved. It is read again daily while the action is open and for 30 days after it is completed.diff --git a/server/src/lib/action-center/validate.js b/server/src/lib/action-center/validate.jsindex 31dfdfcdd..03c80f6b2 100644--- a/server/src/lib/action-center/validate.js+++ b/server/src/lib/action-center/validate.js@@ -217,6 +217,33 @@ export function deriveOutcome(metrics) {return 'no_meaningful_change';}+/**+ * What became of the signals that raised the action, when it is measured+ * (learning A3): how many ended (resolved, the condition gone), turned into+ * another kind of the same subject (resolved with `supersededBy`: still+ * there), were dismissed by a person, or are still open. The closest+ * measure to the action's own aim, and a cheap one. Null for an action no+ * signal raised (one sent from Content, Insights, Mentions…).+ */+export async function signalOutcome(actionId) {+ const { data, error } = await supabaseAdmin+ .from('action_signals')+ .select('signals(status, payload)')+ .eq('action_id', actionId);+ if (error) throw new Error(`action_signals: ${error.message}`);+ const signals = (data ?? []).map((row) => row.signals).filter(Boolean);+ if (!signals.length) return null;+ const counts = { total: signals.length, ended: 0, replaced: 0, dismissed: 0, open: 0 };+ for (const signal of signals) {+ if (signal.status === 'resolved') {+ if (signal.payload?.supersededBy) counts.replaced += 1;+ else counts.ended += 1;+ } else if (signal.status === 'dismissed') counts.dismissed += 1;+ else counts.open += 1;+ }+ return counts;+}+/*** Measure one closed action and record the result.*@@ -235,6 +262,10 @@ export async function validateAction(action, { now = new Date() } = {}) {// action, and would file most recent work as a decline.if (afterWindow.to >= utcDay(now)) return null;+ // What became of the signals that raised it, kept beside the metrics.+ const signals = await signalOutcome(action.id);+ const withSignals = (validation) => (signals ? { ...validation, signals } : validation);+// An action sent from a content opportunity is measured on its own prompts// and pages; the brand-wide numbers would bury a single piece of content.// An Improve action (PROMPT-004) likewise, on its one prompt, and a topic@@ -265,13 +296,13 @@ export async function validateAction(action, { now = new Date() } = {}) {const outcome = deriveOutcome(metrics);await write(action.id,- {+ withSignals({measuredAt: now.toISOString(),beforeWindow,afterWindow,metrics,scope: { kind: 'basket', prompts: scope.promptIds.length, pages: scope.pages.length },- },+ }),outcome,now,);@@ -284,7 +315,12 @@ export async function validateAction(action, { now = new Date() } = {}) {// in the rule that produced it, not a failure here — say so plainly rather// than inventing a metric it never claimed.if (kpiKeys.length === 0) {- await write(action.id, null, 'not_measurable', now);+ await write(+ action.id,+ signals ? { measuredAt: now.toISOString(), signals } : null,+ 'not_measurable',+ now,+ );return 'not_measurable';}@@ -303,7 +339,7 @@ export async function validateAction(action, { now = new Date() } = {}) {const outcome = deriveOutcome(metrics);await write(action.id,- { measuredAt: now.toISOString(), beforeWindow, afterWindow, metrics },+ withSignals({ measuredAt: now.toISOString(), beforeWindow, afterWindow, metrics }),outcome,now,);diff --git a/server/src/lib/action-center/validate.test.js b/server/src/lib/action-center/validate.test.jsindex 2addc1996..2530137fe 100644--- a/server/src/lib/action-center/validate.test.js+++ b/server/src/lib/action-center/validate.test.js@@ -20,8 +20,8 @@ import {const NOW = new Date('2026-09-20T04:00:00Z');const daysAgo = (n) => new Date(NOW.getTime() - n * 86_400_000).toISOString();-/** Records every write so a test can assert what was stored. */-function mockWrites() {+/** Records every write so a test can assert what was stored; `rows` answers a table's reads. */+function mockWrites(rows = {}) {const writes = { updated: [], inserted: [] };from.mockImplementation((table) => {const builder = {@@ -41,7 +41,7 @@ function mockWrites() {return builder;},then: (resolve, reject) =>- Promise.resolve({ data: [], error: null, count: 0 }).then(resolve, reject),+ Promise.resolve({ data: rows[table] ?? [], error: null, count: 0 }).then(resolve, reject),};return builder;});@@ -336,6 +336,45 @@ describe('validateAction', () => {expect(patch.validation).toBeNull();});+ it('keeps what became of the signals that raised it beside the metrics (learning A3)', async () => {+ const signal = (status, payload = {}) => ({ signals: { status, payload } });+ const writes = mockWrites({+ action_signals: [+ signal('resolved'),+ signal('resolved'),+ signal('resolved', { supersededBy: 'topic_dropped' }),+ signal('dismissed'),+ signal('acknowledged'),+ signal('new'),+ ],+ });+ rpc.mockResolvedValue({ data: { total_citations: 10 }, error: null });++ await validateAction(action(), { now: NOW });++ const patch = writes.updated.find((w) => w.table === 'actions').patch;+ expect(patch.validation.signals).toEqual({+ total: 6,+ ended: 2,+ replaced: 1,+ dismissed: 1,+ open: 2,+ });+ expect(patch.validation.metrics).toHaveLength(1);+ });++ it('keeps the signals of an action with nothing else to measure', async () => {+ const writes = mockWrites({ action_signals: [{ signals: { status: 'resolved' } }] });++ expect(await validateAction(action({ kpi_keys: [] }), { now: NOW })).toBe('not_measurable');++ const patch = writes.updated.find((w) => w.table === 'actions').patch;+ expect(patch.validation).toEqual({+ measuredAt: NOW.toISOString(),+ signals: { total: 1, ended: 1, replaced: 0, dismissed: 0, open: 0 },+ });+ });+it('does nothing for an action that never closed', async () => {const writes = mockWrites();diff --git a/web/messages/en.json b/web/messages/en.jsonindex 64b60e52d..d7487f542 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -2590,6 +2590,7 @@"goal": "What was the goal?","whatHappened": "What happened?","triggeredBy": "Consolidated from {count, plural, one {# signal} other {# signals}}",+ "signalsAfter": "Of the {total, plural, one {signal} other {# signals}} that raised it, when measured: {ended} ended{replaced, plural, =0 {} other {, # turned into another}}{dismissed, plural, =0 {} other {, # dismissed}}{open, plural, =0 {} other {, # still open}}.","result": "Result","visibilityChange": "Visibility Change","citationsChange": "Citations Change",diff --git a/web/src/components/action-center/history-drawer.test.tsx b/web/src/components/action-center/history-drawer.test.tsxindex 69707a9e4..c2d169057 100644--- a/web/src/components/action-center/history-drawer.test.tsx+++ b/web/src/components/action-center/history-drawer.test.tsx@@ -129,6 +129,30 @@ describe('HistoryDrawer', () => {expect(under('What was the goal?')).toContain('Nov 9');});+ it('says what became of the signals that raised it, beside the result (learning A3)', async () => {+ getActionSignals.mockResolvedValue([]);+ render(+ <HistoryDrawer+ brandId="b1"+ item={{+ ...item,+ signalsAfter: { total: 4, ended: 2, replaced: 1, dismissed: 0, open: 1 },+ }}+ onOpenChange={() => {}}+ />,+ );+ await act(async () => {});+ expect(under('Result')).toContain(+ 'Of the 4 signals that raised it, when measured: 2 ended, 1 turned into another, 1 still open.',+ );++ render(+ <HistoryDrawer brandId="b1" item={{ ...item, signalsAfter: null }} onOpenChange={() => {}} />,+ );+ await act(async () => {});+ expect(under('Result')).not.toContain('that raised it');+ });+it('keeps the general sentences when the signals cannot be read', async () => {getActionSignals.mockRejectedValue(new Error('offline'));render(<HistoryDrawer brandId="b1" item={item} onOpenChange={() => {}} />);diff --git a/web/src/components/action-center/history-drawer.tsx b/web/src/components/action-center/history-drawer.tsxindex 671accdce..1b75cae84 100644--- a/web/src/components/action-center/history-drawer.tsx+++ b/web/src/components/action-center/history-drawer.tsx@@ -208,6 +208,10 @@ export function HistoryDrawer({<section><p className="text-xs font-medium text-muted-foreground">{t('drawer.result')}</p>+ {item.signalsAfter && (+ // The closest measure to the action's own aim: did what raised it end?+ <p className="mt-1 text-xs">{t('drawer.signalsAfter', { ...item.signalsAfter })}</p>+ )}{!measured && (// The honest state, and the reason for it. Everything above this// line is recorded; the effect is not, because nothing re-readsdiff --git a/web/src/lib/action-center/history.ts b/web/src/lib/action-center/history.tsindex f1e8d7126..7ccfd876c 100644--- a/web/src/lib/action-center/history.ts+++ b/web/src/lib/action-center/history.ts@@ -80,6 +80,19 @@ export interface TriggerSignal {detectedAt: string;}+/**+ * What became of the signals that raised an action, when it was measured+ * (learning A3): ended (the condition gone), replaced (still there as+ * another kind), dismissed by a person, or still open.+ */+export interface SignalOutcome {+ total: number;+ ended: number;+ replaced: number;+ dismissed: number;+ open: number;+}+export interface ActionHistoryItem {id: string;actionNo: number;@@ -102,6 +115,8 @@ export interface ActionHistoryItem {affected: AffectedEntity[];/** Empty until something measures an action's effect. */results: ActionResultMetric[];+ /** Its signals when it was measured; absent before, or with no signal behind it. */+ signalsAfter?: SignalOutcome | null;/** Improve actions only: positions per platform against the baseline (PROMPT-008). */positionOutcome: ImproveOutcome | null;tasks: ActionHistoryTask[];diff --git a/web/src/lib/actions/action-history.ts b/web/src/lib/actions/action-history.tsindex 875f8c51f..d9d044ee9 100644--- a/web/src/lib/actions/action-history.ts+++ b/web/src/lib/actions/action-history.ts@@ -28,6 +28,7 @@ import {type ActionHistoryTask,type ActionResultMetric,type AffectedEntity,+ type SignalOutcome,type TriggerSignal,} from '@/lib/action-center/history';@@ -57,14 +58,32 @@ const HISTORY_COLUMNS =/** What the validation sweep stores on an action. */interface ValidationSnapshot {measuredAt: string;- beforeWindow: { from: string; to: string };- afterWindow: { from: string; to: string };- metrics: {+ // Absent for an action with no metric to measure, kept for its signals.+ beforeWindow?: { from: string; to: string };+ afterWindow?: { from: string; to: string };+ metrics?: {metric: string;unit: string;before: number | null;after: number | null;}[];+ /** What became of the signals that raised it (learning A3). */+ signals?: SignalOutcome;+}++/** The signals' counts, when the sweep kept them and they add up. */+function signalsFrom(validation: ValidationSnapshot | null): SignalOutcome | null {+ const s = validation?.signals;+ if (!s || typeof s !== 'object') return null;+ const n = (value: unknown) => (typeof value === 'number' && value >= 0 ? value : 0);+ const counts = {+ total: n(s.total),+ ended: n(s.ended),+ replaced: n(s.replaced),+ dismissed: n(s.dismissed),+ open: n(s.open),+ };+ return counts.total > 0 ? counts : null;}/**@@ -262,6 +281,7 @@ export async function getActionHistory(triggerSignals,affected: affectedFrom(row.kind, row.payload ?? {}, triggerSignals.length),results,+ signalsAfter: signalsFrom(row.validation),tasks: tasksByAction.get(row.id) ?? [],assignee: row.assignee_id ? (profiles.get(row.assignee_id) ?? null) : null,dueDate: row.due_date ?? null,