Our Gemara on Amud Aleph discusses the wells made for the people from Babylonia who would use them when ascending to Israel for the festivals. These wells are discussed as well in Mishna Nedarim 5:5 and Gemara Bava Kama 50a. The Gemara over there in Bava Kama tells us an interesting story about a sage who was famous for maintaining and digging these wells as a public service:

⁦Having mentioned the deeds of Neḥunya, the Gemara relates that the Sages taught: An incident occurred involving the daughter of Neḥunya the ditchdigger, where she fell into a large cistern and no one could extricate her from it. They came and informed Rabbi Ḥanina ben Dosa so that he would pray on her behalf. When the first hour had passed from the time of her fall, he said to them: She is at peace and unharmed. After the second hour, he said to them: She is at peace. After the third hour, he said to them: She has ascended from the well, and indeed this was the case.

⁦They said to her: Who brought you up out of the well? She said to them: A male sheep, i.e., a ram, happened to come to me, and a certain old man, i.e., Abraham, was leading it, and he pulled me out. They said to Rabbi Ḥanina ben Dosa: Are you a prophet? How did you know she had ascended? Rabbi Ḥanina ben Dosa said to them: “I am no prophet, neither am I a prophet’s son” (Amos 7:14), but this is what I said to myself: Shall the offspring of Neḥunya stumble by means of the very matter which that righteous man sacrificed and invested effort?

⁦Rabbi Aḥa says: Although Neḥunya ensured that others would have water, even so, his son died of thirst, fulfilling that which is stated: “And around Him it storms [nisara] mightily” (Psalms 50:3). This teaches that the Holy One, Blessed be He, is scrupulous with those around Him, i.e., the righteous, even to the extent of a hairsbreadth [hasa’ara], so that even minor transgressions elicit a severe punishment. Rabbi Neḥunya says: The same idea may be learned from here, in the following verse: “A God dreaded in the great council of the holy ones, and feared by all those that surround Him” (Psalms 89:8), indicating that God is most careful and exacting with those that surround Him, i.e., the righteous.

This story is troubling.  It starts out with what seems to be an assurance that someone who makes sacrifices for a mitzvah will be afforded some kind of protection, at least in regard to objects and matters related to that endeavor. However, confusingly, the Gemara ends with a story of the opposite nature. While Nehunya’s daughter was miraculously saved by drowning, his son ended up dying of thirst! The Gemara concludes with the observation that Hashem judges the righteous by a very high standard, and even the great Nehunya 

must have been some lacking and had sins of omission that resulted in this sad outcome.

Tosafos raises the obvious question: If it is true that God judges the righteous with a high standard and that is why Rav Nehunya’s son died, how did Rav Chanina ben Dosa know that his daughter would survive? Tosafos answers that the two situations were different. The daughter was drowning IN THE WELL, while his son merely died from lack of water that a well could procure. According to this answer, even though God may judge the righteous harshly, there is a limit. That is, it is too ironic and too cruel to die at the hand of the very object of the mitzvah. Thus Rabbi Chanina ben Dosa knew that there was no way Nehunya’s daughter could drown in the very well that he dug as a public service. But, his son still could possibly die of thirst.

Tosafos then adds something that seems to be a non-sequitur. According to the Yerushalmi, the old man wasn’t Avraham, but instead it was some kind of angelic projection of Chanina ben Dosa’s will to save the girl. The Chida suggests that in fact, it’s not a non-sequitur, but actually a new answer in Tosafos. Tosafos is saying since the old man was some kind of projection/angel/apparition representing Rav Chanina ben Dosa, he obviously knew that Nachunya’s merit would work, while in the son’s situation he did nor receive those powers.

Taken on a pashut pshat level, the Gemara seems to be saying that though at a moment in time, be that as it may, Rav Chaninah ben Dosa intuited that Nehunya’s daughter would merit salvation, God’s ways are unknowable. The very same person’s son did not merit a miraculous salvation. We may even postulate that since the salvation of his daughter came first, perhaps Nehunya had some small sin that put his daughter in danger but his merit still protected her. However, since apparently Nehunya was not able to sufficiently address whatever minor deficiencies he had, the next time a child of his was in danger, he no longer had the merit. This would be similar to what we find Yaakov worrying about in Bereishis (32:11): “I have been made unworthy from all the kindness that You have so steadfastly shown Your servant.” (See Rashi Op. Cit. and Gemara Shabbos 32a)