Repository navigation
fix(tiktok): re-check comments whose commenter lookup came back empty - #1785
Merged
Merged
Conversation
TikTok's comment lookup can miss a comment on a photo post for a moment right after its webhook, and the automation was then withheld for good (#1715). - Store the withheld comment in Redis and re-run the incomingComment job after 5 s, 30 s and 2 min until the author is known. - Send `set_to_public` on as a re-check; it acts only on a withheld comment and runs on the comment as first delivered. - Remember the account's own unique_identifier once a lookup answers `owner: true`, so a later miss can still tell the account's own comments apart. - Log the reason and clock skew when a webhook signature is rejected. Closes #1715 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for this, and for covering both cases. I have not tested it yet: our install is still on 29e848d, from before this PR was merged. We plan to move to the first release after v1.23.0. Once we are on a build that includes it, I will leave a fresh comment on a photo (carousel) post and report back which case the worker log shows: a re-check that finds the comment, or |
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.
Summary
Fixes #1715. On a TikTok photo (carousel) post, comment automation never ran. The commenter lookup (
business/comment/list/) did not return the comment, soreceiveCommentwithheld the automation. This is by design, to avoid the account replying to itself. But it only ever looked once, so the comment was never answered. About a second later TikTok sentset_to_publicfor the same comment, and the webhook ignored it.It is still unknown whether TikTok returns the comment a moment later or never returns comments on photo posts. This PR covers both cases and logs which one happens.
Changes
withholdTiktokCommentthen stores the comment in Redis (tiktok:comment-identity-withheld:{openId}:{commentId}, 1 hour) and runs theincomingCommentjob again after 5 s, 30 s and 2 min (tiktokIdentityRecheck: { source: "retry", attempt }). The first run that finds the author clears the Redis entry, and the remaining re-checks stop early.set_to_publictriggers a re-check. The webhook now sends it on withtiktokIdentityRecheck: { source: "visibility" }. The worker acts on it only while the comment is still withheld, and uses the comment stored at the first delivery, becauseset_to_publicmay not include the text. So un-hiding an old comment never triggers a reply.owner: true, thatunique_identifieris saved onauth.metadata.ownerUniqueIdentifier. The write uses a single-fieldjsonb_set, likecommentToMessage, so it cannot restore tokens that a refresh just replaced. After a lookup miss,resolveTiktokAuthorshipcompares against the saved id: a different id is a customer, the same id is the account itself. If TikTok never returns photo-post comments, they are still answered once the account has had one comment of its own looked up, for example an automated reply on a video.missing/malformed/mismatch/timestamp) and, for a timestamp outside the window, the computedageSeconds. The reporter spent time on a server clock running about 3 s behind, which looked exactly like a wrong secret.Running the job again is safe: the comment is not saved twice, post-comment triggers are claimed per comment (
emitClaimedEvent), and the automation job is keyed by comment id (comment-auto-{commentId}). Missed-comment replays do not schedule re-checks. No schema change and no migration.Test plan
set_to_publicdoes not start a second chain, nothing scheduled when Redis fails), andreceiveComment(withheld comment is re-checked, fallback answers or skips, re-check stops when settled, re-check uses the stored text and clears the Redis entry).set_to_publicis sent on as a re-check, including withoutunique_identifier/text;set_to_hidden/set_to_friends_onlystill do nothing; signature rejections log the reason and skew.rememberOwnerUniqueIdentifierwrites only the metadata field; Redis entry save/read/clear.integrations/tiktok(217),packages/worker-config(200),packages/business(11,851),apps/worker(5,763).pnpm lint; type checks for 20 packages including builder (pre-commit hook);invariant-guardclean.commenter still unknown after every re-checkmeans TikTok does not return photo-post comments, and only the owner-id fallback helps.🤖 Generated with Claude Code