{"record":{"id":"34b31a0413792fd0","repo":"JuliusBrussee/caveman","slug":"unknown-trace-filter-s-unknown-sort-join","errorCode":null,"errorMessage":"unknown trace filter(s): ${unknown.sort().join(\", \")}","messagePattern":"unknown trace filter\\(s\\): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/agent-mcp.ts","lineNumber":450,"sourceCode":"    content: [{ type: \"text\", text: JSON.stringify(structuredContent) }],\n    structuredContent,\n    isError: true,\n  };\n}\n\nasync function withProjectQuery(client: AgentMcpClient, path: string): Promise<string> {\n  if (!PROJECT_QUERY_PATHS.has(path)) return path;\n  const projectId = await client.projectId();\n  const query = new URLSearchParams({ project_id: projectId });\n  return `${path}?${query}`;\n}\n\nfunction validateTraceFilters(args: JSONObject): void {\n  const filters = args.filters;\n  if (filters === undefined) return;\n  if (!filters || typeof filters !== \"object\" || Array.isArray(filters)) throw new Error(\"filters must be an object\");\n  const unknown = Object.keys(filters).filter((key) => !TRACE_FILTER_KEYS.has(key));\n  if (unknown.length > 0) throw new Error(`unknown trace filter(s): ${unknown.sort().join(\", \")}`);\n  const stringListKeys = [\n    \"workflow\",\n    \"agent\",\n    \"model\",\n    \"provider\",\n    \"error_code\",\n    \"auth_mode\",\n    \"runtime_mode\",\n    \"cache_status\",\n    \"session_id\",\n    \"client_user_hash\",\n    \"trace_id\",\n    \"member_user_id\",\n    \"api_key_id\",\n    \"optimization_id\",\n    \"status_class\",\n  ];\n  for (const key of stringListKeys) {","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/agent-mcp.ts#L432-L468","documentation":"After confirming filters is an object, validateTraceFilters checks every key against the TRACE_FILTER_KEYS allowlist. Any key outside the allowlist throws with a sorted, comma-separated list of the offending keys, so callers cannot silently pass unrecognized filters that would be ignored downstream.","triggerScenarios":"Calling trace search with filters containing a key not in TRACE_FILTER_KEYS, e.g. filters: { user: 'bob' } or a misspelled known key like workflow_name or errorcode.","commonSituations":"Typos in filter names; inventing filters based on docs for a different API; forwarding user-supplied filter dicts verbatim; drift after a filter key was renamed in a newer version.","solutions":["Remove or rename the unknown keys listed in the message to ones in TRACE_FILTER_KEYS","Check the supported filter keys (workflow, agent, model, provider, error_code, status_class, cost/token/latency bounds, has_error, compressed, monitor, etc.)","Validate user-supplied filters against the allowlist before forwarding","If a needed filter genuinely doesn't exist, use the supported keys or an alternate tool rather than guessing"],"exampleFix":"// before\nsearchTraces({ filters: { username: ['bob'] } });\n// after\nsearchTraces({ filters: { agent: ['bob'] } });","handlingStrategy":"validation","validationCode":"const TRACE_FILTER_KEYS = new Set(['workflow','agent','model','provider','error_code','status_class','min_cost_usd','max_cost_usd','min_total_tokens','max_total_tokens','min_latency_ms','max_latency_ms','has_error','compressed','monitor']);\nfunction assertKnownFilterKeys(filters) {\n  const unknown = Object.keys(filters ?? {}).filter((k) => !TRACE_FILTER_KEYS.has(k));\n  if (unknown.length) throw new Error(`unknown trace filter(s): ${unknown.sort().join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await searchTraces({ filters });\n} catch (error) {\n  if (error.message.startsWith('unknown trace filter(s)')) {\n    const bad = error.message.split(': ')[1].split(', ');\n    // drop or rename bad keys and retry\n  }\n}","preventionTips":["Keep a shared constant of allowed filter keys in client code and validate against it","Never forward raw user filter dicts verbatim; map them through an allowlist","Check the current tool docs when upgrading — filter keys can be renamed","Fix typos by validating filter keys in an IDE against the exported constant"],"tags":["mcp","validation","traces","allowlist"],"backgroundTag":"invalid-query-parameter","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}