JuliusBrussee/caveman · error
cave_memory_namespace_invalid
cave_memory_namespace_invalid
Error message
cave_memory_namespace_invalid
What it means
`memoryFilePath` validates the memory `namespace` against `/^[a-z0-9][a-z0-9_-]{0,95}$/` since it becomes the JSON file name (`<namespace>.json`). Namespaces must be lowercase alphanumeric, underscore, or hyphen, start with a letter or digit, and be at most 96 characters; anything else (uppercase, dots, slashes, empty) throws this error.
Solutions
- Use a lowercase slug: `namespace: "user-notes"` or "notes_drafts".
- Normalize before calling: `ns.toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").slice(0, 96)`.
- Encode hierarchy with hyphens or nested namespaces fields if the API supports them, never `.` or `/`.
Example fix
// before
memory.remember({ namespace: "ProjectNotes", text: "..." });
// after
memory.remember({ namespace: "project-notes", text: "..." }); Defensive patterns
Strategy: validation
Validate before calling
const NS_RE = /^[a-z0-9][a-z0-9_-]{0,95}$/;
function safeNamespace(raw) {
const ns = String(raw).toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").slice(0, 96);
if (!ns || !NS_RE.test(ns)) throw new TypeError(`namespace invalid after normalize: ${raw}`);
return ns;
}
memory.remember({ namespace: safeNamespace("UserNotes"), text }); Type guard
const isValidNamespace = (ns) => typeof ns === "string" && /^[a-z0-9][a-z0-9_-]{0,95}$/.test(ns); Try / catch
try {
await memory.remember({ namespace, text });
} catch (e) {
if (e.message === "cave_memory_namespace_invalid") {
throw new Error(`Namespace '${namespace}' must be lowercase [a-z0-9_-], <=96 chars, no dots/slashes`, { cause: e });
}
throw e;
} Prevention
- Adopt a lowercase kebab-case naming convention for memory namespaces
- Lowercase and slugify any identifier reused as a namespace
- Use hyphens for hierarchical scopes, never `.` or `/`
- Cap namespace length at 96 characters in your naming helper
When it happens
Trigger: Calling memory APIs with `namespace: "UserNotes"` (uppercase), `namespace: "notes.drafts"` (dot), `namespace: "a/b"` (slash — also a traversal attempt), `namespace: ""`, or a namespace longer than 96 characters.
Common situations: Reusing camelCase or dotted Java/TS identifiers as namespaces; passing a file path or URL segment as a namespace; encoding hierarchical scopes with `.` instead of `-`.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- cave_memory_agent_invalid
- cave_memory_tenant_invalid
- apiKey, baseURL, and agent are required
- ASGI context resolver or request bounds are invalid
- bedrock endpoint must be runtime or mantle
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/7cfd5683eb19c628.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/memory-store.ts:62
return process.env.CAVE_AGENT_MEMORY_ROOT ?? join(homedir(), ".caveman", "agent-memory");
}
/**
* The durable file for (tenant, agentId, namespace). The three scoping
* components are validated to a `[a-z0-9_-]`-class charset with no `.` or path
* separator, so no component can traverse out of the memory root.
*/
export function memoryFilePath(
config: MemoryStoreConfig | undefined,
agentId: string,
namespace: string,
): string {
const tenant = config?.tenant ?? "_";
if (tenant !== "_" && !TENANT_PATTERN.test(tenant)) {
throw new Error("cave_memory_tenant_invalid");
}
if (!AGENT_PATTERN.test(agentId)) throw new Error("cave_memory_agent_invalid");
if (!NAMESPACE_PATTERN.test(namespace)) throw new Error("cave_memory_namespace_invalid");
return join(config?.root ?? defaultRoot(), tenant, agentId, `${namespace}.json`);
}
function isMemoryEntry(value: unknown): value is MemoryEntry {
return value !== null && typeof value === "object" &&
typeof (value as { text?: unknown }).text === "string" &&
Number.isSafeInteger((value as { createdAt?: unknown }).createdAt);
}
/** Read the durable entries. A missing or corrupt file is an empty store, never a throw into a run. */
export async function readMemories(filePath: string): Promise<MemoryEntry[]> {
try {
const parsed: unknown = JSON.parse(await readFile(filePath, "utf8"));
return Array.isArray(parsed) ? parsed.filter(isMemoryEntry) : [];
} catch {
return [];
}
}View on GitHub (pinned to 3ee70a1026)