Recommended way for running cleanup activity on workflow timeout

We have a workflow that uses session to run all activities on one worker, one of these activities creates a temp directory that needs to be cleaned up even if the workflow fails for any reason (and to communicate to the user that workflow fails)

We use WorkflowExecutionTimeout to set the max time duration for the workflow

The question is, what is the recommended way to run a cleanup activity (and report failure to the user) if workflow fails for ANY reason?

The recommended way is not to use terminate (which is like kill -9) and workflow timeout, which is the terminate on a timer.

For any business logic timeouts, use timers inside the workflow code.

Thanks for the info.
I assume that this termination is done on server, Does this also sends anything to the worker? (cancellation request or signal)

If so, is there some way to listen of this “termination” request? using interceptor for example

No. The whole idea of termination is that it is a hard kill that terminates a workflow without any chance of cleanup. If you need to perform cleanup, use workflow cancellation. Or if you need to perform cleanup after some time use timers inside the workflow code.