Budibase/budibase · error

Expected indexed request IDs to contain only strings

Error message

Expected indexed request IDs to contain only strings

What it means

parseIndexedRequestIds accepts a JSON array but every element must be a string request ID. If any element is a non-string (number, object, null, etc.), it throws Error("Expected indexed request IDs to contain only strings") because the return value must be a Set<string>.

Source

Thrown at packages/server/src/sdk/workspace/ai/agentLogs/shared.ts:283

}

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)
}

export function getLiteLLMRequestUser(
  data: LiteLLMRequestDetail | AgentLogSessionIndexDoc

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Rewrite the stored array so every element is a string (String(id) on numeric IDs)
  2. Fix the writer to serialize IDs with JSON.stringify([...ids]) where ids is a string[]
  3. Catch the error and reindex the session's request IDs from the raw logs

Example fix

// before
const ids = parseIndexedRequestIds(value) // throws if [123]
// after
const parsed: unknown[] = JSON.parse(value)
const ids = parseIndexedRequestIds(JSON.stringify(parsed.map(String)))
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")
}
const parsed: unknown = JSON.parse(value)
if (!isStringArray(parsed)) {
  // coerce or reindex before calling parseIndexedRequestIds
  parsed = Array.isArray(parsed) ? parsed.map(String) : []
}

Type guard

function isStringArray(value: unknown): value is string[] {
  return Array.isArray(value) && value.every(item => typeof item === "string")
}

Try / catch

try {
  const ids = parseIndexedRequestIds(value)
} catch (err) {
  if (err instanceof Error && /only strings/.test(err.message)) {
    // reindex the session or coerce: new Set(JSON.parse(value).map(String))
  }
}

Prevention

When it happens

Trigger: The stored JSON array of indexed request IDs contains at least one non-string element, e.g. [12345], [null], or [{"id":"x"}].

Common situations: IDs were serialized as numbers by a previous writer; a migration or external script wrote raw LiteLLM numeric IDs; corrupted index documents from a failed write.

Related errors


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