Skip to content

fix: is_spam always returned None due to missing return statement#7

Open
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen:fix/spam-detection-missing-return
Open

fix: is_spam always returned None due to missing return statement#7
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen:fix/spam-detection-missing-return

Conversation

@Ridwannurudeen
Copy link

Summary

Fixes #4.

is_spam() in reply_manager.py built an extensive list of regex patterns for detecting crypto spam but never evaluated them — the function fell off the end and implicitly returned None. As a result, _should_reply() never applied the -3 spam penalty, and the agent replied to every piece of spam as if it were legitimate.

Root cause

# Before — no return statement; function silently returns None
def is_spam(self, content: str) -> bool:
    ...
    patterns = [ ... ]
    # <-- nothing here

Fix

# After
        return any(re.search(pattern, clean) for pattern in patterns)

Also removes two redundant per-call imports (import re and from unicodedata import normalize) that duplicated the module-level imports already present at the top of the file.

Changes

  • agent/engines/twitter/reply_manager.py
    • Add missing return to is_spam()
    • Move from unicodedata import normalize to module-level imports
    • Remove import re / from unicodedata import normalize from inside the function body

Test plan

  • is_spam("🚀 100x moon soon buy now") returns True
  • is_spam("interesting take on the consensus mechanism") returns False
  • _should_reply() correctly penalises spam content with a -3 score adjustment

is_spam() built a list of regex patterns for spam detection but never
evaluated them — the function fell off the end and implicitly returned
None, so spam content was never identified and _should_reply() never
penalised it.

- Add the missing `return any(re.search(pattern, clean) for pattern in patterns)`
- Move `from unicodedata import normalize` to the module-level imports
  and remove the redundant per-call `import re` / `from unicodedata import normalize`
  that were shadowing the top-level imports inside the function body

Fixes NousResearch#4
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.

Fails to detect any spam

1 participant