fix(automations): include nodeId in SEND_DM payloads and keep single execution + ordered dispatch for multi-node turns
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript
- Domain
- backend, distributed-systems
Research direction
Read apps/api/src/instagram/services/instagram-automation-runner.service.ts alongside apps/workers/src/workers/message-worker.ts, focusing on resumeWaitingExecution, triggerMatchingAutomations, and processSendMessageJob. Trace how multi-node turns create execution rows and schedule jobs, then check the existing worker handling of nodeId and isTerminalStep. Done means one execution per trigger, correct node IDs, ordered sends, and unchanged single-node and AI agent flows.
Written by the indexing model from the issue text.
Description
Problem Description
In apps/api/src/instagram/services/instagram-automation-runner.service.ts:
-
Missing
nodeIdinSEND_DMjob payloads:
NeitherresumeWaitingExecution(lines 486-498) nortriggerMatchingAutomations(lines 867-879) passesnodeId: actionNode.nodeIdinbackgroundJob.payload.
As a result,processSendMessageJob(apps/workers/src/workers/message-worker.ts, lines 293 & 313) logsExecutionStep.nodeIdas the generic fallback'ACTION_SEND_DM'instead of the actual canvas node ID, and falls back tocurrentExec.currentNodeIdfor downstream node checks. -
Duplicate / overwritten execution state & out-of-order risk when
waitForReplyAfterSend === false:
WhenDM 1haswaitForReplyAfterSend: falseand chains intoDM 2,resolveExecutableActionNodesreturns[DM 1, DM 2]in the same turn:triggerMatchingAutomations(lines 835-884) creates a separateAutomationExecutionrow for each node in the loop. BecauseDM 1hasnextNodeIds,message-worker.ts(line 315) seeshasNextNodes === trueand leaves Execution #1 stuck inPENDINGinstead ofCOMPLETED.resumeWaitingExecution(lines 467-475) overwritescurrentNodeIdon the samewaitingExecution.idin a loop before the worker runs.- Both jobs are queued with
runAfter = new Date()when delays are0, so across multiple worker replicasDM 2can be picked up beforeDM 1.
(Note: Normal single-node-per-reply flows with waitForReplyAfterSend: true are unaffected.)
Expected Behavior
- Every
SEND_DMBackgroundJobpayload includesnodeId: actionNode.nodeIdsoExecutionSteprecords the exact node ID. - Each automation trigger creates one
AutomationExecution(not one per node in a non-waiting chain), andWAITING/COMPLETEDstate is driven cleanly by the final node in that turn (isTerminalStep). - Sequential nodes queued in the same turn (
waitForReplyAfterSend: false) preserve send order (DM 1beforeDM 2) via cumulativerunAftertimestamps. - Single-node (
waitForReplyAfterSend: true) andACTION_AI_AGENTflows continue to behave identically with zero regressions.
Where to Look
apps/api/src/instagram/services/instagram-automation-runner.service.ts(resumeWaitingExecutionL404-508,triggerMatchingAutomationsL770-889)apps/workers/src/workers/message-worker.ts(processSendMessageJobL288-334 — already readsjob.data.nodeIdandjob.data.isTerminalStep)
Solution / Implementation Guide (Safe, Minimal Changes)
-
Pass
nodeIdin both payloads:- Add
nodeId: actionNode.nodeIdtobackgroundJob.payloadin bothresumeWaitingExecutionandtriggerMatchingAutomations.
- Add
-
Keep one
AutomationExecutionper trigger & preserveDM 1 -> DM 2order:- In
triggerMatchingAutomations, create oneAutomationExecutionper trigger (instead of creating a new row on every iteration ofactionNodesToExecute), updatingcurrentNodeIdandstatus(WAITINGvsPENDING) based on the final node in the turn. - Pass
isTerminalStep: isLastNodeInTurn && !shouldWaitinbackgroundJob.payload(whichmessage-worker.tslines 316-319 already support) soDM 1doesn't prematurely complete a waiting execution and single-node turns behave identically. - Track a cumulative
nextRunAfterMsacross nodes queued in the same turn (e.g.,Math.max(Date.now() + delaySec * 1000, prevRunAfterMs + 1000)for subsequent nodes) soDM 1is always eligible beforeDM 2.
- In
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day