{"record":{"id":"a1c99310b549ce32","repo":"JuliusBrussee/caveman","slug":"errmemorytoolarge","errorCode":"ErrMemoryTooLarge","errorMessage":"%w: memory is %d bytes, over the %d-byte cap","messagePattern":"%w: memory is (.+?) bytes, over the (.+?)-byte cap","errorType":"error_code","errorClass":"ErrMemoryTooLarge","httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":270,"sourceCode":"\t}\n\tif n, _ := res.RowsAffected(); n != 1 {\n\t\treturn Memory{}, fmt.Errorf(\"memory %s changed during supersede\", oldID)\n\t}\n\tif err := tx.Commit(); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"supersede commit: %w\", err)\n\t}\n\treturn Memory{\n\t\tID:         newID,\n\t\tText:       newText,\n\t\tCreatedAt:  now,\n\t\tValidFrom:  now,\n\t\tSupersedes: oldID,\n\t}, nil\n}\n\nfunc validateMemorySize(text string) error {\n\tif len(text) > MaxMemoryBytes {\n\t\treturn fmt.Errorf(\"%w: memory is %d bytes, over the %d-byte cap\", ErrMemoryTooLarge, len(text), MaxMemoryBytes)\n\t}\n\treturn nil\n}\n\n// History returns the complete oldest-to-newest supersession chain containing\n// id. Broken/cyclic lineage is rejected rather than returning partial history.\nfunc (s *Store) History(id string) ([]Memory, error) {\n\tif strings.TrimSpace(id) == \"\" {\n\t\treturn nil, fmt.Errorf(\"history requires memory id\")\n\t}\n\tcurrent, err := s.memoryByID(id)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tseen := map[string]bool{current.ID: true}\n\tvar before []Memory\n\tcursor := current\n\tfor cursor.Supersedes != \"\" {","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/mem/store.go#L252-L288","documentation":"Returned by validateMemorySize when the text passed to Remember/Supersede exceeds MaxMemoryBytes (256 KiB). The store deliberately fails closed with the sentinel ErrMemoryTooLarge (surfaced as cave_memoryTooLarge / CLI exit 65) because a memory is a recallable fact, not a file dump. The wrapper text includes the offending size and the cap so you can see how far over you are.","triggerScenarios":"Calling Remember or Supersede with a string longer than 262144 bytes: pasting a whole file/log dump, a huge JSON blob, or building memory text from unbounded user input without measuring it first.","commonSituations":"Scripts that pipe files or command output straight into remember (`cavemem remember < big.log`), agents summarizing transcripts into one memory instead of chunking, or a version change where a previously accepted payload grew past the cap.","solutions":["Split the content into multiple memories under 256 KiB each, or store a summary/reference and keep the full payload elsewhere","Truncate deliberately before calling Remember if only a prefix matters, after measuring len(text)","If you truly need unlimited single memories, that is not supported by design — reconsider what you are storing"],"exampleFix":"// before\nerr := store.Remember(string(fileContents)) // 1 MB file -> ErrMemoryTooLarge\n\n// after\nconst chunk = 200 * 1024\nfor len(text) > 0 {\n    n := min(chunk, len(text))\n    if err := store.Remember(text[:n]); err != nil { return err }\n    text = text[n:]\n}","handlingStrategy":"validation","validationCode":"if err := mem.ValidateSize(text); err != nil { // or: if len(text) > mem.MaxMemoryBytes\n    return err\n}\nerr := store.Remember(text)","typeGuard":"func fitsMemoryCap(text string) bool { return len(text) <= mem.MaxMemoryBytes }","tryCatchPattern":"err := store.Remember(text)\nif err != nil {\n    if errors.Is(err, mem.ErrMemoryTooLarge) {\n        // split, summarize, or truncate before retrying once\n    }\n    return err\n}","preventionTips":["Measure len(text) at the boundary where untrusted/large input enters (file reads, HTTP bodies)","Chunk or summarize large payloads instead of storing them whole","Check errors.Is(err, mem.ErrMemoryTooLarge) rather than string matching — it is a sentinel","CLI callers exit 65 on this error; wrappers should map it, not swallow it"],"tags":["go","validation","size-limit","memory-store"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}