From 522347426425b336291615a9c86f71a4172a9bb3 Mon Sep 17 00:00:00 2001 From: Arseniy Shishaev Date: Mon, 26 Oct 2026 00:45:18 +0000 Subject: [PATCH] fix: cap incident issue load in agent-run context to prevent unbounded IN clause #SUPERLOG Delivery-Id: 4edfa37d3357f2b56f3f44a51f5c782bef5ace93a093263f2dd1ab0154c1511a Delivery-Base: main --- apps/worker/src/agent-run-context.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/worker/src/agent-run-context.ts b/apps/worker/src/agent-run-context.ts index cacdf1c6..3deff8c5 100644 --- a/apps/worker/src/agent-run-context.ts +++ b/apps/worker/src/agent-run-context.ts @@ -226,10 +226,17 @@ export async function loadAgentRunContext( }); if (!org) return null; const automation = await getProjectAutomation(project.id); + // Cap the issue set so the subsequent inArray never exceeds Postgres's + // 65,535 bind parameter limit. Join issues here to sort by lastSeen before + // applying the limit, ensuring the most-recent issues are always included. + const ISSUE_CONTEXT_LIMIT = 200; const issueIds = await db .select({ issueId: schema.incidentIssues.issueId }) .from(schema.incidentIssues) - .where(eq(schema.incidentIssues.incidentId, incident.id)); + .innerJoin(schema.issues, eq(schema.issues.id, schema.incidentIssues.issueId)) + .where(eq(schema.incidentIssues.incidentId, incident.id)) + .orderBy(desc(schema.issues.lastSeen)) + .limit(ISSUE_CONTEXT_LIMIT); const issueRows = issueIds.length > 0 ? await db.query.issues.findMany({