Skip to content

fix(tiktok): re-check comments whose commenter lookup came back empty - #1785

Merged
sung17 merged 1 commit into
mainfrom
fix/tiktok-comment-identity-retry
Nov 27, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/tiktok-comment-identity-retry

Conversation

@sung17

@sung17 sung17 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1715. On a TikTok photo (carousel) post, comment automation never ran. The commenter lookup (business/comment/list/) did not return the comment, so receiveComment withheld 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 sent set_to_public for 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

  • Re-check instead of giving up. When the author is unknown, the comment is still saved as before. withholdTiktokComment then stores the comment in Redis (tiktok:comment-identity-withheld:{openId}:{commentId}, 1 hour) and runs the incomingComment job 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_public triggers a re-check. The webhook now sends it on with tiktokIdentityRecheck: { source: "visibility" }. The worker acts on it only while the comment is still withheld, and uses the comment stored at the first delivery, because set_to_public may not include the text. So un-hiding an old comment never triggers a reply.
  • Fallback for ownership. When a lookup returns owner: true, that unique_identifier is saved on auth.metadata.ownerUniqueIdentifier. The write uses a single-field jsonb_set, like commentToMessage, so it cannot restore tokens that a refresh just replaced. After a lookup miss, resolveTiktokAuthorship compares 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.
  • Clock skew in the logs. A rejected webhook signature now logs the reason (missing / malformed / mismatch / timestamp) and, for a timestamp outside the window, the computed ageSeconds. 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

  • Worker: authorship rule (owner flag, saved-id fallback, unknown), saving the owner id (write once, skip when unchanged, never throws), re-check scheduling (first, next, stops after the last, set_to_public does not start a second chain, nothing scheduled when Redis fails), and receiveComment (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).
  • TikTok webhook: set_to_public is sent on as a re-check, including without unique_identifier/text; set_to_hidden/set_to_friends_only still do nothing; signature rejections log the reason and skew.
  • Business: rememberOwnerUniqueIdentifier writes only the metadata field; Redis entry save/read/clear.
  • Full suites: 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-guard clean.
  • Not yet verified on a real TikTok account. The reporter offered to test this branch on the photo post from the issue. The worker log shows which case applies: a re-check that finds the comment means it was a timing issue; commenter still unknown after every re-check means TikTok does not return photo-post comments, and only the owner-id fallback helps.

🤖 Generated with Claude Code

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]>
@github-actions github-actions Bot added the bug Something isn't working as expected label Nov 26, 2026
@sung17
sung17 merged commit 052ab2e into main Nov 27, 2026
15 checks passed
@rancaHoratiu

Copy link
Copy Markdown

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 commenter still unknown after every re-check.

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

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TikTok comment automation never fires on photo (carousel) posts: commenter lookup returns nothing

2 participants