Repository navigation
Commit 85ede8b
committed
fix: eliminate per-request plugin manager rebuilds (#6532)
Two root causes drove the plugin manager (including the external OPA
rules plugin) to re-initialize on nearly every request:
Root cause A — DEFAULT_CACHE_TTL=30 forced a full manager rebuild every
30 seconds under sustained traffic. Each rebuild called manager.initialize()
which re-imports and re-instantiates every configured plugin.
Root cause B — per-tool context_id fragmentation created one cache slot
per (team_id, tool_name) pair, triggering O(N tools) cold-start rebuilds.
Fix A: set DEFAULT_CACHE_TTL=0 so managers live for the worker lifetime.
Add PLUGIN_MANAGER_CACHE_TTL config knob (default 0) so operators can
re-enable timed refresh when needed. Explicit invalidation signals
(Redis pub/sub mode_change, binding_change, team_binding_change) already
handle config propagation; TTL-driven expiry was a blunt workaround.
Fix B: introduce TEAM_SCOPED_TOOL_SENTINEL ('__team__'). When
_build_manager finds no per-tool ToolPluginBinding rows, it normalises
the cache key from '<team_id>::<tool_name>' to '<team_id>::__team__'.
get_manager checks the canonical team-scoped slot before spawning a new
build task. All unbound tools in the same team share one manager instance
instead of each creating their own slot. Tools with explicit bindings
retain their per-tool key and dedicated manager.
Security invariant preserved: the manager holds no per-request state.
Per-request identity and auth context are passed as hook call arguments
on every invocation; manager lifetime does not affect cross-tenant
isolation.
Closes #6532
Signed-off-by: Lang-Akshay <akshay.shinde26@ibm.com>1 parent a211ab7 commit 85ede8b
6 files changed
Lines changed: 284 additions & 11 deletions
File tree
- mcpgateway
- plugins
- tests/unit/mcpgateway/plugins
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1392 | 1392 | | |
1393 | 1393 | | |
1394 | 1394 | | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
1395 | 1406 | | |
1396 | 1407 | | |
1397 | 1408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1592 | 1592 | | |
1593 | 1593 | | |
1594 | 1594 | | |
| 1595 | + | |
1595 | 1596 | | |
1596 | 1597 | | |
1597 | 1598 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
310 | 311 | | |
311 | 312 | | |
312 | 313 | | |
| |||
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
| 325 | + | |
324 | 326 | | |
325 | 327 | | |
326 | 328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
86 | 91 | | |
87 | 92 | | |
88 | 93 | | |
89 | | - | |
| 94 | + | |
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
| |||
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
130 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
131 | 145 | | |
132 | 146 | | |
133 | 147 | | |
| |||
140 | 154 | | |
141 | 155 | | |
142 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
143 | 168 | | |
144 | 169 | | |
145 | 170 | | |
| |||
164 | 189 | | |
165 | 190 | | |
166 | 191 | | |
167 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
168 | 200 | | |
169 | 201 | | |
170 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
171 | 219 | | |
172 | 220 | | |
173 | 221 | | |
| |||
180 | 228 | | |
181 | 229 | | |
182 | 230 | | |
183 | | - | |
184 | | - | |
| 231 | + | |
| 232 | + | |
185 | 233 | | |
186 | 234 | | |
187 | 235 | | |
188 | 236 | | |
189 | 237 | | |
190 | 238 | | |
191 | | - | |
| 239 | + | |
192 | 240 | | |
193 | 241 | | |
194 | 242 | | |
| |||
0 commit comments