Bug: Action flow email and SMS still send after job is cancelled
Objective
- Stop action flow emails and SMS from sending on a cancelled inspection/job after cancellation, except where product explicitly configures
job_cancelledteardown communications. - Prevent customer confusion and duplicate outreach when a job is no longer active (reported sends on multiple dates after a May 8 cancellation).
Background
- When an inspection
statusbecomescancelled, the system is intended to halt routine lifecycle automations: removeAllScheduled(inspectionId)removes delayed BullMQ flow jobs matching*-inspection_{id}.flowEventTriggerer('job_cancelled', …)runs cancellation-specific flow actions only.queueFlowOnJobDisablesetsFlowOnJob.active = falseafter a 5 second delay sojob_cancelledactions can still query flows.- Reported behavior: job cancelled May 8, but action-flow email/SMS still fired May 9, 10, 11, 12, 16, 23, and 30 — consistent with time-based
reminders/follow_up(or other delayed actions) not being fully cancelled, not a same-day duplicate send. - At send time,
handleEventTriggerdByBull.tsblocks actions whenFlowOnJobis inactive exceptjob_cancelled, but does not check whether the inspection/quotestatus === 'cancelled'before rendering email or SMS. reminders/follow_upare skipped only when status isunconfirmed, notcancelled.payment_createdis triggered frominspectionStream.tson payment changes without a cancelled guard (unlikeservices_updated/job_rescheduled, which requireconfirmed).
Scope
Backend — cancel handling
- Cancel detection and cleanup live in
attik-backend/src/events/streamHandlers/inspectionStream.tswhenstatustransitions tocancelled. attik-backend/src/util/functions/actionFlows/removeAllScheduled.ts— Redis SCAN + remove delayed jobs by pattern; decision needed whether all job id formats are covered (flow_*andscheduled-flow_*prefixes fromflowEventTriggerer.tsandhandleScheduledFlowEvent.ts).attik-backend/src/events/bullmq/flowOnJobDisableWorker.ts—JOB_DELAY_MS = 5000beforeFlowOnJob.activeis false; race window for non–job_cancelledsends.
Backend — send gate
attik-backend/src/util/functions/actionFlows/handleEventTriggerdByBull.ts— final gate beforerenderEmailFromTemplate/renderSmsFromTemplate; add cancelled-job filtering (decision needed: allowlist onlyjob_cancelledvs allactionTypevalues).attik-backend/src/util/functions/actionFlows/flowEventTriggerer.ts— queues delayed actions; should not enqueue routine lifecycle actions for cancelled jobs.attik-backend/src/routes/inspection.ts—POST /:id/cancelsetsstatus,canceledBy,canceledAt(canonical cancel path).
Backend — triggers to audit
inspectionStream.ts—payment_createdonhasPaymentsChangewithout status check.chargeUpdateResolveAndTrigger.ts— skips non-confirmedinspections for charge events; confirm cancelled is excluded.handleFlowStart.ts/handleScheduledFlowEvent.ts— time-based scheduling relative to inspectiondatetime; ensure cancel cleanup removesscheduled-flow_*jobs and nothing reschedules them while cancelled.handleRescheduleTimeUpdates.ts— reschedules time-based jobs on datetime change; decision needed whether this can run on cancelled inspections.
Out of scope
- Activity feed vs Booking Details cancel display (separate concern).
- Whether
job_cancelledflows should send email/SMS (product configuration; only non-teardown sends are in scope).
References
attik-backend/src/util/functions/actionFlows/ACTIVITY_SYSTEM_README.md(related systems; action flow worker inattik-backend/src/events/bullmq/flowWorker.ts)attik-frontend/src/app/tools/action-flow/[flow_id]/data/eventCategories.ts(job_cancelled,follow_up,reminders,payment_createdevent ids)
Status: Planned
Log in to comment and vote
No comments yet
Be the first to share your thoughts.