Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automod: action limits; create reports for interaction churn #465

Merged
merged 12 commits into from
Dec 15, 2023

Conversation

bnewbold
Copy link
Collaborator

@bnewbold bnewbold commented Dec 7, 2023

The motivation here is to start auto-reporting in production based on specific rules. Specifically, this PR would start reporting on interactions churn (follow/unfollow), letting human mods confirm before taking action on an account.

Before we do that, need to de-duplicate reports. For example, if an account creates thousands of spammy posts, only want to report the account once. Generally want to prevent run-away rules from creating millions of reports, or doing thousands of automated account takedowns (for example).

This PR prevents re-reporting based on daily counters (fast checks), as well as double-checking against the mod service API just before filing a report (slower, but reliable).

This PR also adds "quotas" for mod actions, implemented using the counter system. This isn't perfect (the counter system itself might be buggy or broken (causing duplicate actions), but seems like a good start. If quotas are exceeded, automod will log and skip taking additional actions until the next day.

@bnewbold bnewbold requested a review from warpfork December 8, 2023 11:03
Copy link
Contributor

@warpfork warpfork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me.

I'm getting a little twitchy at the sheer size of the PersistAccountActions func, though. I think I read it, and I think I understand it, and together with the tests I think it's probably correct... but it's getting harder to be confident, and taking longer to read. It might be good to break it up soon. I tried to offer a few inline thoughts about where, but they're very preliminary and it's up to you if you can make any use of them :)

automod/event.go Outdated Show resolved Hide resolved
automod/event.go Show resolved Hide resolved
automod/event.go Outdated Show resolved Hide resolved
automod/event.go Outdated
e.Increment("automod-quota", "takedown")
}
}

if newTakedown || len(newLabels) > 0 || len(newFlags) > 0 || len(newReports) > 0 {
Copy link
Contributor

@warpfork warpfork Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(again in the "i'm not quite sure how I'd factor these things out, but, thinking out loud" vein...)

These four condition clauses seem like a good focal point for guiding a (?future) refactor.

When I was reviewing this, I noticed myself checking this line against all the other branches below to see if a slack notification would be accurately sent for exactly every event that would have at least one other persisted effect.

I think the answer is still "yes", as intended. It's just getting a bit harder to see as all the other instances of the same condition are drifting further apart. Maybe roughly a function per section below that's gated on each of these clauses? Or perhaps if we bundle all these values in a small struct, so their collective role is easier to see (and maybe add some logging methods to that, as a bonus? because I think "what updates we're about to push" is actually about what belongs in the slack message too)?

Also: I believe all the needsPurge = true assignments and eventual check of that bool can be replaced by... just checking 3 of these 4 again, directly, too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a bit of a corner case with reports, where it might not be known that they were not created until the actual attempt to do so (because there is an existing report). in that case a slack message gets sent out, but no report is created, and the account metadata cache is not purged.

I guess we could treat the skip-record-creation-at-last-minute thing as a real corner-case and always purge the cache?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was wondering about that too.

I was wondering if maybe the heavier query for prior reports should actually move earlier? Because it's also potentially mildly confusing if the slack notification gets sent out saying a report to happen but it's actually not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't super great how it is, but it does enable running with pushing to slack without actual admin-token access to the mod service, which I think is helpful as a possible way to deploy/operate, both for internal folks and third parties. The idea there is folks can develop rules and just manually independently report them in-app, based on a slack channel. Maybe that is too jank to care about, but I was running that way for a bit.

@bnewbold
Copy link
Collaborator Author

I agree overall, these persist functions have gotten unwieldy and hard to understand, even for me. I'll look in to refactoring.

@bnewbold bnewbold force-pushed the bnewbold/automod-action-limits branch from 1a1224c to 0d4a31f Compare December 14, 2023 17:31
@bnewbold
Copy link
Collaborator Author

I took at pass at breaking this function out and refactoring it. The control flow and behavior should be the same (still pretty complex), but hopefully clearer and more readable.

Copy link
Contributor

@warpfork warpfork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty darn good to me!

@bnewbold bnewbold merged commit fb51430 into main Dec 15, 2023
7 checks passed
@bnewbold bnewbold deleted the bnewbold/automod-action-limits branch December 15, 2023 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants