Skip to content

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.

feat(action-center): read an action's effect a week, two weeks and a month after it closed (learning B1) (#1694)

Cihan5e7f80d1dd66
diff --git a/docs/guides/action-center.mdx b/docs/guides/action-center.mdx
index c42f55d07..abf7fc7ef 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, Completed
Click 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**, **Mixed**, **No meaningful change** or **Declined**, judged by the action's main metric (the first one it names): **Mixed** when another metric it names moved the other way, or, without the main one measured, when the ones it names moved both ways. Other metrics show beside but don't count. It is measured after the action, not proven to be caused by it. An action that names its prompts or pages is measured on them, with the brand-wide figures over the same days beside; when they can't show its main metric (citations, for prompts), it is measured brand-wide. A Site Audit fix is judged by its pages audited again since it closed: the check that raised it passing, or a low score past the line; with none audited again yet, by the metrics. When tracking missed nights in either week, the drawer says so, and mentions and citations are read at a full week's worth from the nights that ran. More than two in one week are too few to read them from: they're left out of the result, and an action whose main metric is one of them reads **Not measurable**. 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 completed action's metrics are read three times: over the week ending 7, 14 and 30 days after it closed, each against the 7 days before it was raised. Until the reading on day 30, which is final, the result reads *so far*, and the drawer lists each reading. The result reads **Improved**, **Mixed**, **No meaningful change** or **Declined**, judged by the action's main metric (the first one it names): **Mixed** when another metric it names moved the other way, or, without the main one measured, when the ones it names moved both ways. Other metrics show beside but don't count. It is measured after the action, not proven to be caused by it. An action that names its prompts or pages is measured on them, with the brand-wide figures over the same days beside; when they can't show its main metric (citations, for prompts), it is measured brand-wide. A Site Audit fix is judged by its pages audited again since it closed: the check that raised it passing, or a low score past the line; with none audited again yet, by the metrics. When tracking missed nights in either week, the drawer says so, and mentions and citations are read at a full week's worth from the nights that ran. More than two in one week are too few to read them from: they're left out of the result, and an action whose main metric is one of them reads **Not measurable**. 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.
- Only a completed action is measured: a dismissed one reads **Not measured**, dismissed. One with no metric to read is **Not measurable**.
- 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/config/action-engine.js b/server/src/config/action-engine.js
index da8ba25f1..9069c1554 100644
--- a/server/src/config/action-engine.js
+++ b/server/src/config/action-engine.js
@@ -378,6 +378,17 @@ export const ENGINE_THRESHOLDS = Object.freeze({
* the main metric is one).
*/
maxGapDays: 2,
+
+ /**
+ * The day after an action closed its last, final reading is taken on
+ * (learning B1). Its effect is read a week and two weeks on too, each
+ * over the window's length ending that day, against the same week
+ * before it was raised: a week is short for AI answers to take in a
+ * change to a page, so the final read is a month on, as an Improve
+ * action's is (improve-outcome.js); the earlier ones show where it was
+ * heading.
+ */
+ finalReadingDay: 30,
}),
});
diff --git a/server/src/lib/action-center/validate.js b/server/src/lib/action-center/validate.js
index 899c875a7..d7e5dd61f 100644
--- a/server/src/lib/action-center/validate.js
+++ b/server/src/lib/action-center/validate.js
@@ -59,6 +59,22 @@ export const VALIDATION_WAIT_DAYS = MEASUREMENT_WINDOW_DAYS + 1;
*/
export const MEANINGFUL_CHANGE_RATIO = validation.meaningfulChangeRatio;
+/** The days after closing an action's effect is read on; the last is final (learning B1). */
+export const FINAL_READING_DAY = validation.finalReadingDay;
+export const READING_DAYS = [
+ MEASUREMENT_WINDOW_DAYS,
+ 2 * MEASUREMENT_WINDOW_DAYS,
+ FINAL_READING_DAY,
+];
+
+/** The window a reading `day` days after the close covers: the week ending that day. */
+export function readingWindow(closedAt, day) {
+ return windowStartingAfter(
+ new Date(closedAt + (day - MEASUREMENT_WINDOW_DAYS) * DAY_MS),
+ MEASUREMENT_WINDOW_DAYS,
+ );
+}
+
/** Days a window may lack a tracking run and still be compared (learning A6). */
export const MAX_GAP_DAYS = validation.maxGapDays;
@@ -380,18 +396,64 @@ export async function validateAction(action, { now = new Date() } = {}) {
if (!closedAt) return null;
const beforeWindow = windowEndingBefore(new Date(action.created_at), MEASUREMENT_WINDOW_DAYS);
- const afterWindow = windowStartingAfter(new Date(closedAt), MEASUREMENT_WINDOW_DAYS);
- // The window has to be complete. Measuring a window whose last days have
+ // The readings due (learning B1): the days whose week is over, not read
+ // yet. A window has to be complete: measuring one whose last days have
// not happened yet reads low for a reason that has nothing to do with the
// action, and would file most recent work as a decline.
- if (afterWindow.to >= utcDay(now)) return null;
+ const previous = Array.isArray(action.validation?.readings) ? action.validation.readings : [];
+ const taken = new Set(previous.map((r) => r.day));
+ const due = READING_DAYS.filter(
+ (day) => !taken.has(day) && readingWindow(closedAt, day).to < utcDay(now),
+ );
+ if (due.length === 0) return null;
// What became of the signals that raised it (A3), and for a Site Audit
// fix whether its pages pass when audited again (A2), kept beside the
// metrics. A fix whose pages were audited again is judged by that: the
// check passing is its aim.
const [signals, audit] = await Promise.all([signalOutcome(action.id), auditRecheck(action)]);
+
+ // Each reading due, in order; the action keeps the last one's figures and
+ // verdict, every reading's verdict and metrics, and whether it's final.
+ const readings = [...previous];
+ let last = null;
+ for (const day of due) {
+ last = await measureReading(action, {
+ beforeWindow,
+ afterWindow: readingWindow(closedAt, day),
+ signals,
+ audit,
+ now,
+ });
+ readings.push({
+ day,
+ outcome: last.verdict,
+ ...(last.kept?.afterWindow ? { afterWindow: last.kept.afterWindow } : {}),
+ ...(last.kept?.metrics ? { metrics: last.kept.metrics } : {}),
+ });
+ }
+ const final = readings.some((r) => r.day === FINAL_READING_DAY);
+ await write(
+ action.id,
+ {
+ measuredAt: now.toISOString(),
+ ...(last.kept ?? {}),
+ readings,
+ ...(final ? { final: true } : {}),
+ },
+ last.verdict,
+ now,
+ { day: due[due.length - 1], final },
+ );
+ return last.verdict;
+}
+
+/**
+ * One reading of a closed action (learning B1): what it keeps and its
+ * verdict, over the week `afterWindow` against the week before it was raised.
+ */
+async function measureReading(action, { beforeWindow, afterWindow, signals, audit, now }) {
// The verdict from the metrics kept, by its main metric; given `aims`,
// only the metrics the action names count (see deriveOutcome).
const finish = async (validation, aims = null) => {
@@ -438,8 +500,7 @@ export async function validateAction(action, { now = new Date() } = {}) {
? 'not_measurable'
: deriveOutcome(comparable, read.primary, aims);
const verdict = (audit && auditOutcome(audit)) ?? outcome;
- await write(action.id, kept, verdict, now);
- return verdict;
+ return { kept, verdict };
};
// An action sent from a content opportunity is measured on its own prompts
@@ -580,7 +641,7 @@ export async function validateAction(action, { now = new Date() } = {}) {
});
}
-async function write(actionId, validation, outcome, now) {
+async function write(actionId, validation, outcome, now, { day = null, final = false } = {}) {
const { error } = await supabaseAdmin
.from('actions')
.update({ validation, outcome, validated_at: now.toISOString() })
@@ -589,11 +650,19 @@ async function write(actionId, validation, outcome, now) {
// The trail carries the verdict, so the drawer's History tab shows when the
// measurement happened alongside the work that preceded it.
- await supabaseAdmin
- .from('action_events')
- .insert({ action_id: actionId, event: 'outcome_measured', data: { outcome } });
+ await supabaseAdmin.from('action_events').insert({
+ action_id: actionId,
+ event: 'outcome_measured',
+ // Which reading (learning B1), and whether it's the final one.
+ data: { outcome, ...(day ? { day } : {}), ...(final ? { final: true } : {}) },
+ });
}
+/** The actions the sweep reads, and how many at a time. */
+export const SWEEP_FILTER =
+ 'outcome.eq.pending_measurement,and(validation->readings.not.is.null,validation->>final.is.null)';
+const SWEEP_PAGE = 500;
+
/**
* Nightly sweep: measure every closed action whose settling period has passed.
*
@@ -602,28 +671,40 @@ async function write(actionId, validation, outcome, now) {
*/
export async function sweepActionValidation({ now = new Date() } = {}) {
const cutoff = new Date(now.getTime() - VALIDATION_WAIT_DAYS * DAY_MS).toISOString();
- const { data, error } = await supabaseAdmin
- .from('actions')
- .select('id, brand_id, kind, payload, kpi_keys, created_at, completed_at')
- .eq('status', 'completed')
- .eq('outcome', 'pending_measurement')
- .not('completed_at', 'is', null)
- .lte('completed_at', cutoff)
- .limit(500);
- if (error) {
- logger.error({ err: error }, '[action-validation] could not list pending actions');
- return { measured: 0, failed: 0 };
- }
-
let measured = 0;
let failed = 0;
- for (const action of data ?? []) {
- try {
- if (await validateAction(action, { now })) measured += 1;
- } catch (err) {
- failed += 1;
- logger.error({ err, actionId: action.id }, '[action-validation] measurement failed');
+ // In pages by id: an action waiting for a later reading stays on the list
+ // night after night, and must not crowd out the ones due.
+ let afterId = null;
+ for (;;) {
+ let query = supabaseAdmin
+ .from('actions')
+ .select('id, brand_id, kind, payload, kpi_keys, created_at, completed_at, validation')
+ .eq('status', 'completed')
+ // Never measured, or read but not for the last time yet (learning B1).
+ // One measured once before the later readings came keeps its result.
+ .or(SWEEP_FILTER)
+ .not('completed_at', 'is', null)
+ .lte('completed_at', cutoff)
+ .order('id')
+ .limit(SWEEP_PAGE);
+ if (afterId) query = query.gt('id', afterId);
+ const { data, error } = await query;
+ if (error) {
+ logger.error({ err: error }, '[action-validation] could not list pending actions');
+ break;
+ }
+
+ for (const action of data ?? []) {
+ try {
+ if (await validateAction(action, { now })) measured += 1;
+ } catch (err) {
+ failed += 1;
+ logger.error({ err, actionId: action.id }, '[action-validation] measurement failed');
+ }
}
+ if (!data || data.length < SWEEP_PAGE) break;
+ afterId = data[data.length - 1].id;
}
logger.info({ measured, failed }, '[action-validation] sweep complete');
diff --git a/server/src/lib/action-center/validate.test.js b/server/src/lib/action-center/validate.test.js
index 3a0b2eb1b..d0704f418 100644
--- a/server/src/lib/action-center/validate.test.js
+++ b/server/src/lib/action-center/validate.test.js
@@ -11,6 +11,8 @@ vi.mock('../logger.js', () => ({
import {
MAX_GAP_DAYS,
+ sweepActionValidation,
+ SWEEP_FILTER,
MEANINGFUL_CHANGE_RATIO,
VALIDATION_WAIT_DAYS,
deriveOutcome,
@@ -27,9 +29,13 @@ const EVERY_NIGHT = Array.from({ length: 60 }, (_, i) => ({ completed_at: daysAg
/** Records every write so a test can assert what was stored; `rows` answers a table's reads. */
function mockWrites(rows = {}) {
rows = { tracking_runs: EVERY_NIGHT, ...rows };
- const writes = { updated: [], inserted: [] };
+ const writes = { updated: [], inserted: [], ors: [] };
from.mockImplementation((table) => {
const builder = {
+ or: (filter) => {
+ writes.ors.push({ table, filter });
+ return builder;
+ },
select: () => builder,
eq: () => builder,
is: () => builder,
@@ -395,7 +401,11 @@ describe('validateAction', () => {
expect(outcome).toBe('not_measurable');
expect(rpc).not.toHaveBeenCalled();
const patch = writes.updated.find((w) => w.table === 'actions').patch;
- expect(patch.validation).toBeNull();
+ // Nothing measured, the reading kept (learning B1).
+ expect(patch.validation).toEqual({
+ measuredAt: NOW.toISOString(),
+ readings: [{ day: 7, outcome: 'not_measurable' }],
+ });
});
it('keeps what became of the signals that raised it beside the metrics (learning A3)', async () => {
@@ -434,6 +444,7 @@ describe('validateAction', () => {
expect(patch.validation).toEqual({
measuredAt: NOW.toISOString(),
signals: { total: 1, ended: 1, replaced: 0, dismissed: 0, open: 0 },
+ readings: [{ day: 7, outcome: 'not_measurable' }],
});
});
@@ -744,6 +755,140 @@ describe('validateAction', () => {
});
});
+ describe('read a week, two weeks and a month on (learning B1)', () => {
+ /** The brand's citations by the window's last day: 100 before, then by `after`. */
+ const byDay = (after) =>
+ rpc.mockImplementation(async (_name, args) => {
+ const end = args.p_day_to;
+ const value = Object.entries(after).find(([since]) => end >= since)?.[1] ?? 100;
+ return { data: { total_citations: value }, error: null };
+ });
+
+ it('takes the week-on reading first, final later, the event naming the day', async () => {
+ const writes = mockWrites();
+ byDay({ [daysAgo(7).slice(0, 10)]: 140 });
+
+ expect(await validateAction(action(), { now: NOW })).toBe('improved');
+ const { validation } = writes.updated.find((w) => w.table === 'actions').patch;
+ expect(validation.readings.map((r) => [r.day, r.outcome])).toEqual([[7, 'improved']]);
+ expect(validation.final).toBeUndefined();
+ const event = writes.inserted.find((w) => w.table === 'action_events');
+ expect(event.rows.data).toEqual({ outcome: 'improved', day: 7 });
+ });
+
+ it('takes every reading due at once, the last one final and the verdict', async () => {
+ const writes = mockWrites();
+ // Closed 40 days ago: up by week one and two, back down by the month.
+ byDay({ [daysAgo(12).slice(0, 10)]: 96, [daysAgo(34).slice(0, 10)]: 150 });
+
+ const outcome = await validateAction(
+ action({ created_at: daysAgo(50), completed_at: daysAgo(40) }),
+ { now: NOW },
+ );
+ expect(outcome).toBe('no_meaningful_change');
+ const { validation, outcome: stored } = writes.updated.find(
+ (w) => w.table === 'actions',
+ ).patch;
+ expect(stored).toBe('no_meaningful_change');
+ expect(validation.readings.map((r) => [r.day, r.outcome])).toEqual([
+ [7, 'improved'],
+ [14, 'improved'],
+ [30, 'no_meaningful_change'],
+ ]);
+ expect(validation.final).toBe(true);
+ // The weeks ending 7, 14 and 30 days after the close.
+ expect(validation.readings.map((r) => r.afterWindow.to)).toEqual([
+ daysAgo(33).slice(0, 10),
+ daysAgo(26).slice(0, 10),
+ daysAgo(10).slice(0, 10),
+ ]);
+ expect(writes.inserted.find((w) => w.table === 'action_events').rows.data).toEqual({
+ outcome: 'no_meaningful_change',
+ day: 30,
+ final: true,
+ });
+ });
+
+ it('adds the readings due to those it has, and reads nothing once final', async () => {
+ let writes = mockWrites();
+ byDay({ [daysAgo(20).slice(0, 10)]: 140 });
+ const earlier = { readings: [{ day: 7, outcome: 'improved' }] };
+ await validateAction(action({ completed_at: daysAgo(20), validation: earlier }), {
+ now: NOW,
+ });
+ const { validation } = writes.updated.find((w) => w.table === 'actions').patch;
+ expect(validation.readings.map((r) => r.day)).toEqual([7, 14]);
+
+ writes = mockWrites();
+ const final = {
+ final: true,
+ readings: [7, 14, 30].map((day) => ({ day, outcome: 'improved' })),
+ };
+ expect(
+ await validateAction(action({ completed_at: daysAgo(40), validation: final }), {
+ now: NOW,
+ }),
+ ).toBeNull();
+ expect(writes.updated).toHaveLength(0);
+ });
+ });
+
+ it('sweeps the closed actions not read for the last time yet (learning B1)', async () => {
+ const writes = mockWrites({
+ actions: [
+ {
+ id: 'a1',
+ brand_id: 'brand-1',
+ kpi_keys: ['citations'],
+ created_at: daysAgo(30),
+ completed_at: daysAgo(10),
+ validation: null,
+ },
+ ],
+ });
+ rpc.mockResolvedValue({ data: { total_citations: 10 }, error: null });
+
+ expect(await sweepActionValidation({ now: NOW })).toEqual({ measured: 1, failed: 0 });
+ expect(writes.ors).toEqual([{ table: 'actions', filter: SWEEP_FILTER }]);
+ });
+
+ it('reads the list in pages, so actions waiting for a later reading crowd out none due', async () => {
+ // A full page of actions read a week on, their next reading not due yet.
+ const waiting = Array.from({ length: 500 }, (_, i) => ({
+ id: `w${String(i).padStart(3, '0')}`,
+ brand_id: 'brand-1',
+ kpi_keys: ['citations'],
+ created_at: daysAgo(30),
+ completed_at: daysAgo(10),
+ validation: { readings: [{ day: 7, outcome: 'improved' }] },
+ }));
+ const pages = [waiting, []];
+ const after = [];
+ from.mockImplementation(() => {
+ const page = pages.shift();
+ const builder = {
+ select: () => builder,
+ eq: () => builder,
+ or: () => builder,
+ not: () => builder,
+ lte: () => builder,
+ order: () => builder,
+ limit: () => builder,
+ gt: (_column, id) => {
+ after.push(id);
+ return builder;
+ },
+ then: (resolve, reject) =>
+ Promise.resolve({ data: page, error: null }).then(resolve, reject),
+ };
+ return builder;
+ });
+
+ expect(await sweepActionValidation({ now: NOW })).toEqual({ measured: 0, failed: 0 });
+ expect(after).toEqual(['w499']);
+ expect(pages).toEqual([]);
+ });
+
it('does nothing for an action that never closed', async () => {
const writes = mockWrites();
diff --git a/web/messages/en.json b/web/messages/en.json
index a9ce859a0..f8a13863a 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -1307,7 +1307,7 @@
"task_run_failed": "{task} — the automatic attempt failed; it needs doing by hand",
"task_awaiting_approval": "{task} — waiting for your approval before it reaches outside Ansvisor",
"position_outcome_recorded": "{measurable, plural, =0 {30-day result: not enough data to compare positions} other {30-day result: position improved on {improved} of # platforms}}",
- "outcome_measured": "{outcome, select, improved {Result: metrics improved after this action closed} mixed {Result: mixed after this action closed} declined {Result: metrics declined after this action closed} no_meaningful_change {Result: no meaningful change in metrics after this action closed} not_measurable {Result: could not be measured} other {Result measured}}"
+ "outcome_measured": "{day, plural, =0 {} other {Day #{final, select, yes {, final} other {}} · }}{outcome, select, improved {Result: metrics improved after this action closed} mixed {Result: mixed after this action closed} declined {Result: metrics declined after this action closed} no_meaningful_change {Result: no meaningful change in metrics after this action closed} not_measurable {Result: could not be measured} other {Result measured}}"
},
"deleteTask": "Delete task",
"addTask": "Add task",
@@ -2616,11 +2616,14 @@
"whatHappened": "What happened?",
"triggeredBy": "Consolidated from {count, plural, one {# signal} other {# signals}}",
"dismissedBecause": "Dismissed: {reason}.",
+ "readings": "Read after it closed: {list}.",
+ "reading": "day {day}, {outcome}",
+ "finalOn": "The final reading is on day {day}.",
"measuredOn": "Measured on the {entity, select, pages {{count, plural, one {page} other {# pages}}} other {{count, plural, one {prompt} other {# prompts}}}} it named.",
"brandWide": "Brand-wide over the same days: {list}",
"primary": "Judged by {metric}, its main metric.",
- "gaps": "Tracking missed {before, plural, =0 {} one {# night of the week before it} other {# nights of the week before it}}{before, plural, =0 {} other {{after, plural, =0 {} other { and }}}}{after, plural, =0 {} one {# night of the week after it} other {# nights of the week after it}}: mentions and citations are counted as for a full week.",
- "gapsTooMany": "Tracking missed {before, plural, =0 {} one {# night of the week before it} other {# nights of the week before it}}{before, plural, =0 {} other {{after, plural, =0 {} other { and }}}}{after, plural, =0 {} one {# night of the week after it} other {# nights of the week after it}}: too many to compare mentions and citations fairly, so they are left out of the result.",
+ "gaps": "Tracking missed {before, plural, =0 {} one {# night of the week before it} other {# nights of the week before it}}{before, plural, =0 {} other {{after, plural, =0 {} other { and }}}}{after, plural, =0 {} one {# night of the week of the latest reading} other {# nights of the week of the latest reading}}: mentions and citations are counted as for a full week.",
+ "gapsTooMany": "Tracking missed {before, plural, =0 {} one {# night of the week before it} other {# nights of the week before it}}{before, plural, =0 {} other {{after, plural, =0 {} other { and }}}}{after, plural, =0 {} one {# night of the week of the latest reading} other {# nights of the week of the latest reading}}: too many to compare mentions and citations fairly, so they are left out of the result.",
"auditAfter": "Audited again since it closed: {passed} of {audited} {audited, plural, one {page passes} other {pages pass}}.",
"auditNotYet": "None of its {pages, plural, one {page} other {# pages}} was audited again since it closed: the result is from the metrics.",
"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}}.",
@@ -2657,6 +2660,7 @@
"description": "Select a brand to view its action history."
},
"positionResult": "{measurable, plural, =0 {Positions: not enough data} other {Position improved on {improved} of # platforms}}",
+ "outcomeSoFar": "so far: day {day} of {final}",
"outcomeHint": {
"pending_measurement": "no result recorded",
"improved": "vs before",
diff --git a/web/src/components/action-center/history-drawer.test.tsx b/web/src/components/action-center/history-drawer.test.tsx
index d6cdb3cd9..0d1659e0d 100644
--- a/web/src/components/action-center/history-drawer.test.tsx
+++ b/web/src/components/action-center/history-drawer.test.tsx
@@ -236,7 +236,7 @@ describe('HistoryDrawer', () => {
);
await act(async () => {});
expect(under('Result')).toContain(
- 'Tracking missed 1 night of the week before it and 2 nights of the week after it: mentions and citations are counted as for a full week.',
+ 'Tracking missed 1 night of the week before it and 2 nights of the week of the latest reading: mentions and citations are counted as for a full week.',
);
render(
@@ -248,7 +248,7 @@ describe('HistoryDrawer', () => {
);
await act(async () => {});
expect(under('Result')).toContain(
- 'Tracking missed 4 nights of the week after it: too many to compare mentions and citations fairly, so they are left out of the result.',
+ 'Tracking missed 4 nights of the week of the latest reading: too many to compare mentions and citations fairly, so they are left out of the result.',
);
});
@@ -265,6 +265,29 @@ describe('HistoryDrawer', () => {
expect(under('Result')).toContain('Dismissed: The data behind it is wrong.');
});
+ it('lists the readings after it closed, and when the final one comes (learning B1)', async () => {
+ getActionSignals.mockResolvedValue([]);
+ render(
+ <HistoryDrawer
+ brandId="b1"
+ item={{
+ ...item,
+ outcome: 'mixed',
+ readings: [
+ { day: 7, outcome: 'improved' },
+ { day: 14, outcome: 'mixed' },
+ ],
+ outcomeFinal: false,
+ }}
+ onOpenChange={() => {}}
+ />,
+ );
+ await act(async () => {});
+ expect(under('Result')).toContain(
+ 'Read after it closed: day 7, Improved · day 14, Mixed. The final reading is on day 30.',
+ );
+ });
+
it('says a dismissed action was not measured, not that nothing could be read', async () => {
getActionSignals.mockResolvedValue([]);
for (const outcome of ['not_measurable', 'pending_measurement'] as const) {
diff --git a/web/src/components/action-center/history-drawer.tsx b/web/src/components/action-center/history-drawer.tsx
index 72e464c67..dc9445680 100644
--- a/web/src/components/action-center/history-drawer.tsx
+++ b/web/src/components/action-center/history-drawer.tsx
@@ -14,7 +14,7 @@ import {
SheetTitle,
} from '@/components/ui/sheet';
import { actionGoal, actionTexts } from '@/lib/action-center/display';
-import type { ActionHistoryItem } from '@/lib/action-center/history';
+import { FINAL_READING_DAY, type ActionHistoryItem } from '@/lib/action-center/history';
import { UNCOUNTED_TASK_STATUSES } from '@/lib/action-center/registry';
import { ActionIcon, PriorityBadge } from './action-table';
import { HistoryStatusBadge } from './history-table';
@@ -92,6 +92,7 @@ export function HistoryDrawer({
const tSources = useTranslations('actionCenter.signalsPage.sources');
const tRegistry = useTranslations('actionCenter.registry');
const tDismiss = useTranslations('actionCenter.dismissReason');
+ const tOutcome = useTranslations('actionCenter.actionOutcome');
const tAffected = useTranslations('actionCenter.historyPage.affected');
const router = useRouter();
@@ -216,6 +217,21 @@ export function HistoryDrawer({
})}
</p>
)}
+ {!!item.readings?.length && (
+ <p className="mt-1 text-xs">
+ {t('drawer.readings', {
+ list: item.readings
+ .map((r) => t('drawer.reading', { day: r.day, outcome: tOutcome(r.outcome) }))
+ .join(' · '),
+ })}
+ {!item.outcomeFinal && (
+ <span className="text-muted-foreground">
+ {' '}
+ {t('drawer.finalOn', { day: FINAL_READING_DAY })}
+ </span>
+ )}
+ </p>
+ )}
{item.primaryMetric && (
<p className="mt-1 text-xs text-muted-foreground">
{t('drawer.primary', { metric: tRegistry(`${item.primaryMetric}.name`) })}
diff --git a/web/src/components/action-center/history-table.test.tsx b/web/src/components/action-center/history-table.test.tsx
index 26546705e..4606c24e9 100644
--- a/web/src/components/action-center/history-table.test.tsx
+++ b/web/src/components/action-center/history-table.test.tsx
@@ -110,6 +110,31 @@ describe('HistoryTable', () => {
await act(async () => root.unmount());
});
+ it('says a result is so far until its final reading, a month on (learning B1)', async () => {
+ const result = async (over: Partial<ActionHistoryItem>) => {
+ const root = await render(
+ <HistoryTable items={[item(over)]} selectedId={null} onSelect={() => {}} />,
+ );
+ const text = document.body.querySelector('tbody')!.textContent;
+ await act(async () => root.unmount());
+ return text;
+ };
+ const readings = [
+ { day: 7, outcome: 'improved' as const },
+ { day: 14, outcome: 'mixed' as const },
+ ];
+ expect(await result({ outcome: 'mixed', readings, outcomeFinal: false })).toContain(
+ 'so far: day 14 of 30',
+ );
+ expect(
+ await result({
+ outcome: 'improved',
+ readings: [...readings, { day: 30, outcome: 'improved' }],
+ outcomeFinal: true,
+ }),
+ ).not.toContain('so far');
+ });
+
// Only a completed action is measured; one dismissed before 00084 reads
// not measurable, one since pending: neither is what happened.
it.each(['not_measurable', 'pending_measurement'] as const)(
diff --git a/web/src/components/action-center/history-table.tsx b/web/src/components/action-center/history-table.tsx
index c4d4327bb..29836a522 100644
--- a/web/src/components/action-center/history-table.tsx
+++ b/web/src/components/action-center/history-table.tsx
@@ -11,7 +11,7 @@ import {
TableRow,
} from '@/components/ui/table';
import { actionTexts } from '@/lib/action-center/display';
-import type { ActionHistoryItem } from '@/lib/action-center/history';
+import { FINAL_READING_DAY, type ActionHistoryItem } from '@/lib/action-center/history';
import type { ActionStatus } from '@/lib/action-center/registry';
import { ActionIcon, PriorityBadge } from './action-table';
import { cn } from '@/lib/utils';
@@ -114,7 +114,15 @@ function ResultCell({ item }: { item: ActionHistoryItem }) {
return (
<div className="space-y-0.5">
<p className="text-xs text-muted-foreground">{tOutcome(item.outcome)}</p>
- <p className="text-[11px] text-muted-foreground/70">{t(`outcomeHint.${item.outcome}`)}</p>
+ <p className="text-[11px] text-muted-foreground/70">
+ {/* Not final yet (learning B1): the reading so far, of the month's. */}
+ {item.readings?.length && !item.outcomeFinal
+ ? t('outcomeSoFar', {
+ day: item.readings[item.readings.length - 1].day,
+ final: FINAL_READING_DAY,
+ })
+ : t(`outcomeHint.${item.outcome}`)}
+ </p>
</div>
);
}
diff --git a/web/src/lib/action-center/display.test.ts b/web/src/lib/action-center/display.test.ts
index cce220983..a0ce8c4ef 100644
--- a/web/src/lib/action-center/display.test.ts
+++ b/web/src/lib/action-center/display.test.ts
@@ -422,6 +422,20 @@ describe('actionEventText', () => {
'Result: metrics improved after this action closed',
);
});
+
+ /** Read three times after the close, each result names its day (learning B1). */
+ it('names the reading a result came from, and the final one', () => {
+ expect(
+ actionEventText(event('outcome_measured', { outcome: 'improved', day: 14 }), tPage, t),
+ ).toBe('Day 14 · Result: metrics improved after this action closed');
+ expect(
+ actionEventText(
+ event('outcome_measured', { outcome: 'mixed', day: 30, final: true }),
+ tPage,
+ t,
+ ),
+ ).toBe('Day 30, final · Result: mixed after this action closed');
+ });
});
/**
@@ -468,6 +482,8 @@ describe('History events', () => {
title: 'Ask the agency',
outcome: 'improved',
reviews: 0,
+ day: 0,
+ final: 'no',
};
const eventText = (event: string, data: Partial<typeof values> = {}) =>
tPage(`drawer.events.${event}` as Parameters<typeof tPage>[0], { ...values, ...data });
diff --git a/web/src/lib/action-center/display.ts b/web/src/lib/action-center/display.ts
index 242613eca..6ff10175c 100644
--- a/web/src/lib/action-center/display.ts
+++ b/web/src/lib/action-center/display.ts
@@ -240,6 +240,10 @@ export function actionEventText(
// The validation sweep's verdict once the action closed: improved,
// declined, and so on.
outcome: String(event.data.outcome ?? ''),
+ // Which reading it was, counted from the close, and whether the last
+ // (learning B1); none for one measured once before.
+ day: Number(event.data.day ?? 0),
+ final: event.data.final === true ? 'yes' : 'no',
});
}
diff --git a/web/src/lib/action-center/history.ts b/web/src/lib/action-center/history.ts
index d5d9cd312..effcdae9d 100644
--- a/web/src/lib/action-center/history.ts
+++ b/web/src/lib/action-center/history.ts
@@ -78,6 +78,18 @@ export interface ActionHistoryTask {
completedAt?: string;
}
+/**
+ * The day after closing an action's final reading is taken on (learning
+ * B1): the API's validation.finalReadingDay (server config/action-engine.js).
+ */
+export const FINAL_READING_DAY = 30;
+
+/** One reading of an action's effect: the day after closing, and its verdict. */
+export interface OutcomeReading {
+ day: number;
+ outcome: ActionOutcome;
+}
+
/** A signal that opened the action. Several signals consolidate into one
* action, so this is a list rather than a field. */
export interface TriggerSignal {
@@ -121,6 +133,12 @@ export interface ActionHistoryItem {
affected: AffectedEntity[];
/** Empty until something measures an action's effect. */
results: ActionResultMetric[];
+ /**
+ * Its readings a week, two weeks and a month after it closed (learning
+ * B1), and whether the last, final one is in. Empty before the first.
+ */
+ readings?: OutcomeReading[];
+ outcomeFinal?: boolean;
/** Why it was dismissed, when someone said (learning A5). */
dismissReason?: ActionDismissReason | null;
/** Its signals when it was measured; absent before, or with no signal behind it. */
diff --git a/web/src/lib/actions/action-history.ts b/web/src/lib/actions/action-history.ts
index 1d07e112b..e22307d0e 100644
--- a/web/src/lib/actions/action-history.ts
+++ b/web/src/lib/actions/action-history.ts
@@ -18,6 +18,7 @@ import { createClient } from '@/lib/supabase/server';
import type { ActionCategory } from '@/lib/action-center/registry';
import {
ACTION_DISMISS_REASONS,
+ ACTION_OUTCOMES,
type ActionDismissReason,
type ActionOutcome,
type ActionStatus,
@@ -34,6 +35,7 @@ import {
type ActionHistoryTask,
type ActionResultMetric,
type AffectedEntity,
+ type OutcomeReading,
type SignalOutcome,
type TriggerSignal,
} from '@/lib/action-center/history';
@@ -86,6 +88,22 @@ interface ValidationSnapshot {
primary?: string;
/** Nights tracking missed in each window (learning A6). */
gaps?: { before?: number; after?: number; tooMany?: boolean };
+ /** Its readings, and whether the final one is in (learning B1). */
+ readings?: { day?: number; outcome?: string }[];
+ final?: boolean;
+}
+
+/** Its readings, the days known and verdicts it can name, in order. */
+function readingsFrom(validation: ValidationSnapshot | null): OutcomeReading[] {
+ if (!Array.isArray(validation?.readings)) return [];
+ return validation.readings
+ .filter(
+ (r) =>
+ Number.isInteger(r?.day) &&
+ (ACTION_OUTCOMES as readonly string[]).includes(r?.outcome ?? ''),
+ )
+ .map((r) => ({ day: r.day as number, outcome: r.outcome as ActionOutcome }))
+ .sort((a, b) => a.day - b.day);
}
/** Nights tracking missed in its windows, when there were any. */
@@ -338,6 +356,8 @@ export async function getActionHistory(
measuredOn: measuredOnFrom(row.validation),
auditAfter: auditFrom(row.validation),
dataGaps: gapsFrom(row.validation),
+ readings: readingsFrom(row.validation),
+ outcomeFinal: row.validation?.final === true,
// Shown only when it was measured: a main metric with no pair says nothing.
primaryMetric: resultsFrom(row.validation).some((m) => m.metric === row.validation?.primary)
? (row.validation?.primary ?? null)
diff --git a/web/src/lib/mcp/action-history.test.ts b/web/src/lib/mcp/action-history.test.ts
new file mode 100644
index 000000000..f09a1e564
--- /dev/null
+++ b/web/src/lib/mcp/action-history.test.ts
@@ -0,0 +1,100 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import type { McpAuthContext } from '@/lib/mcp-auth';
+
+/**
+ * list_action_history says whether an action's outcome is the result or a
+ * reading so far (learning B1): an action is read 7, 14 and 30 days after it
+ * closed, and only the day-30 reading is final.
+ */
+
+let actionRows: Record<string, unknown>[] = [];
+
+function builder(table: string) {
+ const chain = {
+ select: () => chain,
+ eq: () => chain,
+ is: () => chain,
+ in: () => chain,
+ order: () => chain,
+ limit: () => chain,
+ maybeSingle: async () => ({ data: { id: 'brand-1' }, error: null }),
+ then: (resolve: (v: { data: unknown; error: null }) => void) =>
+ resolve({ data: table === 'actions' ? actionRows : [], error: null }),
+ };
+ return chain;
+}
+
+vi.mock('@/lib/supabase/admin', () => ({
+ supabaseAdmin: { from: (table: string) => builder(table) },
+}));
+
+const { listActionHistoryFor } = await import('./data');
+
+const auth: McpAuthContext = {
+ userId: 'user-1',
+ email: null,
+ organizationId: 'org-1',
+ apiKeyId: 'key-1',
+};
+
+function action(outcome: string | null, validation: Record<string, unknown> | null) {
+ return {
+ id: 'a1',
+ action_no: 7,
+ category: 'recover',
+ kind: 'recover_lost_citations',
+ impact: 'high',
+ status: 'completed',
+ outcome,
+ validation,
+ created_at: '2026-09-01T00:00:00Z',
+ completed_at: '2026-09-10T00:00:00Z',
+ };
+}
+
+async function row() {
+ const rows = await listActionHistoryFor(auth, { brandId: 'brand-1' });
+ return rows?.[0];
+}
+
+describe('listActionHistoryFor readings', () => {
+ beforeEach(() => {
+ actionRows = [];
+ });
+
+ it('is a reading so far until the day-30 one, on its latest day', async () => {
+ actionRows = [
+ action('improved', {
+ readings: [
+ { day: 7, outcome: 'no_meaningful_change' },
+ { day: 14, outcome: 'improved' },
+ ],
+ }),
+ ];
+ expect(await row()).toMatchObject({ outcome: 'improved', final: false, reading_day: 14 });
+ });
+
+ it('is final once the day-30 reading is in', async () => {
+ actionRows = [
+ action('declined', {
+ readings: [
+ { day: 7, outcome: 'improved' },
+ { day: 14, outcome: 'improved' },
+ { day: 30, outcome: 'declined' },
+ ],
+ final: true,
+ }),
+ ];
+ expect(await row()).toMatchObject({ outcome: 'declined', final: true, reading_day: 30 });
+ });
+
+ it('keeps the result of one measured once, before readings began', async () => {
+ actionRows = [action('improved', { metrics: [] })];
+ expect(await row()).toMatchObject({ final: true, reading_day: null });
+ });
+
+ it('is not final while its first reading is pending', async () => {
+ actionRows = [action('pending_measurement', null)];
+ expect(await row()).toMatchObject({ final: false, reading_day: null });
+ });
+});
diff --git a/web/src/lib/mcp/data.ts b/web/src/lib/mcp/data.ts
index 54502306e..e83262084 100644
--- a/web/src/lib/mcp/data.ts
+++ b/web/src/lib/mcp/data.ts
@@ -3257,6 +3257,13 @@ export interface ActionHistoryRow {
completed_at: string | null;
/** Before/after pairs the validation sweep measured; empty until it runs. */
results: Array<{ metric: string; unit: string; before: number; after: number }>;
+ /**
+ * Whether `outcome` is the result rather than a reading so far (learning
+ * B1): the day-30 reading is in, or it was measured once, before readings.
+ */
+ final: boolean;
+ /** The day after closing its latest reading was taken on; null before one. */
+ reading_day: number | null;
}
interface ValidationMetric {
@@ -3266,6 +3273,13 @@ interface ValidationMetric {
after: number | null;
}
+interface ValidationSnapshot {
+ metrics?: ValidationMetric[];
+ /** Its readings a week, two weeks and a month after it closed (learning B1). */
+ readings?: { day?: unknown }[];
+ final?: boolean;
+}
+
export async function listActionHistoryFor(
auth: McpAuthContext,
params: { brandId: string; limit?: number },
@@ -3286,7 +3300,12 @@ export async function listActionHistoryFor(
if (error) throw new Error(error.message);
return (data ?? []).map((r) => {
- const metrics = (r.validation as { metrics?: ValidationMetric[] } | null)?.metrics ?? [];
+ const validation = r.validation as ValidationSnapshot | null;
+ const metrics = validation?.metrics ?? [];
+ const days = (Array.isArray(validation?.readings) ? validation.readings : [])
+ .map((reading) => reading?.day)
+ .filter((day): day is number => Number.isInteger(day));
+ const outcome = r.outcome ?? null;
return {
id: r.id,
action_no: Number(r.action_no),
@@ -3294,7 +3313,7 @@ export async function listActionHistoryFor(
kind: r.kind,
impact: r.impact,
status: r.status,
- outcome: r.outcome ?? null,
+ outcome,
created_at: r.created_at,
completed_at: r.completed_at ?? null,
// A metric missing either half was not measured; dropped, as on the dashboard.
@@ -3306,6 +3325,12 @@ export async function listActionHistoryFor(
before: m.before as number,
after: m.after as number,
})),
+ // A reading so far until the day-30 one; one measured once before the
+ // readings came keeps its result, as History reads it.
+ final:
+ validation?.final === true ||
+ (days.length === 0 && outcome != null && outcome !== 'pending_measurement'),
+ reading_day: days.length ? Math.max(...days) : null,
};
});
}
diff --git a/web/src/lib/mcp/server.ts b/web/src/lib/mcp/server.ts
index 0ab8ed315..af892a766 100644
--- a/web/src/lib/mcp/server.ts
+++ b/web/src/lib/mcp/server.ts
@@ -1263,7 +1263,7 @@ export function createMcpServer(auth: McpAuthContext): McpServer {
'list_action_history',
{
description:
- 'List closed Action Center actions (completed or dismissed) for a brand with their measured result, most recently closed first. `outcome` is the verdict (improved, mixed when its metrics moved both ways or only some of a fix\u2019s pages pass, no_meaningful_change, declined, not_measurable, or pending_measurement while the after-window is still open) and `results` holds the before/after values the validation sweep measured. Use this to answer "did what we did last month work?".',
+ 'List closed Action Center actions (completed or dismissed) for a brand with their measured result, most recently closed first. `outcome` is the verdict (improved, mixed when its metrics moved both ways or only some of a fix\u2019s pages pass, no_meaningful_change, declined, not_measurable, or pending_measurement while the first week after it closed is still open; read again 14 and 30 days on, the day-30 reading final) and `results` holds the before/after values the validation sweep measured. `reading_day` is the day after closing the latest reading was taken on (7, 14 or 30; null before the first, or for one measured once before readings began). Until `final` is true, the outcome is a reading so far (day 7 or 14), not the result. Use this to answer "did what we did last month work?".',
inputSchema: {
brand_id: relaxedUuid.describe('Brand UUID, from list_brands.'),
limit: z