If I create a temporary directory on a worker using the Session API (think the file processing example but everything is going in a temporary directory), how can I guarantee deleting the temporary directory when the workflow succeeds/fails/gets cancelled?
I think in this case you want to run the whole session in a disconnected context and use some other mechanism to notify activities in the session that cancellation has happened.
The most straightforward way I know of is by creating a host specific taskqueue on each worker and then passing that to the context when you invoke the cleanup activity. There is a decent example in the Java version of the file processing code: