Budibase/budibase · error
Expected indexed request IDs to be an array
Error message
Expected indexed request IDs to be an array
What it means
parseIndexedRequestIds parses a stored/serialized string of indexed LiteLLM request IDs. It JSON.parses the value and requires the result to be an array; anything else (object, number, string, etc.) throws a plain Error("Expected indexed request IDs to be an array"). This guards against corrupted or wrongly-shaped persisted data for the agent log session index document.
Source
Thrown at packages/server/src/sdk/workspace/ai/agentLogs/shared.ts:280
function encodeKeyPart(value: string): string {
return encodeURIComponent(value)
}
export function getSessionDocId(agentId: string, sessionId: string): string {
const encodedAgentId = encodeKeyPart(agentId)
const encodedSessionId = encodeKeyPart(sessionId)
return `${DocumentType.AGENT_LOG_SESSION}${SEPARATOR}${encodedAgentId}${SEPARATOR}${encodedSessionId}`
}
export function parseIndexedRequestIds(value?: string): Set<string> {
if (!value) {
return new Set()
}
const parsed = JSON.parse(value)
if (!Array.isArray(parsed)) {
throw new Error("Expected indexed request IDs to be an array")
}
if (parsed.some(item => typeof item !== "string")) {
throw new Error("Expected indexed request IDs to contain only strings")
}
return new Set(parsed)
}
export function getWorkspaceDbForEnvironment(environment: AgentLogEnvironment) {
if (environment === "development") {
return context.getDevWorkspaceDB()
}
if (environment === "production") {
return context.getProdWorkspaceDB()
}
throw new HTTPError("Invalid environment query", 400)
}View on GitHub (pinned to a81a902e9a)
Solutions
- Inspect the stored document and rewrite the field as a JSON array of string IDs
- Fix the writer that persisted the wrong shape so it stores an array
- Wrap the parse call in try/catch and fall back to an empty Set or reindex the session
Example fix
// before
const ids = parseIndexedRequestIds(doc.requestIds) // throws on corrupted doc
// after
function safeParseIndexedRequestIds(value?: string): Set<string> {
try {
return parseIndexedRequestIds(value)
} catch {
return new Set()
}
} Defensive patterns
Strategy: type-guard
Validate before calling
function isStringArray(value: unknown): value is string[] {
return Array.isArray(value) && value.every(item => typeof item === "string")
} Type guard
function isStringArray(value: unknown): value is string[] {
return Array.isArray(value) && value.every(item => typeof item === "string")
}
function safeParse(value?: string): Set<string> {
if (!value) return new Set()
const parsed: unknown = JSON.parse(value)
return isStringArray(parsed) ? new Set(parsed) : new Set()
} Try / catch
try {
const ids = parseIndexedRequestIds(value)
} catch (err) {
console.warn("Corrupt indexed request IDs, treating as empty", err)
const ids = new Set<string>()
} Prevention
- Always serialize request IDs as JSON.stringify of a string[]
- Add a migration check that rewrites non-array or non-string index fields
- Read the field defensively and fall back to an empty Set
When it happens
Trigger: Reading an AgentLogSessionIndexDoc (or other doc) whose request-IDs field holds JSON that parses to a non-array — e.g. an object {"id":...}, a bare number, or a JSON string like "\"abc\"".
Common situations: A document was hand-edited or written by an older/newer code version with a different shape; a migration wrote an object instead of an array; a client supplied a non-array value that got persisted verbatim.
Related errors
- Expected indexed request IDs to contain only strings
- Unknown plugin type - check schema.json: ${schema.type}
- Error fetching agent log detail: ${text || response.statusTe
- Agent log detail not found
- Cannot execute multiple queries for agent log search
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/d89545d83deb7722.
Report an issue: GitHub.