1st button press doesn’t trigger Stream Deck action

I’ve set up a series of Stream Deck buttons. Each has a “Run Real JavaScript” action that calls a locally running API. Each button follows the template for a self-executing async function described in the BTT documentation. For example,

(async () => {

// put the shell script into a string (single backticks are great for multiline strings)
let shellScript = `export PATH=$PATH:/opt/homebrew/bin/ ; curl -X GET "http://127.0.0.1:5555/score" -H  "accept: */*"  | jq '.[0]'`;

let shellScriptWrapper = {
    script: shellScript, // mandatory
    launchPath: '/bin/bash', //optional - default is /bin/bash
    parameters: '-c', // optional - default is -c. If you use multiple parameters please separate them by ;; e.g. -c;;date
    environmentVariables: '' //optional e.g. VAR1=/test/;VAR2=/test2/;
};

let result = await runShellScript(shellScriptWrapper);
await callBTT('set_string_variable', {variable_name: 'score', to: result});
returnToBTT(result);
})();

To test it’s working, I examine the output from the API in a “Show HUD Overlay” action that uses {BTTLastTerminalCommandResult}.

The problem is this: The first time I press a button, the HUD shows the output of the previous button push. But any time I press that same button again the results are what I expect.

Can anyone theorize why this is happening? Appreciate all thought.

— Robert