# Subprocess elements limit

**URL:** <https://forum.camunda.io/t/subprocess-elements-limit/54099>\
**Category:** Discussion & Questions\
**Tags:** process-engine, bpmn\
**Created:** [August 7, 2024, 6:27am UTC](https://forum.camunda.io/t/subprocess-elements-limit/54099 "2024-08-07T06:27:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaansrivastava](https://forum.camunda.io/user_avatar/forum.camunda.io/shaansrivastava/32/27271_2.png) [@shaansrivastava](https://forum.camunda.io/u/shaansrivastava)\
**Post date:** [August 7, 2024, 6:27am UTC](https://forum.camunda.io/t/subprocess-elements-limit/54099/1 "2024-08-07T06:27:49Z")

</div>

Hi, is there any limit on number of elements in any subprocess?  
We create agi-call flow using bpmn-modeller, we can introduce several custom components in the flow such as: User input, Voice, Record Voice etc.  
We can also create a subprocess which can include our custom components.

Now, for AGI calling we have used asterisk, and bpmn-engine to load the flow while agi calling.

My doubts are regarding modeller and engine:

- Whenever we create any new subprocess and expand it, it creates a start event by default, but does not adds end event (`bpmn:IntermediateThrowEvent`), why is it so?
- What exactly is the role of '`bpmn:IntermediateThrowEvent`, does it throw any event or is it a simple end event?

We are using following process to create an instance of engine and implement onStart and onWait, which is executed at start of an AGI call:

```auto
bpmnEngine = Engine({
      name: 'Call Listener', extensions: {
        bpmnSaveServiceResultToVar, bpmnActivityHandler
      }
    });

    const sourceContext = await getSourceContext(session, xmlData);
    bpmnEngine.addSource({ sourceContext });
    console.log("Loading BPMN flow");
    activityListener.on("wait", BpmnActivityHandler.onWait);

    bpmnEngine.on(EVENT_TYPES.BPMN.END, () => {
      console.log("AGI call ended");
    });

    await bpmnEngine.execute({
      listener: activityListener,
      // activity variables
      variables: {
        var1: var1,
        var2: var2
      },
      services: { ...listOfServices }
    });

```

and function **bpmnActivityHandler** :

```auto
return {
    activate() {
      bpmnActivity.on("enter", async (elementApi, engineApi) => {
        bpmnActivity.broker.publish('format', 'run.format.start', { endRoutingKey: 'run.format.complete' });
        try {
          const response = await BpmnActivityHandler.onStart(elementApi, engineApi);
          // response (true: continue the call, false: ended the call)
          // returning only in case of false response to exit the activate block.
          if (!response) {
            // exiting the activate block
            return false;
          }
        } catch (err) {
          console.error("Error:",err);
          return CallService.endCall();
        }
        bpmnActivity.broker.publish('format', 'run.format.complete', { msg: "testmm" });
      }, { consumerTag: 'format-on-enter' });
    },
    deactivate() {
      bpmnActivity.broker.cancel('format-on-enter');
    },
  };
}

```

Now the issue I am facing is that I am using **multiple custom components** (around 40-50 components) inside a single **subprocess** , but after a point it does not ends the subprocess, i.e. **the AGI call continues and gets stuck at the end** , it should have moved to next subprocess, but it gets stuck. There is no issue in custom component, it is due to bpmn-engine, because when I remove a part of subprocess, it works fine, but I don’t want to do so.  
Can someone please help me with these doubts?

---

<div class="post-metadata">

**Author:** ![DatyEighty](https://forum.camunda.io/user_avatar/forum.camunda.io/datyeighty/32/24850_2.png) [@DatyEighty](https://forum.camunda.io/u/DatyEighty)\
**Post date:** [August 7, 2024, 7:44am UTC](https://forum.camunda.io/t/subprocess-elements-limit/54099/2 "2024-08-07T07:44:18Z")

</div>

This issue is about [bpmn-engine](https://github.com/paed01/bpmn-engine) and has been discussed [there](https://github.com/paed01/bpmn-engine/issues/188) and on the [bpmnio forum](https://forum.bpmn.io/t/subprocess-elements-limit/11173) as well.

There is no limit of elements within a subprocess. Maybe there’s an issue within your process model. Can you share the model? What part did you remove to make it work?
