I turned on the hot water in my sink on Shabbos by mistake, may I turn it off or must it stay running the whole Shabbos?
It would depend on the type of water heater. One would have to determine how their specific water heater works.
There are two main types of heaters: tank heaters and tankless/instant-on heaters.
With a tank heater:
If your heater doesn’t refill unless the water level is below a certain point and you are certain that the water did not hit that point, you may close the hot water tap.
But if the heater refills as soon as any water leaves (usually this is the case), then when you close the tap you are causing the fire or electricity to turn off earlier (as it has to heat up less water). Even in this case, however, if the water was on only briefly or it was just dripping, it would not cause enough cold water to replace the water and cause the heater to go on, and you may straight away close the tap.
[The fact that the water in the tank is still Yad Soledes Bo would not make a difference because you are still causing the heater to turn off earlier. This is not like the ruling brought in the 39 Malachos book you quoted].
With a tankless heater:
When turning off the faucet you are directly causing the heater to go off and it would not make a difference how long it was on; the tap should not be closed.
#12534