Skip to content

Comment automation with Private reply = Flow strands the flow on the post-anchored conversation; the user's reply lands on the DM conversation and is never processed #1063

Closed

Description

@rawdaymx

Summary

When an Instagram comment automation is configured with Private reply (inbox) = Flow, the flow's first message is delivered correctly, but the flow session is left waiting on the conversation anchored to the post (Conversation.sourceId = postId). The contact's reply arrives on the DM conversation (Conversation.sourceId IS NULL). The two never meet, so the flow never advances past its first step.

There are no errors in any queue and no sendError on any message — nothing fails, the reply is simply never picked up.

The same flow, triggered by a keyword in a DM instead, runs to completion. So the flow engine itself is fine; the problem is isolated to the comment-automation → flow handoff.

Reproduced twice on a clean contact, with two different flows — one starting with getUserData, one starting with sendText.

Environment

Deployment self-hosted, chatbotx-docker-compose
chatbotx-builder ghcr.io/chatbotxio/chatbotx-builder:latest, digest sha256:c2dcdf5d4493b719556858de8a9ae3933ed995c8fa129d4dc33ed5b165b94b50
chatbotx-worker ghcr.io/chatbotxio/chatbotx-worker:latest, digest sha256:e207740041cce8755931a613d771955f51c673ae4cf76d1ea5529db74675f6c2
Channel Instagram, Business Login
Meta app published (Live), webhooks delivering normally
Date of the run 2026-08-29

Steps to reproduce

  1. Create a flow that asks a question and stores the answer (a getUserData step), then applies a tag and disables the bot. Publish it.
  2. Create an Instagram comment automation on a post:
    • Public reply: any text
    • Private reply (inbox): Flow → the flow from step 1
  3. From a new contact, comment the trigger keyword on that post.
  4. The public reply and the flow's first message are both delivered — the DM arrives fine.
  5. Reply to that DM.

Expected: the flow advances, stores the answer, applies the tag, hands off.

Actual: nothing happens. The reply is stored as a message and never processed.

Evidence

Run on a freshly created contact (the previous contact was deleted beforehand), with a freshly imported and published flow using synthetic node/step ids so attribution is unambiguous, and the bot enabled on both conversations.

Traced by conversationId:

Conversation A   sourceId = <postId>
  23:05:52.038  "<keyword>"            incoming   <- the comment
  23:05:52.114  "<public reply text>"  outgoing   <- public reply
  23:05:52.198  "<flow first message>" outgoing   <- THE FLOW STARTS HERE

Conversation B   sourceId = NULL      (the DM)
  23:05:53.410  "<flow first message>" outgoing   <- copy recorded here
  23:06:02.095  "<user's reply>"       incoming   <- THE REPLY ARRIVES HERE

Final state:

Check Result
Conversation A currentStep = <first step id>, botEnabled = true — the flow is still waiting there
Conversation B currentStep empty
FlowNodeStat 1 row
ContactCustomField 0 rows — the answer was never stored
ContactToTag 0 rows — the tag was never applied
Message.sendError empty on every message
Queue errors none, in any queue

Control run, same flow engine, same day, same workspace, triggered by a keyword in a DM instead of a comment: 4 rows in FlowNodeStat, all three custom fields stored, tag applied, botEnabled = false. The flow completes end to end.

The only difference between the two runs is what starts the flow.

Second run: the same result with sendText as the first step

Because MESSAGE_PRODUCING_STEP_TYPES does not include getUserData, we repeated the whole thing with a second flow whose first step is a plain sendText, followed by the same getUserData steps, tag and handoff. Fresh contact again, fresh import, published, distinct synthetic ids.

Conversation A   sourceId = <postId>
  23:34:47.453  "<keyword>"             incoming   <- the comment
  23:34:47.520  "<public reply text>"   outgoing
  23:34:47.600  "<sendText message>"    outgoing   <- step 1 runs
  23:34:48.589  "<first question>"      outgoing   <- step 2 runs, then waits

Conversation B   sourceId = NULL
  23:34:48.981  "<sendText message>"    outgoing   <- copies recorded here
  23:34:50.078  "<first question>"      outgoing
  23:34:56.336  "<user's reply>"        incoming   <- THE REPLY ARRIVES HERE

Final state: Conversation A holds currentStep = <first getUserData step id>, FlowNodeStat has 2 rows (one per delivered message), ContactCustomField and ContactToTag are empty, no sendError, no queue errors.

This is informative in itself: the flow executes correctly through every step until it reaches the first one that waits for input, and then parks on conversation A. What never happens is the resume, because the reply is on conversation B.

So the first step's type is irrelevant — the split happens in the comment handler, before any step type is considered.

Where it comes from

All three snippets below are quoted from the shipped worker image named above (/app/apps/worker/dist/integration/worker.mjs), not from the repository.

