Sayyiduna Anas (may Allah be pleased with him) narrates that the Prophet (peace and blessings be upon him) said: "Three men from the people of earlier times set out; they had gone out to seek (provision) for their families. Rain overtook them, and they entered a cave. A rock fell upon them which (sealed the mouth of the cave), until they could not see even a chink through it. One of them said to the others: 'The rock has fallen and the traces have been effaced; now no one knows of your whereabouts except Allah Almighty. So supplicate to Allah Almighty by means of your most reliable deed!'" The Prophet (peace and blessings be upon him) said: "One of them said: 'O Allah! You know that I had parents. I used to milk for them in their vessel. Once I came to them and found them both asleep, so I stood at their heads, disliking to disturb their sleep, until they woke up by themselves when they were to wake. O Allah! You know that I did this hoping for Your mercy and fearing Your punishment, so grant us relief!'" The Prophet (peace and blessings be upon him) said: "Then a third of the rock moved away. The second man said: 'O Allah! You know that I hired a labourer for a job, and he kept doing that work. Then he came to me to take his wages while I was in a state of anger. I scolded him, so he went away and left those wages of his. I gathered (those wages) and invested them to make them grow, until a great deal of wealth came of them. Then one day he came to me to take his wages, and I handed all of it over to him; had I wished, I could have given him only his original wages. O Allah! If You know that I did this hoping for Your mercy and fearing Your punishment, then grant us relief!' Then a third of the rock moved away. The third man said: 'O Allah! You know that I was attracted to a woman. He fixed a certain payment for her, and when he gained power over her, he left her alone and also let her keep her payment.' (The man said:) 'O Allah! You know that if I did this hoping for Your mercy and fearing Your punishment, then grant us relief!' Then the rock moved away, and they came out walking."
Ahmad recorded it as a marfu' report (attributed to the Prophet), as you can see, and al-Bazzar and Abu Ya'la also recorded it. Abdullah recorded it as mawquf on Sayyiduna Anas (may Allah be pleased with him). The narrators of Ahmad and Abu Ya'la, both of them, are the narrators of the Sahih.