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

Abierto
#49 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
postgresql, typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
2
Forks
1
Merge medio
6 min
PR fusionados (30 d)
27

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sumamakhan761/tryinstance

Todos los issues de sumamakhan761/tryinstance

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.