Process Instance Modification after compensation from within Engine

Dear all,

I’m currently implementing some behaviour revolving around compensation in the Camunda 7 engine for my master thesis. Currently, I’m trying to enable partial compensation with a re-execution after the partial compensation.

Say for example we have the following process:

Then we can place a savepoint (defined by me, not a Camunda savepoint) at, for example, Book Hotel. This will lead to the compensation triggered from the error event to only execute the Cancel Car task and then stopping the compensation. Then execution is continued with the outgoing flow of Book Hotel.

I was able to implement the partial rollbacking, by ignoring thrown compensation events if they are before the savepoint. But I’m unable to restart the execution. Here is where I could need some help.

As you can see in this commit, I tried to follow this guide for the process instance modification. Unfortunately, this always lead to problems with the executions/scope, throwing an (Index -1 out of bounds) error when creating an ActivityExecutionMapping (here). It seems like the scopes/executions are out of sync? I’m not sure.

Maybe somebody can point me in the right direction, how I could start a new task instance from within the CompensationEventHandler. I’d really appreciate it. My UnitTests can be found here.

Thanks in advance!

Hi @SandroSp

The problem I would assume lies in the fact, that the whole compensation will be performed inside one transaction.
So the execution of the compensation events is changing the state of the process and in the same transaction you’re trying to also perform a process instance modification.
I’m not sure if there’s some way to make this work like that.
What you could try, is to call some other service that executes your process instance modification in a new transaction.
When doing that, you then need to make sure, that you’re modification is only done when the compensation is fully executed.

Thanks for your response @rohwerj!

Do you have any resources to read up on the transactions? I’m aware of the wait states and the transactional boundaries that revolve around this but do not understand how this works for compensation.

Is there a specific call that is triggered for a transaction which I could read up on?

Currently, I found a work around that simply replaces the compensation task in the comensation handler for the savepoint with the savepoint task itself. This somehow only works for the savepoint task and not for the task referenced by its outgoing transitions, weird.

But there I’m facing a different error now, that the process instance is not completing when the re-execution has finished.
(So in the example above: Book Flight - Book Hotel - Book Car - Pay Booking - Error - Compensation Throw Event - Cancel Car - (here starts the reexecution) Book Car - Pay Booking)
Then the compensation throw event remains uncompleted, which could hint to the transaction problematic you mentioned. A workaround for this is to have the end event for the “happy-path” be a terminating end event, so that all other task instances are cancelled aswell. But I’m unsure of the effects of this regarding the transactions.

If you’re interested, feel free to check out this commit, and especially this line.

Thanks again!

As far as I know Camunda 7, I would imagine that there is one transaction opened once the error boundary event is thrown and in that one transaction all compensation is executed (as well as your event handler).
So either the whole compensation is committed as one or not at all.