feat(comment-spam): 3-tier moderation alerting to admin Telegram (notify-only)#4851
Merged
Conversation
…ify-only)
A high spam score alone can't separate true spam from false positives: on
matters_prod (7-day, >=0.94 band) precision is only ~60% — escort ads (0.996)
score the same as 中文 creative writing (0.992) and short genuine replies.
Account age doesn't separate either (an escort account was 818d old / 883
articles). What cleanly partitions them (ZERO false positives on the real
high-score set) is a compound gate:
Tier A (auto): score>=threshold AND contact-channel AND solicitation-keyword
→ escort / paid-services / account-selling / betting promo.
Tier B (ring): author repeats near-identical content across comments.
Tier C (review): high score but neither → surface to humans, never auto-act
(creative writing / opinions / replies land here).
This wires the gate into detectSpam and surfaces all three tiers to the admin
Telegram chat by reusing the existing report-alert SQS → reportTelegramAlert
pipeline (new source 'spam_detection'). NOTIFY-ONLY: it never hides a comment —
auto-action stays behind the separate, still-off commentSpamAutoCollapse flag —
so we validate the gate's precision in production before enabling enforcement.
Gated by MATTERS_COMMENT_SPAM_ALERT (default off).
Signal logic lives in a pure, fully unit-tested module (commentSpamSignals.ts);
the ring check is one bounded read of the author's recent comments, run only for
the rare high-score comments.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The ring near-duplicate check only stripped bare digits, so a rotated contact token (sk3826, abc123) left a letter remnant (sk, abc) and otherwise-identical spam templates failed to match. Drop whole alphanumeric tokens containing a digit instead — the IDs/phone numbers spammers rotate — while keeping pure-letter words so English templates still ring-match. Fixes the two failing ring tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4851 +/- ##
===========================================
+ Coverage 72.59% 72.68% +0.08%
===========================================
Files 1067 1068 +1
Lines 21178 21246 +68
Branches 4623 4641 +18
===========================================
+ Hits 15374 15442 +68
+ Misses 5326 5325 -1
- Partials 478 479 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jun 16, 2026
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
Wires a 3-tier spam classification into
detectSpamand surfaces all three tiers to the admin Telegram chat, reusing the existingreport-alertSQS →reportTelegramAlertworker (new alert sourcespam_detection).Notify-only. This never hides a comment — auto-action stays behind the separate, still-off
commentSpamAutoCollapse. Gated byMATTERS_COMMENT_SPAM_ALERT(default off), so it's a no-op until ops opts in.Why
A high spam score alone can't separate true spam from false positives. On
matters_prod(7-day window,spamScore ≥ 0.94band, the live system threshold) precision is only ~60%:What cleanly partitions them (zero false positives on the real high-score set) is a compound gate:
How
commentSpamSignals.ts— pure, fully unit-tested gate (regexes + char-3gram Jaccard ring helpers). Validated against the real prod high-score set.commentService.detectSpam→_alertSpamIfHighScore(tier + enqueue) and_isAuthorRepeating(one bounded read of the author's recent comments, only for the rare high-score comments).reportTelegramAlertworker: newspam_detectionsource + per-tier reason labels.Rollout
Ship behind the flag → turn on
MATTERS_COMMENT_SPAM_ALERTin prod → watch the Telegram feed to confirm Tier A stays clean → only then consider enabling auto-action.🤖 Generated with Claude Code