{"record":{"id":"fe2ebbc54654ee9c","repo":"JuliusBrussee/caveman","slug":"read-back-memory-w","errorCode":null,"errorMessage":"read back memory: %w","messagePattern":"read back memory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":190,"sourceCode":"\t}\n\tid := memID(text)\n\tcreated := time.Now().UTC().Format(time.RFC3339Nano)\n\t// INSERT OR IGNORE keeps the original created_at on a repeat remember.\n\t// RetryOnBusy: under a fan-out of cavemem processes, a queued writer can\n\t// outlast a single busy_timeout (Windows file locking is the slowest case).\n\tif err := ccr.RetryOnBusy(func() error {\n\t\t_, e := s.db.Exec(\n\t\t\t`INSERT OR IGNORE INTO memories (id, text, created_at, valid_from) VALUES (?, ?, ?, ?)`,\n\t\t\tid, text, created, created,\n\t\t)\n\t\treturn e\n\t}); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"store memory: %w\", err)\n\t}\n\tvar stored Memory\n\trow := s.db.QueryRow(memorySelect+` WHERE id = ?`, id)\n\tif err := scanMemory(row, &stored); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"read back memory: %w\", err)\n\t}\n\tif stored.ValidUntil != nil {\n\t\treturn Memory{}, fmt.Errorf(\"memory %s exists only as an expired historical version and cannot be re-remembered as current\", stored.ID)\n\t}\n\treturn stored, nil\n}\n\n// Supersede atomically replaces one current memory with a new current version.\n// The old row remains durable for history and byte-exact audit, but normal recall\n// excludes it. An already-expired or unknown id fails closed.\nfunc (s *Store) Supersede(oldID, newText string) (Memory, error) {\n\tif strings.TrimSpace(oldID) == \"\" {\n\t\treturn Memory{}, fmt.Errorf(\"supersede requires old memory id\")\n\t}\n\tif strings.TrimSpace(newText) == \"\" {\n\t\treturn Memory{}, fmt.Errorf(\"cannot supersede with empty text\")\n\t}\n\tif err := validateMemorySize(newText); err != nil {","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L172-L208","documentation":"After inserting, Remember reads the row back with the standard memorySelect query to return the stored Memory. This error wraps any failure of that SELECT/scan (e.g. sql.ErrNoRows, scan type mismatch, db error). It is an internal consistency check: the row that was just written could not be read back.","triggerScenarios":"Calling Remember when the read-back SELECT fails due to db lock/errors, or a scan/type mismatch between memorySelect's column layout and the Memory struct, or (rarely) the row vanishing between insert and select under concurrent modification.","commonSituations":"Schema drift — an older/newer table shape than the code expects after a partial migration; concurrent writers interfering; transient SQLITE_BUSY on the query.","solutions":["Check the wrapped cause; if sql.ErrNoRows, another writer may have removed the row — inspect concurrent modifications.","Verify the memories table schema matches what this binary's migrateMemorySchema produces (partial migration suspect).","Retry after transient lock errors.","If scan mismatches persist, rebuild the db with the current version's migration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"m, err := store.Remember(text)\nif err != nil {\n    if strings.Contains(err.Error(), \"read back memory\") {\n        log.Printf(\"insert ok but read-back failed; verify schema/migration: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep binary version and db schema in sync (complete migrations)","Avoid multiple writers racing the same row","Rebuild the db if scan errors persist after upgrade","Log the full wrapped error chain for diagnosis"],"tags":["database","sqlite","read-failure","consistency"],"backgroundTag":"record-not-found","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"}