Repository navigation
fix(comments): persist threads_comment_id, dedup re-fetches, in-place attribution backfill (#261) - #262
Merged
Conversation
… attribution backfill (#261) ## What - Store::insert_comment now accepts and persists threads_comment_id (column existed since migration 001 but the insert never wrote it, which made POST /api/comments/{id}/reply permanently fail with NO_THREADS_ID). - Dedup on insert: exact threads_comment_id match reuses the row; Meta's standard-access /replies may omit id/from for third-party commenters (observed + consistent with the docs note that username/ permalink only work for public users and your own user), so id-less rows dedup by (post_id, text). - Attribution backfill: when an id-less row later arrives with id and author, the legacy row is updated in place via COALESCE (original row id, sentiment and reply state preserved) instead of inserting a twin. - Empty-string Meta ids ("" when the field is absent) normalize to None on both the API and MCP fetch paths. - 5 new integration tests (store_comments.rs): id persistence, id dedup, text-fallback dedup, backfill-in-place, distinct-text separation. ## Why First real inbound comment exposed the pipeline end-to-end broken: text stored but author/id null, reply-via-API guaranteed to fail, and re-fetches duplicating rows. Verified live on v0.9.3 across two accounts (#261). Identity redaction behavior validated against the official Threads docs (username/permalink are conditional), so the text-fallback dedup is the durable design, not a workaround. ## Testing - 5 new integration tests, all green. - Full workspace: 245 passed / 0 failed. - clippy -D warnings clean, cargo fmt clean.
🔍 Cora AI Code Review❌ Blocked — critical issues found. 🔴 Error (1)
Review powered by cora-code · BYOK · MIT |
…ng findings - Id-less dedup now matches author too: two different users posting identical text stay distinct rows. - Attribution backfill restricted to same-author or still-anonymous rows (most recent candidate wins): an unrelated commenter's row can never absorb the incoming threads_comment_id. - +2 regression tests covering both scenarios (7 total in suite). Workspace: 247 passed / 0 failed; clippy -D warnings + fmt clean.
This was referenced Sep 10, 2026
Closed
ajianaz
added a commit
that referenced
this pull request
Sep 11, 2026
…in (#268) Legacy fetches before #262 stored comment rows without threads_comment_id. The #261 backfill can never reconcile rows that already have an attributed twin: once the twin exists, every fetch takes the exact-id match branch, so the id-less row lives forever and double-counts the comment in sentiment and reply workflows. Add Store::cleanup_superseded_comments() and run it at the end of migrate(): delete id-less rows that have an attributed twin (same post_id + text) with a matching or absent author. Rows carrying reply workflow state (reply_status != 'new', replied_at, reply_text) are never deleted. Idempotent; purge count logged at startup. Closes #266 Co-authored-by: ajianaz <ajianaz@users.noreply.github.com>
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.
What
Store::insert_commentnow accepts and persiststhreads_comment_id— the column existed since migration 001,CommentDatacarried it, and the reply route requires it, but the insert never wrote it. Every API reply was guaranteed to fail withNO_THREADS_ID.threads_comment_idmatch reuses the existing row;(post_id, text).Why
The first real inbound comment (canary carousel post, 2026-09-10) exposed the pipeline broken end-to-end: text stored but
author_username/threads_comment_idnull, reply-via-API guaranteed dead, and re-fetches duplicating rows. Verified across two accounts (#261).Behavior validated against the official Threads docs:
username/permalinkfields are documented as only working for public users and your own user, so third-party identity can legitimately be absent → the text-fallback dedup is the durable design (consequence of the platform contract, not a workaround).Testing
store_comments.rs): id persistence, id dedup, text-fallback dedup, backfill-in-place, distinct-text separation.-D warningsclean; cargo fmt clean.Known limitations (conscious trade-offs, follow-up candidates)