Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. πŸ”₯

Simplify search run: remove LLM stages

Developers Digest3fe814c910f7
diff --git a/apps/api/src/services/monitoring/search/criteria.ts b/apps/api/src/services/monitoring/search/criteria.ts
index 8eece502a..eac3d63a8 100644
--- a/apps/api/src/services/monitoring/search/criteria.ts
+++ b/apps/api/src/services/monitoring/search/criteria.ts
@@ -1,14 +1,4 @@
-import { generateObject } from "ai";
import { z } from "zod";
-import {
- googleModel,
- googleProviderOptions,
- type LlmUsageLabels,
-} from "./tuning";
-import { recordLlmCall } from "./cost";
-import type { CostTracking } from "../../../lib/cost-tracking";
-
-const CRITERIA_MODEL = "gemini-flash-lite-latest";
export type GoalCriteria = {
goalVersion: string;
@@ -21,12 +11,10 @@ export type GoalCriteria = {
};
export function tokenizeContent(text: string | null | undefined): string[] {
- return (
- String(text ?? "")
- .toLowerCase()
- .split(/[^a-z0-9]+/)
- .filter(token => token.length >= 2)
- );
+ return String(text ?? "")
+ .toLowerCase()
+ .split(/[^a-z0-9]+/)
+ .filter(token => token.length >= 2);
}
function normalizeForContainment(text: string | null | undefined): string {
@@ -133,36 +121,3 @@ export function mergeCompiledCriteria(
);
return merged;
}
-
-export async function compileGoalCriteriaWithLlm(params: {
- goal: string;
- subject: string;
- queries: string[];
- goalVersion: string;
- costTracking?: CostTracking;
- labels?: LlmUsageLabels;
-}): Promise<GoalCriteria> {
- const deterministic = compileGoalCriteria(params);
- const { object, usage } = await generateObject({
- model: googleModel(CRITERIA_MODEL),
- schema: criteriaSchema,
- system:
- "You compile a web-monitoring goal into machine-checkable criteria. The criteria are evaluated with exact string containment and set membership β€” no interpretation happens later, so be complete (list product names, abbreviations, obvious competitors). Only include entries you are confident about; an empty list disables that check, which is always safe.",
- prompt: JSON.stringify({
- goal: params.goal,
- subject: params.subject,
- queries: params.queries,
- }),
- temperature: 0,
- ...googleProviderOptions("compileGoalCriteria", params.labels),
- });
- if (params.costTracking) {
- recordLlmCall({
- costTracking: params.costTracking,
- model: CRITERIA_MODEL,
- usage,
- stage: "compileGoalCriteria",
- });
- }
- return mergeCompiledCriteria(deterministic, object);
-}
diff --git a/apps/api/src/services/monitoring/search/llm.ts b/apps/api/src/services/monitoring/search/llm.ts
index 4953ea4bf..5dd78a88e 100644
--- a/apps/api/src/services/monitoring/search/llm.ts
+++ b/apps/api/src/services/monitoring/search/llm.ts
@@ -5,13 +5,9 @@ import {
googleProviderOptions,
type LlmUsageLabels,
} from "./tuning";
-import type { GoalCriteria } from "./criteria";
import { recordLlmCall } from "./cost";
import type { CostTracking } from "../../../lib/cost-tracking";
-const EVENT_MODEL = "gemini-flash-lite-latest";
-const SUMMARY_MODEL = "gemini-flash-lite-latest";
-const SKEPTIC_MODEL = "gemini-flash-lite-latest";
const ROUTER_MODEL = "gemini-3-flash-preview";
export type KnownEvent = {
@@ -21,252 +17,6 @@ export type KnownEvent = {
alertCount?: number;
};
-export type EventResolution = {
- matchedKey: string | null;
- isNew: boolean;
- label: string;
- reason: string;
-};
-
-const eventResolverSchema = z.object({
- matchedKey: z.string().nullable(),
- isNew: z.boolean(),
- label: z.string(),
- reason: z.string(),
-});
-
-export async function resolveEvent(params: {
- goal: string;
- subject: string;
- result: { title: string; url: string; evidence: string };
- candidates: KnownEvent[];
- costTracking?: CostTracking;
- labels?: LlmUsageLabels;
-}): Promise<EventResolution> {
- const { object, usage } = await generateObject({
- model: googleModel(EVENT_MODEL),
- schema: eventResolverSchema,
- system:
- "You deduplicate real-world events for a monitoring product. Given a new meaningful result and a list of already-known events, decide if the result describes the SAME underlying event as one of them (a different outlet, headline, or wording still counts as the same event) or a genuinely NEW event. Match to an existing event whenever it is the same development. Return structured JSON only.",
- prompt: JSON.stringify({
- monitor: { goal: params.goal, subject: params.subject },
- knownEvents: params.candidates
- .slice(0, 20)
- .map(c => ({ key: c.key, label: c.label })),
- newResult: {
- title: params.result.title,
- url: params.result.url,
- evidence: (params.result.evidence || "").slice(0, 500),
- },
- instructions: `If newResult is the same underlying event as a knownEvent, set matchedKey to that event's key and isNew false.
-Only set isNew true when this is a distinct development not represented by any knownEvent.
-label: when matched, reuse the matched event's label; when new, write a short reusable label naming the company/product/event.
-A new article from a different publisher about the same filing/launch/recall is NOT a new event.`,
- }),
- temperature: 0,
- ...googleProviderOptions("resolveEvent", params.labels),
- });
-
- if (params.costTracking) {
- recordLlmCall({
- costTracking: params.costTracking,
- model: EVENT_MODEL,
- usage,
- stage: "resolveEvent",
- });
- }
-
- return {
- matchedKey: object.matchedKey ?? null,
- isNew: object.matchedKey ? false : object.isNew !== false,
- label: object.label ?? "",
- reason: object.reason ?? "",
- };
-}
-
-const materialDevSchema = z.object({
- material: z.boolean(),
- reason: z.string(),
-});
-
-export async function judgeMaterialDevelopment(params: {
- goal: string;
- subject: string;
- eventLabel: string;
- result: { title: string; evidence: string };
- costTracking?: CostTracking;
- labels?: LlmUsageLabels;
-}): Promise<{ material: boolean; reason: string }> {
- const { object, usage } = await generateObject({
- model: googleModel(EVENT_MODEL),
- schema: materialDevSchema,
- system:
- "You decide whether a new search result represents a MATERIAL development of an already-known, already-alerted event, versus a duplicate retelling that adds nothing new. Material = a concrete new stage, fact, or change in the event's status. A different outlet covering the same already-known facts is NOT material. Return structured JSON only.",
- prompt: JSON.stringify({
- monitor: { goal: params.goal, subject: params.subject },
- knownEvent: params.eventLabel,
- newResult: {
- title: params.result.title,
- evidence: (params.result.evidence || "").slice(0, 500),
- },
- instructions: `Set material true only when the new result reports a genuinely new development of the known event.
-Set material false when it restates already-known facts, even from a new source or headline.`,
- }),
- temperature: 0,
- ...googleProviderOptions("judgeMaterialDevelopment", params.labels),
- });
- if (params.costTracking) {
- recordLlmCall({
- costTracking: params.costTracking,
- model: EVENT_MODEL,
- usage,
- stage: "judgeMaterialDevelopment",
- });
- }
- return { material: object.material === true, reason: object.reason ?? "" };
-}
-
-const alertSkepticSchema = z.object({
- refuted: z.boolean(),
- failureMode: z.enum([
- "wrong_subject",
- "listing_surface",
- "not_completed",
- "adjacent_event",
- "query_echo",
- "self_contradiction",
- "other",
- "none",
- ]),
- reason: z.string(),
-});
-
-export type SkepticVerdict = z.infer<typeof alertSkepticSchema>;
-
-export async function reviewAlert(params: {
- goal: string;
- subject: string;
- criteria: GoalCriteria | null;
- result: {
- title: string;
- url: string;
- snippet: string;
- concept: string;
- judgeAnswer: string;
- };
- costTracking?: CostTracking;
- labels?: LlmUsageLabels;
-}): Promise<SkepticVerdict> {
- const { object, usage } = await generateObject({
- model: googleModel(SKEPTIC_MODEL),
- schema: alertSkepticSchema,
- system:
- "You are the adversarial reviewer for a web-monitoring alert that is about to be sent to a paying user. Try to REFUTE it. Refute when any of these hold: (1) wrong_subject β€” the story's protagonist is a different entity than the monitored subject; the subject being name-dropped, compared against, or listed among others is NOT coverage of the subject; (2) listing_surface β€” the page is an aggregator, directory, category, calendar, homepage, or feed surface rather than a single story; (3) not_completed β€” the goal asks for a completed event but this is upcoming, rumored, or planned; (4) adjacent_event β€” a related-but-different event type OR an off-topic subject in the same broad field (funding news on a release monitor, a partnership on a lawsuit monitor, or a coding/productivity/impact study on a monitor that asks only for safety/alignment research). A credible source or the right organization is NOT enough if the core subject is merely adjacent to the goal's specific topic, or falls into a category the goal says to ignore; (5) query_echo β€” the only evidence is the search query's own wording reflected back in a snippet; (6) self_contradiction β€” the judge's own rationale undercuts the alert (admits the evidence is missing, insufficient, unconfirmed, or merely related). UPHOLD the alert (refuted=false, failureMode=none) when the result directly and concretely satisfies the goal β€” do not refute clear matches on technicalities. The subject's OWN official announcement satisfies an event goal (release, launch, filing, pricing change); never refute an official primary source unless the goal explicitly asks for third-party coverage. Return structured JSON only.",
- prompt: JSON.stringify({
- monitor: {
- goal: params.goal,
- subject: params.subject,
- ...(params.criteria
- ? {
- subjectAliases: params.criteria.subjectAliases,
- excludedSubjects: params.criteria.excludedSubjects,
- mustConcern: params.criteria.mustConcern,
- }
- : {}),
- },
- alertCandidate: {
- title: params.result.title,
- url: params.result.url,
- snippet: params.result.snippet.slice(0, 600),
- judgeConcept: params.result.concept,
- judgeAnswer: params.result.judgeAnswer.slice(0, 800),
- },
- }),
- temperature: 0,
- ...googleProviderOptions("reviewAlert", params.labels),
- });
- if (params.costTracking) {
- recordLlmCall({
- costTracking: params.costTracking,
- model: SKEPTIC_MODEL,
- usage,
- stage: "reviewAlert",
- });
- }
- return object;
-}
-
-const routerSchema = z.object({
- decisions: z.array(
- z.object({
- id: z.string(),
- decision: z.enum(["scrape", "skip"]),
- priority: z.number(),
- reason: z.string(),
- }),
- ),
-});
-
-export type RouteDecision = {
- id: string;
- decision: "scrape" | "skip";
- priority: number;
- reason: string;
-};
-
-export async function routeSearchResults(params: {
- goal: string;
- subject: string;
- searchWindow: string;
- maxResults: number;
- candidates: Array<{
- id: string;
- query: string;
- title: string;
- url: string;
- snippet: string;
- }>;
- costTracking?: CostTracking;
- labels?: LlmUsageLabels;
-}): Promise<RouteDecision[]> {
- const candidates = params.candidates.slice(0, 50);
- const { object, usage } = await generateObject({
- model: googleModel(ROUTER_MODEL),
- schema: routerSchema,
- system:
- "You route search results for a monitoring product. Decide which indexed results are worth spending scrape/judge credits on. Use only the SERP title, URL, snippet, query, monitor goal, and search window. Return structured JSON only.",
- prompt: JSON.stringify({
- monitor: { goal: params.goal, subject: params.subject },
- searchWindow: params.searchWindow,
- maxResults: params.maxResults,
- instructions: `Select scrape only when the result could plausibly contain primary evidence or substantive discussion satisfying the monitor goal.
-Skip obvious jobs, directories, tag pages, search pages, marketplaces, profiles, irrelevant foreign-language spam, generic tool lists, or pages where the monitored subject appears only as a skill, integration, or incidental keyword.
-Do not use keyword overlap alone. Explain the user-facing reason.
-Never select more than maxResults.`,
- candidates,
- }),
- temperature: 0,
- ...googleProviderOptions("routeSearchResults", params.labels),
- });
- if (params.costTracking) {
- recordLlmCall({
- costTracking: params.costTracking,
- model: ROUTER_MODEL,
- usage,
- stage: "routeSearchResults",
- });
- }
- const validIds = new Set(candidates.map(c => c.id));
- return object.decisions
- .filter(d => validIds.has(d.id))
- .map(d => ({
- id: d.id,
- decision: d.decision,
- priority: Math.min(1, Math.max(0, d.priority)),
- reason: d.reason.slice(0, 500),
- }));
-}
-
const snippetVerdictSchema = z.object({
verdicts: z.array(
z.object({
@@ -322,42 +72,3 @@ export async function judgeSnippets(params: {
const validIds = new Set(params.candidates.map(c => c.id));
return object.verdicts.filter(v => validIds.has(v.id));
}
-
-const runSummarySchema = z.object({
- label: z.enum(["meaningful", "already_satisfied", "not_meaningful"]),
- summary: z.string(),
-});
-
-export async function summarizeRun(params: {
- goal: string;
- subject: string;
- evidence: Array<{ title: string; url: string; rationale: string }>;
- costTracking?: CostTracking;
- labels?: LlmUsageLabels;
-}): Promise<{ label: string; summary: string }> {
- const { object, usage } = await generateObject({
- model: googleModel(SUMMARY_MODEL),
- schema: runSummarySchema,
- system:
- "You write concise user-facing search-monitor check summaries. Use only the provided monitor goal and meaningful source evidence. Do not introduce facts not present in the evidence. Return structured JSON only.",
- prompt: JSON.stringify({
- monitor: { goal: params.goal, subject: params.subject },
- evidence: params.evidence.slice(0, 8),
- instructions: `Summarize why the meaningful sources satisfy the goal as a group, in one short sentence.
-If sources are meaningful but already reported, say they are related evidence, not a new notification.`,
- }),
- temperature: 0,
- ...googleProviderOptions("summarizeRun", params.labels),
- });
-
- if (params.costTracking) {
- recordLlmCall({
- costTracking: params.costTracking,
- model: SUMMARY_MODEL,
- usage,
- stage: "summarizeRun",
- });
- }
-
- return { label: object.label, summary: object.summary };
-}
diff --git a/apps/api/src/services/monitoring/search/run.test.ts b/apps/api/src/services/monitoring/search/run.test.ts
index 168b5a5d2..9adffa0d0 100644
--- a/apps/api/src/services/monitoring/search/run.test.ts
+++ b/apps/api/src/services/monitoring/search/run.test.ts
@@ -1,19 +1,18 @@
import type { Logger } from "winston";
-import { type SearchVerdict, verdictJsonSchema, buildJudgePrompt } from "./judge";
-import type { EventResolution } from "./llm";
+import {
+ type SearchVerdict,
+ verdictJsonSchema,
+ buildJudgePrompt,
+} from "./judge";
import { canonicalizeUrl, stableSerpFingerprint } from "./dedupe";
import { scrapeRequestSchema } from "../../../controllers/v2/types";
// vi.mock is hoisted above declarations, so the mocks its factories reference
// are created in vi.hoisted() (also hoisted) to avoid any TDZ surprises.
-const { searchMock, scrapePageMock, resolveEventMock, summarizeRunMock, materialDevMock } =
- vi.hoisted(() => ({
- searchMock: vi.fn(),
- scrapePageMock: vi.fn(),
- resolveEventMock: vi.fn(),
- summarizeRunMock: vi.fn(),
- materialDevMock: vi.fn(),
- }));
+const { searchMock, scrapePageMock } = vi.hoisted(() => ({
+ searchMock: vi.fn(),
+ scrapePageMock: vi.fn(),
+}));
vi.mock("uuid", () => ({ v7: () => "00000000-0000-7000-8000-000000000000" }));
vi.mock("../../../search/v2", () => ({
@@ -24,11 +23,9 @@ vi.mock("../../../search/v2", () => ({
return Array.isArray(r) ? { web: r } : r;
},
}));
-vi.mock("./llm", () => ({
- resolveEvent: (...a: unknown[]) => resolveEventMock(...a),
- summarizeRun: (...a: unknown[]) => summarizeRunMock(...a),
- judgeMaterialDevelopment: (...a: unknown[]) => materialDevMock(...a),
-}));
+// Deep mode (these tests) scrapes + parses a per-page JSON verdict and dedups by
+// canonical URL β€” no LLM chain. judgeSnippets (standard mode) is never reached.
+vi.mock("./llm", () => ({ judgeSnippets: vi.fn() }));
vi.mock("./tuning", () => ({
hasLlmProvider: () => false,
googleProviderOptions: () => ({}),
@@ -90,9 +87,7 @@ function run(
over: {
target?: Partial<typeof baseTarget> & { recheckAfter?: string };
knownPages?: Map<string, KnownPage>;
- knownEvents?: EventResolution[] extends never
- ? never
- : { key: string; label: string }[];
+ knownEvents?: { key: string; label: string }[];
goalVersion?: string;
alertMode?: "first_match" | "every_new_result" | "material_dev";
} = {},
@@ -116,17 +111,6 @@ function run(
beforeEach(() => {
vi.clearAllMocks();
- resolveEventMock.mockResolvedValue({
- matchedKey: null,
- isNew: true,
- label: "OpenAI IPO",
- reason: "",
- });
- summarizeRunMock.mockResolvedValue({
- label: "meaningful",
- summary: "OpenAI filed for IPO.",
- });
- materialDevMock.mockResolvedValue({ material: false, reason: "" });
});
describe("runSearchTarget orchestration", () => {
@@ -146,7 +130,7 @@ describe("runSearchTarget orchestration", () => {
expect(out.sources[0].status).toBe("alert");
expect(out.sources[0].eventKey).toBeTruthy();
expect(out.pageUpserts[0].status).toBe("alert");
- expect(out.summary).toBe("OpenAI filed for IPO.");
+ expect(out.summary).toBe("1 match across 1 result.");
expect(scrapePageMock).toHaveBeenCalledTimes(1);
});
@@ -284,50 +268,31 @@ describe("runSearchTarget orchestration", () => {
expect(out.sources[0].status).toBe("alert");
});
- it("first_match: suppresses a second result resolving to the same event", async () => {
+ it("first_match: suppresses a result whose URL is an already-satisfied event", async () => {
setSearchResults([
{
url: "https://sec.gov/openai",
title: "OpenAI S-1",
description: "filing",
},
- {
- url: "https://nytimes.com/openai-ipo",
- title: "OpenAI to IPO",
- description: "report",
- },
]);
- setVerdictsByUrl({
- "https://sec.gov/openai": verdict(),
- "https://nytimes.com/openai-ipo": verdict({ concept: "openai-ipo" }),
+ setVerdictsByUrl({ "https://sec.gov/openai": verdict() });
+ const canonical = canonicalizeUrl("https://sec.gov/openai");
+
+ const out = await run({
+ alertMode: "first_match",
+ knownEvents: [{ key: canonical, label: "OpenAI IPO" }],
});
- resolveEventMock
- .mockResolvedValueOnce({
- matchedKey: null,
- isNew: true,
- label: "OpenAI IPO",
- reason: "",
- })
- .mockResolvedValueOnce({
- matchedKey: "00000000-0000-7000-8000-000000000000",
- isNew: false,
- label: "OpenAI IPO",
- reason: "same",
- });
-
- const out = await run({ alertMode: "first_match" });
-
- const statuses = out.sources.map(s => s.status);
- expect(statuses).toContain("alert");
- expect(statuses).toContain("already_seen");
- expect(out.matches).toBe(1);
+
+ expect(out.matches).toBe(0);
+ expect(out.sources[0].status).toBe("already_seen");
// the suppressed result was still deep-scraped and judged
const seen = out.pageUpserts.find(u => u.status === "already_seen")!;
expect(seen.scraped).toBe(true);
expect(seen.metadata.searchStatus).toBe("already_seen");
});
- it("mints a stable opaque key for new events (not a label slug)", async () => {
+ it("uses the canonical URL as the event key (label is the verdict concept)", async () => {
setSearchResults([
{
url: "https://sec.gov/openai",
@@ -335,42 +300,34 @@ describe("runSearchTarget orchestration", () => {
description: "filing",
},
]);
- setVerdictsByUrl({ "https://sec.gov/openai": verdict() });
- resolveEventMock.mockResolvedValue({
- matchedKey: null,
- isNew: true,
- label: "OpenAI's IPO Filing!!!",
- reason: "",
+ setVerdictsByUrl({
+ "https://sec.gov/openai": verdict({ concept: "OpenAI IPO filing" }),
});
const out = await run();
expect(out.sources[0].eventKey).toBe(
- "00000000-0000-7000-8000-000000000000",
- );
- expect(out.pageUpserts[0].metadata.eventLabel).toBe(
- "OpenAI's IPO Filing!!!",
+ canonicalizeUrl("https://sec.gov/openai"),
);
+ expect(out.pageUpserts[0].metadata.eventLabel).toBe("OpenAI IPO filing");
});
- it("reuses a matched event's key even when the new label differs (no drift)", async () => {
+ it("every_new_result: re-alerts a URL that is already a known event", async () => {
setSearchResults([
{
- url: "https://reuters.com/openai",
- title: "Reuters: OpenAI IPO",
- description: "report",
+ url: "https://sec.gov/openai",
+ title: "OpenAI S-1",
+ description: "filing",
},
]);
- setVerdictsByUrl({ "https://reuters.com/openai": verdict() });
- resolveEventMock.mockResolvedValue({
- matchedKey: "evt-stable-123",
- isNew: false,
- label: "A completely reworded label",
- reason: "same event",
- });
+ setVerdictsByUrl({ "https://sec.gov/openai": verdict() });
+ const canonical = canonicalizeUrl("https://sec.gov/openai");
+
const out = await run({
- knownEvents: [{ key: "evt-stable-123", label: "OpenAI IPO" }],
+ alertMode: "every_new_result",
+ knownEvents: [{ key: canonical, label: "OpenAI IPO" }],
});
- expect(out.sources[0].eventKey).toBe("evt-stable-123");
- expect(out.pageUpserts[0].metadata.eventLabel).toBe("OpenAI IPO");
+
+ expect(out.matches).toBe(1);
+ expect(out.sources[0].status).toBe("alert");
});
it("keeps a judge-watched (e.g. old-news) verdict at watch (no notify)", async () => {
@@ -389,7 +346,6 @@ describe("runSearchTarget orchestration", () => {
expect(out.sources[0].status).toBe("watching");
expect(out.matches).toBe(0);
- expect(resolveEventMock).not.toHaveBeenCalled();
});
it("marks a result skipped when the scrape fails", async () => {
diff --git a/apps/api/src/services/monitoring/search/run.ts b/apps/api/src/services/monitoring/search/run.ts
index c84b89247..d3e3a8ff2 100644
--- a/apps/api/src/services/monitoring/search/run.ts
+++ b/apps/api/src/services/monitoring/search/run.ts
@@ -1,4 +1,3 @@
-import { v7 as uuidv7 } from "uuid";
import type { Logger } from "winston";
import { search } from "../../../search/v2";
import { buildSearchQuery } from "../../../lib/search-query-builder";
@@ -12,23 +11,8 @@ import {
windowToMs,
type SearchVerdict,
} from "./judge";
-import {
- judgeMaterialDevelopment,
- judgeSnippets,
- resolveEvent,
- reviewAlert,
- routeSearchResults,
- summarizeRun,
- type KnownEvent,
- type RouteDecision,
- type SkepticVerdict,
- type SnippetVerdict,
-} from "./llm";
-import {
- compileGoalCriteria,
- compileGoalCriteriaWithLlm,
- type GoalCriteria,
-} from "./criteria";
+import { judgeSnippets, type KnownEvent, type SnippetVerdict } from "./llm";
+import { compileGoalCriteria, type GoalCriteria } from "./criteria";
import {
verifyAlertCandidate,
type VerificationResult,
@@ -334,67 +318,14 @@ export async function runSearchTarget(params: {
const judgeGoal: string = goal ?? "";
- let criteria: GoalCriteria = compileGoalCriteria({
+ // Deterministic criteria for the (non-LLM) verifier β€” no LLM enrich/router.
+ const criteria: GoalCriteria = compileGoalCriteria({
goal: judgeGoal,
subject,
goalVersion,
});
- if (llmStagesAvailable && depth !== "raw") {
- try {
- criteria = await compileGoalCriteriaWithLlm({
- goal: judgeGoal,
- subject,
- queries: target.queries,
- goalVersion,
- costTracking,
- labels,
- });
- } catch (error) {
- logger.warn(
- "search monitor criteria compile failed, keeping deterministic",
- {
- error,
- },
- );
- }
- }
- let selected = candidates.slice(0, target.maxResults);
- if (depth === "deep" && llmStagesAvailable && candidates.length > 0) {
- if (candidates.length > 50) {
- logger.info("search monitor router capped candidates at 50", {
- total: candidates.length,
- });
- }
- try {
- const decisions = await routeSearchResults({
- goal: judgeGoal,
- subject,
- searchWindow: target.searchWindow,
- maxResults: target.maxResults,
- costTracking,
- labels,
- candidates: candidates.map((c, i) => ({
- id: `result_${i + 1}`,
- query: c.query,
- title: c.title,
- url: c.url,
- snippet: c.description,
- })),
- });
- const byId = new Map<string, RouteDecision>(
- decisions.map(d => [d.id, d]),
- );
- const routed = candidates
- .map((c, i) => ({ c, routing: byId.get(`result_${i + 1}`) }))
- .filter(r => r.routing?.decision === "scrape")
- .sort((a, b) => (b.routing?.priority ?? 0) - (a.routing?.priority ?? 0))
- .map(r => r.c);
- selected = routed.slice(0, target.maxResults);
- } catch (error) {
- logger.warn("search monitor router failed open to top-K", { error });
- }
- }
+ const selected = candidates.slice(0, target.maxResults);
const recheckMs = target.recheckAfter ? windowToMs(target.recheckAfter) : 0;
const pageNeedsJudgment = (c: {
@@ -709,34 +640,6 @@ export async function runSearchTarget(params: {
}
}
- if (decision === "notify" && llmStagesAvailable) {
- try {
- const skeptic: SkepticVerdict = await reviewAlert({
- goal: judgeGoal,
- subject,
- criteria,
- costTracking,
- labels,
- result: {
- title: c.title,
- url: c.url,
- snippet: c.description,
- concept: verdict.concept,
- judgeAnswer: verdict.rationale,
- },
- });
- if (skeptic.refuted) {
- decision = "watch";
- logger.info("search monitor alert refuted by skeptic", {
- url: c.url,
- failureMode: skeptic.failureMode,
- reason: skeptic.reason,
- });
- }
- } catch (error) {
- logger.warn("search monitor skeptic failed open", { error });
- }
- }
const baseMeta = {
fingerprint,
goalVersion,
@@ -782,60 +685,14 @@ export async function runSearchTarget(params: {
continue;
}
- let resolution;
- try {
- resolution = await resolveEvent({
- goal: judgeGoal,
- subject,
- costTracking,
- labels,
- result: {
- title: c.title,
- url: c.url,
- evidence: verdict.rationale,
- },
- candidates: events,
- });
- } catch (error) {
- logger.warn("search monitor event resolver failed open to new event", {
- error,
- });
- resolution = {
- matchedKey: null,
- isNew: true,
- label: verdict.concept,
- reason: "resolver_failed",
- };
- }
- const matched =
- resolution.matchedKey &&
- events.find(e => e.key === resolution.matchedKey);
- const eventKey = matched ? matched.key : uuidv7();
- const eventLabel = matched
- ? matched.label
- : resolution.label || verdict.concept;
-
- let alreadySatisfied = false;
- if (satisfied.has(eventKey)) {
- if (target.alertMode === "first_match") {
- alreadySatisfied = true;
- } else if (target.alertMode === "material_dev") {
- try {
- const dev = await judgeMaterialDevelopment({
- goal: judgeGoal,
- subject,
- eventLabel,
- costTracking,
- labels,
- result: { title: c.title, evidence: verdict.rationale },
- });
- alreadySatisfied = !dev.material;
- } catch (error) {
- logger.warn("search monitor material judge failed closed", { error });
- alreadySatisfied = true;
- }
- }
- }
+ // Deterministic event key: dedup by canonical URL (no LLM event resolver).
+ const eventKey = canonical;
+ const eventLabel = verdict.concept || canonical;
+
+ // Re-alert on every new result only in every_new_result mode; otherwise the
+ // canonical URL is deduped so we don't re-alert the same page.
+ const alreadySatisfied =
+ satisfied.has(eventKey) && target.alertMode !== "every_new_result";
const eventMeta = { ...baseMeta, eventKey, eventLabel };
if (alreadySatisfied) {
@@ -905,32 +762,10 @@ export async function runSearchTarget(params: {
s => s.status === "alert" || s.status === "already_seen",
).length;
- let summary = "";
- if (matches > 0 && depth === "raw") {
- summary = `${matches} new search result${matches === 1 ? "" : "s"} matched the monitor queries.`;
- } else if (matches > 0) {
- try {
- const out = await summarizeRun({
- goal: judgeGoal,
- subject,
- costTracking,
- labels,
- evidence: sources
- .filter(s => s.status === "alert")
- .map(s => ({
- title: s.title,
- url: s.url,
- rationale: s.rationale ?? "",
- })),
- });
- summary = out.summary;
- } catch (error) {
- logger.warn("search monitor summarizer failed; using fallback summary", {
- error,
- });
- summary = `${matches} new result${matches === 1 ? "" : "s"} matched the monitor goal.`;
- }
- }
+ let summary =
+ matches > 0
+ ? `${matches} match${matches === 1 ? "" : "es"} across ${resultCount} result${resultCount === 1 ? "" : "s"}.`
+ : "";
const deepJudgeFailed =
depth === "deep" &&