# Deploying the state machine node does not change its status

**URL:** https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196
**Category:** General
**Created:** [24 February 2020 14:23 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196 "2020-02-24T14:23:20Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 14:23 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/1 "2020-02-24T14:23:20Z")

</div>

I was under impression that by adding a node to a flow, or moving a node, and deploying the flow through **Deploy-Modified Flows** the flows containing nodes marked with blue circle should restart.

It does not seem to be always the case.

* * *

Import the following flow:

```auto
[{"id":"a1b23951.ce6a58","type":"tab","label":"State machine example","disabled":false,"info":""},{"id":"721c9d74.48aec4","type":"state-machine","z":"a1b23951.ce6a58","name":"","triggerProperty":"topic","triggerPropertyType":"msg","stateProperty":"topic","statePropertyType":"msg","outputStateChangeOnly":false,"throwException":false,"states":["initial","updated"],"transitions":[{"name":"update","from":"*","to":"updated"}],"x":300,"y":100,"wires":[["e8c4a0eb.cc77d"]]},{"id":"2806cff8.27fd6","type":"inject","z":"a1b23951.ce6a58","name":"","topic":"update","payload":"updated payload","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":40,"wires":[["721c9d74.48aec4"]]},{"id":"cafda122.04bfa","type":"debug","z":"a1b23951.ce6a58","name":"payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":820,"y":220,"wires":[]},{"id":"57e3d16a.d9ba1","type":"change","z":"a1b23951.ce6a58","name":"payload → \"initial payload\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"initial payload","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":120,"wires":[["cafda122.04bfa"]]},{"id":"e8c4a0eb.cc77d","type":"switch","z":"a1b23951.ce6a58","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"initial","vt":"str"},{"t":"eq","v":"updated","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":160,"wires":[["57e3d16a.d9ba1"],["cafda122.04bfa"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43a3c3f6c381d56df791039c63441ee5c8fc70bd.png)

Deploy it:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b0fca3325e37e200431cddd359e19add90f92b3.png)

Inject the message to update `state machine` state:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a2684d1a027f88efc617441aef7d8e8918f39f4.png)

Modify the flow without modifying the node (e.g., move the node, or add a new node not connected to the rest):

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94b33147090aeec4be3344b366d325bf45715458.png)

Deploy using **Modified flows** or **Modified nodes** option:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/937110c2d6e9ed09df3ca60482234a50bc743b45.png)

Result: the `state machine` remains in the `updated` state and announces it instead of starting in `initial` state.

As a bonus, in the above example, I get a message with _undefined_ payload.

**If** I did the same using used **Deploy-Full** instead, the `state machine` would reset to `initial` state and send the message with `Initial payload`.

* * *

So, either of the following causes the `state machine` node to reset back to the initial state:

- **Deploy-Full**
- **Deploy-Restart Flows**
- modifying the actual flow (connected to the `state machine`), other than moving the nodes (e.g., changing a name, deleting and recreating a connection) and deploying with any option (full, modified flows, or modified nodes)

but not:

- **Deploy-Modified Flows**
- **Deploy-Modified Nodes**

* * *

I'm not sure if it's a problem with the `state machine` node, or a general one, but it looks buglike to me.

Whether I tamper with the `state machine` node by moving it, or renaming it, I get the same blue circle indication in the editor, yet the results of **Deploy** options differ.

What do you think?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [24 February 2020 15:19 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/2 "2020-02-24T15:19:21Z")

</div>

Just moving a node does not count as it being 'modified' for the purposes of deciding what gets restarted. Only a material change to the nodes configuration will get counted.

---

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 15:28 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/3 "2020-02-24T15:28:01Z")

</div>

> [@knolleary](#):
>
> Just moving a node does not count as it being 'modified' for the purposes of deciding what gets restarted. Only a material change to the nodes configuration will get counted.

Fine.

Then:

1. When a node is moved:

2. When an unrelated node is added to a flow:

It's inconsistent, imho.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [24 February 2020 15:32 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/4 "2020-02-24T15:32:05Z")

</div>

> [@techraf](#):
>
> When a node is moved:
> 
> - Why does the **Deploy** button activate? Pressing it does nothing according to the above.
> - Why do we need the blue circle on the moved node?

Because you want to save the change.

This was done based on user feedback. Users wanted to be able to 'tidy up' their flows by repositioning the nodes and be able to save the change, without disrupting the running nodes.

> [@techraf](#):
>
> When an unrelated node is added to a flow:
> 
> - Why does the description for the **Deploy-Modified Flows** say " _only deploys flows that contain changed nodes_ "? When in fact it does not "deploy flows that contain changed nodes", but acts the same as the **Deploy-Modified Nodes**

In this context, 'flow' means a collection of nodes that are wired together. It doesn't mean the tab in the editor.

---

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 15:42 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/5 "2020-02-24T15:42:01Z")

</div>

> [@knolleary](#):
>
> Because you want to save the change.

Fine.

It wouldn't hurt if a "material change," as you called it, caused the circle to be e.g., yellow, and other changes - blue.

> [@knolleary](#):
>
> In this context, 'flow' means a collection of nodes that are wired together. It doesn't mean the tab in the editor.

See? I just told you it's inconsistent. 🙂

---

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 15:49 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/6 "2020-02-24T15:49:59Z")

</div>

> [@knolleary](#):
>
> Just moving a node does not count as it being 'modified' for the purposes of deciding what gets restarted. Only a material change to the nodes configuration will get counted.

Errrr, but after second thought, not really "fine."

The screenshots, which I posted in my initial message, show that by moving the `state machine` and pressing **Deploy-Modified Flows** , the node injects a new message (with its current state).

It should not, if "_moving a node does not count as it being 'modified' for the purposes of deciding what gets restarted_."

So just by moving the node and deploying changed flows, which you said was just to save a layout, I actually did somewhat (re)start it.

Quoting the `state machine` docs:

> At start up, the node will emit a message with the initial state if the `state output` property is set to a `msg` property.

It emitted a message with the state, but not entered the initial state.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 February 2020 16:12 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/7 "2020-02-24T16:12:31Z")

</div>

you may need to check with the author of that node.

---

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 16:26 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/8 "2020-02-24T16:26:14Z")

</div>

> [@dceejay](#):
>
> you may need to check with the author of that node.

Maybe. So far I'm trying to figure out what is happening there.

If as @knolleary suggested, Node-RED does nothing but saving a layout, unless there was a material change in a node, then how does this `state machine` node emit a message?

The node doesn't capture editor's UI button actions and act on its own, does it?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 February 2020 16:50 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/9 "2020-02-24T16:50:13Z")

</div>

So yes - looking at the code - [https://github.com/DeanCording/node-red-contrib-state-machine/blob/master/state-machine.js#L98](https://github.com/DeanCording/node-red-contrib-state-machine/blob/master/state-machine.js#L98)  
For some reason he is hooking to the overall start message

```auto
RED.events.on("nodes-started", node.startup);

```

So fires his start message on every deploy... not just flow or node specific ones...

---

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 18:47 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/10 "2020-02-24T18:47:31Z")

</div>

Okay.

Please bear with me, I'm using Node-RED for less than a week.

So this is a runtime event as described [here](https://nodered.org/docs/api/modules/v/1.0/@node-red_runtime_events.html), right?

Where can I see the types of events?

* * *

And when **Debug-Modified Flows** is pressed - what event does it produce?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 February 2020 19:06 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/11 "2020-02-24T19:06:00Z")

</div>

As the line of code suggests it emits a "nodes-started" event.  
If a node listens for that general message it is up to the node to handle it appropriately.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 February 2020 19:26 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/12 "2020-02-24T19:26:22Z")

</div>

> [@dceejay](#):
>
> For some reason he is hooking to the overall start message

My understanding (but please check with the author) is that the message being sent is the one the state machine would send when entering the initial state. From the README:

> The node will always start in the first state on the state list and will emit a message with the initial state if the state output is set to a message property.

This behavior makes sense for a state machine that is programmed to perform an entry action (in this case, sending a message) when it makes a transition into a new state. Treating a startup as an entry into the initial state allows any downstream nodes to know the state of the machine and is consistent with the subsequent behavior of the machine.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 February 2020 19:34 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/13 "2020-02-24T19:34:12Z")

</div>

> [@dceejay](#):
>
> As the line of code suggests it emits a "nodes-started" event.  
> If a node listens for that general message it is up to the node to handle it appropriately.

Does this event mean that the entire flow has been deployed and is ready? Could I use it in a contributed node to hold off displaying the initial status of the node until any `status` nodes in the flow are ready to catch that status? ([See the discussion in this thread.](https://discourse.nodered.org/t/getting-the-initial-status-of-nodes/22162))

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 February 2020 19:38 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/14 "2020-02-24T19:38:24Z")

</div>

no - it means all nodes have been asked to start. It doesn't mean they have started - nodes that do async initialisation (like making connections) may take a long time to start (or indeed never complete).

---

<div class="post-metadata">

### Author: ![techraf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techraf/32/17389_2.png) [@techraf](https://discourse.nodered.org/u/techraf)
#### Post date: [24 February 2020 19:39 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/15 "2020-02-24T19:39:28Z")

</div>

> [@dceejay](#):
>
> As the line of code suggests it emits a "nodes-started" event.

Yes. And I can't find anything about `nodes-started` on [nodered.org](http://nodered.org) except for [five messages on the Discourse](https://www.google.com/search?q=%22nodes-started%22+site%3Anodered.org&oq=%22nodes-started%22+site%3Anodered.org). Hence my question.

I assume it is a Node-RED's message -- where can I find anything about it? And about other events that are emitted?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 February 2020 19:45 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/16 "2020-02-24T19:45:44Z")

</div>

It's part of an internal API so not documented. It is not expected for nodes to use this directly.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 February 2020 19:46 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/17 "2020-02-24T19:46:00Z")

</div>

> [@dceejay](#):
>
> no - it means all nodes have been asked to start.

Thanks. You've answered my first question, but about the second: if the `status` nodes start up synchronously, could listening for "nodes-started" still help?.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 February 2020 19:47 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/18 "2020-02-24T19:47:09Z")

</div>

> [@dceejay](#):
>
> It is not expected for nodes to use this directly

OK, I withdraw my annoying questions...

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [24 April 2020 19:47 UTC](https://discourse.nodered.org/t/deploying-the-state-machine-node-does-not-change-its-status/22196/19 "2020-04-24T19:47:15Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
