Skip to content

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

monitor search: judge, billing & degraded handling

Developers Digest8a6e156b9f03
diff --git a/apps/api/src/__tests__/snips/v2/types-validation.test.ts b/apps/api/src/__tests__/snips/v2/types-validation.test.ts
index a003619f9..e6938b01b 100644
--- a/apps/api/src/__tests__/snips/v2/types-validation.test.ts
+++ b/apps/api/src/__tests__/snips/v2/types-validation.test.ts
@@ -1428,6 +1428,32 @@ describe("V2 Types Validation", () => {
const result = updateMonitorSchema.parse({ goal: null });
expect(result.goal).toBeNull();
});
+
+ it("create allows a raw search target (judgeEnabled:false) without a goal", () => {
+ const result = createMonitorSchema.parse({
+ name: "Raw search monitor",
+ schedule: { text: "every 30 minutes" },
+ targets: searchTargets,
+ judgeEnabled: false,
+ });
+ expect(result.targets).toHaveLength(1);
+ expect(result.judgeEnabled).toBe(false);
+ });
+
+ it("create still defaults judgeEnabled true when a goal is present", () => {
+ const result = createMonitorSchema.parse({
+ name: "Judged search monitor",
+ schedule: { text: "every 30 minutes" },
+ targets: searchTargets,
+ goal: "Alert when Firecrawl launches",
+ });
+ expect(result.judgeEnabled).toBe(true);
+ });
+
+ it("update with just { goal } does NOT silently enable judging", () => {
+ const result = updateMonitorSchema.parse({ goal: "Alert when X ships" });
+ expect(result.judgeEnabled).toBeUndefined();
+ });
});
describe("Edge cases", () => {
diff --git a/apps/api/src/controllers/v2/monitor.ts b/apps/api/src/controllers/v2/monitor.ts
index e1c98b6f5..3e850744b 100644
--- a/apps/api/src/controllers/v2/monitor.ts
+++ b/apps/api/src/controllers/v2/monitor.ts
@@ -295,13 +295,15 @@ export async function updateMonitorController(
const input = updateMonitorSchema.parse(req.body);
- // Validate the merged monitor state: a partial update can add search
- // targets that rely on the stored goal, or clear the goal while search
- // targets remain on the monitor. Both must leave a non-empty goal behind.
const mergedTargets = input.targets ?? existing.targets;
const mergedGoal = input.goal !== undefined ? input.goal : existing.goal;
+ const mergedJudgeEnabled =
+ input.judgeEnabled !== undefined
+ ? input.judgeEnabled
+ : existing.judge_enabled;
if (
mergedTargets.some(t => t.type === "search") &&
+ mergedJudgeEnabled !== false &&
(typeof mergedGoal !== "string" || mergedGoal.trim().length === 0)
) {
return res.status(400).json({
diff --git a/apps/api/src/lib/tracking.test.ts b/apps/api/src/lib/tracking.test.ts
index e9bd7f9ce..4b02034c8 100644
--- a/apps/api/src/lib/tracking.test.ts
+++ b/apps/api/src/lib/tracking.test.ts
@@ -117,6 +117,12 @@ describe("monitor target interest tracking", () => {
expect(signatureFor({ ...searchTarget })).toBe(base);
expect(signatureFor({ ...searchTarget, maxResults: 25 })).not.toBe(base);
expect(signatureFor({ ...searchTarget, depth: "standard" })).not.toBe(base);
+ expect(
+ signatureFor({ ...searchTarget, includeDomains: ["firecrawl.dev"] }),
+ ).not.toBe(base);
+ expect(
+ signatureFor({ ...searchTarget, excludeDomains: ["spam.example"] }),
+ ).not.toBe(base);
});
it("sends rows to the monitor target ClickHouse table", async () => {
diff --git a/apps/api/src/lib/tracking.ts b/apps/api/src/lib/tracking.ts
index eaf61d31c..07b907115 100644
--- a/apps/api/src/lib/tracking.ts
+++ b/apps/api/src/lib/tracking.ts
@@ -138,6 +138,8 @@ function monitorTargetSignature(target: MonitorTarget): string {
alertMode: target.alertMode,
maxResults: target.maxResults,
depth: target.depth ?? null,
+ includeDomains: [...(target.includeDomains ?? [])].sort(),
+ excludeDomains: [...(target.excludeDomains ?? [])].sort(),
});
}
diff --git a/apps/api/src/services/monitoring/runner.ts b/apps/api/src/services/monitoring/runner.ts
index e50d1b461..0a0247f46 100644
--- a/apps/api/src/services/monitoring/runner.ts
+++ b/apps/api/src/services/monitoring/runner.ts
@@ -126,14 +126,7 @@ type MonitorTargetRun =
resultCount?: number;
matches?: number;
summary?: string;
- // True when a query failed at the provider after retries (not legitimately
- // empty); persisted so an empty-but-degraded run isn't read as "no changes".
- searchDegraded?: boolean;
- // True when the deep (scrape+judge) path was expected to evaluate results
- // but evaluated ~none because the per-result scrapes failed; persisted so a
- // judged check that scraped nothing isn't read as a clean "no changes".
judgeDegraded?: boolean;
- // Human-readable explanation for whichever degraded flag is set.
degradedReason?: string | null;
// Flat, deterministic credits recorded onto target_results when the search
// completes; actual_credits is summed from these, not reconstructed from
@@ -991,7 +984,6 @@ async function runMonitorSearchTarget(params: {
resultCount: number;
matches: number;
summary: string;
- searchDegraded: boolean;
judgeDegraded: boolean;
degradedReason: string | null;
// Flat, deterministic credits, recorded onto target_results by the caller.
@@ -1005,7 +997,6 @@ async function runMonitorSearchTarget(params: {
resultCount: 0,
matches: 0,
summary: "",
- searchDegraded: false,
judgeDegraded: false,
degradedReason: null,
searchCredits: 0,
@@ -1014,7 +1005,11 @@ async function runMonitorSearchTarget(params: {
};
}
const { monitor, check, target } = params;
- const goalVersion = computeGoalVersion(monitor.goal, target.queries);
+ const goalVersion = computeGoalVersion(
+ monitor.goal,
+ monitor.name,
+ target.queries,
+ );
// Rebuild per-URL dedup memory + event index from this target's prior pages.
const priorPages = await listActiveMonitorPages({
@@ -1119,7 +1114,6 @@ async function runMonitorSearchTarget(params: {
resultCount: result.resultCount,
matches: result.matches,
summary: result.summary,
- searchDegraded: result.searchDegraded,
judgeDegraded: result.judgeDegraded,
degradedReason: result.degradedReason,
searchCredits,
@@ -1230,7 +1224,6 @@ export async function processMonitorCheckJob(
targetRun.resultCount = searchResult.resultCount;
targetRun.matches = searchResult.matches;
targetRun.summary = searchResult.summary;
- targetRun.searchDegraded = searchResult.searchDegraded;
targetRun.judgeDegraded = searchResult.judgeDegraded;
targetRun.degradedReason = searchResult.degradedReason;
// Persisted onto target_results below so they survive to finalization.
diff --git a/apps/api/src/services/monitoring/search/billing.ts b/apps/api/src/services/monitoring/search/billing.ts
new file mode 100644
index 000000000..2d014916b
--- /dev/null
+++ b/apps/api/src/services/monitoring/search/billing.ts
@@ -0,0 +1,17 @@
+const SEARCH_CREDITS_PER_TEN_RESULTS = 2;
+const SEARCH_CREDITS_PER_TEN_RESULTS_ZDR = 10;
+const SEARCH_JUDGE_CREDITS_PER_RESULT = 5;
+
+export function searchCreditsForResultCount(
+ rawResultCount: number,
+ isZDR: boolean,
+): number {
+ const perBatch = isZDR
+ ? SEARCH_CREDITS_PER_TEN_RESULTS_ZDR
+ : SEARCH_CREDITS_PER_TEN_RESULTS;
+ return Math.ceil(Math.max(0, rawResultCount) / 10) * perBatch;
+}
+
+export function judgeCreditsForJudgedCount(judgedCount: number): number {
+ return Math.max(0, judgedCount) * SEARCH_JUDGE_CREDITS_PER_RESULT;
+}
diff --git a/apps/api/src/services/monitoring/search/dedupe.test.ts b/apps/api/src/services/monitoring/search/dedupe.test.ts
new file mode 100644
index 000000000..8e0c3bafe
--- /dev/null
+++ b/apps/api/src/services/monitoring/search/dedupe.test.ts
@@ -0,0 +1,23 @@
+import { computeGoalVersion } from "./dedupe";
+
+describe("computeGoalVersion", () => {
+ it("is stable for the same goal, subject, and queries", () => {
+ expect(computeGoalVersion("g", "OpenAI", ["a", "b"])).toBe(
+ computeGoalVersion("g", "OpenAI", ["b", "a"]),
+ );
+ });
+
+ it("changes when the subject (monitor name) changes", () => {
+ // Renaming the monitor must invalidate prior judgments even when the goal
+ // and queries are unchanged.
+ expect(computeGoalVersion("g", "OpenAI", ["a"])).not.toBe(
+ computeGoalVersion("g", "Anthropic", ["a"]),
+ );
+ });
+
+ it("changes when the goal changes", () => {
+ expect(computeGoalVersion("g1", "s", ["a"])).not.toBe(
+ computeGoalVersion("g2", "s", ["a"]),
+ );
+ });
+});
diff --git a/apps/api/src/services/monitoring/search/dedupe.ts b/apps/api/src/services/monitoring/search/dedupe.ts
index bdd78bb20..e6eeed314 100644
Binary files a/apps/api/src/services/monitoring/search/dedupe.ts and b/apps/api/src/services/monitoring/search/dedupe.ts differ
diff --git a/apps/api/src/services/monitoring/search/run-defenses.test.ts b/apps/api/src/services/monitoring/search/run-defenses.test.ts
index 52fbb61ab..6dde28819 100644
--- a/apps/api/src/services/monitoring/search/run-defenses.test.ts
+++ b/apps/api/src/services/monitoring/search/run-defenses.test.ts
@@ -458,11 +458,17 @@ describe("deep-path scrape failures mark the check degraded (no silent empty)",
expect(result.resultsJudged).toBe(0);
expect(result.matches).toBe(0);
expect(result.judgeDegraded).toBe(true);
- expect(result.degradedReason).toMatch(/scrape/i);
- // searchDegraded is the provider-level signal and stays false here.
- expect(result.searchDegraded).toBe(false);
+ expect(result.degradedReason).toMatch(/judged|incomplete/i);
// A non-empty summary so the check never reads as a clean "nothing new".
expect(result.summary).not.toBe("");
+ // Each unscrapeable result is persisted as a "skipped" page so it surfaces
+ // as an error check page (skipped -> error) instead of silently vanishing.
+ const skippedUpserts = result.pageUpserts.filter(
+ u => u.status === "skipped",
+ );
+ expect(skippedUpserts).toHaveLength(2);
+ expect(skippedUpserts[0].metadata.searchStatus).toBe("skipped");
+ expect(skippedUpserts[0].metadata.judgedThisRun).toBe(false);
});
it("degraded=true when scrapes throw", async () => {
@@ -472,7 +478,7 @@ describe("deep-path scrape failures mark the check degraded (no silent empty)",
expect(result.resultsJudged).toBe(0);
expect(result.judgeDegraded).toBe(true);
- expect(result.degradedReason).toMatch(/scrape/i);
+ expect(result.degradedReason).toMatch(/judged|incomplete/i);
});
it("NOT degraded when at least one scrape succeeds and is judged", async () => {
@@ -524,8 +530,19 @@ describe("deep-path scrape failures mark the check degraded (no silent empty)",
expect(result.resultCount).toBe(0);
expect(result.judgeDegraded).toBe(false);
- expect(result.searchDegraded).toBe(false);
expect(result.degradedReason).toBeNull();
expect(scrapeURLMock).not.toHaveBeenCalled();
});
+
+ it("degraded=true when the standard snippet judge fails for every candidate", async () => {
+ searchMock.mockResolvedValue([serpRow(1), serpRow(2)]);
+ snippetsMock.mockRejectedValue(new Error("snippet judge outage"));
+
+ const result = await runSearchTarget(runParams({ depth: "standard" }));
+
+ expect(result.resultsJudged).toBe(0);
+ expect(result.matches).toBe(0);
+ expect(result.judgeDegraded).toBe(true);
+ expect(result.degradedReason).toMatch(/judged|incomplete/i);
+ });
});
diff --git a/apps/api/src/services/monitoring/search/run.ts b/apps/api/src/services/monitoring/search/run.ts
index 3ba50072d..40adca9b3 100644
--- a/apps/api/src/services/monitoring/search/run.ts
+++ b/apps/api/src/services/monitoring/search/run.ts
@@ -38,8 +38,10 @@ import {
type VerifyEvidence,
} from "./verify";
import { hasGeminiKey } from "./tuning";
-
-const JUDGE_CREDITS_PER_RESULT = 5;
+import {
+ searchCreditsForResultCount,
+ judgeCreditsForJudgedCount,
+} from "./billing";
function windowToTbs(window: string): string {
if (window === "5m" || window === "15m" || window === "1h") return "qdr:h";
@@ -142,7 +144,6 @@ type SearchTargetRunResult = {
meaningful: number;
matches: number;
summary: string;
- searchDegraded: boolean;
judgeDegraded: boolean;
degradedReason: string | null;
sources: SearchSource[];
@@ -202,6 +203,7 @@ export async function runSearchTarget(params: {
let searchResultsBilled = 0;
let resultsJudged = 0;
let judgeScrapeFailures = 0;
+ let snippetJudgeFailed = false;
const seenThisRun = new Map<string, number>();
const candidates: Array<{
@@ -382,6 +384,7 @@ export async function runSearchTarget(params: {
}
});
} catch (error) {
+ snippetJudgeFailed = true;
logger.warn("search monitor snippet judge failed; results skipped", {
error,
});
@@ -395,6 +398,24 @@ export async function runSearchTarget(params: {
title: c.title,
snippet: c.description,
});
+ const pushUnevaluatedPage = (error: string) => {
+ skipped += 1;
+ sources.push({ url: c.url, title: c.title, status: "skipped" });
+ pageUpserts.push({
+ url: canonical,
+ urlHash: hashMonitorUrl(canonical),
+ status: "skipped",
+ scraped: false,
+ metadata: {
+ fingerprint,
+ goalVersion,
+ searchStatus: "skipped",
+ matchedQueries: c.matchedQueries,
+ judgedThisRun: false,
+ error,
+ },
+ });
+ };
const known = knownPages.get(canonical);
const knownCurrent =
known && known.goalVersion === goalVersion ? known : undefined;
@@ -516,8 +537,12 @@ export async function runSearchTarget(params: {
if (depth === "standard") {
verdict = snippetVerdicts.get(canonical) ?? null;
if (!verdict) {
- skipped += 1;
- sources.push({ url: c.url, title: c.title, status: "skipped" });
+ if (snippetJudgeFailed) {
+ pushUnevaluatedPage("snippet judge failed");
+ } else {
+ skipped += 1;
+ sources.push({ url: c.url, title: c.title, status: "skipped" });
+ }
continue;
}
pagesChecked += 1;
@@ -546,16 +571,16 @@ export async function runSearchTarget(params: {
} catch (error) {
logger.warn("search monitor scrape threw", { url: c.url, error });
judgeScrapeFailures += 1;
- skipped += 1;
- sources.push({ url: c.url, title: c.title, status: "skipped" });
+ pushUnevaluatedPage(
+ error instanceof Error ? error.message : "scrape threw",
+ );
continue;
}
if (!res.success) {
logger.warn("search monitor scrape failed", { url: c.url });
judgeScrapeFailures += 1;
- skipped += 1;
- sources.push({ url: c.url, title: c.title, status: "skipped" });
+ pushUnevaluatedPage("scrape failed");
continue;
}
pagesChecked += 1;
@@ -563,8 +588,7 @@ export async function runSearchTarget(params: {
verdict = parseVerdict(res.document.json);
if (!verdict) {
judgeScrapeFailures += 1;
- skipped += 1;
- sources.push({ url: c.url, title: c.title, status: "skipped" });
+ pushUnevaluatedPage("verdict unparseable");
continue;
}
pageText = res.document.markdown ?? "";
@@ -820,36 +844,40 @@ export async function runSearchTarget(params: {
}
}
- const searchDegraded = false;
-
- const judgeExpected = depth === "deep" && candidates.length > 0;
- const judgeDegraded =
- judgeExpected && resultsJudged === 0 && judgeScrapeFailures > 0;
+ const deepJudgeFailed =
+ depth === "deep" &&
+ candidates.length > 0 &&
+ resultsJudged === 0 &&
+ judgeScrapeFailures > 0;
+ const standardJudgeFailed =
+ depth === "standard" && resultsJudged === 0 && snippetJudgeFailed;
+ const judgeDegraded = deepJudgeFailed || standardJudgeFailed;
if (judgeDegraded) {
logger.warn(
- "search monitor run is degraded: deep-path scrapes failed for every candidate so nothing was judged; results may be incomplete (NOT a clean no-results)",
+ "search monitor run is degraded: results were found but none could be judged; results may be incomplete (NOT a clean no-results)",
{
monitorId: params.monitor.id,
targetId: target.id,
+ depth,
candidates: candidates.length,
scrapeFailures: judgeScrapeFailures,
+ snippetJudgeFailed,
resultsJudged,
},
);
if (!summary) {
summary =
- "Results were found but could not be fetched for evaluation (scrapes failed or timed out); this check is incomplete and may have missed new developments.";
+ "Results were found but could not be evaluated (the judge step failed); this check is incomplete and may have missed new developments.";
}
}
const degradedReason: string | null = judgeDegraded
- ? "deep-path scrapes failed for every candidate so nothing was judged; results may be incomplete"
+ ? "results were found but none could be judged; results may be incomplete"
: null;
const isZDR = params.zeroDataRetention;
- const searchCredits =
- Math.ceil(searchResultsBilled / 10) * (isZDR ? 10 : 2);
- const judgeCredits = resultsJudged * JUDGE_CREDITS_PER_RESULT;
+ const searchCredits = searchCreditsForResultCount(searchResultsBilled, isZDR);
+ const judgeCredits = judgeCreditsForJudgedCount(resultsJudged);
return {
targetId: target.id,
@@ -860,7 +888,6 @@ export async function runSearchTarget(params: {
meaningful,
matches,
summary,
- searchDegraded,
judgeDegraded,
degradedReason,
sources,
diff --git a/apps/api/src/services/monitoring/search/verify.test.ts b/apps/api/src/services/monitoring/search/verify.test.ts
index 1554a04f4..220ae2d68 100644
--- a/apps/api/src/services/monitoring/search/verify.test.ts
+++ b/apps/api/src/services/monitoring/search/verify.test.ts
@@ -161,6 +161,17 @@ describe("verifyAlertCandidate", () => {
);
});
+ it("downgrades a subject-only concept that misses the topic (funding vs launch)", () => {
+ // "Firecrawl funding" names the subject but not the goal's topic (launch);
+ // a subject-alias token must NOT satisfy the must-concern gate.
+ const result = verifyAlertCandidate({
+ criteria: baseCriteria(),
+ concept: "Firecrawl Series B funding",
+ evidence: evidence(),
+ });
+ expect(result.failures.map(f => f.check)).toContain("concept_off_goal");
+ });
+
it("fails owned-surface only when the goal wants third-party coverage", () => {
const owned = verifyAlertCandidate({
criteria: baseCriteria({ thirdPartyOnly: true }),
diff --git a/apps/api/src/services/monitoring/search/verify.ts b/apps/api/src/services/monitoring/search/verify.ts
index 469117dad..eb6da75ba 100644
--- a/apps/api/src/services/monitoring/search/verify.ts
+++ b/apps/api/src/services/monitoring/search/verify.ts
@@ -76,14 +76,13 @@ export function verifyAlertCandidate(params: {
conceptText
) {
const conceptTokens = new Set(tokenizeContent(conceptText));
- const aliasTokens = criteria.subjectAliases.flatMap(tokenizeContent);
- const relevant = [...criteria.mustConcern, ...aliasTokens].some(token =>
+ const topicPresent = criteria.mustConcern.some(token =>
conceptTokens.has(token),
);
- if (conceptTokens.size > 0 && !relevant) {
+ if (conceptTokens.size > 0 && !topicPresent) {
failures.push({
check: "concept_off_goal",
- detail: `alert concept "${conceptText.slice(0, 80)}" shares no content terms with the goal`,
+ detail: `alert concept "${conceptText.slice(0, 80)}" shares no goal terms with the monitor`,
});
}
}
diff --git a/apps/api/src/services/monitoring/store.test.ts b/apps/api/src/services/monitoring/store.test.ts
index 3e1370090..8d30936c8 100644
--- a/apps/api/src/services/monitoring/store.test.ts
+++ b/apps/api/src/services/monitoring/store.test.ts
@@ -242,13 +242,14 @@ describe("FLAT deterministic search-monitor billing", () => {
).toBe(2);
});
- it("scales with queries and maxResults as an upper bound", () => {
+ it("scales search with queries but caps judge at maxResults total", () => {
const t = searchTarget({
maxResults: 20,
queries: ["a", "b", "c"],
});
- // search = ceil(20/10)*2*3 = 12; judge = 5 * (20*3) = 300 β†’ 312.
- expect(estimateMonitorCreditsPerRun([t], true)).toBe(312);
+ // search = ceil((20*3)/10)*2 = 12; judge = 5 * 20 (total cap, NOT *queries)
+ // = 100 β†’ 112. The runner judges at most maxResults candidates total.
+ expect(estimateMonitorCreditsPerRun([t], true)).toBe(112);
});
});
diff --git a/apps/api/src/services/monitoring/store.ts b/apps/api/src/services/monitoring/store.ts
index 9c700e004..667c6de2a 100644
--- a/apps/api/src/services/monitoring/store.ts
+++ b/apps/api/src/services/monitoring/store.ts
@@ -10,6 +10,10 @@ import {
estimateRunsPerMonth,
validateMonitorCron,
} from "./cron";
+import {
+ searchCreditsForResultCount,
+ judgeCreditsForJudgedCount,
+} from "./search/billing";
import type {
CreateMonitorRequest,
MonitorCheckPageInsert,
@@ -41,13 +45,6 @@ const REMOVED_PAGE_CREDITS = 0;
const X_TWITTER_POSTPROCESSOR_CREDIT_BONUS = 29;
const DEFAULT_CRAWL_LIMIT_FOR_ESTIMATE = 10000;
const MONITOR_CHECK_PAGE_BATCH_SIZE = 1000;
-// Flat search-monitor billing: search() bills 2 per 10 results per query; the
-// judge bills 5 per result evaluated. The estimate is an upper bound (all
-// results judged); real runs dedupe + cap, so actual ≀ estimate.
-// SEARCH_JUDGE_CREDITS_PER_RESULT MUST stay in sync with JUDGE_CREDITS_PER_RESULT
-// in ./search/run.ts.
-const SEARCH_CREDITS_PER_TEN_RESULTS = 2;
-const SEARCH_JUDGE_CREDITS_PER_RESULT = 5;
type MonitorCreditMetadata = {
creditsUsed?: unknown;
@@ -145,29 +142,25 @@ function estimateBaseCreditsPerPage(
return credits;
}
-// Upper bound on results the judge could evaluate in one run: every result of
-// every query, before dedupe. Real runs dedupe/cap, so actual ≀ this.
function estimateSearchJudgedResults(
target: Extract<MonitorTarget, { type: "search" }>,
): number {
- return Math.max(1, target.maxResults) * Math.max(1, target.queries.length);
+ return Math.max(1, target.maxResults);
}
function estimateSearchTargetCredits(
target: Extract<MonitorTarget, { type: "search" }>,
judgeEnabled: boolean,
): number {
- const searchCallCredits =
- Math.ceil(Math.max(1, target.maxResults) / 10) *
- SEARCH_CREDITS_PER_TEN_RESULTS *
- Math.max(1, target.queries.length);
- // No judging in raw mode or when the judge is off.
+ const rawResults =
+ Math.max(1, target.maxResults) * Math.max(1, target.queries.length);
+ const searchCallCredits = searchCreditsForResultCount(rawResults, false);
if (target.depth === "raw" || !judgeEnabled) {
return searchCallCredits;
}
return (
searchCallCredits +
- estimateSearchJudgedResults(target) * SEARCH_JUDGE_CREDITS_PER_RESULT
+ judgeCreditsForJudgedCount(estimateSearchJudgedResults(target))
);
}
diff --git a/apps/api/src/services/monitoring/types.ts b/apps/api/src/services/monitoring/types.ts
index 7f20d06b0..58dd8a160 100644
--- a/apps/api/src/services/monitoring/types.ts
+++ b/apps/api/src/services/monitoring/types.ts
@@ -169,9 +169,8 @@ const createMonitorBaseSchema = z.strictObject({
origin: z.string().optional().prefault("api"),
});
-// A search target can only be judged with a goal β€” enforce it whenever one is present.
function requireGoalForSearchTargets(
- input: { targets?: unknown; goal?: unknown },
+ input: { targets?: unknown; goal?: unknown; judgeEnabled?: unknown },
ctx: z.RefinementCtx,
): void {
const targets = input.targets;
@@ -180,11 +179,10 @@ function requireGoalForSearchTargets(
t =>
t && typeof t === "object" && (t as { type?: unknown }).type === "search",
);
+ if (!hasSearchTarget) return;
+ if (input.judgeEnabled === false) return;
const goal = input.goal;
- if (
- hasSearchTarget &&
- (typeof goal !== "string" || goal.trim().length === 0)
- ) {
+ if (typeof goal !== "string" || goal.trim().length === 0) {
ctx.addIssue({
code: "custom",
message: "A search target requires a non-empty goal",
@@ -201,7 +199,7 @@ export const createMonitorSchema = createMonitorBaseSchema
// when the patch includes search targets AND explicitly clears the goal. The
// controller re-validates the merged monitor.
function rejectGoalClearedWithSearchTargets(
- input: { targets?: unknown; goal?: unknown },
+ input: { targets?: unknown; goal?: unknown; judgeEnabled?: unknown },
ctx: z.RefinementCtx,
): void {
const targets = input.targets;
@@ -211,6 +209,7 @@ function rejectGoalClearedWithSearchTargets(
t && typeof t === "object" && (t as { type?: unknown }).type === "search",
);
if (!hasSearchTarget) return;
+ if (input.judgeEnabled === false) return;
const goal = input.goal;
if (goal === undefined) return;
if (goal === null || (typeof goal === "string" && goal.trim().length === 0)) {
@@ -228,8 +227,7 @@ export const updateMonitorSchema = createMonitorBaseSchema
status: z.enum(["active", "paused"]).optional(),
})
.superRefine(rejectGoalClearedWithSearchTargets)
- .refine(x => Object.keys(x).length > 0, "Update body cannot be empty")
- .transform(applyJudgeEnabledDefault);
+ .refine(x => Object.keys(x).length > 0, "Update body cannot be empty");
export const listMonitorsQuerySchema = z.object({
limit: z.coerce.number().int().positive().max(100).optional().default(25),
diff --git a/apps/js-sdk/firecrawl/src/v2/types.ts b/apps/js-sdk/firecrawl/src/v2/types.ts
index ae8ebcbe6..9e39360d2 100644
--- a/apps/js-sdk/firecrawl/src/v2/types.ts
+++ b/apps/js-sdk/firecrawl/src/v2/types.ts
@@ -983,7 +983,6 @@ export interface MonitorSearchTargetResult {
resultCount?: number;
matches?: number;
summary?: string;
- searchDegraded?: boolean;
judgeDegraded?: boolean;
degradedReason?: string | null;
searchCredits?: number;
@@ -1005,7 +1004,8 @@ export interface MonitorCheck {
| "completed"
| "failed"
| "partial"
- | "skipped_overlap";
+ | "skipped_overlap"
+ | "skipped_no_credits";
trigger: "scheduled" | "manual";
scheduledFor?: string | null;
startedAt?: string | null;
diff --git a/apps/python-sdk/firecrawl/v2/types.py b/apps/python-sdk/firecrawl/v2/types.py
index 88f370045..763528513 100644
--- a/apps/python-sdk/firecrawl/v2/types.py
+++ b/apps/python-sdk/firecrawl/v2/types.py
@@ -1201,7 +1201,6 @@ class MonitorTargetResult(BaseModel):
result_count: Optional[int] = Field(default=None, alias="resultCount")
matches: Optional[int] = None
summary: Optional[str] = None
- search_degraded: Optional[bool] = Field(default=None, alias="searchDegraded")
judge_degraded: Optional[bool] = Field(default=None, alias="judgeDegraded")
degraded_reason: Optional[str] = Field(default=None, alias="degradedReason")
search_credits: Optional[int] = Field(default=None, alias="searchCredits")
@@ -1214,7 +1213,7 @@ class MonitorCheck(BaseModel):
id: str
monitor_id: str = Field(alias="monitorId")
- status: Literal["queued", "running", "completed", "failed", "partial", "skipped_overlap"]
+ status: Literal["queued", "running", "completed", "failed", "partial", "skipped_overlap", "skipped_no_credits"]
trigger: Literal["scheduled", "manual"]
scheduled_for: Optional[str] = Field(default=None, alias="scheduledFor")
started_at: Optional[str] = Field(default=None, alias="startedAt")