I don't thunk your model is correct. Opening the fridge causes the accumulated cold air to fall out over a period of a few (maybe 4-7?) seconds, after which it doesn't really matter how long you leave it open, as the air is all room temp. The stuff will slowly take heat from the room temp air, at a rate of about 1 degree/minute. Once the door is closed, it takes a few minutes (again, IDK how long) to get the air back to 40F, and then however long to extract the heat from the stuff. If you are chosing between "stand there with it open" and "take something out, use it, amd put it back within a few minutes" there is no appreciable difference in the air temp inside the fridge for those two options - in both cases things will return to temp some minutes after the last closing. You can empirically test how long it takes to re-cool the air simply by getting a fridge thermometer and seeing how the temperature varies with different wait times. Or just see how long before the escaping air "feels cold" again.
Something that may help build a better model/intuition is this video from Technology Connections: https://www.youtube.com/watch?v=CGAhWgkKlHI
I mentally visualize the cold air as a liquid when I open the door, or maybe picturing it looking similar to the fog from dry ice.
Since it's cold, it falls downward, "pouring" out onto the floor, and probably does not take more than a few seconds, though I would love to see someone capture it on video with a thermal camera.
After that, I figure it doesn't really matter how long the door is open, until you start talking...
The model here is not a very good one in one important respect: opening the door twice in quick succession does not cost anywhere near twice as much as opening it once.
When you leave open the door, the colder air falls out the bottom and drags more warm air in past the contents, raising their temperature quite rapidly. While there is some additional turbulent mixing in the airflow around the initially moving door, it is not really significant compared with the overall downward convection flow inside the fridge. The flowing air cools and falls out the bottom continuously.
When you close it again, the airflow quickly reduces to almost nothing as the air stratifies by temperature - the coldest air is no longer free to flow out. The rate of heat transfer into the food reduces substantially. Eventually the air cools via the refrigerated walls and starts cooling the contents back to an equilibrium temperature, though this takes quite a few minutes.
So in terms of the important thing - temperature of the contents - you're better off opening it each time as an open door heats the contents much faster than a closed one even with the same warm air in it.
The real answer is that you should minimize the risk that you walk away and leave the door open for hours, and open it zero times whenever possible. The relative heat loss from 1 vs many separate openings is not significantly different from each-other, but it is much more than 0, and the tail risk of "all the food gets warm and spoils" should dominate the decisions
Why are you asking? I'd say in general the answer is that you should be thinking about more important things. The consequences of getting the fridge timing either right or wrong are very small compared to many things in life. Social interactions and social skills are an overlooked area worthy of a ton of thought and analysis.
I agree that this particular question isn't important, but I think it's good to encourage this general kind of curiosity.
I assume you are not actually trying to save money or energy this way, since the savings if any would be minuscule, but are doing a calculation for fun. In that case a simple rule of thumb is likely to give you all the savings you want, such as closing the door whenever the time is indeterminate and/or longer than, say, 10 seconds in expectation.
Amusing exploration, regardless of whether it's impactful.
My main observation is that this is very dependent on both modeling and specifics of relative loss. Dependent to the point that I trust my un-modeled intuition (leave it open if likely to be under 20 seconds, or under 30 seconds to re-opening (say, when stowing groceries)).
I would upvote if you had some measurements to back the theory - temperature readings at 0, 10s, 20s, etc. at a few points in the fridge.
To your actual question, if you have no idea how long something will take, you are in an impossible situation - you ALWAYS have some distribution you can use, that's what "prior" means.
I'm almost sure the energy you'd save in your lifetime by doing it the optimal way would be less than the energy you spent to write this post...
(I don't have a useful thing to add but feel kinda delighted having this sort of question on LessWrong)
Say an open fridge door loses 1 Joule's worth of cool air every second. Opening or closing the door blows a lot of air so you lose 10J.
If I'm just pouring milk in my coffee I can usually do that in 5 seconds so I should keep the fridge open because 10+5+10 < 10+1+10 + 10+1+10 (if it takes 1 second to get milk).
If I am making a sandwich then I should definitely grab everything (12 seconds), close the door, make a sandwich (3 minutes), then put everything back because 10+12+10 + 10+12+10 < 10 + 180 + 10.
Say it takes g seconds to grab or return something and u seconds to grab it and use it and return it. Then we should close the fridge if u>2g+20.
What if I'm not sure how long something will take?
Suppose the time to pour my coffee is drawn from a nearly normal distribution with mean 8 seconds and s.d. 2 seconds. I'm better off on average leaving the door open. Even if it's already been 10 seconds, I expect to be done very soon. So I should always leave the door open.
(Scaled) geometric distribution: Half the time, when I would be done, another thing comes up (milk is sealed, spoon not in drawer) that takes another 4 seconds. I always expect to be done 8 seconds later, so I should still always keep the door open I think.
What if I have no idea how long something will take? The door is open and I'm waiting and waiting for the toddler to give back the iced mocha latte and it's sure been a while. Must I take some prior? Is there a mystery here or is this just standard bayesian stuff?