Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): refuse data source discovery and pause monitors for teams that require ZDR (#5446)

Gergő Móricz7f1785ea8e2d
diff --git a/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts b/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts
index 84f57f0b3..7aaca6522 100644
--- a/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts
+++ b/apps/api/src/__tests__/routes/exchange-agent-managed-key.routes.test.ts
@@ -255,6 +255,26 @@ describe("hosted MCP keys on the Exchange routes the agent calls", () => {
expect(mocks.upstreamFetch).toHaveBeenCalledTimes(2);
});
+ it.each([{ searchZDR: "forced-zdr" }, { searchZDR: "forced-anon" }])(
+ "refuses discover before any upstream call for a team with %o",
+ async flags => {
+ keyResolvesAs(flags);
+ const response = await send("get", "/exchange/discover?q=gdp", "header");
+ expect(response.status).toBe(403);
+ expect(response.body.error).toBe(
+ "Provider discovery does not support zero data retention.",
+ );
+ expect(mocks.upstreamFetch).not.toHaveBeenCalled();
+ },
+ );
+
+ it("proxies discover for a team that forces scrape ZDR only", async () => {
+ keyResolvesAs({ scrapeZDR: "forced" });
+ const response = await send("get", "/exchange/discover?q=gdp", "header");
+ expect(response.status).not.toBe(403);
+ expect(mocks.upstreamFetch).toHaveBeenCalledTimes(1);
+ });
+
it.each([
[200, true],
[502, false],
diff --git a/apps/api/src/__tests__/snips/v2/lib.ts b/apps/api/src/__tests__/snips/v2/lib.ts
index 3360b5126..75e2a2dd1 100644
--- a/apps/api/src/__tests__/snips/v2/lib.ts
+++ b/apps/api/src/__tests__/snips/v2/lib.ts
@@ -119,6 +119,10 @@ export type MonitorCreateInput = {
crawlOptions?: Record<string, unknown>;
scrapeOptions?: Record<string, unknown>;
}
+ | {
+ type: "search";
+ queries: string[];
+ }
>;
retentionDays?: number;
goal?: string;
diff --git a/apps/api/src/__tests__/snips/v2/monitor.test.ts b/apps/api/src/__tests__/snips/v2/monitor.test.ts
index 47251522f..661325de4 100644
--- a/apps/api/src/__tests__/snips/v2/monitor.test.ts
+++ b/apps/api/src/__tests__/snips/v2/monitor.test.ts
@@ -128,6 +128,78 @@ describeIf(ALLOW_TEST_SUITE_WEBSITE && !TEST_SELF_HOST)("/v2/monitor", () => {
expect(del.body.success).toBe(true);
});
+ describe("when the team requires zero data retention for search", () => {
+ let searchZdr: Identity;
+
+ beforeAll(async () => {
+ searchZdr = await idmux({
+ name: "monitor/search-zdr",
+ credits: 10000,
+ flags: { searchZDR: "forced-zdr" },
+ });
+ }, 10000);
+
+ it("refuses a search monitor", async () => {
+ const create = await monitorCreateRaw(
+ {
+ name: "search zdr monitor",
+ schedule: { cron: "0 * * * *", timezone: "UTC" },
+ goal: "New releases of the firecrawl SDK",
+ targets: [{ type: "search", queries: ["firecrawl sdk release"] }],
+ notification: { email: { enabled: false } },
+ },
+ searchZdr,
+ );
+
+ expect(create.statusCode).toBe(400);
+ expect(create.body.success).toBe(false);
+ expect(create.body.error).toContain("zero data retention");
+ });
+
+ it("keeps a scrape monitor and refuses adding a search target to it", async () => {
+ const create = await monitorCreateRaw(
+ {
+ name: "scrape monitor on a search zdr team",
+ schedule: { cron: "0 * * * *", timezone: "UTC" },
+ targets: [
+ {
+ type: "scrape",
+ urls: [createTestIdUrl()],
+ scrapeOptions: { formats: ["markdown"] },
+ },
+ ],
+ notification: { email: { enabled: false } },
+ },
+ searchZdr,
+ );
+ expect(create.statusCode).toBe(200);
+ const id = create.body.data.id;
+
+ try {
+ const addSearch = await monitorPatchRaw(
+ id,
+ {
+ goal: "New releases of the firecrawl SDK",
+ targets: [{ type: "search", queries: ["firecrawl sdk release"] }],
+ },
+ searchZdr,
+ );
+ expect(addSearch.statusCode).toBe(400);
+ expect(addSearch.body.error).toContain("zero data retention");
+
+ const pause = await monitorPatchRaw(
+ id,
+ { status: "paused" },
+ searchZdr,
+ );
+ expect(pause.statusCode).toBe(200);
+ expect(pause.body.data.status).toBe("paused");
+ } finally {
+ await monitorDeleteRaw(id, searchZdr);
+ }
+ });
+ });
+
it("accepts an origin field in the create body", async () => {
const create = await monitorCreateRaw(
{
diff --git a/apps/api/src/__tests__/snips/v2/zdr.test.ts b/apps/api/src/__tests__/snips/v2/zdr.test.ts
index 565437a84..7b6c5da0c 100644
--- a/apps/api/src/__tests__/snips/v2/zdr.test.ts
+++ b/apps/api/src/__tests__/snips/v2/zdr.test.ts
@@ -1,3 +1,4 @@
+import request from "supertest";
import { getJobFromGCS } from "../../../lib/gcs-jobs";
import {
scrape,
@@ -14,6 +15,7 @@ import {
describeIf,
itIf,
concurrentIf,
+ TEST_API_URL,
TEST_PRODUCTION,
TEST_SUITE_WEBSITE,
HAS_PRODUCT_SERVICE,
@@ -272,6 +274,24 @@ describeIf(TEST_PRODUCTION)("Zero Data Retention", () => {
expect(response.body.success).toBe(true);
}, 60000);
+ it("should refuse data source discovery when searchZDR is forced", async () => {
+ const identity = await idmux({
+ name: "zdr/discover-searchZDR",
+ credits: 100,
+ flags: { searchZDR: "forced-zdr" },
+ });
+
+ const response = await request(TEST_API_URL)
+ .get("/exchange/discover")
+ .query({ q: "company funding rounds" })
+ .set("Authorization", `Bearer ${identity.apiKey}`);
+
+ expect(response.statusCode).toBe(403);
+ expect(response.body.error).toBe(
+ "Provider discovery does not support zero data retention.",
+ );
+ }, 60000);
+
describe.each(scopes)("%s audio, video and product formats", scope => {
let identity: Identity;
diff --git a/apps/api/src/controllers/v2/monitor.ts b/apps/api/src/controllers/v2/monitor.ts
index 28713cf7d..a42d93480 100644
--- a/apps/api/src/controllers/v2/monitor.ts
+++ b/apps/api/src/controllers/v2/monitor.ts
@@ -3,7 +3,6 @@ import { z } from "zod";
import { logger as _logger } from "../../lib/logger";
import { RequestWithAuth } from "./types";
import { externalRequestId } from "../../lib/external-request-id";
-import { getScrapeZDR } from "../../lib/zdr-helpers";
import { getMonitorDiffArtifact } from "../../lib/gcs-monitoring";
import {
createMonitorSchema,
@@ -28,7 +27,9 @@ import {
} from "../../services/monitoring/store";
import {
enqueueMonitorCheck,
+ MONITOR_ZDR_REFUSED_ERROR,
monitorIsSearch,
+ monitorRefusedForZdr,
} from "../../services/monitoring/scheduler";
import {
estimateRunsPerMonth,
@@ -66,13 +67,10 @@ const monitorCheckParamsSchema = monitorParamsSchema.extend({
function rejectZdr(
req: RequestWithAuth<any, any, any>,
res: Response,
+ targets: { type: string }[],
): boolean {
- if (getScrapeZDR(req.acuc?.flags) === "forced") {
- res.status(400).json({
- success: false,
- error:
- "Monitoring requires retained snapshots and diffs, and is not supported for zero data retention teams.",
- });
+ if (monitorRefusedForZdr(req.acuc?.flags, targets)) {
+ res.status(400).json({ success: false, error: MONITOR_ZDR_REFUSED_ERROR });
return true;
}
return false;
@@ -191,9 +189,8 @@ export async function createMonitorController(
req: RequestWithAuth<{}, any, unknown>,
res: Response,
) {
- if (rejectZdr(req, res)) return;
-
const input = createMonitorSchema.parse(req.body);
+ if (rejectZdr(req, res, input.targets)) return;
let schedule;
try {
schedule = validateMonitorCron(
@@ -290,8 +287,6 @@ export async function updateMonitorController(
req: RequestWithAuth<{ monitorId: string }, any, unknown>,
res: Response,
) {
- if (rejectZdr(req, res)) return;
-
const { monitorId } = monitorParamsSchema.parse(req.params);
const existing = await getMonitorForUpdate(req.auth.team_id, monitorId);
if (!existing) {
@@ -301,6 +296,7 @@ export async function updateMonitorController(
const input = updateMonitorSchema.parse(req.body);
const mergedTargets = input.targets ?? existing.targets;
+ if (rejectZdr(req, res, mergedTargets)) return;
const mergedGoal = input.goal !== undefined ? input.goal : existing.goal;
const mergedJudgeEnabled =
input.judgeEnabled !== undefined
@@ -438,13 +434,12 @@ export async function runMonitorController(
req: RequestWithAuth<{ monitorId: string }, any, unknown>,
res: Response,
) {
- if (rejectZdr(req, res)) return;
-
const { monitorId } = monitorParamsSchema.parse(req.params);
const monitor = await getMonitorForUpdate(req.auth.team_id, monitorId);
if (!monitor) {
return res.status(404).json({ success: false, error: "Monitor not found" });
}
+ if (rejectZdr(req, res, monitor.targets)) return;
if (monitor.status === "paused") {
return res.status(409).json({
success: false,
diff --git a/apps/api/src/routes/exchange.ts b/apps/api/src/routes/exchange.ts
index 104f8b7df..2cbde8327 100644
--- a/apps/api/src/routes/exchange.ts
+++ b/apps/api/src/routes/exchange.ts
@@ -2,6 +2,7 @@ import { bountyBlocklistMiddleware } from "./exchange-blocklist";
import { providerScrapeController } from "../controllers/v2/scrape-alexandria";
import { billingCountryForTeam } from "../lib/billing-country";
import { orgIdFromAcuc } from "../lib/team-org";
+import { getSearchForcedKind } from "../lib/zdr-helpers";
import {
acceptProviderTerms,
acceptTermsSchema,
@@ -150,6 +151,7 @@ function exchangeProxy(
options: {
requiresRetrieveFlag?: boolean;
opensFeedbackWindow?: boolean;
+ refusesZeroDataRetention?: boolean;
} = {},
) {
const requiresRetrieveFlag = options.requiresRetrieveFlag !== false;
@@ -164,6 +166,17 @@ function exchangeProxy(
teamId: authedReq.auth.team_id,
});
+ if (
+ options.refusesZeroDataRetention &&
+ getSearchForcedKind(authedReq.acuc?.flags) !== null
+ ) {
+ return exchangeError(
+ res,
+ 403,
+ "Provider discovery does not support zero data retention.",
+ );
+ }
+
const base = upstreamBase();
if (!base) {
return exchangeError(res, 503, "This endpoint is not available.");
@@ -325,6 +338,8 @@ exchangeRouter.use(
// Discover is a flat 10,000/min catalogue read. Retrieve and records/fetch take
// the plan's scrape-equivalent budget (base 10/min, multiplier scaled).
// Dashboard and publisher routes below stay on the flat Labs limit.
+// It sends the caller's query to services that do not honour zero data
+// retention, so teams whose search requires it are refused.
exchangeRouter.get(
"/discover{/*path}",
authMiddleware(RateLimiterMode.ExchangeDiscover, {
@@ -334,6 +349,7 @@ exchangeRouter.get(
exchangeProxy(DISCOVER_TIMEOUT_MS, {
requiresRetrieveFlag: false,
opensFeedbackWindow: true,
+ refusesZeroDataRetention: true,
}),
),
);
diff --git a/apps/api/src/services/integrations/slack/commands.ts b/apps/api/src/services/integrations/slack/commands.ts
index 436e3b929..0f5a8af1c 100644
--- a/apps/api/src/services/integrations/slack/commands.ts
+++ b/apps/api/src/services/integrations/slack/commands.ts
@@ -10,7 +10,11 @@ import {
listMonitors,
updateMonitor,
} from "../../monitoring/store";
-import { enqueueMonitorCheck } from "../../monitoring/scheduler";
+import {
+ enqueueMonitorCheck,
+ MONITOR_ZDR_REFUSED_ERROR,
+ monitorRefusedForZdr,
+} from "../../monitoring/scheduler";
import { validateMonitorCron } from "../../monitoring/cron";
import {
createMonitorSchema,
@@ -55,6 +59,16 @@ function invalidIdResponse(id: string): SlackCommandResponse {
);
}
+async function zdrRefusal(
+ teamId: string,
+ targets: { type: string }[],
+): Promise<SlackCommandResponse | null> {
+ const acuc = await getACUCTeam(teamId);
+ return monitorRefusedForZdr(acuc?.flags ?? undefined, targets)
+ ? ephemeral(MONITOR_ZDR_REFUSED_ERROR)
+ : null;
+}
+
function truncate(input: string, max: number): string {
if (input.length <= max) return input;
return input.slice(0, Math.max(0, max - 1)) + "…";
@@ -325,6 +339,12 @@ async function createWebsiteMonitor(
origin: "slack",
});
+ const refusal = await zdrRefusal(
+ input.installation.team_id,
+ parsedInput.targets,
+ );
+ if (refusal) return refusal;
+
const monitor = await createMonitorFromInput(input, parsedInput);
const lead = hasGoal
@@ -372,6 +392,12 @@ async function createSearchMonitor(
origin: "slack",
});
+ const refusal = await zdrRefusal(
+ input.installation.team_id,
+ parsedInput.targets,
+ );
+ if (refusal) return refusal;
+
const monitor = await createMonitorFromInput(input, parsedInput);
return ephemeral(
@@ -628,6 +654,8 @@ async function runResponse(
`No monitor with id \`${escapeSlackText(trimmed)}\` on your team.`,
);
}
+ const refusal = await zdrRefusal(installation.team_id, monitor.targets);
+ if (refusal) return refusal;
if (monitor.status === "paused") {
return ephemeral(
`*${escapeSlackText(monitor.name)}* is paused. Resume it first: \`/monitor resume ${monitor.id}\`.`,
@@ -666,6 +694,8 @@ async function resumeResponse(
`No monitor with id \`${escapeSlackText(trimmed)}\` on your team.`,
);
}
+ const refusal = await zdrRefusal(installation.team_id, existing.targets);
+ if (refusal) return refusal;
const updated = await updateMonitor({
teamId: installation.team_id,
diff --git a/apps/api/src/services/monitoring/scheduler.test.ts b/apps/api/src/services/monitoring/scheduler.test.ts
index bdded5c43..66618889f 100644
--- a/apps/api/src/services/monitoring/scheduler.test.ts
+++ b/apps/api/src/services/monitoring/scheduler.test.ts
@@ -1,6 +1,12 @@
import type { MockedFunction } from "vitest";
+import { getACUCTeam } from "../../controllers/auth";
+import type { TeamFlags } from "../../controllers/v2/types";
import { addMonitorCheckJob } from "./queue";
-import { enqueueDueMonitorChecks } from "./scheduler";
+import {
+ enqueueDueMonitorChecks,
+ MONITOR_ZDR_PAUSED_ERROR,
+ monitorRefusedForZdr,
+} from "./scheduler";
import { isMonitorCheckStale } from "./stale";
import {
advanceMonitorAfterSkippedCheck,
@@ -8,12 +14,17 @@ import {
createMonitorCheck,
dispatchScheduledMonitorCheck,
getMonitorCheckForUpdate,
+ updateMonitor,
updateMonitorCheck,
updateMonitorCheckIfStatus,
updateMonitorScheduleAfterRun,
} from "./store";
import { autumnService } from "../autumn/autumn.service";
+vi.mock("../../controllers/auth", () => ({
+ getACUCTeam: vi.fn(),
+}));
+
vi.mock("./queue", () => ({
addMonitorCheckJob: vi.fn(),
}));
@@ -24,6 +35,7 @@ vi.mock("./store", () => ({
createMonitorCheck: vi.fn(),
dispatchScheduledMonitorCheck: vi.fn(),
getMonitorCheckForUpdate: vi.fn(),
+ updateMonitor: vi.fn(),
updateMonitorCheck: vi.fn(),
updateMonitorCheckIfStatus: vi.fn(),
updateMonitorScheduleAfterRun: vi.fn(),
@@ -75,6 +87,45 @@ const mockUpdateMonitorScheduleAfterRun =
updateMonitorScheduleAfterRun as MockedFunction<
typeof updateMonitorScheduleAfterRun
>;
+const mockGetACUCTeam = getACUCTeam as MockedFunction<typeof getACUCTeam>;
+const mockUpdateMonitor = updateMonitor as MockedFunction<typeof updateMonitor>;
+
+describe("monitorRefusedForZdr", () => {
+ const scrape = [{ type: "scrape" }];
+ const search = [{ type: "scrape" }, { type: "search" }];
+
+ it.each<[string, TeamFlags | undefined, { type: string }[], boolean]>([
+ ["no ZDR flags", undefined, search, false],
+ ["scrapeZDR forced, scrape targets", { scrapeZDR: "forced" }, scrape, true],
+ ["searchZDR forced, search target", { searchZDR: "forced" }, search, true],
+ [
+ "searchZDR forced-zdr, search target",
+ { searchZDR: "forced-zdr" },
+ search,
+ true,
+ ],
+ [
+ "searchZDR forced-anon, search target",
+ { searchZDR: "forced-anon" },
+ search,
+ true,
+ ],
+ [
+ "searchZDR forced-zdr, scrape targets only",
+ { searchZDR: "forced-zdr" },
+ scrape,
+ false,
+ ],
+ [
+ "searchZDR allowed, search target",
+ { searchZDR: "allowed" },
+ search,
+ false,
+ ],
+ ])("%s", (_label, flags, targets, refused) => {
+ expect(monitorRefusedForZdr(flags, targets)).toBe(refused);
+ });
+});
describe("monitoring scheduler", () => {
const monitor = {
@@ -106,6 +157,8 @@ describe("monitoring scheduler", () => {
mockGetMonitorCheckForUpdate.mockResolvedValue(null);
mockIsMonitorCheckStale.mockReturnValue(false);
mockFinalizeCreditsLock.mockResolvedValue(true);
+ mockGetACUCTeam.mockResolvedValue(null);
+ mockUpdateMonitor.mockResolvedValue(null);
});
it("dispatches and advances a scheduled monitor before enqueueing its job", async () => {
@@ -154,6 +207,93 @@ describe("monitoring scheduler", () => {
);
});
+ it("pauses a monitor whose team requires zero data retention instead of running it", async () => {
+ const refused = { id: check.id, status: "failed" } as any;
+ mockGetACUCTeam.mockResolvedValue({
+ flags: { scrapeZDR: "forced" },
+ } as any);
+ mockUpdateMonitorCheck.mockResolvedValue(refused);
+
+ await expect(
+ enqueueDueMonitorChecks({ workerId: "worker-1" }),
+ ).resolves.toBe(0);
+
+ expect(mockGetACUCTeam).toHaveBeenCalledWith(monitor.team_id);
+ expect(mockCreateMonitorCheck).toHaveBeenCalledExactlyOnceWith({
+ monitor,
+ trigger: "scheduled",
+ scheduledFor: monitor.next_run_at,
+ status: "failed",
+ });
+ expect(mockUpdateMonitorCheck).toHaveBeenCalledWith(check.id, {
+ status: "failed",
+ finished_at: expect.any(String),
+ error: MONITOR_ZDR_PAUSED_ERROR,
+ });
+ expect(mockUpdateMonitor).toHaveBeenCalledWith({
+ teamId: monitor.team_id,
+ monitorId: monitor.id,
+ input: { status: "paused" },
+ });
+ expect(mockAdvanceMonitorAfterSkippedCheck).toHaveBeenCalledWith({
+ monitor,
+ check: refused,
+ });
+ expect(mockUpdateMonitor.mock.invocationCallOrder[0]).toBeLessThan(
+ mockAdvanceMonitorAfterSkippedCheck.mock.invocationCallOrder[0],
+ );
+ expect(mockDispatchScheduledMonitorCheck).not.toHaveBeenCalled();
+ expect(mockAddMonitorCheckJob).not.toHaveBeenCalled();
+ });
+
+ it("pauses a search monitor whose team requires zero data retention for search", async () => {
+ const searchMonitor = {
+ ...monitor,
+ targets: [{ id: "t-1", type: "search" }],
+ } as any;
+ mockClaimDueMonitors.mockResolvedValue([searchMonitor]);
+ mockGetACUCTeam.mockResolvedValue({
+ flags: { searchZDR: "forced-zdr" },
+ } as any);
+
+ await expect(
+ enqueueDueMonitorChecks({ workerId: "worker-1" }),
+ ).resolves.toBe(0);
+
+ expect(mockCreateMonitorCheck).toHaveBeenCalledExactlyOnceWith({
+ monitor: searchMonitor,
+ trigger: "scheduled",
+ scheduledFor: searchMonitor.next_run_at,
+ status: "failed",
+ });
+ expect(mockUpdateMonitor).toHaveBeenCalledWith({
+ teamId: searchMonitor.team_id,
+ monitorId: searchMonitor.id,
+ input: { status: "paused" },
+ });
+ expect(mockAddMonitorCheckJob).not.toHaveBeenCalled();
+ });
+
+ it("keeps running a scrape monitor when only search requires zero data retention", async () => {
+ mockGetACUCTeam.mockResolvedValue({
+ flags: { searchZDR: "forced-anon" },
+ } as any);
+
+ await expect(
+ enqueueDueMonitorChecks({ workerId: "worker-1" }),
+ ).resolves.toBe(1);
+
+ expect(mockUpdateMonitor).not.toHaveBeenCalled();
+ expect(mockAddMonitorCheckJob).toHaveBeenCalledWith(
+ {
+ monitorId: monitor.id,
+ checkId: check.id,
+ teamId: monitor.team_id,
+ },
+ { search: false },
+ );
+ });
+
it("fails and clears a dispatched check when enqueueing fails", async () => {
const error = new Error("queue unavailable");
const failed = { id: check.id, status: "failed" } as any;
diff --git a/apps/api/src/services/monitoring/scheduler.ts b/apps/api/src/services/monitoring/scheduler.ts
index 6560c8b36..89a51be88 100644
--- a/apps/api/src/services/monitoring/scheduler.ts
+++ b/apps/api/src/services/monitoring/scheduler.ts
@@ -1,5 +1,8 @@
import { randomUUID } from "crypto";
+import { getACUCTeam } from "../../controllers/auth";
import { logger as _logger } from "../../lib/logger";
+import { getScrapeZDR, getSearchForcedKind } from "../../lib/zdr-helpers";
+import type { TeamFlags } from "../../controllers/v2/types";
import { addMonitorCheckJob } from "./queue";
import {
advanceMonitorAfterSkippedCheck,
@@ -8,6 +11,7 @@ import {
deferMonitorClaim,
dispatchScheduledMonitorCheck,
getMonitorCheckForUpdate,
+ updateMonitor,
updateMonitorCheck,
updateMonitorCheckIfStatus,
updateMonitorScheduleAfterRun,
@@ -21,11 +25,29 @@ import type { MonitorRow } from "./types";
const logger = _logger.child({ module: "monitoring-scheduler" });
+export const MONITOR_ZDR_PAUSED_ERROR =
+ "Monitoring is not supported for zero data retention teams, so this monitor was paused.";
+
+export const MONITOR_ZDR_REFUSED_ERROR =
+ "Monitoring requires retained snapshots and diffs, and is not supported for zero data retention teams.";
+
// 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");
}
+/** Monitors run without zero data retention, so a team that requires it for scrape, or for search when a target is a search, cannot run one. */
+export function monitorRefusedForZdr(
+ flags: TeamFlags | undefined,
+ targets: { type: string }[],
+): boolean {
+ return (
+ getScrapeZDR(flags) === "forced" ||
+ (getSearchForcedKind(flags) !== null &&
+ targets.some(target => target.type === "search"))
+ );
+}
+
export async function enqueueMonitorCheck(params: {
monitorId: string;
checkId: string;
@@ -71,6 +93,39 @@ export async function enqueueDueMonitorChecks(
}
}
+ // A monitor created before its team required zero data retention would
+ // otherwise keep running without it.
+ const acuc = await getACUCTeam(monitor.team_id);
+ if (
+ monitorRefusedForZdr(acuc?.flags ?? undefined, monitor.targets ?? [])
+ ) {
+ const refused = await createMonitorCheck({
+ monitor,
+ trigger: "scheduled",
+ scheduledFor: monitor.next_run_at,
+ status: "failed",
+ });
+ const finished = await updateMonitorCheck(refused.id, {
+ status: "failed",
+ finished_at: new Date().toISOString(),
+ error: MONITOR_ZDR_PAUSED_ERROR,
+ });
+ await updateMonitor({
+ teamId: monitor.team_id,
+ monitorId: monitor.id,
+ input: { status: "paused" },
+ });
+ // Advanced as active so next_run_at stays set and a resume by status
+ // alone schedules it again, as for a monitor its owner paused.
+ await advanceMonitorAfterSkippedCheck({ monitor, check: finished });
+ logger.warn("Paused monitor: its team requires zero data retention", {
+ monitorId: monitor.id,
+ checkId: finished.id,
+ teamId: monitor.team_id,
+ });
+ continue;
+ }
+
if (monitor.current_check_id) {
const skipped = await createMonitorCheck({
monitor,