fix(automations): fix ExecutionStep status mismatch, branch operator precedence, and 10k row cap in getAutomationAnalytics

Aperta
#50 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

Start with getAutomationAnalytics in apps/api/src/automations/automations.service.ts and compare its status checks with the writes in apps/workers/src/workers/comment-worker.ts and message-worker.ts. Inspect the Prisma models and existing aggregation patterns before replacing the capped queries with database aggregations. Done means both success statuses count, branch values resolve correctly, and analytics totals are no longer truncated by the row caps.

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

Descrizione

backend bug
Problem Description

In apps/api/src/automations/automations.service.ts (getAutomationAnalytics, lines 950-1014):

  1. Step successCount is always 0 ('SUCCESS' vs 'COMPLETED'):

    • Workers (apps/workers/src/workers/comment-worker.ts line 157 and apps/workers/src/workers/message-worker.ts line 294) write ExecutionStep.status = 'SUCCESS'.
    • getAutomationAnalytics (line 1006) checks if (step.status === 'COMPLETED'), so successful DM and comment-reply steps are never counted toward successCount.
  2. Operator precedence bug turns out.branch into 'undefined':

    • Line 1014 writes:
      const branchKey = out.branch || out.conditionResult !== undefined ? String(out.conditionResult) : null;
    • Because || binds tighter than !==, JavaScript evaluates (out.branch || out.conditionResult) !== undefined. Whenever out.branch is truthy and out.conditionResult is undefined, branchKey evaluates to the literal string 'undefined' instead of out.branch.
  3. Independent in-memory row caps skew totals at scale:

    • getAutomationAnalytics independently caps executions (take: 2000) and executionSteps (take: 10000) and aggregates in memory, causing totalTriggers and per-node step metrics to silently truncate and drift for high-volume automations.

Expected Behavior
  1. getAutomationAnalytics counts both 'SUCCESS' and 'COMPLETED' step statuses as successful.
  2. branchKey resolves out.branch when present, falling back to String(out.conditionResult) only when out.conditionResult !== undefined.
  3. Total trigger counts, execution status breakdowns, and per-node step counts are computed via database aggregations (count / groupBy) rather than loading up to 10,000 rows into Node memory.

Where to Look
  • apps/api/src/automations/automations.service.ts (getAutomationAnalytics, lines 950-1014)
  • apps/workers/src/workers/comment-worker.ts (line 157)
  • apps/workers/src/workers/message-worker.ts (line 294)

Solution / Implementation Guide
  1. Fix status check:
    • Count step.status === 'SUCCESS' || step.status === 'COMPLETED' (or standardize workers and analytics on the same status while keeping backward compatibility for existing 'SUCCESS' rows).
  2. Fix operator precedence on line 1014:
    • Update to:
      const branchKey = out.branch ? String(out.branch) : (out.conditionResult !== undefined ? String(out.conditionResult) : null);
  3. Use DB aggregations instead of take: 2000 / take: 10000 in-memory loops:
    • Use prisma.automationExecution.groupBy({ by: ['status'], ... }) and prisma.executionStep.groupBy({ by: ['nodeId', 'status'], ... }) for accurate totals, and only query output branch counts via targeted SQL aggregation.
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.