Repository navigation
fix(go-policy): key rate-limit state by (action, agent_id, tenant) - #2022
Merged
Imran Siddique (imran-siddique) merged 1 commit intoMay 11, 2026
Merged
Imran Siddique (imran-siddique) merged 1 commit into
Imran Siddique (imran-siddique) merged 1 commit into
Conversation
PolicyEngine.checkRateLimit keyed pe.rateLimits by rule.Action alone. With a 60-second window of N calls, ANY caller's traffic counted against the same budget — one noisy agent (or tenant) could exhaust the budget and starve every other caller for the rest of the window. Thread context through to checkRateLimit and compose the key from (action, agent_id, tenant) so each (caller, tenant) gets its own independent window. Missing context keys collapse to empty segments — callers that pass nil context (e.g. middleware.go:256) retain the previous globally-scoped behavior, which is a safe and intentional fallback: nothing currently relies on cross-caller starvation, and upgrading callers to pass agent_id later is a no-op for nil callers. The key uses 0x1f (ASCII Unit Separator) as the delimiter so the join is unambiguous even if action / agent_id / tenant contain ":" or other printable separators. Adds three regression tests: - TestRateLimitIsolatedPerAgent: alice exhausts her budget; bob is unaffected. - TestRateLimitIsolatedPerTenant: same agent_id, different tenant, independent budget. - TestRateLimitNilContextRetainsGlobalBehavior: nil context still rate-limits at the action level (compatibility for legacy callers). Companion: this is part 2 of REVIEW.md item #7 (PR for part 1 — the check-then-increment fix — is filed separately). Both fixes can be merged in either order; this PR depends only on the public Evaluate/checkRateLimit signatures.
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI Compatibility
|
🤖 AI Agent: test-generator — `policy.go`
|
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
🤖 AI Agent: code-reviewer — View detailsTL;DR: 0 blockers, 0 warnings. No issues found. Clean change.
| 1 | Info | Rate limit state is now keyed by (action, agent_id, tenant) | policy.go | Action items: None. Warnings:
|
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
PR Review Summary
Verdict: ✅ Ready for human review |
Imran Siddique (imran-siddique)
approved these changes
May 11, 2026
Imran Siddique (imran-siddique)
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed. Security fix from finnoybu audit.
Imran Siddique (imran-siddique)
merged commit May 11, 2026
b0da159
into
microsoft:main
13 of 14 checks passed
MohammadHaroonAbuomar
pushed a commit
to MohammadHaroonAbuomar/agt-acs
that referenced
this pull request
Jun 1, 2026
…icrosoft#2022) PolicyEngine.checkRateLimit keyed pe.rateLimits by rule.Action alone. With a 60-second window of N calls, ANY caller's traffic counted against the same budget — one noisy agent (or tenant) could exhaust the budget and starve every other caller for the rest of the window. Thread context through to checkRateLimit and compose the key from (action, agent_id, tenant) so each (caller, tenant) gets its own independent window. Missing context keys collapse to empty segments — callers that pass nil context (e.g. middleware.go:256) retain the previous globally-scoped behavior, which is a safe and intentional fallback: nothing currently relies on cross-caller starvation, and upgrading callers to pass agent_id later is a no-op for nil callers. The key uses 0x1f (ASCII Unit Separator) as the delimiter so the join is unambiguous even if action / agent_id / tenant contain ":" or other printable separators. Adds three regression tests: - TestRateLimitIsolatedPerAgent: alice exhausts her budget; bob is unaffected. - TestRateLimitIsolatedPerTenant: same agent_id, different tenant, independent budget. - TestRateLimitNilContextRetainsGlobalBehavior: nil context still rate-limits at the action level (compatibility for legacy callers). Companion: this is part 2 of REVIEW.md item microsoft#7 (PR for part 1 — the check-then-increment fix — is filed separately). Both fixes can be merged in either order; this PR depends only on the public Evaluate/checkRateLimit signatures.
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.
Summary
PolicyEngine.checkRateLimitkeyedpe.rateLimitsbyrule.Actionalone. With a 60-second window of N calls, any caller's traffic counted against the same budget — one noisy agent (or tenant) could exhaust the budget and starve every other caller for the rest of the window.In a multi-tenant deployment that's a denial-of-service vector: agent A's misbehavior reaches agent B's API budget through nothing more than sharing an action name.
Change
policy.go:checkRateLimitnow takescontext map[string]interface{}and composes the key from(rule.Action, agent_id, tenant). Both context keys are pulled with a small helper that handles non-string values viafmt.Sprint.Evaluatepassescontextthrough tocheckRateLimit.0x1f(ASCII Unit Separator) so the join is unambiguous even if action / agent_id / tenant contain\":\"or other printable characters.Compatibility note
Callers that pass
nilcontext — for examplemiddleware.go:256— collapse to empty segments for both agent_id and tenant, so they retain the previous globally-scoped behavior. This is a deliberate safe fallback: nothing in the codebase currently relies on cross-caller starvation, and upgrading callers later to plumbagent_idis a no-op for the nil case until they actually pass real values.Tests
TestRateLimitIsolatedPerAgent— alice exhausts her budget; bob's calls are unaffected.TestRateLimitIsolatedPerTenant— same agent_id, different tenant, independent budget.TestRateLimitNilContextRetainsGlobalBehavior— nil context still rate-limits at the action level (legacy caller compatibility).Companion
This is part 2 of REVIEW.md item #7. Part 1 — the check-then-increment counter fix — is filed as #2021. The two PRs can be merged in either order; this one depends only on the public
Evaluate/checkRateLimitsignatures.Test plan
TestRateLimitingcontinues to pass under the nil-context defaultSurfaced as part of the AEGIS Initiative review of the agent-governance-toolkit (HIGH severity, Go section). Filed by Ken Tannenbaum (AEGIS Initiative).