I think I may have misunderstood your question. Let us try again:
After John had searched for almost thirty minutes, he realized that his pen had been lying on the desk the entire time.
had been lying - is an error according to my book, so it should be: has been lying, because it still lasts?– No. Since ‘realized’ is past tense and ‘lying’ precedes realization, the present perfect is inappropriate. However, since the order of events is logically clear, '‘had been lying’ is unnecessary; ‘was lying’ will serve.
So, did Sir mean two past events: realized and lying, or searching and lying?
So it takes place the following change:
,…he realizes that his pen is lying on the desk the entire time. to:
,…he realized that his pen was lying on the desk the entire time.???
So it takes place the following change:
,…he realizes that his pen is lying on the desk the entire time. to:
,…he realized that his pen was lying on the desk the entire time.