Bug: Action flow SMS fails when smsBuilderId references a cross-company template
Objective
- Prevent Action Flow SMS actions from failing at send time due to a
_companyIdmismatch between anSmsBuilderdocument and theFlowActionthat references it. - Surface the misconfiguration at setup time (when an SMS action is saved or an Action Flow is copied) rather than at send time, so the failure doesn't silently block a live job.
Background
- Catherine Lemoine (SE/Residential) reported an Action Flow failure on inspection
1008602312(June 24, 2026). The error displayed in the activity feed was:Error: SMS template company mismatch for FlowAction 6a25e8cf2ee5be4f7c0a2693. - The failure has nothing to do with the inspection itself, the contact record, or the flow's conditions — all of those were valid. The action failed before any of that was evaluated.
- In
renderSmsFromTemplate, when aFlowAction.actionTemplatecontains asmsBuilderId, the system fetches the referencedSmsBuilderdocument and comparessaved._companyIdagainstsmsFlowAction._companyId. If they don't match, it returns a hard error and sends nothing. - The ownership check is correct in principle — cross-company template access shouldn't be permitted. The bug is that no validation occurs at configuration time, so an admin can save a
FlowActionpointing to anSmsBuilderfrom a different company without any warning or error. The problem only surfaces when the flow fires on a real job. - The most likely path to this state is the Action Flow copy system (
copyActionFlowToCompany.ts). That function collectssmsBuilderIdvalues from sourceFlowActiondocuments and attempts to copy each referencedSmsBuilderunder the target company, building a mapping. If the SMS copy step silently fails (missing source doc, mapping gap, etc.) and theFlowActionis still saved with the original sourcesmsBuilderId, the cross-company reference is baked into production data with no visible error.
Product Decisions
Locked
- Ownership check — The existing
_companyIdcomparison inrenderSmsFromTemplateis correct behavior and should be preserved. - Validation points — Fix should enforce same-company ownership at both save time (validate on
FlowActionwrite) and copy time (prevent aFlowActionfrom being saved if its SMS mapping is incomplete).
Open
- Failure mode in copy — If an SMS template can't be copied (source doc missing, etc.), should
copyActionFlowToCompanyabort the whole flow copy, skip that action, or save the action in a broken/draft state with a warning? Current behavior logs a warning but may proceed.
Scope
Backend (attik monorepo / attik-backend)
apps/backend/src/util/functions/actionFlows/renderSms.ts— Contains the_companyIdmismatch check. No change needed here; the guard is correct.apps/backend/src/util/functions/actionFlows/copyActionFlowToCompany.ts—copySmsBuilders()andcopyFlowActions()are the likely source of the broken state. WhensmsBuilderMappingdoesn't contain a source ID,copyFlowActionslogs a warning and proceeds without updatingsmsBuilderId, meaning the savedFlowActionretains the original cross-company ID.apps/backend/src/models/flowSchema.ts—FlowActionschema; consider whether a pre-save hook or route-level validation should enforce same-company ownership ofactionTemplate.smsBuilderId.apps/backend/src/models/smsBuilderSchema.ts—SmsBuilderschema; reference point for_companyIdfield structure.
Frontend (attik monorepo / attik-frontend)
apps/frontend/src/components/flowStatus/SmsSendModal.tsx— Surfaces SMS action state in the UI; may need to surface a degraded/broken state for actions with a cross-company template reference, similar to how broken service references are handled.
References
- FlowAction ID from Catherine's failure:
6a25e8cf2ee5be4f7c0a2693 - Inspection: https://www.attik.ai/inspections/1008602312
- Related — broken flows from removed services (same validation-gap pattern): ATT-1511
- Related — replicate SMS templates across instances: ATT-1496
Status: Canceled
Log in to comment and vote
No comments yet
Be the first to share your thoughts.