feat(self_hosted_hub): add per-org rate limiting for agent register/disconnect#1118
feat(self_hosted_hub): add per-org rate limiting for agent register/disconnect#1118loadez wants to merge 1 commit into
Conversation
…isconnect Adds a feature-flagged, per-pod in-memory token-bucket limiter keyed by organization, applied to the agent register and disconnect handlers. Disabled by default; when enabled the limit is per-pod, so the effective cluster-wide rate is the configured value times the replica count. Emits agent.register.rate_limited / agent.disconnect.rate_limited counters per org. Admin bulk operations on the internal API are unaffected.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 296751daa6
ℹ️ 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".
| // Smooth per-org disconnect churn. See the note on Register; same per-pod | ||
| // limiter, and admin bulk operations on the internal API are unaffected. | ||
| orgID := agent.OrganizationID.String() | ||
| if !s.rateLimiter.Allow(orgID) { |
There was a problem hiding this comment.
Keep disconnects out of the register bucket
When rate limiting is enabled, this uses the same per-org bucket that Register consumes, so a burst of successful registrations can empty the bucket and cause the agents' immediate /disconnect calls to return 429 before agent.DisconnectWithContext runs. Those agents remain in registered state and are still counted by agentcounter.countAgentsInOrganization, so normal batch/single-job churn can temporarily exhaust quota or show stale agents; use separate endpoint buckets or let disconnect cleanup bypass the register limiter.
Useful? React with 👍 / 👎.
No description provided.