What happens to an activity that hangs but gets retried?

Assume I have an activity with a heartbeat timeout and heartbeats implemented. Also assume that due to a bug, the activity hangs while performing some work.

Due to hanging, it doesn’t heartbeat, and temporal assumes it died and retries it.

If I understand correctly, the first activity won’t get forcefully terminated by temporal, it will stay hung while the second activity will begin processing. If the second activity hangs due to the same bug, the above repeats.

I’m debugging a situation like the above and now wondering, how do the hung activities ever get killed?

They are killed by restarting the process. Most languages do not provide a way to forcefully kill a thread in a safe manner.