Action flow: job-wide tag conditions fail for company internal email (false successful, no Resend)

Objective

  • Ensure Action Flow email actions that use contact tag conditions (e.g. Tags Contains vip agent - dana) behave as ops expect: send when any contact on the work order has the tag, including when To is company internal (user-company).
  • Stop false-positive “successful” action status when no email was queued or sent to Resend.
  • Align job-wide condition semantics across trigger time and per-recipient send time so internal alerts are reliable.

Background

  • NHI reported an internal VIP agent notification that appeared triggered successfully on the work order but had no matching send in Resend. Example: inspection 1008592748.
  • The action is configured with a single condition: Tags Contains vip agent - dana, with intent “send if any contact on the job has this tag.” That mental model matches how tags are resolved when the full inspection is evaluated (all people on the job).
  • Current behavior: On email send, sendToRecipient in renderEmail.ts re-runs action conditions per To recipient with people: [toPerson]. For Send to company, toPerson is a synthetic company contact (companyFlagToFakeContact) with tags: []. The tags resolver in attributePathResolver.ts reads inspection.people only (not _conditionScopePeople), so the second pass sees no tags → condition fails → no queueRawEmail / no Resend.
  • The flow action worker can still record completed / UI successful because handleEventTriggerdByBull treats the action as sent when renderEmailFromTemplate returns no top-level error, even if every recipient returned “Contact filtered out by conditions” in resData.data and emailResults was never populated.
  • Related sibling bug: ATT-1485 — same subsystem (Action Flow condition evaluation at send time). ATT-1485 is contact-already-on-job / role replacement; this ticket is tags (and similar job-wide attributes) + company recipient. Fixes can share patterns (e.g. _conditionScopePeople) but are not duplicates and should not block each other.
  • Separate timing note: If the tagged agent was added after confirmed_job fired, the action would not re-run (people changes do not re-trigger that event). Confirm on example jobs whether failure was scope bug vs late contact add.

Scope

Backend

  • Condition evaluation: attik-backend/src/util/functions/actionFlows/attributePathResolver.tstags (and other job-wide contact attributes as needed) should respect _conditionScopePeople when set, consistent with contact-already-on-job.
  • Per-recipient send: attik-backend/src/util/functions/emailBuilder/renderEmail.tssendToRecipient already sets _conditionScopePeople: jobData.people; ensure job-wide attributes use it on the second pass.
  • Action execution: attik-backend/src/util/functions/actionFlows/handleEventTriggerdByBull.ts — do not return sent / completed when all recipients were filtered or nothing was queued.
  • Status API: attik-backend/src/routes/flowOnJob.tsnormalizedStatus: successful should require evidence of send (e.g. emailResults with resendId, or documented queued+completed path), not only FlowActionResult.status === completed.
  • Async email path: attik-backend/src/util/functions/emails/handleRawEmail.ts, attik-backend/src/events/bullmq/emailWorker.tsemailResults / resendId appended after Resend; gaps here explain empty Resend when UI looks green.
  • Tests: Extend tests/integration/email.rendering.test.ts and/or tests/unit/attributePathResolver.test.tscompany To + tags Contains on full job should queue/send; zero recipients should not report success.

Frontend

  • Flow status UI: attik-frontend/src/components/flowStatus/ActionStatusCard.tsx, FlowAccordion.tsx — surface per-recipient filter errors when emailResults is empty but resData.data has errors (e.g. “Contact filtered out by conditions”).
  • Builder guardrail (optional): attik-frontend/src/app/tools/action-flow/ — warn when To includes company and conditions reference tags / contact roles.

Out of scope (unless investigation proves otherwise)

  • Changing the meaning of Tags Contains (substring match on any single tag value is current behavior).
  • ATT-1485 role-replacement / contact-already-on-job logic (track on that ticket).

Investigation outcomes (draft acceptance)

  • [ ] Repro: action with Tags Contains + To: company; confirm first pass passes when any person has tag, second pass fails today; no Resend row.
  • [ ] Fix: with tag on any contact, company internal email queues and Resend receives the message.
  • [ ] Fix: action status not successful when all recipients filtered / no send.
  • [ ] Regression test(s) committed.
  • [ ] Verify example 1008592748 or cloned scenario.

References

Please authenticate to join the conversation.

Upvoters
Status

In Progress

Board
🏠

Main App

Date

13 days ago

Author

Linear

Subscribe to post

Get notified by email when there are changes.