affaan-m/ECC · warning · Error
memory search query is too long (maximum ${MAX_QUERY_CHARS}
Error message
memory search query is too long (maximum ${MAX_QUERY_CHARS} characters). What it means
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.
Source
Thrown at scripts/lib/memory-vault.js:593
if (index < 0) return best;
return best < 0 ? index : Math.min(best, index);
}, -1);
const start = Math.max(0, (matchIndex < 0 ? 0 : matchIndex) - 60);
const prefix = start > 0 ? '…' : '';
const suffix = start + maxChars < normalized.length ? '…' : '';
return `${prefix}${normalized.slice(start, start + maxChars)}${suffix}`;
}
function summarizeMemory(memory) {
return Object.fromEntries(
Object.entries(memory).filter(([key]) => key !== 'body')
);
}
function searchMemories(query, options = {}) {
const normalizedQuery = typeof query === 'string' ? query.trim() : '';
if (normalizedQuery.length > MAX_QUERY_CHARS) {
throw new Error(`memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).`);
}
if (hasUnsafeControlCharacters(normalizedQuery)) {
throw new Error('memory search query must not contain control characters.');
}
const kinds = options.kinds
? uniqueStrings(options.kinds, {
label: 'kinds',
limit: MEMORY_KINDS.length,
validator: value => validateEnum(value, MEMORY_KINDS, 'memory kind'),
})
: null;
const trust = options.trust
? validateEnum(options.trust, MEMORY_TRUST_STATES, 'memory trust')
: null;
const targetHarness = options.targetHarness
? validateSlug(options.targetHarness, 'target harness')
: null;View on GitHub (pinned to 01e15490f0)
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).
Example fix
// before
const results = searchMemories(hugeErrorLogString); // > 500 chars
// after
const results = searchMemories(hugeErrorLogString.trim().slice(0, 500));
// or better: extract the distinctive token
const results = searchMemories('ECC_MEMORY_LOCATION_MISMATCH'); Defensive patterns
Strategy: validation
Validate before calling
const { MAX_QUERY_CHARS } = require('./scripts/lib/memory-vault');
function assertQueryLength(query) {
const q = String(query || '').trim();
if (q.length > MAX_QUERY_CHARS) {
throw new Error(`memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).`);
}
return q;
}
// before searchMemories:
const q = assertQueryLength(rawQuery); Try / catch
try { searchMemories(query); }
catch (error) {
if (/query is too long/i.test(error.message)) {
return searchMemories(query.trim().slice(0, MAX_QUERY_CHARS));
}
throw error;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${label} is too large (${opened.size} bytes).
- memory search query must not contain control characters.
- Memory ${memoryId} was not found.
- Consult requires a natural language query, for example: secu
- ${label} must be a non-empty string.
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/80ff04ca385cda5b.
Report an issue: GitHub.