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.

fix(signals): stop closing signals that only dipped for a night or changed kind (#853)

Gökhan Geyik6288a4bc6a8a
diff --git a/server/src/config/action-engine.js b/server/src/config/action-engine.js
index 98ceccba4..6f6645c20 100644
--- a/server/src/config/action-engine.js
+++ b/server/src/config/action-engine.js
@@ -153,6 +153,13 @@ export const ENGINE_THRESHOLDS = Object.freeze({
maxSignalsPerKind: 5,
// Prompts
+ /**
+ * How long an open signal may go undetected before it is closed. Longer
+ * than a day, so one quiet night — a value dipping just under its
+ * threshold and back — does not close a signal and raise it again the
+ * next morning. Two missed nights close it.
+ */
+ resolveAfterHours: 36,
/** Tracked on at least this many days of the window before absence counts… */
promptMinDays: 3,
/**
diff --git a/server/src/lib/signals/library/kinds.js b/server/src/lib/signals/library/kinds.js
index 4a1f0074d..70924f794 100644
--- a/server/src/lib/signals/library/kinds.js
+++ b/server/src/lib/signals/library/kinds.js
@@ -100,3 +100,25 @@ export const LIBRARY_KINDS = Object.freeze({
weak_internal_links: meta('technical', 'low', []),
content_gap: meta('technical', 'medium', ['ai_visibility']),
});
+
+/**
+ * Kinds one classifier chooses between for the same subject — a topic is
+ * uncovered or slipping or dropped, never two at once. When tonight's pass
+ * files a subject under a different kind of its group, the old signal did not
+ * end: it changed. The recorder closes it as superseded rather than resolved.
+ *
+ * Only groups that are exclusive by construction belong here. A competitor
+ * can lead and gain at the same time; those stay independent.
+ */
+export const EXCLUSIVE_KIND_GROUPS = Object.freeze([
+ Object.freeze(['topic_gap', 'topic_uncovered', 'topic_slipping', 'topic_drop']),
+ Object.freeze(['platform_slipping', 'platform_drop']),
+ Object.freeze([
+ 'competitor_winning_source',
+ 'competitor_cited_source',
+ 'third_party_presence_gap',
+ 'authority_citation_gap',
+ 'third_party_citation_gap',
+ ]),
+ Object.freeze(['page_citation_slipping', 'owned_page_citation_lost']),
+]);
diff --git a/server/src/lib/signals/record.js b/server/src/lib/signals/record.js
index e05fdc447..cfb21c2aa 100644
--- a/server/src/lib/signals/record.js
+++ b/server/src/lib/signals/record.js
@@ -30,7 +30,7 @@ import supabaseAdmin from '../../config/supabase.js';
import { computePulseMetrics } from '../pulse/metrics.js';
import { logger } from '../logger.js';
import { resolve } from '../../config/action-engine.js';
-import { LIBRARY_KINDS } from './library/kinds.js';
+import { EXCLUSIVE_KIND_GROUPS, LIBRARY_KINDS } from './library/kinds.js';
import { libraryCandidates } from './library/detect.js';
const DAY_MS = 86_400_000;
@@ -41,7 +41,7 @@ function utcDay(date) {
// What counts as a signal is decided in config/action-engine.js (#818 phase
// 2.5), alongside every other threshold the engine judges by.
-const { detection } = resolve();
+const { detection, library: libraryThresholds } = resolve();
/**
* Library kinds that report a fall. Suppressed during a platform outage, when
@@ -515,21 +515,57 @@ export function overflowRefreshes(overflow, existing) {
.filter(({ current }) => current && isOpen(current));
}
+/** What a single-subject key is about: `topic_drop:<id>` → `<id>`. */
+const subjectOf = (dedupKey) => {
+ const at = dedupKey.indexOf(':');
+ return at < 0 ? null : dedupKey.slice(at + 1);
+};
+
+const GROUP_OF = new Map(
+ EXCLUSIVE_KIND_GROUPS.flatMap((group, i) => group.map((kind) => [kind, i])),
+);
+
/**
- * Open, persistent signals nothing detected tonight — the ones that ended.
+ * Open, persistent signals nothing detected tonight, split by why.
+ *
+ * - `superseded`: the subject is still there under another kind of the same
+ * exclusive group — a topic that went from slipping to dropped. Closed now,
+ * naming what replaced it, so the list does not show the same topic twice
+ * and does not call a worsening "resolved".
+ * - `resolved`: not detected at all, for longer than `resolveAfterHours`.
+ * One quiet night is not an ending: values near a threshold dip under it
+ * and back, and closing on the dip reopened the same signal a day later.
+ *
* `detected` must include over-cap findings: a finding that moved down a
* list has not ended. A kind whose detector failed was not looked at, and a
* condition nobody looked at has not ended either.
*/
-export function signalsToResolve(existingRows, detected, unreadKinds) {
+export function signalsToResolve(existingRows, detected, unreadKinds, { now, graceHours }) {
const detectedKeys = new Set(detected.map((candidate) => candidate.dedupKey));
- return existingRows.filter(
- (row) =>
- KIND_META[row.kind]?.persistent &&
- isOpen(row) &&
- !detectedKeys.has(row.dedup_key) &&
- !unreadKinds.has(row.kind),
- );
+ const detectedIn = new Map();
+ for (const { kind, dedupKey } of detected) {
+ const group = GROUP_OF.get(kind);
+ const subject = subjectOf(dedupKey);
+ if (group !== undefined && subject) detectedIn.set(`${group}|${subject}`, kind);
+ }
+ const cutoff = now.getTime() - graceHours * 60 * 60 * 1000;
+
+ const superseded = [];
+ const resolved = [];
+ for (const row of existingRows) {
+ if (!KIND_META[row.kind]?.persistent || !isOpen(row)) continue;
+ if (detectedKeys.has(row.dedup_key) || unreadKinds.has(row.kind)) continue;
+
+ const group = GROUP_OF.get(row.kind);
+ const subject = subjectOf(row.dedup_key);
+ const successor = group !== undefined && subject && detectedIn.get(`${group}|${subject}`);
+ if (successor) {
+ superseded.push({ row, by: successor });
+ } else if (new Date(row.last_detected_at).getTime() < cutoff) {
+ resolved.push(row);
+ }
+ }
+ return { superseded, resolved };
}
export async function recordSignalsForBrand(brandId, { now = new Date() } = {}) {
@@ -581,7 +617,7 @@ export async function recordSignalsForBrand(brandId, { now = new Date() } = {})
// small (tens), so reading it whole is cheaper than being clever.
const { data: existingRows, error: readErr } = await supabaseAdmin
.from('signals')
- .select('id, dedup_key, kind, status')
+ .select('id, dedup_key, kind, status, last_detected_at, payload')
.eq('brand_id', brandId)
.limit(1000);
if (readErr) throw new Error(readErr.message);
@@ -660,18 +696,39 @@ export async function recordSignalsForBrand(brandId, { now = new Date() } = {})
// them. Not during an outage: the engine suppresses drop/loss warnings
// while a platform is degraded, and treating that silence as recovery
// would close real signals.
- const toResolve = outage
- ? []
- : signalsToResolve(existingRows ?? [], [...candidates, ...overflow], unreadKinds);
- for (const row of toResolve) {
+ const closing = outage
+ ? { superseded: [], resolved: [] }
+ : signalsToResolve(existingRows ?? [], [...candidates, ...overflow], unreadKinds, {
+ now,
+ graceHours: libraryThresholds.resolveAfterHours,
+ });
+ for (const row of closing.resolved) {
const { error } = await supabaseAdmin
.from('signals')
.update({ status: 'resolved', resolved_at: nowIso, updated_at: nowIso })
.eq('id', row.id);
if (error) throw new Error(error.message);
}
+ for (const { row, by } of closing.superseded) {
+ const { error } = await supabaseAdmin
+ .from('signals')
+ .update({
+ status: 'resolved',
+ resolved_at: nowIso,
+ updated_at: nowIso,
+ payload: { ...(row.payload ?? {}), supersededBy: by },
+ })
+ .eq('id', row.id);
+ if (error) throw new Error(error.message);
+ }
- const summary = { inserted, refreshed, reopened, autoResolved: toResolve.length };
+ const summary = {
+ inserted,
+ refreshed,
+ reopened,
+ autoResolved: closing.resolved.length,
+ superseded: closing.superseded.length,
+ };
logger.info({ brandId, ...summary }, '[signals] recorded');
return summary;
}
diff --git a/server/src/lib/signals/resolution.test.js b/server/src/lib/signals/resolution.test.js
index 8b1bfcf26..7ea5b12a0 100644
--- a/server/src/lib/signals/resolution.test.js
+++ b/server/src/lib/signals/resolution.test.js
@@ -11,7 +11,8 @@ vi.mock('../pulse/metrics.js', () => ({
isTransientDbError: () => false,
}));
-import { overflowRefreshes, signalsToResolve } from './record.js';
+import { KIND_META, overflowRefreshes, signalsToResolve } from './record.js';
+import { EXCLUSIVE_KIND_GROUPS } from './library/kinds.js';
import { cap } from './library/detect.js';
import { ENGINE_THRESHOLDS } from '../../config/action-engine.js';
@@ -19,12 +20,22 @@ const max = ENGINE_THRESHOLDS.library.maxSignalsPerKind;
const KIND = 'competitor_cited_source';
const finding = (i) => ({ kind: KIND, dedupKey: `${KIND}:d${i}`, currentValue: 100 - i });
-const row = (i, status = 'new') => ({
+const NOW = new Date('2026-09-29T03:00:00Z');
+const hoursAgo = (h) => new Date(NOW.getTime() - h * 60 * 60 * 1000).toISOString();
+const GRACE = ENGINE_THRESHOLDS.library.resolveAfterHours;
+// Last seen two nights ago by default: past the grace window, so a test about
+// something else is not quietly passing because of it.
+const row = (i, status = 'new', over = {}) => ({
id: `s${i}`,
kind: KIND,
dedup_key: `${KIND}:d${i}`,
status,
+ last_detected_at: hoursAgo(48),
+ ...over,
});
+const closing = (existing, detected, unread = new Set()) =>
+ signalsToResolve(existing, detected, unread, { now: NOW, graceHours: GRACE });
+const resolvedIds = (result) => result.resolved.map((r) => r.id);
describe('the per-kind cap', () => {
const found = Array.from({ length: max + 2 }, (_, i) => finding(i));
@@ -52,22 +63,106 @@ describe('which signals a night closes', () => {
*/
it('does not close a signal whose finding only moved down the ranking', () => {
const existing = [row(0), row(5)];
- const kept = [finding(0)];
- const overflow = [finding(5)];
- expect(signalsToResolve(existing, [...kept, ...overflow], new Set())).toEqual([]);
+ const result = closing(existing, [finding(0), finding(5)]);
+ expect(result).toEqual({ superseded: [], resolved: [] });
});
- it('closes one whose finding is gone', () => {
+ it('closes one whose finding has been gone past the grace window', () => {
const existing = [row(0), row(9)];
- expect(signalsToResolve(existing, [finding(0)], new Set()).map((r) => r.id)).toEqual(['s9']);
+ expect(resolvedIds(closing(existing, [finding(0)]))).toEqual(['s9']);
+ });
+
+ /**
+ * The second failure: a source at 21 results against a threshold of 20
+ * dipped to 19 for a night, was closed, and reopened the next morning — 64
+ * of one night's 74 closures had lived a single night.
+ */
+ it('keeps a signal open through one quiet night', () => {
+ const existing = [row(9, 'new', { last_detected_at: hoursAgo(24) })];
+ expect(closing(existing, [])).toEqual({ superseded: [], resolved: [] });
+ });
+
+ it('closes it once the grace window has passed', () => {
+ const existing = [row(9, 'new', { last_detected_at: hoursAgo(GRACE + 1) })];
+ expect(resolvedIds(closing(existing, []))).toEqual(['s9']);
});
it('does not close a kind whose detector failed tonight', () => {
- expect(signalsToResolve([row(9)], [], new Set([KIND]))).toEqual([]);
+ expect(closing([row(9)], [], new Set([KIND]))).toEqual({ superseded: [], resolved: [] });
});
it('leaves signals someone already closed alone', () => {
- expect(signalsToResolve([row(9, 'dismissed'), row(8, 'resolved')], [], new Set())).toEqual([]);
+ expect(closing([row(9, 'dismissed'), row(8, 'resolved')], [])).toEqual({
+ superseded: [],
+ resolved: [],
+ });
+ });
+});
+
+describe('a subject that changed kind', () => {
+ const topic = (kind, over = {}) => ({
+ id: kind,
+ kind,
+ dedup_key: `${kind}:topic-1`,
+ status: 'new',
+ last_detected_at: hoursAgo(24),
+ ...over,
+ });
+ const found = (kind, subject = 'topic-1') => ({ kind, dedupKey: `${kind}:${subject}` });
+
+ /** A worsening is not a resolution, and one topic should not be listed
+ * twice. Closed at once — no grace — naming its successor. */
+ it('is superseded by its successor, straight away', () => {
+ const result = closing([topic('topic_slipping')], [found('topic_drop')]);
+ expect(result.superseded).toEqual([{ row: topic('topic_slipping'), by: 'topic_drop' }]);
+ expect(result.resolved).toEqual([]);
+ });
+
+ it('is not superseded by the same kind on another subject', () => {
+ const result = closing([topic('topic_slipping')], [found('topic_drop', 'topic-2')]);
+ expect(result).toEqual({ superseded: [], resolved: [] });
+ });
+
+ /** A competitor can lead and gain at once; one appearing is not the other
+ * ending. */
+ it('is not superseded by a kind outside its exclusive group', () => {
+ const lead = {
+ id: 'm',
+ kind: 'competitor_momentum',
+ dedup_key: 'competitor_momentum:c1',
+ status: 'new',
+ last_detected_at: hoursAgo(24),
+ };
+ const result = closing([lead], [{ kind: 'competitor_leads', dedupKey: 'competitor_leads:c1' }]);
+ expect(result).toEqual({ superseded: [], resolved: [] });
+ });
+
+ it('applies to the source classes too', () => {
+ const source = {
+ id: 'x',
+ kind: 'third_party_presence_gap',
+ dedup_key: 'third_party_presence_gap:example.com',
+ status: 'acknowledged',
+ last_detected_at: hoursAgo(24),
+ };
+ const result = closing(
+ [source],
+ [{ kind: 'competitor_cited_source', dedupKey: 'competitor_cited_source:example.com' }],
+ );
+ expect(result.superseded.map((s) => s.by)).toEqual(['competitor_cited_source']);
+ });
+});
+
+describe('the exclusive kind groups', () => {
+ it('name only kinds that exist, each in one group', () => {
+ const seen = new Set();
+ for (const group of EXCLUSIVE_KIND_GROUPS) {
+ for (const kind of group) {
+ expect({ kind, known: Boolean(KIND_META[kind]) }).toEqual({ kind, known: true });
+ expect({ kind, repeated: seen.has(kind) }).toEqual({ kind, repeated: false });
+ seen.add(kind);
+ }
+ }
});
});
diff --git a/web/messages/en.json b/web/messages/en.json
index 131d5656a..9b7ff6f17 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -253,6 +253,7 @@
"resolved": "Resolved",
"dismissed": "Dismissed"
},
+ "superseded": "Changed",
"impact": {
"high": "High",
"medium": "Medium",
diff --git a/web/src/components/action-center/action-drawer.tsx b/web/src/components/action-center/action-drawer.tsx
index 95781efc7..89e82bc6b 100644
--- a/web/src/components/action-center/action-drawer.tsx
+++ b/web/src/components/action-center/action-drawer.tsx
@@ -56,7 +56,7 @@ import {
} from '@/lib/action-center/display';
import { signalTexts } from '@/lib/signals/display';
import { isKpiKey } from '@/lib/kpis/registry';
-import { ImpactDots, SignalStatusBadge } from './signal-table';
+import { ImpactDots, isSuperseded, SignalStatusBadge } from './signal-table';
import { ActionIcon } from './action-table';
import { cn } from '@/lib/utils';
@@ -317,7 +317,7 @@ export function ActionDrawer({
>
<div className="flex items-center justify-between gap-2">
<p className="truncate text-xs font-medium">{st.title}</p>
- <SignalStatusBadge status={signal.status} />
+ <SignalStatusBadge status={signal.status} superseded={isSuperseded(signal)} />
</div>
<p className="truncate text-xs text-muted-foreground">{st.description}</p>
</button>
diff --git a/web/src/components/action-center/signal-drawer.tsx b/web/src/components/action-center/signal-drawer.tsx
index 4bc1b0359..012bf82e4 100644
--- a/web/src/components/action-center/signal-drawer.tsx
+++ b/web/src/components/action-center/signal-drawer.tsx
@@ -17,7 +17,13 @@ import type { Signal } from '@/lib/actions/signals';
import { SIGNAL_KINDS, type SignalStatus } from '@/lib/signals/registry';
import { signalAffected, signalTexts } from '@/lib/signals/display';
import { isKpiKey } from '@/lib/kpis/registry';
-import { ImpactDots, SignalKindIcon, SignalStatusBadge, SourceList } from './signal-table';
+import {
+ ImpactDots,
+ isSuperseded,
+ SignalKindIcon,
+ SignalStatusBadge,
+ SourceList,
+} from './signal-table';
/**
* Signal detail: the evidence view. Deliberately light in v1 — identity,
@@ -82,7 +88,7 @@ export function SignalDrawer({
<div className="flex-1 space-y-5 overflow-y-auto px-6 py-4 text-sm">
<div className="grid grid-cols-2 gap-x-4 gap-y-3">
<DetailItem label={t('drawer.status')}>
- <SignalStatusBadge status={signal.status} />
+ <SignalStatusBadge status={signal.status} superseded={isSuperseded(signal)} />
</DetailItem>
<DetailItem label={t('drawer.source')}>
<SourceList sources={signal.source} />
diff --git a/web/src/components/action-center/signal-table.tsx b/web/src/components/action-center/signal-table.tsx
index 1db45bc08..18035a37f 100644
--- a/web/src/components/action-center/signal-table.tsx
+++ b/web/src/components/action-center/signal-table.tsx
@@ -132,12 +132,27 @@ const STATE_TEXT: Record<string, string> = {
opportunity: 'text-emerald-600 dark:text-emerald-400',
};
-export function SignalStatusBadge({ status }: { status: SignalStatus }) {
+/**
+ * A signal the engine closed because its subject moved to another kind — a
+ * topic that went from slipping to dropped — reads "Changed", not "Resolved":
+ * nothing was fixed, the finding became a different one.
+ */
+export function isSuperseded(signal: Pick<Signal, 'status' | 'payload'>): boolean {
+ return signal.status === 'resolved' && typeof signal.payload?.supersededBy === 'string';
+}
+
+export function SignalStatusBadge({
+ status,
+ superseded = false,
+}: {
+ status: SignalStatus;
+ superseded?: boolean;
+}) {
const t = useTranslations('actionCenter.signalsPage');
return (
- <Badge variant="outline" className={STATUS_BADGE[status]}>
+ <Badge variant="outline" className={superseded ? STATUS_BADGE.dismissed : STATUS_BADGE[status]}>
<span aria-hidden="true" className="h-1.5 w-1.5 rounded-full bg-current opacity-70" />
- {t(`status.${status}`)}
+ {superseded ? t('superseded') : t(`status.${status}`)}
</Badge>
);
}
@@ -259,7 +274,7 @@ export function SignalTable({
</p>
</TableCell>
<TableCell>
- <SignalStatusBadge status={signal.status} />
+ <SignalStatusBadge status={signal.status} superseded={isSuperseded(signal)} />
</TableCell>
<TableCell onClick={(e) => e.stopPropagation()}>
<DropdownMenu>