# Inconsistent context of the JOB\_EXECUTION\_FAILURE event with and without asyncComplete flag

**URL:** <https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170>\
**Category:** Flowable Engine\
**Created:** [April 5, 2022, 4:45pm UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170 "2022-04-05T16:45:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [April 5, 2022, 4:45pm UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/1 "2022-04-05T16:45:14Z")

</div>

Dear Flowable experts,

The Flowable Engine dispatches a `JOB_EXECUTION_FAILURE` event when an exception is thrown during the `EndExecutionOperation` of a process instance. The failing job is converted into a `DeadLetterJob`.

In our environment, a `CallActivity` is used to trigger (one or multiple) SubProcess instance(s). In addition to that, there is an event listener which handles failing subprocess instances.

We’ve discovered that the context of the `JOB_EXECUTION_FAILURE` event is set differently depending on the `asyncComplete` flag of the `CallActivity`:

- In case of `asyncComplete=false`, the `JOB_EXECUTION_FAILURE` event is triggered in the context of the subprocess execution, the DeadLetterJob belongs to the subprocess execution.
- In case of `asyncComplete=true`, the `JOB_EXECUTION_FAILURE` event is triggered in the context of the super process execution, the DeadLetterJob belongs to the super process execution.

Is it an intended behavior? If yes, why?

From our perspective, the `JOB_EXECUTION_FAILURE` event should always be dispatched in the context of the execution which caused the exception.  
Currently, this is the case for `CallActivity` triggered with `asyncComplete=false`, but not for `asyncComplete=true`.  
[The following PR](https://github.com/flowable/flowable-engine/pull/3264) adjusts the behaviour accordingly.

Thank you!

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [April 20, 2022, 9:13am UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/2 "2022-04-20T09:13:31Z")

</div>

Any opinion would be highly appreciated here 🙂

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [April 20, 2022, 7:21pm UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/3 "2022-04-20T19:21:16Z")

</div>

> [@VasilTsimashchuk](#):
>
> The Flowable Engine dispatches a `JOB_EXECUTION_FAILURE` event when an exception is thrown during the `EndExecutionOperation` of a process instance. The failing job is converted into a `DeadLetterJob` .

Just be precise: this only happens when executing the last part of the instance asynchronously, right?

> [@VasilTsimashchuk](#):
>
> Is it an intended behavior? If yes, why?

Looking at the javadoc in the AsyncCompleteCallActivityJobHandler, it does look like that. If that jobs fails, it should be retried in the context of the parent execution as that’s the job failing.

However, in this use case there are multiple jobs at play:

- the job for the async call activity
- the job for completing asynchronously a multi-instance

A unit test would clarify things here, to make sure we’re talking about the same thing.

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [April 28, 2022, 9:01am UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/4 "2022-04-28T09:01:38Z")

</div>

Hi @joram,  
Thank you for your reply!

> [@joram](#):
>
> Just be precise: this only happens when executing the last part of the instance asynchronously, right?

In our environment, all the flow elements are with the flag `async=true`. And all the observations we’ve made relate to this configuration.

> [@joram](#):
>
> If that jobs fails, it should be retried in the context of the parent execution as that’s the job failing.

With the change proposed, the retry will still be correct, as the corresponding job [gets created](https://github.com/flowable/flowable-engine/pull/3264/files#diff-f9127f0936a2ba1034b2b955e9da5de8e4e4f52f0c6a25f23530584a9e6f87faR738-R745) accordingly from the dead-letter job.

> [@joram](#):
>
> A unit test would clarify things here, to make sure we’re talking about the same thing.

We would be ready to introduce a unit test, but some inspiration on its design would be highly appreciated. Could you please briefly describe the scope of the expected test and/or give a link to an example in the code which we could use as a starting point?  
Thank you very much in advance!

Best,  
Vasil

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [May 16, 2022, 3:18pm UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/5 "2022-05-16T15:18:40Z")

</div>

Sorry for not responding sooner - was a very busy few last weeks …

> [@VasilTsimashchuk](#):
>
> With the change proposed, the retry will still be correct, as the corresponding job [gets created](https://github.com/flowable/flowable-engine/pull/3264/files#diff-f9127f0936a2ba1034b2b955e9da5de8e4e4f52f0c6a25f23530584a9e6f87faR738-R745) accordingly from the dead-letter job.

The retry will still be correct, but I don’t think we’re talking about the same thing yet.  
When using asyncComplete=true, the engine is instructed to create an **additional** job when all multi instances of the call activity are finished. When using asyncComplete=false, this job is not created.

If I look at the PR, it changes the process instance / execution id of that particular job and **not of the actual jobs that execute the call activity**. That’s a fundamental difference: the completion happens in the context of the calling process instance and thus that should be the reference imho.

Unless I’m mistaken here and you’re talking about a difference in behavior for the ‘regular’ async jobs (the ones doing the call activity)? But looking at the PR, I don’t think so.

> [@VasilTsimashchuk](#):
>
> We would be ready to introduce a unit test, but some inspiration on its design would be highly appreciated. Could you please briefly describe the scope of the expected test and/or give a link to an example in the code which we could use as a starting point?

A unit test with a multi-instance call activity with once asyncComplete=true and once with false, showing the differences.That would be required to accept this PR anyway :-). I’m still struggling to see the use case here, so an example of the current (assumed) wrong behavior would clarify a lot here, I think.

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [May 20, 2022, 1:12pm UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/6 "2022-05-20T13:12:04Z")

</div>

Thanks @joram! We’ll introduce the test - this should clarify the concerns.

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [July 8, 2022, 12:50pm UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/7 "2022-07-08T12:50:47Z")

</div>

Hi @joram,

Wanted to give you a short update here.  
Sorry for the delay! We are still on the topic - needed all the capacity for some urgent initiatives. We now have a “go” from the PO side. Please expect the test to be added to the PR within the next 2 weeks.

Best,  
Vasil

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [October 13, 2022, 11:33am UTC](https://forum.flowable.org/t/inconsistent-context-of-the-job-execution-failure-event-with-and-without-asynccomplete-flag/9170/8 "2022-10-13T11:33:51Z")

</div>

Hi @joram,

sorry for the delay! We have updated [the PR](https://github.com/flowable/flowable-engine/pull/3264) with the relevant tests. Could you please have a look whenever you have a minute?  
Thank you very much in advance!

Best,  
Vasil
