Repository navigation
feat(abuse): send abuse-control events and errors to PostHog - #109
Merged
Merged
Conversation
Abuse flags reached PostHog without their kind or severity (dropped by the property allowlist), and refused signups, scans, team pauses, operator decisions and new-account pacing sent nothing. Add recordAbuseEvent (abuse/telemetry.ts), which logs and captures: signup_blocked, content_scanned, team_paused_for_review, abuse_flag_raised, abuse_flag_resolved, organization_sending_(un)suspended and marketing_send_paced (once per sequence per hour). Allow the codes and internal ids they carry, report recordSignup and operator-alert failures as exceptions, and flush telemetry before the operator CLI exits. AGENTS.md: always send important events and errors through @codelitdev/observability. Closes #108
Contributor
Author
|
Verified in PostHog (DEPLOY_ENV=predator-agent): signup_blocked (disposable_email, too_many_signups), content_scanned (blocked/clean, heuristic), abuse_flag_raised (content, high), team_paused_for_review (content_review), organization_sending_suspended/unsuspended from the operator CLI all arrived with their properties. Two Platform (@codelitdev/observability) problems seen while verifying, not fixed here:
|
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.
Closes #108 (sub-issue of #75).
What changed
abuse/telemetry.ts:recordAbuseEventwrites a log line (shipped to PostHog Logs) and sends a PostHog product event for each abuse-control decision:signup_blockedreason(disposable_email,free_email,too_many_signups)abuse/signup.tscontent_scannedverdict,scan_mode(heuristicorai)abuse/content-scan.ts, only when a scan runsabuse_flag_raisedkind,severity,organization_idabuse/flags.tsteam_paused_for_reviewreason,organization_idabuse/flags.tsabuse_flag_resolvedkind,outcome(releasedorconfirmed),organization_idabuse/flags.tsorganization_sending_suspended/_unsuspendedorganization_idabuse/flags.tsmarketing_send_pacedreason,sequence_id,organization_idautomation/process-ongoing-sequence.ts, at most once per sequence per UTC hour (RedisSET NX)Allowlist:
PROPERTY_ALLOWLISTnow lets throughkind,severity,verdict,reason,outcome,scan_mode,organization_idandform_id. Before this,abuse_flag_raisedlost its kind and severity, and Signup forms: block double opt-in without a sender, and show an error when the confirmation can't be sent #102's signup-form errors lostform_id. No email addresses or IPs are sent.Errors:
recordSignupfailures and failed operator alert emails go throughcaptureErrorinstead of only being logged.CLI flush:
scripts/abuse.tsflushes telemetry beforeprocess.exit, so operator decisions aren't lost.AGENTS.md: a new development tip says to always send important events and errors to PostHog through
@codelitdev/observability.Testing
Unit: new tests check the exact events and properties for a refused signup, a blocked email flagged, paused and confirmed, and once-per-hour pacing; one more checks that the allowlist keeps abuse codes and drops
email. The full API suite passes (742 tests), as do typecheck, lint, format,check:driftandtest:conformance.Live E2E (cloud mode, the real PostHog project with
DEPLOY_ENV=predator-agent, scratch DB):@mail.tmwas refused..exelink was refused from the API and from the dashboard's Send now, which showed the "could harm recipients" message.The events need checking in PostHog itself before merging.
Found while testing (not changed here)
createOutboundMessageinserts anoutbound_messagesrow, whose foreign key takesFOR KEY SHAREon the team row.reserveSendthen locksorganization_plan_policiesFOR UPDATE, then the team rowFOR UPDATE. Two concurrent sends deadlock on these locks. A 10-recipient broadcast failed completely and paused itself (consecutive_failures). Likely fix:FOR NO KEY UPDATEon the team row. This is whymarketing_send_pacedcouldn't be triggered live; it's covered by a unit test.sending_pausedon Send now.