fix: rate limit unsupported source issue creation - #321
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d5005d20b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| last_reported_at = self._last_reported_hosts.get(host) | ||
| if ( | ||
| self.unsupported_source_report_cooldown_seconds > 0 | ||
| and last_reported_at is not None | ||
| and (current_time - last_reported_at) |
There was a problem hiding this comment.
Guard host cooldown map with a lock
_report_unsupported_source performs a read-then-write on _last_reported_hosts without synchronization, so concurrent requests can both pass the cooldown check and both call report_unsupported_source for the same host. In this repo the service runs on ThreadingHTTPServer (manga_watch/run_service.py), so this race is reachable in production and undermines the new rate-limit goal (extra GitHub API calls and possible duplicate issue creation under burst traffic). Please make the check/update atomic (e.g., lock per handler or per-host reservation) so the throttle is effective across threads.
Useful? React with 👍 / 👎.
Motivation
/addflow invoked GitHub issue creation on every unsupported-source error with no local gating, enabling spam and GitHub API token/rate exhaustion.Description
AddCommandHandlerwith a default ofDEFAULT_UNSUPPORTED_SOURCE_REPORT_COOLDOWN_SECONDS = 3600and a configurableunsupported_source_report_cooldown_secondsproperty._last_reported_hoststracking and anowinjection point so the cooldown check usesnow()and is testable.unsupported_source_reporter.report_unsupported_sourcewhen the host was reported recently and return a user-facing rate-limit message viaUNSUPPORTED_SOURCE_REPORT_RATE_LIMIT_MESSAGEwhile keeping existing error/result messages intact.test_start_rate_limits_unsupported_source_issue_reporting_per_hostto validate throttling and update imports/constants used by tests.Testing
python -m unittest tests.test_discord_add tests.test_discord_interactions tests.test_github_issue_reportingand all tests passed (36 tests ran and returnedOK).Codex Task