Skip to content

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

Handle missing monitor.targets and route search queue

Developers Digestc81c83e79a29
diff --git a/apps/api/src/services/monitoring/scheduler.test.ts b/apps/api/src/services/monitoring/scheduler.test.ts
index ba7dbe009..40764150f 100644
--- a/apps/api/src/services/monitoring/scheduler.test.ts
+++ b/apps/api/src/services/monitoring/scheduler.test.ts
@@ -80,6 +80,7 @@ describe("monitoring scheduler", () => {
team_id: "team-1",
current_check_id: null,
next_run_at: "2026-05-05T18:45:00.000Z",
+ targets: [{ id: "t-1", type: "scrape" }],
} as any;
const check = { id: "check-1" } as any;
@@ -110,16 +111,38 @@ describe("monitoring scheduler", () => {
monitor,
checkId: check.id,
});
- expect(mockAddMonitorCheckJob).toHaveBeenCalledWith({
- monitorId: monitor.id,
- checkId: check.id,
- teamId: monitor.team_id,
- });
+ expect(mockAddMonitorCheckJob).toHaveBeenCalledWith(
+ {
+ monitorId: monitor.id,
+ checkId: check.id,
+ teamId: monitor.team_id,
+ },
+ { search: false },
+ );
expect(
mockDispatchScheduledMonitorCheck.mock.invocationCallOrder[0],
).toBeLessThan(mockAddMonitorCheckJob.mock.invocationCallOrder[0]);
});
+ it("routes a search monitor to the dedicated search queue", async () => {
+ mockClaimDueMonitors.mockResolvedValue([
+ { ...monitor, targets: [{ id: "t-1", type: "search" }] } as any,
+ ]);
+
+ await expect(
+ enqueueDueMonitorChecks({ workerId: "worker-1" }),
+ ).resolves.toBe(1);
+
+ expect(mockAddMonitorCheckJob).toHaveBeenCalledWith(
+ {
+ monitorId: monitor.id,
+ checkId: check.id,
+ teamId: monitor.team_id,
+ },
+ { search: true },
+ );
+ });
+
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 00db2edb4..371d1876b 100644
--- a/apps/api/src/services/monitoring/scheduler.ts
+++ b/apps/api/src/services/monitoring/scheduler.ts
@@ -22,7 +22,7 @@ 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.
export function monitorIsSearch(monitor: MonitorRow): boolean {
- return monitor.targets.some(target => target.type === "search");
+ return (monitor.targets ?? []).some(target => target.type === "search");
}
export async function enqueueMonitorCheck(params: {