affaan-m/ECC · error · Error
memory search query must not contain control characters.
Error message
memory search query must not contain control characters.
What it means
searchMemories runs hasUnsafeControlCharacters on the trimmed query and refuses queries containing control characters (NUL, ESC, BEL, other C0 controls). Control characters can corrupt terminal output, break tokenization/regex, and be used to smuggle content past naïve filters. The vault rejects them at the API boundary rather than attempt to sanitize.
Source
Thrown at scripts/lib/memory-vault.js:596
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;
const limit = Math.max(1, Math.min(Number(options.limit) || 20, MAX_RESULTS));
const loaded = readMemoryFiles({ ...options, scopes: options.scopes || options.scope });
View on GitHub (pinned to 01e15490f0)
Solutions
- Strip control characters from the query before calling: query.replace(/[\x00-\x1f\x7f]/g, ' ').trim().
- If you pasted terminal output, re-copy with 'copy as plain text' or pipe through col -b / sed to strip ANSI sequences.
- Sanitize programmatic input: validate the query is a string and filter it through a printable-char whitelist.
- Reproduce the offending byte with console.log(JSON.stringify(query)) to see the exact control char, then remove it at the source.
Example fix
// before const results = searchMemories(rawTerminalOutput); // contains ESC[0m etc. // after const cleanQuery = rawTerminalOutput.replace(/[\x00-\x1f\x7f]/g, ' ').trim(); const results = searchMemories(cleanQuery);
Defensive patterns
Strategy: validation
Validate before calling
function assertQuerySafe(query) {
const q = String(query || '').trim();
if (/[\x00-\x1f\x7f]/.test(q)) {
throw new Error('memory search query must not contain control characters.');
}
return q;
}
// before searchMemories:
const q = assertQuerySafe(rawQuery); Try / catch
try { searchMemories(query); }
catch (error) {
if (/control characters/i.test(error.message)) {
const clean = query.replace(/[\x00-\x1f\x7f]/g, ' ').trim();
return searchMemories(clean);
}
throw error;
} Prevention
- Strip ANSI/control chars from pasted terminal output before searching.
- Sanitize programmatic input through a printable-char whitelist.
- Inspect suspicious queries with console.log(JSON.stringify(query)) to see the exact bytes.
- Never pass raw binary/buffer content as a search query.
When it happens
Trigger: Calling searchMemories with a query that contains any C0 control character (code points U+0000–U+001F, and typically U+007F DEL). Happens when pasting from a terminal capture that includes escape sequences, when a binary blob is passed as a query, or when programmatic input contains a literal NUL or newline-ish control char.
Common situations: Pasting terminal output that includes ANSI escape codes (ESC, CSI); passing a query built from binary data or a buffer that was not decoded as UTF-8 text; a log line containing a NUL byte; copy-paste from a PDF or document carrying invisible control chars.
Related errors
- ${label} must not contain control or bidirectional formattin
- memory body must not contain unsafe control or bidirectional
- No trusted boundary policy is configured for memory scope "$
- ${label} must be a regular, non-symlink file.
- Project memory .gitignore does not contain the required fail
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/d4896ea5aaa61258.
Report an issue: GitHub.