Budibase/budibase · error

Cannot execute multiple queries for agent log search

Error message

Cannot execute multiple queries for agent log search

What it means

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.

Source

Thrown at packages/server/src/sdk/workspace/ai/agentLogs/sessionIndex.ts:60

      },
      requestIds: {
        name: "requestIds",
        type: FieldType.STRING,
      },
    },
  }
}

async function querySql<T extends Document>(
  request: EnrichedQueryJson,
  table: Table,
  db = context.getWorkspaceDB()
): Promise<T[]> {
  await tableSqs.ensureStaticTables(db)

  const query = builder._query(request)
  if (Array.isArray(query)) {
    throw new Error("Cannot execute multiple queries for agent log search")
  }

  const rows = await db.sql<T>(query.sql, query.bindings)
  return builder.convertJsonStringColumns(
    table,
    rows as Array<T & Record<string, unknown>>
  ) as T[]
}

function buildSessionFilters(
  agentId: string,
  startDate: string,
  endDate: string,
  statusFilter?: string,
  triggerFilter?: string
): SearchFilters {
  const oneOf: NonNullable<SearchFilters["oneOf"]> = {
    agentId: [agentId],

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Inspect the SearchAgentLogsRequest being passed and remove/merge filter combinations that produce compound queries
  2. Simplify the request to a single filter set, or run multiple searches and merge rows in application code
  3. Log/JSON-stringify builder._query(request) locally to see why it returns an array
  4. Upgrade/align the query-builder and session-index modules so their shapes match

Example fix

// before
const rows = await searchAgentLogs({ ...filtersA, ...filtersB })
// after
const rowsA = await searchAgentLogs(filtersA)
const rowsB = await searchAgentLogs(filtersB)
const rows = [...rowsA, ...rowsB]
Defensive patterns

Strategy: validation

Validate before calling

function isSingleQueryRequest(req: SearchAgentLogsRequest): boolean {
  return !Array.isArray((req as any).queries) && !req.union
}

Try / catch

try {
  const rows = await querySql(request, table)
} catch (err) {
  if ((err as Error).message.includes("multiple queries")) {
    throw new HTTPError("Agent log search supports a single query", 400)
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/91a2add148ef217d. Report an issue: GitHub.