fix(automations): include nodeId in SEND_DM payloads and keep single execution + ordered dispatch for multi-node turns

Aperta
#49 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

backend bug good first issue workers
Problem Description

In apps/api/src/instagram/services/instagram-automation-runner.service.ts:

  1. Missing nodeId in SEND_DM job payloads:
    Neither resumeWaitingExecution (lines 486-498) nor triggerMatchingAutomations (lines 867-879) passes nodeId: actionNode.nodeId in backgroundJob.payload.
    As a result, processSendMessageJob (apps/workers/src/workers/message-worker.ts, lines 293 & 313) logs ExecutionStep.nodeId as the generic fallback 'ACTION_SEND_DM' instead of the actual canvas node ID, and falls back to currentExec.currentNodeId for downstream node checks.

  2. Duplicate / overwritten execution state & out-of-order risk when waitForReplyAfterSend === false:
    When DM 1 has waitForReplyAfterSend: false and chains into DM 2, resolveExecutableActionNodes returns [DM 1, DM 2] in the same turn:

    • triggerMatchingAutomations (lines 835-884) creates a separate AutomationExecution row for each node in the loop. Because DM 1 has nextNodeIds, message-worker.ts (line 315) sees hasNextNodes === true and leaves Execution #1 stuck in PENDING instead of COMPLETED.
    • resumeWaitingExecution (lines 467-475) overwrites currentNodeId on the same waitingExecution.id in a loop before the worker runs.
    • Both jobs are queued with runAfter = new Date() when delays are 0, so across multiple worker replicas DM 2 can be picked up before DM 1.

(Note: Normal single-node-per-reply flows with waitForReplyAfterSend: true are unaffected.)


Expected Behavior
  1. Every SEND_DM BackgroundJob payload includes nodeId: actionNode.nodeId so ExecutionStep records the exact node ID.
  2. Each automation trigger creates one AutomationExecution (not one per node in a non-waiting chain), and WAITING / COMPLETED state is driven cleanly by the final node in that turn (isTerminalStep).
  3. Sequential nodes queued in the same turn (waitForReplyAfterSend: false) preserve send order (DM 1 before DM 2) via cumulative runAfter timestamps.
  4. Single-node (waitForReplyAfterSend: true) and ACTION_AI_AGENT flows continue to behave identically with zero regressions.

Where to Look
  • apps/api/src/instagram/services/instagram-automation-runner.service.ts (resumeWaitingExecution L404-508, triggerMatchingAutomations L770-889)
  • apps/workers/src/workers/message-worker.ts (processSendMessageJob L288-334 — already reads job.data.nodeId and job.data.isTerminalStep)

Solution / Implementation Guide (Safe, Minimal Changes)
  1. Pass nodeId in both payloads:

    • Add nodeId: actionNode.nodeId to backgroundJob.payload in both resumeWaitingExecution and triggerMatchingAutomations.
  2. Keep one AutomationExecution per trigger & preserve DM 1 -> DM 2 order:

    • In triggerMatchingAutomations, create one AutomationExecution per trigger (instead of creating a new row on every iteration of actionNodesToExecute), updating currentNodeId and status (WAITING vs PENDING) based on the final node in the turn.
    • Pass isTerminalStep: isLastNodeInTurn && !shouldWait in backgroundJob.payload (which message-worker.ts lines 316-319 already support) so DM 1 doesn't prematurely complete a waiting execution and single-node turns behave identically.
    • Track a cumulative nextRunAfterMs across nodes queued in the same turn (e.g., Math.max(Date.now() + delaySec * 1000, prevRunAfterMs + 1000) for subsequent nodes) so DM 1 is always eligible before DM 2.
Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
6m
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sumamakhan761/tryinstance

Tutte le issue di sumamakhan761/tryinstance

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.