{"record":{"id":"91a2add148ef217d","repo":"Budibase/budibase","slug":"cannot-execute-multiple-queries-for-agent-log-sear","errorCode":null,"errorMessage":"Cannot execute multiple queries for agent log search","messagePattern":"Cannot execute multiple queries for agent log search","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agentLogs/sessionIndex.ts","lineNumber":60,"sourceCode":"      },\n      requestIds: {\n        name: \"requestIds\",\n        type: FieldType.STRING,\n      },\n    },\n  }\n}\n\nasync function querySql<T extends Document>(\n  request: EnrichedQueryJson,\n  table: Table,\n  db = context.getWorkspaceDB()\n): Promise<T[]> {\n  await tableSqs.ensureStaticTables(db)\n\n  const query = builder._query(request)\n  if (Array.isArray(query)) {\n    throw new Error(\"Cannot execute multiple queries for agent log search\")\n  }\n\n  const rows = await db.sql<T>(query.sql, query.bindings)\n  return builder.convertJsonStringColumns(\n    table,\n    rows as Array<T & Record<string, unknown>>\n  ) as T[]\n}\n\nfunction buildSessionFilters(\n  agentId: string,\n  startDate: string,\n  endDate: string,\n  statusFilter?: string,\n  triggerFilter?: string\n): SearchFilters {\n  const oneOf: NonNullable<SearchFilters[\"oneOf\"]> = {\n    agentId: [agentId],","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agentLogs/sessionIndex.ts#L42-L78","documentation":"querySql uses the SQL query builder to search the agent-log session index, and throws this Error when the builder produces an array of queries (multiple statements) instead of a single query, because db.sql can only execute one statement. It is an internal invariant guard against building a multi-query search request.","triggerScenarios":"Passing a SearchAgentLogsRequest whose shape makes the query builder emit multiple queries — typically a request combining incompatible filters (e.g. multiple bookmark/page segments or a union-style query) so builder._query(request) returns an array.","commonSituations":"A caller assembling a search request from user-supplied filter objects and accidentally producing a compound query; a version mismatch where the builder started returning arrays for queries it previously collapsed into one.","solutions":["Inspect the SearchAgentLogsRequest being passed and remove/merge filter combinations that produce compound queries","Simplify the request to a single filter set, or run multiple searches and merge rows in application code","Log/JSON-stringify builder._query(request) locally to see why it returns an array","Upgrade/align the query-builder and session-index modules so their shapes match"],"exampleFix":"// before\nconst rows = await searchAgentLogs({ ...filtersA, ...filtersB })\n// after\nconst rowsA = await searchAgentLogs(filtersA)\nconst rowsB = await searchAgentLogs(filtersB)\nconst rows = [...rowsA, ...rowsB]","handlingStrategy":"validation","validationCode":"function isSingleQueryRequest(req: SearchAgentLogsRequest): boolean {\n  return !Array.isArray((req as any).queries) && !req.union\n}","typeGuard":null,"tryCatchPattern":"try {\n  const rows = await querySql(request, table)\n} catch (err) {\n  if ((err as Error).message.includes(\"multiple queries\")) {\n    throw new HTTPError(\"Agent log search supports a single query\", 400)\n  }\n  throw err\n}","preventionTips":["Build search requests from a single filter set","Merge results in app code rather than issuing compound queries","Log builder._query() output when debugging","Keep builder and querySql module versions aligned"],"tags":["sql","query-builder","agent-logs","programming-error"],"backgroundTag":"invalid-query-shape","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}