Terminate workflow if cancelation failed

Hi,
I am getting errors with wf cancelation in case the code has breaking changes, for example, I refactored a function and the worker can’t pick up the workflow logic and cannot cancel it.
Shame on me, I am using `import passed through in the code.
I was thinking about a workaround to be like this:

async def cancel_workflow(handle):
    try:
        await handle.cancel()
    except Exception as e:
        print(f"Error cancelling workflow: {e}")
        await handle.terminate()

Also, I can add a health check if a wf was not cancelled in X seconds → terminate it.
What would be the best approach considering my situation?

This makes sense. Cancellation is a request to be processed by the workflow (can even be ignored) and therefore if the workflow cannot execute due to non-determinism error, then it cannot process cancellation. So this is where termination has value.

You may add this health check yourself, like you have there, but there is no general Temporal gracefully-cancel-or-terminate combined call.

Unless your workflow had special cancellation logic you need to invoke, termination is just fine