Comment and story automations have no per-account scope: with two Pages or two Instagram accounts connected, every automation is evaluated against both
Summary
A workspace can connect several accounts of the same channel type: Inbox is unique on (workspaceId, channel, sourceId), and #1107 made connecting several Pages or Instagram accounts in one flow a first-class feature. Comment automations and Instagram story automations carry no account at all. Neither CommentAutomation nor IgStoryAutomation has an inboxId (or any other account) column, and both findActiveAutomations select by workspaceId + isActive + type only. Every active automation of a channel type is therefore evaluated against every comment (or story reply) that arrives on any account of that type.
In practice:
- An automation whose post targeting is
all(the value the create form starts with,create-fb-comment-form.tsx:21) replies on every connected Page of that type, not only on the one the operator had in mind.matchPostreturnstruefor every post type other thanpostIds. - An automation that targets specific posts does end up scoped, because a post id belongs to one Page (the post picker already lists each Page's posts,
facebook-posts.ts). It is still evaluated against every other Page's comments, though, and each of those is recorded as apostNotMatchedmiss for it, so its miss analytics count comments from Pages it was never meant for. - Story automations have the same shape (
all/storyIds) and no account either, so anallstory automation answers story replies on every connected Instagram account.
The product already solved the equivalent problem for broadcasts: #1137 added per-page targeting through a BroadcastTarget table keyed by inboxId.
Environment
| Type | Static (code). Read from the source tree, not from a deployed instance |
| Commit | upstream/main @ 3a1aaeec1 (2026-09-25) |
| How measured | git grep / git show against that commit (commands below). No automation was run against a live workspace with two accounts |
How to see it
This is not a runtime repro: the gap is visible in the schema, the two services and their callers.
Inboxaccepts several accounts of the same channel in one workspace:$ git grep -n "Inbox_workspaceId_channel_sourceId_key" -- packages/database/src/schema/inbox.ts packages/database/src/schema/inbox.ts:40: uniqueIndex("Inbox_workspaceId_channel_sourceId_key").using(- Neither automation table has an account column:
Control: the same pattern over$ git grep -nE "inboxId" -- packages/database/src/schema/comment-automation.ts packages/database/src/schema/ig-story-automation.ts (no output)packages/database/src/schema/matches 19 files, includingbroadcast-target.ts:24. - Both services select by workspace + type only:
// packages/business/src/comment-automation/service.ts:335-346 findActiveAutomations(props: { workspaceId: string; channelType: CommentAutomationType }) { return db.query.commentAutomationModel.findMany({ where: { workspaceId: props.workspaceId, isActive: true, type: props.channelType }, }) }packages/business/src/ig-story-automation/service.ts:50-61has the same shape. - The callers already know the account and never pass it.
loadCommentAutomationContext(apps/worker/src/integration/handlers/comment-automation/index.ts:75-106) resolvesintegrationRowbefore callingfindActiveAutomationsat:92; the only use ofintegrationRow.inboxIdin the file is:188, for tag info.processStoryReplyAutomation(story-reply-automation/index.ts:145-162) loads thecontactInbox, which carriesinboxId, and then callsfindActiveAutomationswith workspace + channel only. - Consequence for post-targeted automations:
matchPostfails for another Page's comment atcomment-automation/index.ts:243,collectMiss(automation.id, "postNotMatched")runs at:251, andrecordMisseswrites it at:780.
Where it comes from
packages/business/src/comment-automation/service.ts:335-346andpackages/business/src/ig-story-automation/service.ts:50-61:where: { workspaceId, isActive, type }.packages/database/src/schema/comment-automation.ts:29-143andpackages/database/src/schema/ig-story-automation.ts:28-71: no account column or index.apps/builder/src/features/fb-comments/components/create-fb-comment-form.tsx:21: new automations start withpost: { type: "all" }.- The fb / ig comment forms and the ig story form have no account selector (no match for
inboxId|pageId|accountId), while 21 files underfeatures/broadcastsreferenceinboxId.
Why we think this is a defect rather than the intended design
The one code comment about this scoping is at comment-automation/index.ts:201-205, added in #1171:
findActiveAutomationsscopes by workspace + channel, not by post, so a single comment is shown to every active automation on the channel
It states the current behavior in order to justify batching the miss inserts. It reasons about posts, not accounts, and we read it as describing the behavior rather than deciding that one automation should span every account. Everything around it points the other way: the Inbox key includes sourceId, #1107 made multi-account connect first-class, and #1137 gave broadcasts per-page targeting. We found no test, doc line or comment saying an automation is meant to apply to all accounts. That is "not found", not "proven absent", so this section is a judgment call.
Suggested fix
No PR from us: how to model the scope is a data-model decision for you. Two options both look reasonable:
- A nullable
inboxIdonCommentAutomation/IgStoryAutomation, whereNULLkeeps today's "every account" behavior, so existing rows need no migration of meaning.findActiveAutomationswould take the caller'sinboxId(both call sites already have it) and filterinboxId IS NULL OR inboxId = :inboxId. The forms would get an account selector. - A join table in the style of
BroadcastTarget, for automations that should cover a subset of accounts. More general, with more migration surface.
Option 1 is the smaller change and keeps current behavior for every existing automation.
Workaround for anyone hitting this
Target specific posts instead of all: the post picker lists each Page's posts, and matchPost compares post ids, so the automation only fires on the Page those posts belong to. The cost is re-selecting posts as new ones are published, plus the postNotMatched misses described above. We established this by reading matchPost, not by running it against two live Pages. Alternatively, keep one account per channel type per workspace.
What we did not verify
- No live reproduction with two connected Pages or two Instagram accounts. The finding comes from the schema, the services and the callers cited above.
- Threads and TikTok go through the same
findActiveAutomations; we did not check whether those channels allow several accounts per workspace today. - The effect on miss analytics was read from the code, not observed in the analytics UI.
- A maintainer with more context may know of a decision we did not find in the tree.
Related issues (none of these describes it)
Searched issues and PRs (--state all) for IgStoryAutomation, findActiveAutomations, per-page automation, multiple pages, account scope: no issue describes this. The closest hits are #863 (closed; automations stored with the wrong type) and #1228 (flow-id validation), both unrelated to account scope. Control query CommentAutomation returns #1228 plus four PRs, so the search itself works.
Thanks a lot for this report, @rawdaymx. It was unusually thorough and easy to act on. The repro commands, file and line references, the "why we think this is a defect" section and the list of what you did not verify saved us a lot of time.
This is fixed in #1500, which went with your option 1:
CommentAutomationandIgStoryAutomationnow have a nullableinboxId.NULLkeeps the old behavior (every account of the channel), so existing automations didn't change.findActiveAutomationsnow requires the incoming account and matchesinboxId IS NULL OR inboxId = :inboxId.- Comments and story replies from another Page or Instagram account are no longer answered, and they no longer add
postNotMatchedmisses.
- The account is checked on every write.
- We read the integration tables to do this, because
Inbox.channelisinstagramfor both Instagram connection types. - The FK is
ON DELETE CASCADErather thanSET NULL, so a Page-scoped automation can never quietly widen to every Page.
- We read the integration tables to do this, because
- All five forms (Facebook, Instagram, Instagram stories, Threads, TikTok) have an account selector.
- When two or more accounts of the channel are connected, choosing one is required.
- Post and story pickers follow the selected account.
- Agents get the same capability through the public API:
commentAutomations.listAccountsinboxIdon create, update, get and list- an
inboxIdfilter on the post and story list endpoints
On your open questions: Threads and TikTok go through the same findActiveAutomations, so they are scoped the same way. The "process missed comments" replay now scans only the scoped account.
Thanks again!