{"record":{"id":"7cfd5683eb19c628","repo":"JuliusBrussee/caveman","slug":"cave-memory-namespace-invalid","errorCode":"cave_memory_namespace_invalid","errorMessage":"cave_memory_namespace_invalid","messagePattern":"cave_memory_namespace_invalid","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/memory-store.ts","lineNumber":62,"sourceCode":"  return process.env.CAVE_AGENT_MEMORY_ROOT ?? join(homedir(), \".caveman\", \"agent-memory\");\n}\n\n/**\n * The durable file for (tenant, agentId, namespace). The three scoping\n * components are validated to a `[a-z0-9_-]`-class charset with no `.` or path\n * separator, so no component can traverse out of the memory root.\n */\nexport function memoryFilePath(\n  config: MemoryStoreConfig | undefined,\n  agentId: string,\n  namespace: string,\n): string {\n  const tenant = config?.tenant ?? \"_\";\n  if (tenant !== \"_\" && !TENANT_PATTERN.test(tenant)) {\n    throw new Error(\"cave_memory_tenant_invalid\");\n  }\n  if (!AGENT_PATTERN.test(agentId)) throw new Error(\"cave_memory_agent_invalid\");\n  if (!NAMESPACE_PATTERN.test(namespace)) throw new Error(\"cave_memory_namespace_invalid\");\n  return join(config?.root ?? defaultRoot(), tenant, agentId, `${namespace}.json`);\n}\n\nfunction isMemoryEntry(value: unknown): value is MemoryEntry {\n  return value !== null && typeof value === \"object\" &&\n    typeof (value as { text?: unknown }).text === \"string\" &&\n    Number.isSafeInteger((value as { createdAt?: unknown }).createdAt);\n}\n\n/** Read the durable entries. A missing or corrupt file is an empty store, never a throw into a run. */\nexport async function readMemories(filePath: string): Promise<MemoryEntry[]> {\n  try {\n    const parsed: unknown = JSON.parse(await readFile(filePath, \"utf8\"));\n    return Array.isArray(parsed) ? parsed.filter(isMemoryEntry) : [];\n  } catch {\n    return [];\n  }\n}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/memory-store.ts#L44-L80","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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 `-`.","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 `/`."],"exampleFix":"// before\nmemory.remember({ namespace: \"ProjectNotes\", text: \"...\" });\n// after\nmemory.remember({ namespace: \"project-notes\", text: \"...\" });","handlingStrategy":"validation","validationCode":"const NS_RE = /^[a-z0-9][a-z0-9_-]{0,95}$/;\nfunction safeNamespace(raw) {\n  const ns = String(raw).toLowerCase().replace(/[^a-z0-9_-]/g, \"-\").replace(/^[-_]+/, \"\").slice(0, 96);\n  if (!ns || !NS_RE.test(ns)) throw new TypeError(`namespace invalid after normalize: ${raw}`);\n  return ns;\n}\nmemory.remember({ namespace: safeNamespace(\"UserNotes\"), text });","typeGuard":"const isValidNamespace = (ns) => typeof ns === \"string\" && /^[a-z0-9][a-z0-9_-]{0,95}$/.test(ns);","tryCatchPattern":"try {\n  await memory.remember({ namespace, text });\n} catch (e) {\n  if (e.message === \"cave_memory_namespace_invalid\") {\n    throw new Error(`Namespace '${namespace}' must be lowercase [a-z0-9_-], <=96 chars, no dots/slashes`, { cause: e });\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["configuration","validation","identifier-format","path-safety"],"backgroundTag":"invalid-identifier-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}