High-performance retry and backoff policy engine for MCP Gateway
Project description
Retry With Backoff (Rust)
High-performance retry and backoff policy engine for ContextForge and MCP Gateway.
Features
- Rust-backed retry state tracking for tool invocations
- Exponential backoff with optional jitter
- Per-tool policy overrides without duplicating whole plugin configs
- Retry decisions based on
isError, structuredstatus_code, or optional parsed text payloads - Automatic state eviction for stale request entries
- Gateway ceiling enforcement for
max_retries - Retry policy metadata returned on tool and resource hooks
Build
make install
Runtime Requirements
This plugin depends on cpex>=0.1.0,<0.2 and imports hook models from cpex.framework. The compiled Rust extension is mandatory; there is no Python fallback implementation.
Usage
The plugin runs on tool_post_invoke and resource_post_fetch.
Typical uses:
- Retry transient upstream failures such as
429,500,502,503, and504 - Clamp aggressive plugin settings to the gateway-wide retry ceiling
- Apply stricter retry budgets to fragile or expensive tools
Configuration
Core settings
max_retries: maximum retry attempts before giving upbackoff_base_ms: base delay for exponential backoffmax_backoff_ms: upper bound for computed retry delaysretry_on_status: HTTP or structured status codes treated as retriablejitter: randomize delay within the current exponential ceilingcheck_text_content: inspect text content for JSON-encoded error payloads when structured content is absent
Per-tool overrides
Use tool_overrides to change retry behavior for a specific tool:
max_retriesbackoff_base_msmax_backoff_msretry_on_statusjitter
Behavior Notes
- Successful responses clear retry state for the
(tool, request_id)pair. - Retry state expires after a short TTL so abandoned request state does not accumulate indefinitely.
- If
check_text_contentis disabled, the hot path uses the Rust state manager directly. - If
check_text_contentis enabled, Python-side payload inspection supplements the Rust state manager before applying retry policy.
Returned Metadata
tool_post_invoke — OpenTelemetry metrics
tool_post_invoke accepts an optional extensions parameter carrying OpenTelemetry trace context. When a trace context is present (via extensions.request.trace_id), the plugin emits operational metrics on result.metadata["retry_with_backoff"] with the following schema:
result.metadata["retry_with_backoff"] = {
"retry_count": 1, # int — consecutive_failures after this call's outcome is recorded; 0 on success
"retry_delay_ms": 100, # int — the per-attempt delay computed for this call; 0 on success or once exhausted
}
Every call (success, within-budget retry, or exhausted) has a meaningful outcome to report, including the all-zero success case — there is deliberately no total_backoff_ms cumulative counter, only these two per-call fields.
Gating: Metrics are only emitted when a valid trace_id is present in the trace context (extensions.request.trace_id). No trace context means no result.metadata write at all, regardless of any config flag.
resource_post_fetch — unchanged config echo
resource_post_fetch is out of scope for the OTel metrics contract above — it never receives extensions and continues to unconditionally emit the plugin's active retry policy configuration (not per-call outcome data) on result.metadata:
max_retriesbackoff_base_msmax_backoff_msretry_on_status
Migration Note
Version 0.3.6 is a breaking change for tool_post_invoke consumers only (resource_post_fetch is unaffected):
tool_post_invokeno longer emits the flat, unconditionalretry_policyconfig echo (max_retries,backoff_base_ms,max_backoff_ms,retry_on_status). That echo is replaced by the namespaced, trace-gatedresult.metadata["retry_with_backoff"]schema above (retry_count,retry_delay_ms).tool_post_invokenow accepts a new optionalextensionsparameter carrying OpenTelemetry trace context. Emission is gated solely onextensions.request.trace_idbeing present and valid — if no trace context is supplied, no metrics are written at all.- Consumers that previously read the config echo from
tool_post_invokeunconditionally must migrate to readingresult.metadata["retry_with_backoff"]and must pass atrace_idviaextensionsto receive metrics. resource_post_fetchkeeps its pre-existing, un-namespaced config echo byte-for-byte unchanged — it is a different contract, not covered by this migration.
Testing
# Full plugin CI
make ci
Performance
The retry state manager is implemented in Rust so the common retry decision path avoids Python bookkeeping overhead for normal structured tool results.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpex_retry_with_backoff-0.3.7.tar.gz.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7.tar.gz
- Upload date:
- Size: 41.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
943d2434c896852669dd66949d6edde545650d4b46c3711e92b9c36aea41677d
|
|
| MD5 |
4cc8a549462b2953492fc42392c6d217
|
|
| BLAKE2b-256 |
7e9ba42bb78b2f6a7c0bcb927ed43ff74239dfa666693e1ef87c24dc7881ff05
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7.tar.gz:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7.tar.gz -
Subject digest:
943d2434c896852669dd66949d6edde545650d4b46c3711e92b9c36aea41677d - Sigstore transparency entry: 2172546812
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_retry_with_backoff-0.3.7-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 205.8 kB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ffdb067b385344dcdd662ac94cc7b290363054068948852624779a6b5949cb2
|
|
| MD5 |
990fabacb4d34eeb9b2d41dc7ba248ac
|
|
| BLAKE2b-256 |
0ac2224ddb0db97922577cd908cf1a72e29920b92f9fd7bf1df4cb8d3c2bb039
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7-cp311-abi3-win_amd64.whl:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7-cp311-abi3-win_amd64.whl -
Subject digest:
3ffdb067b385344dcdd662ac94cc7b290363054068948852624779a6b5949cb2 - Sigstore transparency entry: 2172546886
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 289.2 kB
- Tags: CPython 3.11+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cdbf53ecd2811bc48ee6bb0068feb69732951e83cbc9e01de342824b8038658
|
|
| MD5 |
93c11aa8a4905d2baf5cd85597ee292f
|
|
| BLAKE2b-256 |
bcacb159110260d39e54c65e8a4d0e78ee8ae4f9ce5b2ff21ae45c3648a67ebf
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_x86_64.whl:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
0cdbf53ecd2811bc48ee6bb0068feb69732951e83cbc9e01de342824b8038658 - Sigstore transparency entry: 2172547268
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_s390x.whl.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_s390x.whl
- Upload date:
- Size: 316.0 kB
- Tags: CPython 3.11+, manylinux: glibc 2.34+ s390x
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
652334a92a4d4d2a5cd73997dd4cac4b2aa8f17f0bc2618f52b44fe36b0854fc
|
|
| MD5 |
b288f810b9fb04a593718d1b248077de
|
|
| BLAKE2b-256 |
3d6746459cac3cfe85679ab92dde99d4cc230abccb7b3128db31bd9958f8491d
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_s390x.whl:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_s390x.whl -
Subject digest:
652334a92a4d4d2a5cd73997dd4cac4b2aa8f17f0bc2618f52b44fe36b0854fc - Sigstore transparency entry: 2172546953
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_ppc64le.whl.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_ppc64le.whl
- Upload date:
- Size: 314.5 kB
- Tags: CPython 3.11+, manylinux: glibc 2.34+ ppc64le
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d951f7acdf0448b4041da966aa24571210603a2114a47e6aa303a2431569a46b
|
|
| MD5 |
d3fd2952135baf1a16a716b03cb19322
|
|
| BLAKE2b-256 |
ed4583e698933a191aa4197fe1416ff4405a611b339a6b1396791d61910fe723
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_ppc64le.whl:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_ppc64le.whl -
Subject digest:
d951f7acdf0448b4041da966aa24571210603a2114a47e6aa303a2431569a46b - Sigstore transparency entry: 2172547024
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 272.9 kB
- Tags: CPython 3.11+, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59beefda7242d355667b315c95e34a4fe9554a8a3ccc4d79a021ec600eabd6d9
|
|
| MD5 |
9632c791d328c0dd5c625bd458a2a917
|
|
| BLAKE2b-256 |
c2afe4a666b8ae7bd643a9b2deeee58c263d1489a4a340bfae209eace970ef35
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_aarch64.whl:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7-cp311-abi3-manylinux_2_34_aarch64.whl -
Subject digest:
59beefda7242d355667b315c95e34a4fe9554a8a3ccc4d79a021ec600eabd6d9 - Sigstore transparency entry: 2172547180
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cpex_retry_with_backoff-0.3.7-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: cpex_retry_with_backoff-0.3.7-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 260.9 kB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a53770002f437211bc0d56f1eb0e9eb8f24106cb1a04831d982861ade55c9345
|
|
| MD5 |
6aa7912cb11ba3698f3bb435345fdac8
|
|
| BLAKE2b-256 |
f5f24da58c74fb91a76e77d78e460d2b0cc32c0b5a64ab7a1e71f999090a1096
|
Provenance
The following attestation bundles were made for cpex_retry_with_backoff-0.3.7-cp311-abi3-macosx_11_0_arm64.whl:
Publisher:
release-rust-python-package.yaml on IBM/cpex-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cpex_retry_with_backoff-0.3.7-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
a53770002f437211bc0d56f1eb0e9eb8f24106cb1a04831d982861ade55c9345 - Sigstore transparency entry: 2172547099
- Sigstore integration time:
-
Permalink:
IBM/cpex-plugins@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-rust-python-package.yaml@aa1c18fb82f8bd9018574305df3182cf4b5e4cc4 -
Trigger Event:
workflow_dispatch
-
Statement type: