{"record":{"id":"80ff04ca385cda5b","repo":"affaan-m/ECC","slug":"memory-search-query-is-too-long-maximum-max-que","errorCode":null,"errorMessage":"memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).","messagePattern":"memory search query is too long \\(maximum (.+?) characters\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault.js","lineNumber":605,"sourceCode":"    if (index < 0) return best;\n    return best < 0 ? index : Math.min(best, index);\n  }, -1);\n  const start = Math.max(0, (matchIndex < 0 ? 0 : matchIndex) - 60);\n  const prefix = start > 0 ? '…' : '';\n  const suffix = start + maxChars < normalized.length ? '…' : '';\n  return `${prefix}${normalized.slice(start, start + maxChars)}${suffix}`;\n}\n\nfunction summarizeMemory(memory) {\n  return Object.fromEntries(\n    Object.entries(memory).filter(([key]) => key !== 'body')\n  );\n}\n\nfunction searchMemories(query, options = {}) {\n  const normalizedQuery = typeof query === 'string' ? query.trim() : '';\n  if (normalizedQuery.length > MAX_QUERY_CHARS) {\n    throw new Error(`memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).`);\n  }\n  if (hasUnsafeControlCharacters(normalizedQuery)) {\n    throw new Error('memory search query must not contain control characters.');\n  }\n\n  const kinds = options.kinds\n    ? uniqueStrings(options.kinds, {\n      label: 'kinds',\n      limit: MEMORY_KINDS.length,\n      validator: value => validateEnum(value, MEMORY_KINDS, 'memory kind'),\n    })\n    : null;\n  const trust = options.trust\n    ? validateEnum(options.trust, MEMORY_TRUST_STATES, 'memory trust')\n    : null;\n  const targetHarness = options.targetHarness\n    ? validateSlug(options.targetHarness, 'target harness')\n    : null;","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault.js#L587-L623","documentation":"searchMemories trims the query and enforces a maximum query length of MAX_QUERY_CHARS before searching. Queries longer than the cap are rejected up front rather than processed, keeping search costs and regex/scan work bounded.","triggerScenarios":"Calling searchMemories with a string whose trimmed length exceeds MAX_QUERY_CHARS — e.g. pasting an entire document as the search query.","commonSituations":"Using the memory search as a 'find similar' by feeding whole files; scripting that forwards unbounded user input or command-line blobs straight into the query parameter.","solutions":["Shorten the query to the essential keywords within the character limit.","Pre-process input in scripts: truncate or extract key terms before calling searchMemories.","Check the library's MAX_QUERY_CHARS constant and enforce it in your own input UI."],"exampleFix":"// before\nsearchMemories(entireDocument);\n// after\nconst query = entireDocument.slice(0, MAX_QUERY_CHARS).trim();\nsearchMemories(query);","handlingStrategy":"validation","validationCode":"if (typeof query !== 'string' || query.trim().length > MAX_QUERY_CHARS) throw new Error('Search query too long; extract key terms first.');","typeGuard":"const isValidQuery = (q) => typeof q === 'string' && q.trim().length > 0 && q.trim().length <= MAX_QUERY_CHARS;","tryCatchPattern":"try {\n  searchMemories(query);\n} catch (err) {\n  if (err.message.includes('query is too long')) {\n    searchMemories(query.trim().slice(0, MAX_QUERY_CHARS));\n  } else throw err;\n}","preventionTips":["Always trim and bound-check query strings before searching.","Never pass whole documents as queries; extract keywords.","Enforce the limit in your own UI/CLI input handling.","Import MAX_QUERY_CHARS from the library instead of hardcoding a number."],"tags":["validation","search","memory-vault"],"backgroundTag":"invalid-argument-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}