{"record":{"id":"c23fcb7e56fcb14e","repo":"vxcontrol/pentagi","slug":"pgvector-store-is-not-initialized-c23fcb","errorCode":null,"errorMessage":"pgvector store is not initialized","messagePattern":"pgvector store is not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/memory.go","lineNumber":55,"sourceCode":"\t\tstore:  store,\n\t\tvslp:   vslp,\n\t}\n}\n\nfunc (m *memory) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {\n\tif !m.IsAvailable() {\n\t\treturn \"\", fmt.Errorf(\"memory is not available\")\n\t}\n\n\tctx, observation := obs.Observer.NewObservation(ctx)\n\tlogger := logrus.WithContext(ctx).WithFields(enrichLogrusFields(m.flowID, nil, nil, logrus.Fields{\n\t\t\"tool\": name,\n\t\t\"args\": string(args),\n\t}))\n\n\tif m.store == nil {\n\t\tlogger.Error(\"pgvector store is not initialized\")\n\t\treturn \"\", fmt.Errorf(\"pgvector store is not initialized\")\n\t}\n\n\tswitch name {\n\tcase SearchInMemoryToolName:\n\t\tvar action SearchInMemoryAction\n\t\tif err := json.Unmarshal(args, &action); err != nil {\n\t\t\tlogger.WithError(err).Error(\"failed to unmarshal search in memory action arguments\")\n\t\t\treturn \"\", fmt.Errorf(\"failed to unmarshal %s search in memory action arguments: %w\", name, err)\n\t\t}\n\n\t\tfilters := map[string]any{\n\t\t\t\"flow_id\":  strconv.FormatInt(m.flowID, 10),\n\t\t\t\"doc_type\": memoryVectorStoreDefaultType,\n\t\t}\n\t\tif action.TaskID != nil && *action.TaskID != 0 {\n\t\t\tfilters[\"task_id\"] = action.TaskID.String()\n\t\t}\n\t\tif action.SubtaskID != nil && *action.SubtaskID != 0 {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/memory.go#L37-L73","documentation":"Redundant defensive check inside memory.Handle: even though IsAvailable() passed at entry, the code re-verifies m.store is non-nil before executing any tool action, and errors if the pgvector store is nil. Reaching it means the store became nil or the availability check and this check disagree.","triggerScenarios":"Calling search_in_memory when memory.store is nil despite IsAvailable() returning true (e.g. custom implementations overriding IsAvailable, or store mutated/cleared after construction); in stock code this is effectively unreachable unless NewMemoryTool was handed a nil store with an availability override.","commonSituations":"Custom Tool wrappers reimplementing IsAvailable; tests constructing memory with a nil store; concurrent reinitialization setting the store to nil.","solutions":["Ensure NewMemoryTool is never called with a nil *pgvector.Store.","Keep IsAvailable() consistent with the nil-store check (default implementation returns store != nil).","Check startup ordering so the pgvector store is fully initialized before tools are created.","If this fires in production, inspect for code that nils out or replaces the store at runtime."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if m.store == nil {\n    return errors.New(\"pgvector store missing; configure the vector store before using memory tools\")\n}","typeGuard":"func (m *memory) ready() bool { return m.store != nil }\n\nfunc ensureMemory(m Tool) (*memory, bool) {\n    mm, ok := m.(*memory)\n    return mm, ok && mm.ready()\n}","tryCatchPattern":"out, err := tool.Handle(ctx, \"search_in_memory\", args)\nif err != nil && strings.Contains(err.Error(), \"pgvector store is not initialized\") {\n    log.Println(\"pgvector store unavailable; skipping memory search\")\n    return memoryNotFoundMessage, nil\n}","preventionTips":["Construct tools only after the pgvector store is fully initialized","Keep IsAvailable() and internal nil checks derived from the same field","Avoid mutating the store field after construction","Add a startup assertion that all registered tools are available"],"tags":["pgvector","nil-check","initialization","tool-guard"],"backgroundTag":"uninitialized-dependency","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}