Repository navigation
scarecrow: make stale NSFW_CARD_IMAGE URL verdict cleanup reachable - #8
Merged
Merged
Conversation
Rule 7429 writes an NSFW_CARD_IMAGE verdict (7-day TTL) for a card URL when its image scores near-perfect NSFW, and has a cleanup branch meant to delete that verdict when a later score for the same card comes back clean. The cleanup branch could never run: - The rule condition required IsNearPerfectNsfw (precision >= 0.999), but the cleanup guard required !IsHighPrecisionNsfw (precision < 0.95). Both cannot hold, so the branch was dead code. - The age check computed creation - now, which is never positive. - The threshold 60 * 60 * 1000 was compared against seconds, i.e. about 41 days, longer than the verdict's own 7-day TTL. Widen the condition to also admit clean card-image scores, compute the age as now - creation in seconds, and use a one-hour threshold. Require a present precision score on the cleanup path so a media update with no NSFW score cannot clear a verdict. The write path is unchanged. Co-authored-by: Jon Bailey <Pitchfork-and-Torch@users.noreply.github.com>
Pitchfork-and-Torch
deleted the
cursor/nsfw-card-verdict-cleanup-114b
branch
September 4, 2026 11:14
This was referenced Sep 4, 2026
cursor Bot
pushed a commit
that referenced
this pull request
Sep 8, 2026
Rule 7429 writes an NSFW_CARD_IMAGE verdict (7-day TTL) for a card URL when its image scores near-perfect NSFW, and has a cleanup branch meant to delete that verdict when a later score for the same card comes back clean. The cleanup branch could never run: - The rule condition required IsNearPerfectNsfw (precision >= 0.999), but the cleanup guard required !IsHighPrecisionNsfw (precision < 0.95). Both cannot hold, so the branch was dead code. - The age check computed creation - now, which is never positive. - The threshold 60 * 60 * 1000 was compared against seconds, i.e. about 41 days, longer than the verdict's own 7-day TTL. Widen the condition to also admit clean card-image scores, compute the age as now - creation in seconds, and use a one-hour threshold. Require a present precision score on the cleanup path so a media update with no NSFW score cannot clear a verdict. The write path is unchanged. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Jon Bailey <Pitchfork-and-Torch@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.
Problem
botmaker-rules/scarecrow/bot/NSFW_Card_Image_Media_To_URL_Verdict.bot(rule 7429) runs onmedia_updateevents for link-preview card images. When the image scores near-perfect NSFW it writes anNSFW_CARD_IMAGEverdict for the card URL with a 7-day TTL. Rule 7413 (NSFW_Card_Image_URL_to_Tweet_Verdict.bot) then labels every post linking that URL, andvisibility-filteringputs those posts behind an interstitial and drops them from out-of-network recommendations (NsfwCardImageOonDropRule).Rule 7429 also has a cleanup branch that is meant to delete the verdict when a later score for the same card comes back clean, so that a false positive does not sit on the URL for the full week. That branch could never run, for three independent reasons visible in the repo:
conditionrequiresIsNearPerfectNsfw, which isprecisionNewNsfw >= 0.999(IsNearPerfectNsfwNewModelLogic.df). The cleanup branch requires!IsHighPrecisionNsfw, which isprecisionNewNsfw < 0.95(IsHighPrecisionNsfwNewModelLogic.df). Both cannot be true for the same event, so theelse ifwas dead code.:verdictCreationTime - (CurrentTimeMs()/1000) > ...computes creation minus now, which is never positive for a verdict written in the past.60 * 60 * 1000is compared against a difference in seconds, so it means about 41 days, longer than the verdict's own 7-day TTL. Even with the sign fixed it would never fire before the verdict expired on its own.Net effect: a card URL wrongly scored as near-perfect NSFW once stayed labelled for seven days, and every post linking it stayed interstitialed and out of non-follower recommendations, even if the image was re-scored as clean the next hour. The
URLs_removed_as_NSFW_CARD_IMAGE_in_Rep_Storecounter could never increment.Change
Single file,
NSFW_Card_Image_Media_To_URL_Verdict.bot:condition: also admit card-image updates whose score is clean (Exists(precisionNewNsfw) && !IsHighRecallNsfw && !IsHighPrecisionNsfw). Events in the middle band (high-precision but not near-perfect, or high-recall) still do not fire, as before.now_seconds - creationTimestampInSecand compare against60 * 60(one hour, matching the 1-hour label TTL used by rule 7413).Exists(precisionNewNsfw), so a media update that carries no NSFW score cannot clear a verdict. Without this guard, widening the condition would have let score-less updates delete verdicts, which the original (unreachable) code would also have done.The write path is unchanged: it fires on exactly the same inputs and writes exactly the same verdict, TTL, and source.
Before / after
Modelled from the derived-feature thresholds in
derived-feature/*.df(hold= branch entered, verdict younger than 1 h, nothing deleted):Sweeping precision 0.000–1.000, several recall values, and verdict ages from 0 to 100 weeks, the old cleanup branch produced zero DELETE outcomes.
Verification
botmaker/src/antlr/com/twitter/botmaker/antlr/BotMaker.g, ANTLR 3.5.2) and parsed theconditionandactionblocks of all 20 rules inbotmaker-rules/scarecrow/bot/, before and after this change. All parse; the AST for the changed rule matches the intended shape (DISJUNCTIONin the condition,DIFFERENCE(QUOTIENT(CurrentTimeMs, 1000), :verdictCreationTimeInSec)compared withPRODUCT(60, 60)).CurrentTimeMsis confirmed as milliseconds inbotmaker/src/java/com/twitter/botmaker/function/datetime/CurrentTimeMs.java;creationTimestampInSecis named in seconds by the rule itself.GetUrlVerdictV2/DeleteUrlVerdictIffunctions are not in the repo, so the rule cannot be executed end to end here. The branch logic above was checked with a scratch model of the rule; nothing from that model is committed.Trade-off
The rule now also fires for card-image updates that score clean, which adds one
GetUrlVerdictV2read per such event. That read is what the original design's cleanup branch required; it was never paid before only because the branch was unreachable.Upstream
The file is byte-identical on
xai-org/x-algorithmmain(same blob), so this commit cherry-picks cleanly there.