1. The comment handler anchors the contact to the post:

sourceConversationId: commentData.postId,

2. The conversation is resolved from that value:

const conversationSourceId = incomingContact.sourceConversationId ?? null;

A comment yields the postId → conversation A. An incoming DM never populates that field → null → conversation B. Same lookup, two conversations for the same contact and inbox.

3. The helper that would resolve the DM conversation exists, and this path does not call it.

conversationService.findDMByContact is defined and documented as:

Read receipts always target the DM conversation (sourceId IS NULL). Only TikTok and Facebook comment conversations have a non-null sourceId.

Its only call site in the integration worker is inside contactMarkAsRead — read receipts. It is not used anywhere in the comment-automation → flow path.

Why we think this is a defect rather than the intended design

The post anchoring itself is clearly intentional, and the reason is sound: it lets the flow's first message go out through the comment-anchored Send API and its 7-day window instead of a normal DM gated by the 24-hour window. The commentAnchor machinery confirms that intent — MESSAGE_PRODUCING_STEP_TYPES in flow-utils.ts exists precisely to decide which step "claims" the pending anchor as its first outgoing message.

That is a delivery concern. The problem is that the flow's state is also left on that conversation, and the contact's replies can never reach it. The anchor should travel with the outgoing message while the flow session lives on the DM conversation.

Suggested fix

In the type === "flow" branch of the private-reply handler, resolve the DM conversation before enqueueing the flow instead of reusing the comment-anchored conversationId:

const dmConversation =
  (await conversationService.findDMByContact({ ... })) ??
  (await conversationService.findOrCreate({ ..., sourceId: null }));

…and enqueue sendFlow with conversationId: dmConversation.id. Leave commentAnchor untouched: it travels separately and only governs how the first message is delivered.

The fallback covers a contact whose first ever interaction is the comment — the same pattern detectContactAndConversation already uses.

Workaround for anyone hitting this

Use Private reply = Text message with a message inviting an explicit reply word, and a Keyword automation that starts the flow on that word. Two steps instead of one, and end users do not perceive it as a detour. Verified working end to end on the same deployment.

What we did not verify

  • We did not find any configuration option that controls which conversation a comment-triggered flow runs on. That is not found, not proven absent.
  • Line numbers are deliberately omitted: the snippets come from the compiled bundle in the published image, not from the source tree.

Related issues — neither describes this

Activity

  1. sung17 commented on Sep 8, 2026

    @sung17
    Collaborator

    Fixed in #1105 (merged as 1c60410) and now deployed to production. Thank you for this report — it was genuinely exceptional.

    You did the hard part for us. Tracing it by conversationId, running it twice with different first step types to rule out MESSAGE_PRODUCING_STEP_TYPES, running a keyword-in-DM control on the same flow and workspace the same day, and using a fresh contact with synthetic ids so attribution was unambiguous — that turned a "flow doesn't work" report into a located defect. Your root-cause analysis was correct, your suggested fix is essentially what shipped, and you were right to rule out #879 and #863. You even flagged what you had not verified, which is rarer than it should be.

    Your framing was the key insight: the post anchoring is intentional and stays, because delivery and state are separate concerns. That is exactly the shape of the fix. resolveDirectMessageConversationId now resolves the DM conversation before enqueueing the flow — findDMByContact, falling back to findOrCreate({ sourceId: null }) for a contact whose first interaction is the comment, just as you proposed — while commentAnchor rides the job untouched and still delivers the first message through the comment_id-anchored Send API and its 7-day window.

    Two things we found while confirming it, both worth knowing for your deployment:

    1. The duplicate copies in your trace should stop. Echo dedup is conversation-scoped (findBySourceId(sourceId, conversationId, …)), so an outgoing row on the post conversation could never dedup against its echo on the DM conversation — that is why each flow message appeared twice in your evidence. Both now land on the same conversation. Verified by reading the dedup path, not yet observed in production, so do tell us if you still see doubles.
    2. Human takeover now applies. The flow resumes off the DM conversation's botEnabled / botResumeAt, so an agent who has taken over that DM will stop the flow. That matches how a keyword-triggered flow in a DM already behaves, but it differs from the old path, where the freshly created post conversation was always bot-enabled.

    Your two-step workaround (text private reply + a Keyword automation) is no longer needed, though it will keep working if you would rather migrate at your own pace.

    The public-reply branch deliberately still runs on the post-anchored conversation — a public flow is answered on the post, and the contact's next comment resolves back to that same conversation. There is a regression test pinning that so the two branches don't get "unified" later, plus tests for the existing-DM, first-interaction, and lookup-failure paths, and the behaviour is now written up in docs/fb-comment-automation.md.

    Thanks again. Reports of this quality are rare, and this one saved us a lot of guessing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions