Commit a028028
feat(plugins): enforce per-tool timeouts and enhanced circuit breaker (IBM#2569)
Implement strict per-tool timeout enforcement for all transports
(REST, SSE, StreamableHTTP, A2A) and enhance the CircuitBreakerPlugin
with half-open states, retry headers, and granular configuration.
Changes:
- Wrap all tool invocations in asyncio.wait_for with effective_timeout
- Add per-tool timeout_ms support (ms to seconds conversion)
- Add half-open state for circuit breaker recovery testing
- Add half_open_in_flight flag to prevent concurrent probe requests
- Add retry_after_seconds in violation response for rate limiting
- Add tool_timeout_total and circuit_breaker_open_total Prometheus metrics
- Add cb_timeout_failure context flag for timeout detection in plugins
- Add tool_overrides for per-tool circuit breaker configuration
- Handle both asyncio.TimeoutError and httpx.TimeoutException
- Log actual elapsed time instead of configured timeout
Fixes applied during review:
- Fix _is_error() to detect camelCase isError from model_dump(by_alias=True)
- Fix half-open probe guard: only check when st.half_open is True
- Add stale-probe timeout to prevent permanent wedge if plugin blocks
- Add timeout enforcement to A2A tool invocations
- Call tool_post_invoke on exceptions so circuit breaker tracks failures
- Add ToolTimeoutError subclass to distinguish timeouts from other errors
- Only skip post_invoke for ToolTimeoutError (not all ToolInvocationError)
- Set error_message and span attributes for ToolTimeoutError observability
- Update README to document isError camelCase support
Timeout precedence:
1. Per-tool timeout_ms (if set and non-zero)
2. Global TOOL_TIMEOUT setting (default: 60s)
Closes IBM#2078
Signed-off-by: Mihai Criveti <[email protected]>
Co-authored-by: Mihai Criveti <[email protected]>1 parent 3ee68db commit a028028
File tree
6 files changed
+1536
-41
lines changed- mcpgateway/services
- plugins/circuit_breaker
- tests/unit
- mcpgateway/services
- plugins
6 files changed
+1536
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
53 | 67 | | |
54 | 68 | | |
55 | 69 | | |
| |||
0 commit comments