I heard the Messenger of Allah ﷺ say, or he said, the Messenger of Allah ﷺ said, "The angel comes to the drop of fluid after it has settled in the womb for forty nights." Sufyan once said, "Or fifty and forty nights." "He says, 'My Lord, will this one be wretched or fortunate?' and Allah decrees it, and they write it down. Then they say, 'What about the matter, male or female?' and Allah
decrees it, and they write it down. His deeds, his footsteps, his afflictions, and his provision are also written. Then the page is folded, and nothing is added to or subtracted from what it contains."
حدثنا سفيان عن عمرو عن أبي الطفيل
سمعت رسول الله ﷺ أو قال رسول الله ﷺ يدخل الملك على النطفة بعدما تستقر في الرحم بأربعين ليلة وقال سفيان مرة أو خمسين وأربعين ليلة فيقول يا رب ماذا أشقي أم سعيد أذكر أم أنثى فيقول الله تبارك وتعالى فيكتبان فيقولان ماذا أذكر أم أنثى فيقول الله عز وجل فيكتبان فيكتب عمله وأثره ومصيبته ورزقه ثم تطوى الصحيفة فلا يزاد على ما فيها ولا ينقص
Its isnad is sahih, and its narrators are leading authorities. Amr is Ibn Dinar. The hadith was mentioned before in similar wording under 15205, and it is found in Muslim 4/237, no. 2644, and Bukhari 4/161, Shab edition, in the chapter on the beginning of creation, mention of the angels.