{"record":{"id":"386e8b0c48425a78","repo":"vxcontrol/pentagi","slug":"failed-to-create-vector-store-log-w","errorCode":null,"errorMessage":"failed to create vector store log: %w","messagePattern":"failed to create vector store log: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/vslog.go","lineNumber":75,"sourceCode":"\ttaskID *int64,\n\tsubtaskID *int64,\n) (int64, error) {\n\tvslw.mx.Lock()\n\tdefer vslw.mx.Unlock()\n\n\tvsLog, err := vslw.db.CreateVectorStoreLog(ctx, database.CreateVectorStoreLogParams{\n\t\tInitiator: initiator,\n\t\tExecutor:  executor,\n\t\tFilter:    filter,\n\t\tQuery:     query,\n\t\tAction:    action,\n\t\tResult:    result,\n\t\tFlowID:    vslw.flowID,\n\t\tTaskID:    database.Int64ToNullInt64(taskID),\n\t\tSubtaskID: database.Int64ToNullInt64(subtaskID),\n\t})\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to create vector store log: %w\", err)\n\t}\n\n\tvslw.pub.VectorStoreLogAdded(ctx, vsLog)\n\n\treturn vsLog.ID, nil\n}\n\nfunc (vslw *flowVectorStoreLogWorker) GetLog(ctx context.Context, msgID int64) (database.Vecstorelog, error) {\n\tmsg, err := vslw.db.GetFlowVectorStoreLog(ctx, database.GetFlowVectorStoreLogParams{\n\t\tID:     msgID,\n\t\tFlowID: vslw.flowID,\n\t})\n\tif err != nil {\n\t\treturn database.Vecstorelog{}, fmt.Errorf(\"failed to get vector store log: %w\", err)\n\t}\n\n\treturn msg, nil\n}","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/vslog.go#L57-L93","documentation":"PutLog wraps any error returned by the CreateVectorStoreLog SQLC query with \"failed to create vector store log: %w\". It means inserting a vector-store log row (query, action, result, flow/task/subtask IDs) into PostgreSQL failed. The underlying cause (connection failure, constraint violation, context cancellation) is preserved via %w for errors.Is/As inspection.","triggerScenarios":"Calling PutLog when the DB connection is down; the flow row referenced by FlowID no longer exists (FK violation); an invalid VecstoreActionType violates a check constraint; ctx is cancelled or times out mid-insert.","commonSituations":"Database restart or pool exhaustion during heavy agent activity; running flows pointing at rows deleted by manual cleanup; network partition between the app and PostgreSQL; misconfigured DSN in the environment.","solutions":["Unwrap and log the wrapped error to identify the root cause (check pgconn.PgError code for FK/constraint issues).","Verify PostgreSQL connectivity and the connection pool (docker compose ps, DSN in .env).","If FK violations occur, ensure the flow/task/subtask rows exist before logging, or make TaskID/SubtaskID null.","Add retry with backoff for transient connection errors before failing the agent step."],"exampleFix":"// before\nid, err := worker.PutLog(ctx, init, exec, filter, q, action, result, &taskID, &subtaskID)\nif err != nil { return err }\n// after\nid, err := worker.PutLog(ctx, init, exec, filter, q, action, result, &taskID, &subtaskID)\nif err != nil {\n    var pgErr *pgconn.PgError\n    if errors.As(err, &pgErr) && pgErr.Code == \"23503\" {\n        // foreign key violation: log without task/subtask linkage\n        id, err = worker.PutLog(ctx, init, exec, filter, q, action, result, nil, nil)\n    }\n    if err != nil { return fmt.Errorf(\"put log: %w\", err) }\n}","handlingStrategy":"retry","validationCode":"if vslw.flowID == 0 {\n    return fmt.Errorf(\"cannot put vector store log: flow not set\")\n}\nif err := ctx.Err(); err != nil {\n    return err // context already cancelled, insert would fail\n}\nif err := db.Ping(ctx); err != nil {\n    return fmt.Errorf(\"database unavailable: %w\", err)\n}","typeGuard":"func isFKViolation(err error) bool {\n    var pgErr *pgconn.PgError\n    return errors.As(err, &pgErr) && pgErr.Code == \"23503\"\n}","tryCatchPattern":"id, err := worker.PutLog(ctx, init, exec, filter, q, action, result, taskID, subtaskID)\nif err != nil {\n    var pgErr *pgconn.PgError\n    if errors.As(err, &pgErr) && isTransient(pgErr.Code) {\n        id, err = retryWithBackoff(3, func() (int64, error) {\n            return worker.PutLog(ctx, init, exec, filter, q, action, result, taskID, subtaskID)\n        })\n    }\n    if err != nil { log.Warn(\"vector store log dropped\", \"err\", err) }\n}","preventionTips":["Keep flow/task/subtask rows alive for the lifetime of logging, or pass nil IDs.","Monitor DB connection pool saturation during heavy agent activity.","Use valid VecstoreActionType values only (check-constraint friendly).","Alert on wrapped root causes via errors.As(*pgconn.PgError)."],"tags":["go","database","postgres","insert-failed"],"backgroundTag":"database-insert-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}