Buckets:

AnonymousSpottedToad/securityPatternsRecovery / ground_truth /python /limit_request_rate__stateset_stateset-agents.json
download
raw
9.15 kB
{
"role_mappings": [
{
"patternRole": "Entity",
"entity": "",
"file": "",
"lines": "",
"notes": "The caller of the FastAPI app (stateset_agents/api/main.py) is an outside HTTP client. Looked at stateset_agents/cli_remote.py:397 and stateset_agents/remote/serve_session.py:604, but they only print curl commands for, or call, remote serving pods (/v1/chat/completions), not the in-repo rate-limited API. Tests do not count.",
"status": "missing",
"nodeId": null
},
{
"patternRole": "Enforcer",
"entity": "dispatch",
"file": "stateset_agents/api/middleware.py",
"lines": "494",
"notes": "dispatch in RateLimitMiddleware (a Starlette BaseHTTPMiddleware) is registered by setup_middleware at stateset_agents/api/middleware.py:772, which create_app calls at stateset_agents/api/main.py:224. It derives the bucket id with _rate_limit_key (a hashed validated API key/JWT, otherwise the client IP), calls _check_rate_limit at line 515 and returns HTTP 429 with Retry-After when the request is blocked. Otherwise it calls call_next.",
"status": "present",
"nodeId": null
},
{
"patternRole": "Limiter",
"entity": "check",
"file": "stateset_agents/api/rate_limiter.py",
"lines": "56",
"notes": "Reached from Enforcer dispatch via _check_rate_limit (middleware.py:431, :471) and then UnifiedRateLimiter.is_allowed (rate_limiter.py:125). check in UnifiedRateLimiter prunes expired timestamps, compares the count against the limit and returns RateLimitResult(allowed=...). The default backend is 'memory'. An optional Redis fixed-window limiter (RedisSlidingWindowLimiter.is_allowed, middleware.py:292) is used only when API_RATE_LIMIT_BACKEND=redis.",
"status": "present",
"nodeId": null
},
{
"patternRole": "HistoryProvider",
"entity": "_windows",
"file": "stateset_agents/api/rate_limiter.py",
"lines": "49",
"notes": "The Limiter check reads history at rate_limiter.py:73 (self._windows[key]) and updates it at :93 (window.append(now)). _windows is an in-memory dict of per-key timestamp deques in UnifiedRateLimiter. It is cited as a field because no separate get or update method exists; the access is inline in check. cleanup (line 154) prunes it periodically from dispatch.",
"status": "present",
"nodeId": null
},
{
"patternRole": "PolicyProvider",
"entity": "from_env",
"file": "stateset_agents/api/config.py",
"lines": "204",
"notes": "RateLimitConfig.from_env loads requests_per_minute (API_RATE_LIMIT_PER_MIN, default 60), window_seconds and enabled from the environment. dispatch reads it via get_config() (config.py:406) and passes config.rate_limit.requests_per_minute to the Limiter at middleware.py:515-517, and the window into UnifiedRateLimiter at middleware.py:410. One global policy applies to all ids; the Limiter receives the policy as an argument and does not fetch it.",
"status": "present",
"nodeId": null
},
{
"patternRole": "System",
"entity": "chat_v1",
"file": "stateset_agents/api/routers/v1.py",
"lines": "497",
"notes": "When the request is allowed, Enforcer dispatch forwards it via call_next (middleware.py:552) to the routed handlers included in main.py:227-234. Example: chat_v1 in the v1 router (prefix /api/v1, POST /conversations), which runs inference. Every non-health route is behind the same middleware.",
"status": "present",
"nodeId": null
}
],
"interaction_order": {
"available": true,
"language": "python",
"repo": "stateset_stateset-agents",
"reason": "",
"entryRole": "Enforcer",
"entryRule": "behaviour",
"interactions": [
{
"rank": 1,
"interaction": "Enforcer \u2192 PolicyProvider",
"from": "Enforcer",
"to": "PolicyProvider",
"file": "stateset_agents/api/config.py",
"line": 361,
"via": [
"stateset_agents/api/config.py:<module>.get_config",
"stateset_agents/api/config.py:<module>.APIConfig.from_env"
],
"mechanism": "call",
"path": [
{
"caller": "stateset_agents/api/middleware.py:<module>.RateLimitMiddleware.dispatch",
"file": "stateset_agents/api/middleware.py",
"line": 495,
"code": "get_config()",
"callee": "stateset_agents/api/config.py:<module>.get_config",
"mechanism": "call"
},
{
"caller": "stateset_agents/api/config.py:<module>.get_config",
"file": "stateset_agents/api/config.py",
"line": 410,
"code": "APIConfig.from_env()",
"callee": "stateset_agents/api/config.py:<module>.APIConfig.from_env",
"mechanism": "call"
},
{
"caller": "stateset_agents/api/config.py:<module>.APIConfig.from_env",
"file": "stateset_agents/api/config.py",
"line": 361,
"code": "RateLimitConfig.from_env()",
"callee": "stateset_agents/api/config.py:<module>.RateLimitConfig.from_env",
"mechanism": "call"
}
],
"parent": ""
},
{
"rank": 2,
"interaction": "Enforcer \u2192 HistoryProvider",
"from": "Enforcer",
"to": "HistoryProvider",
"file": "stateset_agents/api/rate_limiter.py",
"line": 166,
"via": [
"stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.cleanup"
],
"mechanism": "data",
"path": [
{
"caller": "stateset_agents/api/middleware.py:<module>.RateLimitMiddleware.dispatch",
"file": "stateset_agents/api/middleware.py",
"line": 511,
"code": "self.limiter.cleanup()",
"callee": "stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.cleanup",
"mechanism": "call"
},
{
"caller": "stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.cleanup",
"file": "stateset_agents/api/rate_limiter.py",
"line": 166,
"code": "",
"callee": "_windows",
"mechanism": "data"
}
],
"parent": ""
},
{
"rank": 3,
"interaction": "Enforcer \u2192 Limiter",
"from": "Enforcer",
"to": "Limiter",
"file": "stateset_agents/api/rate_limiter.py",
"line": 125,
"via": [
"stateset_agents/api/middleware.py:<module>.RateLimitMiddleware._check_rate_limit",
"stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.is_allowed"
],
"mechanism": "call",
"path": [
{
"caller": "stateset_agents/api/middleware.py:<module>.RateLimitMiddleware.dispatch",
"file": "stateset_agents/api/middleware.py",
"line": 515,
"code": "self._check_rate_limit(limit_key, config.rate_limit.requests_per_minute)",
"callee": "stateset_agents/api/middleware.py:<module>.RateLimitMiddleware._check_rate_limit",
"mechanism": "call"
},
{
"caller": "stateset_agents/api/middleware.py:<module>.RateLimitMiddleware._check_rate_limit",
"file": "stateset_agents/api/middleware.py",
"line": 436,
"code": "self.limiter.is_allowed(key, limit)",
"callee": "stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.is_allowed",
"mechanism": "call"
},
{
"caller": "stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.is_allowed",
"file": "stateset_agents/api/rate_limiter.py",
"line": 125,
"code": "self.check(key, limit)",
"callee": "stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.check",
"mechanism": "call"
}
],
"parent": ""
},
{
"rank": 4,
"interaction": "Limiter \u2192 HistoryProvider",
"from": "Limiter",
"to": "HistoryProvider",
"file": "stateset_agents/api/rate_limiter.py",
"line": 68,
"via": [],
"mechanism": "data",
"path": [
{
"caller": "stateset_agents/api/rate_limiter.py:<module>.UnifiedRateLimiter.check",
"file": "stateset_agents/api/rate_limiter.py",
"line": 68,
"code": "",
"callee": "_windows",
"mechanism": "data"
}
],
"parent": "Enforcer \u2192 Limiter"
}
],
"anchoredRoles": [
{
"role": "Enforcer",
"kind": "METHOD"
},
{
"role": "HistoryProvider",
"kind": "MEMBER"
},
{
"role": "Limiter",
"kind": "METHOD"
},
{
"role": "PolicyProvider",
"kind": "METHOD"
}
],
"skippedRoles": [
"Entity",
"System"
]
}
}

Xet Storage Details

Size:
9.15 kB
·
Xet hash:
9f092c42e34616d307da717c54413c6fc3ede6edecc2d07af8a41703fcf77303

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.