Repository navigation
fix(worker): forward commentAnchor to getUserData prompts - #1282
Merged
Merged
Conversation
A flow started by a comment automation with Private reply = Flow never delivered a `getUserData` question. The step was excluded from the anchor path on two independent counts, and neither edit works without the other: 1. `MESSAGE_PRODUCING_STEP_TYPES` was defined as "whatever is mapped to `sendFlowMessage`", which silently excluded every step that sends from its own handler. `getUserData` was handed `commentAnchor: undefined`. 2. Its prompt was enqueued through `enqueueFlowStepMessage` without the anchor, and the field is optional on the job type so nothing flagged it. Two failures, both silent — the challenge row is written before the send and `sendFlowStep`'s catch swallows the channel error, so the step still returns `wait` and the contact's answer is still captured; only the question never arrives: - A question-first flow claimed nothing, so the one comment_id-anchored DM Meta grants per comment went unused and the prompt was rejected as an out-of-window DM. - A question after a `sendText` reached the channel with no anchor, so `isCommentPrivateRun` was false and `assertCommentPrivateReplyFollowUpDeliverable` never ran. Replaces the hand-written set with `STEP_PRODUCES_MESSAGE`, an exhaustive `Record<StepType, boolean>` — a new step type no longer compiles until it is classified. `true` means the step both receives and may claim the anchor, so a step that sends but cannot carry one stays `false`: `appointmentScheduling` and `questionnaires` send through `sendChatMessage`, whose job type has no `commentAnchor` field, and are pinned `false` until that plumbing exists. Also moves the claim to after the handler returns, skipping it on an `error` result. Claiming by step type up front burned the comment's single anchored DM on a step that sent nothing: a handler can fail before its send, and since `getUserData` declares only `[success, skip]` an error does not branch, so the run moved on to the next step with a spent anchor and the guard refused a private reply that was never sent. Fixes the heavy queue's `commentAnchor` zod sub-schema, which omitted `spent` and `automationId`. Zod strips unknown keys and the trailing `.transform(... as HeavyFlowContinuation)` hid the mismatch, so a claimed anchor came back un-spent and the next step re-claimed it, firing a second anchored DM that Meta rejects. Closes #1186 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
A flow started by a comment automation with Private reply = Flow never delivered a `getUserData` question. The step was excluded from the anchor path on two independent counts, and neither edit works without the other: 1. `MESSAGE_PRODUCING_STEP_TYPES` was defined as "whatever is mapped to `sendFlowMessage`", which silently excluded every step that sends from its own handler. `getUserData` was handed `commentAnchor: undefined`. 2. Its prompt was enqueued through `enqueueFlowStepMessage` without the anchor, and the field is optional on the job type so nothing flagged it. Two failures, both silent — the challenge row is written before the send and `sendFlowStep`'s catch swallows the channel error, so the step still returns `wait` and the contact's answer is still captured; only the question never arrives: - A question-first flow claimed nothing, so the one comment_id-anchored DM Meta grants per comment went unused and the prompt was rejected as an out-of-window DM. - A question after a `sendText` reached the channel with no anchor, so `isCommentPrivateRun` was false and `assertCommentPrivateReplyFollowUpDeliverable` never ran. Replaces the hand-written set with `STEP_PRODUCES_MESSAGE`, an exhaustive `Record<StepType, boolean>` — a new step type no longer compiles until it is classified. `true` means the step both receives and may claim the anchor, so a step that sends but cannot carry one stays `false`: `appointmentScheduling` and `questionnaires` send through `sendChatMessage`, whose job type has no `commentAnchor` field, and are pinned `false` until that plumbing exists. Also moves the claim to after the handler returns, skipping it on an `error` result. Claiming by step type up front burned the comment's single anchored DM on a step that sent nothing: a handler can fail before its send, and since `getUserData` declares only `[success, skip]` an error does not branch, so the run moved on to the next step with a spent anchor and the guard refused a private reply that was never sent. Fixes the heavy queue's `commentAnchor` zod sub-schema, which omitted `spent` and `automationId`. Zod strips unknown keys and the trailing `.transform(... as HeavyFlowContinuation)` hid the mismatch, so a claimed anchor came back un-spent and the next step re-claimed it, firing a second anchored DM that Meta rejects. Closes #1186 Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1186.
The bug
A flow started by a comment automation with Private reply = Flow never delivered a
getUserDataquestion. The step was excluded from the anchor path on two independent counts, and neither edit works without the other:MESSAGE_PRODUCING_STEP_TYPESwas defined as "whatever is mapped tosendFlowMessage", which silently excluded every step that sends from its own handler.getUserDatagotcommentAnchor: undefined.enqueueFlowStepMessagewith no anchor, and the field is optional on the job type so nothing flagged it.Both consequences fail silently — the challenge row is written before the send and
sendFlowStep's catch swallows the channel error, so the step still returnswaitand the contact's answer is still captured. Only the question never arrives.getUserDatafirstsendText→getUserDataisCommentPrivateRunwas false andassertCommentPrivateReplyFollowUpDeliverablenever ransendErrorCredit to @rawdaymx for the report: three runs of the same flow version on the same day with one variable (window open vs. closed), plus the observation that
ErrorLogheld zero rows matching%one private reply per comment%— exactly what you'd expect if the guard was never called.Beyond the reported bug
A public-reply flow was broken too. A
publicanchor is never consumed, so after the fix agetUserDataprompt posts as a comment reply — where the contact's next comment resolves back to the same conversation. Before, it went out as a plain DM on the comment-anchored conversation, which nothing can reach. Not mentioned in the issue; covered by a test here.The set is no longer hand-written.
STEP_PRODUCES_MESSAGEis an exhaustiveRecord<StepType, boolean>— a new step type does not compile until it is classified.truemeans the step both receives and may claim the anchor, so a step that sends but cannot carry one staysfalse.appointmentSchedulingandquestionnairessend from their own handlers throughsendChatMessage, whose job type has nocommentAnchorfield, and are pinnedfalsewith a test until that plumbing exists.The claim moved to after the handler runs, and is skipped on
error. Claiming by step type up front burned the comment's single anchored DM on a step that sent nothing: a handler can fail before its send, and sincegetUserDatadeclares only[success, skip]an error does not branch — so the run continued to the next step with a spent anchor and the guard refused a private reply that was never sent. This was a regression introduced while writing this fix, caught in review and pinned by a test.Heavy-queue zod fix (pre-existing).
heavyFlowContinuationSchema'scommentAnchoromittedspentandautomationId. Zod strips unknown keys and the trailing.transform(... as HeavyFlowContinuation)hid the mismatch, so a claimed anchor came back un-spent through an AI step and the next step re-claimed it — firing a second anchored DM that Meta rejects with "The comment is invalid for a private reply".Channel impact
The fix is in shared worker code, so no integration needed changing:
flowoption for private reply (blocked in the form and again in the worker); Threads has no DM API.sendFlowStephandler at all — the comment path is the only one it has.Known gaps (not closed here)
getUserData's date/datetime webview and WhatsApp location prompts still go throughsendChatMessage. Instagram never takes that path (URL_QUICK_REPLY_CAPABLE_CHANNELSexcludes it); Messenger is exposed. Closing it needs the field plus anchor handling in each Meta channel's outgoingsendMessage— a second feature, so it is left out deliberately. Same blocker asappointmentScheduling/questionnaires.runChallenge, the date-picker submit action) carries no anchor and has no field for one, so this fix covers the first prompt only. Pre-existing, unchanged.Verification
pnpm lintclean ·check-typesclean forworkerandworker-configresult.status !== "error"guard is removedinvariant-guardPASS🤖 Generated with Claude Code