Skip to content

Fix: exempt localhost from rate limits by default - #197

Merged
RyanTheRobothead merged 3 commits into
mainfrom
exempt_localhost_rate_limits
Dec 5, 2025
Merged

Fix: exempt localhost from rate limits by default#197
RyanTheRobothead merged 3 commits into
mainfrom
exempt_localhost_rate_limits

Conversation

@RyanTheRobothead

Copy link
Copy Markdown
Member

PR Info

Prevents overwhelming rate limits in situations where services are all running on the same host (and thus all have the same IP).

Developer Checklists

I have:

  • Run Pre-commit and Unit Tests, and ensured that they pass
  • Created or updated documentation relevant to your change
  • Created or updated unit tests relevant to your change

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the ability to exempt specific IP addresses from rate limiting, with localhost IPs (127.0.0.1 and ::1) being exempt by default. This prevents rate limit issues when multiple services run on the same host and share the same IP address.

Key changes:

  • Added exempt_ips parameter to RateLimitMiddleware with localhost as the default
  • Added rate_limit_exempt_ips configuration field to ManagerSettings
  • Updated tests to explicitly disable localhost exemption where rate limit testing is needed

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/madsci_common/madsci/common/middleware.py Added exempt_ips parameter to middleware constructor and early-return logic in dispatch method for exempt IPs
src/madsci_common/madsci/common/types/manager_types.py Added rate_limit_exempt_ips field to ManagerSettings for configuration
src/madsci_common/madsci/common/manager_base.py Added logic to convert exempt IPs list to set and pass to middleware, plus logging support
src/madsci_common/tests/test_middleware.py Added tests for default and custom exempt IPs, updated existing fixtures to disable localhost exemption
src/madsci_common/tests/test_stress.py Updated stress test fixture to explicitly disable localhost exemption
Configuration.md Added documentation for new RATE_LIMIT_EXEMPT_IPS configuration option across all managers
.env.example Added example configuration entries for RATE_LIMIT_EXEMPT_IPS

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/madsci_common/tests/test_middleware.py Outdated
Comment thread src/madsci_common/tests/test_middleware.py
@github-actions

github-actions Bot commented Dec 5, 2025

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/madsci_common/madsci/common
  manager_base.py
  middleware.py
  src/madsci_common/madsci/common/types
  manager_types.py
Project Total  

This report was generated by python-coverage-comment-action

@RyanTheRobothead
RyanTheRobothead merged commit 3135f7c into main Dec 5, 2025
4 checks passed
@RyanTheRobothead
RyanTheRobothead deleted the exempt_localhost_rate_limits branch December 27, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants