Preserving original payload in a flow for later processing

I've got an issue and I'm wondering if there is a simple solution

My real flow makes a Pi speak to an Alexa echo so ends converting text to an mp3
For monitoring / debugging purposes I want to keep the original text bound in same message as the mp3.

I'm using flow context to remember original text and then re-add it back in later on after mp3 produced but I've realised that if another message comes in before the processing is finished - the wrong text is re-added to the message downstream

Here is a simple example of the situation forcing two messages in quick sucession - please assume the group wipes any properties other than msg.payload - if it didn't - then I wouldn't have this problem :slight_smile:

[{"id":"075cafcf3e03a909","type":"inject","z":"04a1000c0394426c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":100,"wires":[["306c1dcd9894fb34","87e28ae8d7e42d44"]]},{"id":"306c1dcd9894fb34","type":"change","z":"04a1000c0394426c","name":"payload =\"1\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":80,"wires":[["199a427ce735b3c3"]]},{"id":"87e28ae8d7e42d44","type":"change","z":"04a1000c0394426c","name":"payload = \"2\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":120,"wires":[["199a427ce735b3c3"]]},{"id":"c27301eff0ed2c7d","type":"debug","z":"04a1000c0394426c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":100,"wires":[]},{"id":"199a427ce735b3c3","type":"change","z":"04a1000c0394426c","name":"","rules":[{"t":"set","p":"originalPayload","pt":"flow","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":100,"wires":[["81097fec7cc38aa4"]]},{"id":"54c596ca1200e345","type":"change","z":"04a1000c0394426c","name":"","rules":[{"t":"set","p":"originalPayload","pt":"msg","to":"originalPayload","tot":"flow","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":100,"wires":[["c27301eff0ed2c7d"]]},{"id":"58a2fd211ccbf25a","type":"group","z":"04a1000c0394426c","name":"Dummy operation - assume that it only passes\\n msg.payload and takes a bit of time","style":{"label":true},"nodes":["81097fec7cc38aa4","cdafe5f730292e07"],"x":594,"y":43,"w":392,"h":98},{"id":"81097fec7cc38aa4","type":"delay","z":"04a1000c0394426c","g":"58a2fd211ccbf25a","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":680,"y":100,"wires":[["cdafe5f730292e07"]]},{"id":"cdafe5f730292e07","type":"change","z":"04a1000c0394426c","g":"58a2fd211ccbf25a","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"","fromt":"str","to":" changed ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":100,"wires":[["54c596ca1200e345"]]}]

There are 3 solutions off the top of my head...

  1. Alter the source code of the problem node to return the original msg
  2. Use a queue/FIFO and push a copy of the original msg then after the problem node, shift the queue to recover the original msg.
  3. Use a gate/queue/semaphore to only permit 1 msg at a time (preventing context being overwritten)

Whichever way you go, I'd raise an issue on the problem node to request that they don't discard the original msg, but instead, reuse it.

Which node is doing the naughty deed?

The delay node in rate limit mode can act as a queue using the flush:1 message to release the next message - but yes it would be useful to identify the node that is dropping things.

Its the TTS-Ultimate node-red-contrib-tts-ultimate (node) - Node-RED node which I'm using to do the text -> mp3 conversion

I didn't occur to me that it was a rogue node - that's why I asked the generic question :slight_smile:

Of course, since posting I've realised that the original text ends up inside the mp3 filename so all I have to do is parse the file name to remove the prefix and suffix to get the original text back so I'm actually sorted for my use case