openreply icon indicating copy to clipboard operation
openreply copied to clipboard

ProcessedComment is never read or written, and two comments describe it as if it is

Open reisvini opened this issue 3 months ago • 2 comments

Not a correctness bug. Dedup works. This is dead schema plus two comments that point at it, which cost me some time while reading the reconciliation path, so it may cost the next reader the same.

What I found

ProcessedComment (prisma/schema.prisma:262, created in prisma/migrations/20260722220418_add_comment_reconciliation) has no reads and no writes anywhere in the repo:

$ grep -rn "prisma\.processedComment" --include="*.ts" . | grep -v node_modules
$ 

Every reference to the name is either the model declaration, the migration, or a comment.

Why it reads as load bearing

Its own docblock states a job it does not do:

Every comment the system has seen, from either the webhook or the polling reconciler. This is the shared dedup set: a comment id present here has already been queued for processing, so neither path acts on it twice.

And lib/queue/client.ts:36-37 describes the source field as being persisted into it:

// Which path enqueued this comment. Recorded in the shared ProcessedComment
// dedup store so the reconciler can tell webhook- from polling-caught comments.
source?: CommentSource;

source is set on the job payload but never stored, so nothing can tell webhook-caught from polling-caught comments after the fact.

What actually does the dedup

For the record, since I checked before filing, and the answer is "the current code is fine":

  • lib/polling/comment-reconciler.ts:192-198 skips comments the account owner already replied to, read live from replies{from}.
  • lib/polling/comment-reconciler.ts:209 skips comments this campaign has already fully handled, via prisma.dmLog.findMany, with the nice detail that "fully handled" depends on whether the campaign posts a public reply.
  • DmLog @@unique([automationId, commentId]) is the backstop.

So the webhook and polling paths are already reconciled without the table.

The one real consequence

The docblock claims the table stops the reconciler re-sweeping non-matching comments each cycle. It does not, so non-matching comments are re-evaluated every sweep. That is CPU and a keyword match, not an API call or a duplicate DM, so at current sweep sizes it is almost certainly not worth optimizing. Worth knowing rather than fixing.

Suggested resolutions

Either is fine, and this is your call since one of them is a migration:

  1. Drop it. Delete the model, add a migration dropping the table, remove source from ProcessCommentJob or keep it as a job-payload-only breadcrumb with a corrected comment.
  2. Keep it and correct the comments, if it is scaffolding for a reconciliation change you have planned. Then the docblock should say "not yet wired" rather than describing present-tense behaviour.

Happy to send a PR for either if you say which you prefer. I did not bundle it into #37 since that one is a behavioural fix with no schema change and this one touches a migration.

Context: I was reading the reconciliation path closely while planning similar work, which is how both this and #37 turned up.

reisvini avatar Aug 27 '26 13:08 reisvini

I verified this against current main (e1b13ca). ProcessedComment still appears only in the Prisma schema/migration and explanatory comments; there are no runtime reads or writes. The reconciler currently uses owner-reply and DmLog guards instead.

Because dropping a Prisma model requires a schema-destructive migration, I would take the conservative option first: keep the table as scaffolding but correct the present-tense comments so they no longer claim it is the active shared dedup store. If removal is preferred, I can instead prepare a dedicated migration PR. Which direction fits the roadmap?

cmondragon023 avatar Aug 28 '26 03:08 cmondragon023

Sure send a PR, as long as it doesn't impact existing users and no significant changes to codebase

diwennee avatar Aug 30 '26 19:08 diwennee