{"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":"warning","filePath":"scripts/lib/memory-vault.js","lineNumber":593,"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":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/memory-vault.js#L575-L611","documentation":"searchMemories trims and then length-checks the query against MAX_QUERY_CHARS (500). Queries above that cap are rejected before any scanning or scoring runs, because the search tokenizes and lowercases the query and walks every memory — unbounded query length would blow up CPU and memory. The cap is a deliberate throughput floor.","triggerScenarios":"Calling searchMemories with a string query whose trimmed length exceeds 500 characters. The trim happens first, so leading/trailing whitespace is not counted, but interior length is.","commonSituations":"Pasting an entire error log or file contents as the query; programmatically concatenating many terms; a UI that submits the whole document body as a search; a misrouted argument that passes a memory body where a query was expected.","solutions":["Shorten the query to its most distinctive few keywords (search is tokenized, so 5–10 terms work better than a long paragraph anyway).","If you are searching for a long phrase, extract the most unique substring (<= 500 chars) and use that.","If you actually want to find a document by its full content, scan the vault with readMemoryFiles and match client-side instead of using searchMemories.","Trim and slice the query before calling: query.trim().slice(0, 500)."],"exampleFix":"// before\nconst results = searchMemories(hugeErrorLogString); // > 500 chars\n// after\nconst results = searchMemories(hugeErrorLogString.trim().slice(0, 500));\n// or better: extract the distinctive token\nconst results = searchMemories('ECC_MEMORY_LOCATION_MISMATCH');","handlingStrategy":"validation","validationCode":"const { MAX_QUERY_CHARS } = require('./scripts/lib/memory-vault');\nfunction assertQueryLength(query) {\n  const q = String(query || '').trim();\n  if (q.length > MAX_QUERY_CHARS) {\n    throw new Error(`memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).`);\n  }\n  return q;\n}\n// before searchMemories:\nconst q = assertQueryLength(rawQuery);","typeGuard":null,"tryCatchPattern":"try { searchMemories(query); }\ncatch (error) {\n  if (/query is too long/i.test(error.message)) {\n    return searchMemories(query.trim().slice(0, MAX_QUERY_CHARS));\n  }\n  throw error;\n}","preventionTips":["Pass distinctive keywords, not full documents, as the query.","Trim and slice user input before searching: query.trim().slice(0, 500).","For full-content matching, scan with readMemoryFiles and match client-side.","Validate query length in the UI before submission."],"tags":["memory-vault","validation","size-limits","search"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}