ruvnet/ruflo · error · Error
Query exceeds maximum length of ${MAX_QUERY_LENGTH} characte
Error message
Query exceeds maximum length of ${MAX_QUERY_LENGTH} characters What it means
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.
Source
Thrown at v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts:79
const MAX_KEY_LENGTH = 1024;
const MAX_VALUE_SIZE = 1024 * 1024; // 1MB
const MAX_QUERY_LENGTH = 4096;
// #1425 — single source of truth for the dangerous-character set rejected by
// validateMemoryInput. Imported by sanitizeMemoryKey so write-side sanitization
// and read-side rejection can never drift apart (the symmetry bug behind #1884).
const DANGEROUS_KEY_CHARS = /[;&|`$(){}[\]<>!#\\\0]|\.\.[/\\]/g;
const DANGEROUS_KEY_PATTERN = /[;&|`$(){}[\]<>!#\\\0]|\.\.[/\\]/;
function validateMemoryInput(key?: string, value?: string, query?: string, namespace?: string): void {
if (key && key.length > MAX_KEY_LENGTH) {
throw new Error(`Key exceeds maximum length of ${MAX_KEY_LENGTH} characters`);
}
if (value && value.length > MAX_VALUE_SIZE) {
throw new Error(`Value exceeds maximum size of ${MAX_VALUE_SIZE} bytes`);
}
if (query && query.length > MAX_QUERY_LENGTH) {
throw new Error(`Query exceeds maximum length of ${MAX_QUERY_LENGTH} characters`);
}
// Reject path traversal and shell metacharacters in keys/namespaces (#1425)
if (key && DANGEROUS_KEY_PATTERN.test(key)) {
throw new Error('Key contains disallowed characters');
}
if (namespace && DANGEROUS_KEY_PATTERN.test(namespace)) {
throw new Error('Namespace contains disallowed characters');
}
}
// #1884 — sanitize a key produced from arbitrary input (markdown headings,
// frontmatter names, file names) so it survives validateMemoryInput on the
// read/delete path. Replaces every dangerous char with `_`. Truncates to
// MAX_KEY_LENGTH so the bound check in validateMemoryInput also passes.
// Keep this in sync with DANGEROUS_KEY_PATTERN — they share DANGEROUS_KEY_CHARS.
function sanitizeMemoryKey(key: string): string {
const safe = key.replace(DANGEROUS_KEY_CHARS, '_');
return safe.length > MAX_KEY_LENGTH ? safe.slice(0, MAX_KEY_LENGTH) : safe;View on GitHub (pinned to 6b01dc5a68)
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.
Example fix
// before memory search --query "$(cat long-doc.md)" // after query=$(head -c 4096 long-doc.md) memory search --query "$query"
Defensive patterns
Strategy: validation
Validate before calling
const MAX_QUERY_LENGTH = 4096;
function clampQuery(q) {
if (typeof q !== 'string') throw new Error('query must be a string');
return q.length > MAX_QUERY_LENGTH ? q.slice(0, MAX_QUERY_LENGTH) : q;
} Prevention
- Summarise documents before using them as a query.
- Search per-chunk for large inputs.
- Validate length at the boundary.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Key exceeds maximum length of ${MAX_KEY_LENGTH} characters
- Value exceeds maximum size of ${MAX_VALUE_SIZE} bytes
- Key contains disallowed characters
- Namespace contains disallowed characters
- memory path is required
AI-assisted analysis of ruvnet/ruflo@6b01dc5a68 (2026-08-12).
Data as JSON: /api/errors/ebef3408d7f86680.
Report an issue: GitHub.