{"record":{"id":"ebef3408d7f86680","repo":"ruvnet/ruflo","slug":"query-exceeds-maximum-length-of-max-query-length","errorCode":null,"errorMessage":"Query exceeds maximum length of ${MAX_QUERY_LENGTH} characters","messagePattern":"Query exceeds maximum length of (.+?) characters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts","lineNumber":79,"sourceCode":"const MAX_KEY_LENGTH = 1024;\nconst MAX_VALUE_SIZE = 1024 * 1024; // 1MB\nconst MAX_QUERY_LENGTH = 4096;\n\n// #1425 — single source of truth for the dangerous-character set rejected by\n// validateMemoryInput. Imported by sanitizeMemoryKey so write-side sanitization\n// and read-side rejection can never drift apart (the symmetry bug behind #1884).\nconst DANGEROUS_KEY_CHARS = /[;&|`$(){}[\\]<>!#\\\\\\0]|\\.\\.[/\\\\]/g;\nconst DANGEROUS_KEY_PATTERN = /[;&|`$(){}[\\]<>!#\\\\\\0]|\\.\\.[/\\\\]/;\n\nfunction validateMemoryInput(key?: string, value?: string, query?: string, namespace?: string): void {\n  if (key && key.length > MAX_KEY_LENGTH) {\n    throw new Error(`Key exceeds maximum length of ${MAX_KEY_LENGTH} characters`);\n  }\n  if (value && value.length > MAX_VALUE_SIZE) {\n    throw new Error(`Value exceeds maximum size of ${MAX_VALUE_SIZE} bytes`);\n  }\n  if (query && query.length > MAX_QUERY_LENGTH) {\n    throw new Error(`Query exceeds maximum length of ${MAX_QUERY_LENGTH} characters`);\n  }\n  // Reject path traversal and shell metacharacters in keys/namespaces (#1425)\n  if (key && DANGEROUS_KEY_PATTERN.test(key)) {\n    throw new Error('Key contains disallowed characters');\n  }\n  if (namespace && DANGEROUS_KEY_PATTERN.test(namespace)) {\n    throw new Error('Namespace contains disallowed characters');\n  }\n}\n\n// #1884 — sanitize a key produced from arbitrary input (markdown headings,\n// frontmatter names, file names) so it survives validateMemoryInput on the\n// read/delete path. Replaces every dangerous char with `_`. Truncates to\n// MAX_KEY_LENGTH so the bound check in validateMemoryInput also passes.\n// Keep this in sync with DANGEROUS_KEY_PATTERN — they share DANGEROUS_KEY_CHARS.\nfunction sanitizeMemoryKey(key: string): string {\n  const safe = key.replace(DANGEROUS_KEY_CHARS, '_');\n  return safe.length > MAX_KEY_LENGTH ? safe.slice(0, MAX_KEY_LENGTH) : safe;","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts#L61-L97","documentation":"Thrown by validateMemoryInput when a search query exceeds 4096 characters (MAX_QUERY_LENGTH). Queries drive semantic/vector search; an overlong query degrades search quality and wastes embedding compute, so the tool caps the length.","triggerScenarios":"Calling memory search with a query string longer than 4096 chars — e.g. pasting a full document, a long error log, or concatenated paragraphs as the query.","commonSituations":"Using an entire document body as a similarity query; concatenating many questions; pasting a stack trace to find related memories; an LLM-generated query that did not summarise.","solutions":["Summarise the query to its first 4096 chars or a representative passage.","Extract the key sentence/paragraph and search on that, then retrieve full context separately.","Pre-check query.length <= 4096 before calling memory search.","If searching a large document, chunk and search per chunk."],"exampleFix":"// before\nmemory search --query \"$(cat long-doc.md)\"\n// after\nquery=$(head -c 4096 long-doc.md)\nmemory search --query \"$query\"","handlingStrategy":"validation","validationCode":"const MAX_QUERY_LENGTH = 4096;\nfunction clampQuery(q) {\n  if (typeof q !== 'string') throw new Error('query must be a string');\n  return q.length > MAX_QUERY_LENGTH ? q.slice(0, MAX_QUERY_LENGTH) : q;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Summarise documents before using them as a query.","Search per-chunk for large inputs.","Validate length at the boundary."],"tags":["memory","validation","search","input-validation","limits"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}