What happens to the soul during heart surgery?
The soul resides within a body for a fixed duration, by the arrangement of superior powers. As Krishna explains in the Bhagavad-gita, the soul can't be cut, burned, dried, moistened, or otherwise affected by any material condition. Only when one's allotted lifespan comes to an end does the soul leave the body.
Heart surgery is just another material condition that doesn't affect the soul or its situation within the body. The soul is situated within the region of the heart, but that doesn't mean that it's situated there like blood is. It's not that during a heart transplant the soul is replaced by another soul in a different heart.
The soul is so small that it can't be seen. By Vedic calculation, it's about a quarter of an Angstrom unit in size. Angstrom units are one hundred-millionth of a centimeter. So, during even the most complicated of heart surgeries, the soul can't even be touched. If destiny and karma decree that the soul remains in the body, it will, despite all apparent disturbance. And if the soul is meant to leave the body, it will do so regardless of even the most expertly performed medical procedures.