Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
Remove search simplify-fallback and polish comments
Developers Digest50207e722f5e
diff --git a/apps/api/src/services/monitoring/queue.ts b/apps/api/src/services/monitoring/queue.tsindex 5675bf125..6347de42f 100644--- a/apps/api/src/services/monitoring/queue.ts+++ b/apps/api/src/services/monitoring/queue.ts@@ -6,11 +6,8 @@ const MONITOR_CHECK_QUEUE = "monitor.checks";const MONITOR_CHECK_DLX = "monitor.checks.dlx";const MONITOR_CHECK_DLQ = "monitor.checks.dlq";-// Search-monitor checks are an order of magnitude heavier than scrape/crawl checks-// (each one scrapes many result pages and runs a multi-stage LLM pipeline). They get-// a DEDICATED queue + consumer so a burst of search checks drains on its own slot-// and can't starve the consumer that processes everyone else's page/site/batch-// checks. prefetch is applied per-consumer, so the two consumers run independently.+// Search checks are far heavier than scrape/crawl checks, so they get a dedicated+// queue + consumer — a burst of them can't starve the page/site/batch checks.const MONITOR_SEARCH_CHECK_QUEUE = "monitor.checks.search";const MONITOR_SEARCH_CHECK_DLX = "monitor.checks.search.dlx";const MONITOR_SEARCH_CHECK_DLQ = "monitor.checks.search.dlq";@@ -26,8 +23,7 @@ export type MonitorCheckJobData = {let connection: amqp.ChannelModel | null = null;let channel: amqp.Channel | null = null;-// Declare a check queue with its dead-letter exchange/queue. Identical topology for-// the default and search queues — only the names differ.+// Declare a check queue + its dead-letter exchange/queue (same topology for both).async function assertCheckQueue(ch: amqp.Channel,queue: string,@@ -123,9 +119,8 @@ async function consumeQueue(handler: (data: MonitorCheckJobData) => Promise<void>,): Promise<void> {const ch = await getChannel();- // Per-consumer prefetch (amqplib default global=false): each consumer on the- // channel gets its own in-flight slot, so the search and default consumers don't- // block one another.+ // Per-consumer prefetch (amqplib default): each consumer gets its own in-flight+ // slot, so the search and default consumers don't block each other.await ch.prefetch(1);await ch.consume(diff --git a/apps/api/src/services/monitoring/scheduler.ts b/apps/api/src/services/monitoring/scheduler.tsindex 371d1876b..2d69bcacc 100644--- a/apps/api/src/services/monitoring/scheduler.ts+++ b/apps/api/src/services/monitoring/scheduler.ts@@ -19,8 +19,7 @@ import type { MonitorRow } from "./types";const logger = _logger.child({ module: "monitoring-scheduler" });-// Search monitors ride a dedicated check queue (see queue.ts) so their heavy checks-// can't starve everyone else's. A monitor is "search" if any of its targets is.+// Search monitors route to a dedicated check queue (see queue.ts).export function monitorIsSearch(monitor: MonitorRow): boolean {return (monitor.targets ?? []).some(target => target.type === "search");}diff --git a/apps/api/src/services/monitoring/search/run.ts b/apps/api/src/services/monitoring/search/run.tsindex ebf9b3306..c84b89247 100644--- a/apps/api/src/services/monitoring/search/run.ts+++ b/apps/api/src/services/monitoring/search/run.ts@@ -82,10 +82,8 @@ function windowToTbs(window: string): string {return "qdr:w";}-// The search backend intermittently returns an empty result set for a query that-// succeeds moments later (observed: the same query swings 0 <-> N across checks).-// Retry a few times with growing backoff so a transient empty doesn't make a whole-// check find nothing.+// Retry an empty result with growing backoff — the backend sometimes returns 0 for+// a query that succeeds moments later.const SEARCH_RETRY_BACKOFF_MS = [400, 1200, 3000, 6000] as const;async function searchWithRetry(@@ -286,43 +284,7 @@ export async function runSearchTarget(params: {},logger,);- let results = response.web ?? [];- // Boolean/over-specified queries (e.g. `X (a OR b OR c)`) frequently return- // zero results from the search backend. When that happens, retry once with a- // simplified, plain-keyword version so a poorly-phrased query still fires.- if (results.length === 0 && shouldSimplifyOnEmpty(query)) {- const simplified = simplifySearchQuery(query);- if (simplified && simplified !== query) {- const { query: simplifiedScoped } = buildSearchQuery(- simplified,- undefined,- {- includeDomains: target.includeDomains,- excludeDomains: target.excludeDomains,- },- );- const retry = await searchWithRetry(- {- query: simplifiedScoped,- logger,- num_results: target.maxResults,- tbs,- },- logger,- );- if ((retry.web?.length ?? 0) > 0) {- logger.info(- "search monitor: empty boolean query, simplified fallback hit",- {- original: query,- simplified,- results: retry.web?.length,- },- );- results = retry.web ?? [];- }- }- }+ const results = response.web ?? [];searchResultsBilled += results.length;for (const r of results) {if (!r.url) continue;@@ -348,9 +310,8 @@ export async function runSearchTarget(params: {}resultCount = candidates.length;- // A check that retrieves nothing looks identical to "nothing happened", so a- // genuine miss (search came back empty despite relevant content existing) is- // invisible. Surface it explicitly so empty-retrieval can be diagnosed/alerted on.+ // An empty retrieval is indistinguishable from "nothing matched", so log it to+ // make a genuine miss diagnosable.if (resultCount === 0) {logger.warn("search monitor: all queries returned no results after retries",@@ -503,11 +464,9 @@ export async function runSearchTarget(params: {}}- // The per-result loop below scrapes deep-mode pages one at a time, serializing- // N×(up to 20s) scrapes per check and pinning the worker for minutes. Scrape the- // new/changed candidates concurrently here and cache the docs (the scrapes are- // bounded downstream by the team's NuQ scrape queue). All dedup/event/counter- // state stays in the single-threaded loop, so only the I/O is parallelized.+ // Pre-scrape deep-mode pages concurrently and cache them, so the loop below isn't+ // a serial scrape→judge→scrape chain. Only the I/O is parallel; all dedup/event+ // state stays in the single-threaded loop. (NuQ bounds the actual scrape fan-out.)const deepDocs = new Map<string,{ doc: ScrapeSearchResult | null; error?: unknown }@@ -670,8 +629,7 @@ export async function runSearchTarget(params: {}pagesChecked += 1;} else {- // Use the doc fetched in the concurrent pre-scrape pass; fall back to an- // inline scrape only if it wasn't pre-fetched (shouldn't happen).+ // Read the doc from the pre-scrape cache; scrape inline only as a fallback.let doc: ScrapeSearchResult | null;const cached = deepDocs.get(canonical);if (cached?.error !== undefined) {diff --git a/apps/api/src/services/monitoring/search/verify.ts b/apps/api/src/services/monitoring/search/verify.tsindex 3690ed67d..82edae5ae 100644--- a/apps/api/src/services/monitoring/search/verify.ts+++ b/apps/api/src/services/monitoring/search/verify.ts@@ -102,11 +102,8 @@ export function verifyAlertCandidate(params: {}}- // `subject_missing` is a literal alias-in-page-text match — fragile: a page- // genuinely about the subject often doesn't contain the exact alias string, and- // a stray monitor name can leak into the aliases (observed: a monitor's own name- // used as the subject). Keep it as a diagnostic signal but don't suppress an- // alert on it alone; the stronger checks below remain blocking.+ // `subject_missing` is a fragile literal alias-in-page check, so keep it as a+ // diagnostic but don't let it alone suppress an alert — only the stronger checks block.const blockingFailures = failures.filter(f => f.check !== "subject_missing");return {diff --git a/apps/api/src/services/queue-worker.ts b/apps/api/src/services/queue-worker.tsindex 210193471..f85753f84 100644--- a/apps/api/src/services/queue-worker.ts+++ b/apps/api/src/services/queue-worker.ts@@ -486,8 +486,7 @@ app.listen(workerPort, (error?: Error) => {_logger.error("Failed to reconcile running monitor checks", { error });});- // Search-monitor checks drain on their own queue/consumer (see queue.ts) so a- // burst of heavy search checks can't starve page/site/batch monitor checks.+ // Search checks drain on their own consumer so they can't starve the rest.await Promise.all([consumeMonitorCheckJobs(processMonitorCheckJob),consumeMonitorSearchCheckJobs(processMonitorCheckJob),