Implements resilient retry strategies with tenacity (Python) and async-retry (Node.js): backoff, jitter, bounded retries, and bail conditions.
Agentic Workflow: Read -> Reason -> Act (async-retry)
You are Async Retry (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for async-retry
- Domain: Implements resilient retry strategies with tenacity (Python) and async-retry (Node.js): backoff, jitter, bounded retries, and bail conditions.
- python-tenacity: Add retry logic to Python async calls with tenacity. —
pip install tenacity
- node-async-retry: Wrap Node.js async functions with async-retry. —
npm install async-retry
- Check
knowledge and prerequisites: node, npm, npx, pip
2. Reason — think for async-retry
- For
python-tenacity: Add retry logic to Python async calls with tenacity. — decide which checks to run
- For
node-async-retry: Wrap Node.js async functions with async-retry. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with async-retry tools
- Tools:
Glob, Grep, Read, Bash, Npx (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
async-retry:c3af4901
Async Retry
What this skill does
Adds production-grade retry behavior to async code: tenacity for Python, async-retry for Node.js. Covers exponential backoff, full jitter, bounded retries, retry-on-specific exceptions, and tests.
When to use
- Transient failures (connection resets, 503s) should not crash jobs
- A third-party API occasionally times out but succeeds on retry
- Retries must not amplify load during an outage (jitter matters)
Real commands
pip install tenacity
npm install async-retry
Python example
from tenacity import retry, stop_after_attempt, wait_exponential_jitter
@retry(stop=stop_after_attempt(4), wait=wait_exponential_jitter(initial=0.5, max=8))
async def fetch():
async with aiohttp.ClientSession() as s:
async with s.get("https://httpbin.org/status/500") as r:
r.raise_for_status()
return await r.json()
Node example
const retry = require('async-retry')
const fetchOrders = async () => {
return retry(async bail => {
const res = await fetch('https://httpbin.org/status/500')
if (res.status === 404) bail(new Error('not found')) // do not retry
if (!res.ok) throw new Error('retryable')
return res.json()
}, { retries: 3, minTimeout: 200, factor: 2, randomize: true })
}
Testing
- Mock failures N times then success; assert call count equals N+1
- Assert non-retryable errors (4xx) are not retried
Best practices
- Never retry non-idempotent writes without dedupe keys
- Cap attempts and total elapsed time
- Add jitter to avoid thundering herds
- Respect the upstream Retry-After header
Capabilities
python-tenacity
Add retry logic to Python async calls with tenacity.
Parameters:
attempts (number): Maximum retry attempts
backoff (string): fixed, exponential, or random backoff
retry_on (string): Exception types or predicates to retry on
Commands:
pip install tenacity
python -c "from tenacity import retry, wait_exponential, stop_after_attempt; print('ok')"
python -m pytest tests/test_retry.py -k retry
python -m unittest discover -s tests
Examples:
- python -c "from tenacity import retry, stop_after_attempt, wait_exponential; print(retry.module)"
- pytest tests/test_retry.py -x
- python -m pip install tenacity==8.2.3
node-async-retry
Wrap Node.js async functions with async-retry.
Parameters:
retries (number): Number of retry attempts
minTimeout (number): Minimum backoff in ms
factor (number): Exponential backoff factor
Commands:
npm install async-retry
npm install --save-dev mocha
npx mocha test/retry.test.js
node -e "const retry=require('async-retry'); retry(async()=>{throw new Error('x')},{retries:2}).catch(e=>console.log('gave up', e.message))"
Examples:
- npm init -y && npm install async-retry
- node -e "const retry=require('async-retry'); retry(()=>Promise.resolve(42),{retries:3}).then(console.log)"
- npx mocha --reporter spec test/retry.test.js
References
1---2name: "async-retry"3description: "Implements resilient retry strategies with tenacity (Python) and async-retry (Node.js): backoff, jitter, bounded retries, and bail conditions. Use when working with python tenacity, node async retry, api or when the user mentions python tenacity, node async retry, api."4license: "MIT"5compatibility: "Requires node, npm, npx, pip, python."6metadata:7 source: https://skillmd.com/skills/opknock/async-retry8 author: Kdesk9 version: 2.0.010 category: api11allowed-tools: "Glob Grep Read Bash(node:*) Bash(npm:*) Bash(npx:*) Bash(pip:*) Bash(python:*)"12---1314Implements resilient retry strategies with tenacity (Python) and async-retry (Node.js): backoff, jitter, bounded retries, and bail conditions.1516## Agentic Workflow: Read -> Reason -> Act (async-retry)1718You are **Async Retry** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — api context for `async-retry`21- Domain: Implements resilient retry strategies with tenacity (Python) and async-retry (Node.js): backoff, jitter, bounded retries, and bail conditions.22- **python-tenacity**: Add retry logic to Python async calls with tenacity. — `pip install tenacity`23- **node-async-retry**: Wrap Node.js async functions with async-retry. — `npm install async-retry`24- Check `knowledge` and `prerequisites: node, npm, npx, pip`2526### 2. Reason — think for `async-retry`27- For `python-tenacity`: Add retry logic to Python async calls with tenacity. — decide which checks to run28- For `node-async-retry`: Wrap Node.js async functions with async-retry. — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `async-retry` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Npx` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `async-retry:c3af4901`3536# Async Retry3738## What this skill does3940Adds production-grade retry behavior to async code: tenacity for Python, async-retry for Node.js. Covers exponential backoff, full jitter, bounded retries, retry-on-specific exceptions, and tests.4142## When to use4344- Transient failures (connection resets, 503s) should not crash jobs45- A third-party API occasionally times out but succeeds on retry46- Retries must not amplify load during an outage (jitter matters)4748## Real commands4950```bash51pip install tenacity52npm install async-retry53```5455## Python example5657```python58from tenacity import retry, stop_after_attempt, wait_exponential_jitter5960@retry(stop=stop_after_attempt(4), wait=wait_exponential_jitter(initial=0.5, max=8))61async def fetch():62 async with aiohttp.ClientSession() as s:63 async with s.get("https://httpbin.org/status/500") as r:64 r.raise_for_status()65 return await r.json()66```6768## Node example6970```js71const retry = require('async-retry')72const fetchOrders = async () => {73 return retry(async bail => {74 const res = await fetch('https://httpbin.org/status/500')75 if (res.status === 404) bail(new Error('not found')) // do not retry76 if (!res.ok) throw new Error('retryable')77 return res.json()78 }, { retries: 3, minTimeout: 200, factor: 2, randomize: true })79}80```8182## Testing8384- Mock failures N times then success; assert call count equals N+185- Assert non-retryable errors (4xx) are not retried8687## Best practices8889- Never retry non-idempotent writes without dedupe keys90- Cap attempts and total elapsed time91- Add jitter to avoid thundering herds92- Respect the upstream Retry-After header9394## Capabilities9596### python-tenacity97Add retry logic to Python async calls with tenacity.9899**Parameters:**100- `attempts` (number): Maximum retry attempts101- `backoff` (string): fixed, exponential, or random backoff102- `retry_on` (string): Exception types or predicates to retry on103104**Commands:**105- `pip install tenacity`106- `python -c "from tenacity import retry, wait_exponential, stop_after_attempt; print('ok')"`107- `python -m pytest tests/test_retry.py -k retry`108- `python -m unittest discover -s tests`109110**Examples:**111- python -c "from tenacity import retry, stop_after_attempt, wait_exponential; print(retry.__module__)"112- pytest tests/test_retry.py -x113- python -m pip install tenacity==8.2.3114115### node-async-retry116Wrap Node.js async functions with async-retry.117118**Parameters:**119- `retries` (number): Number of retry attempts120- `minTimeout` (number): Minimum backoff in ms121- `factor` (number): Exponential backoff factor122123**Commands:**124- `npm install async-retry`125- `npm install --save-dev mocha`126- `npx mocha test/retry.test.js`127- `node -e "const retry=require('async-retry'); retry(async()=>{throw new Error('x')},{retries:2}).catch(e=>console.log('gave up', e.message))"`128129**Examples:**130- npm init -y && npm install async-retry131- node -e "const retry=require('async-retry'); retry(()=>Promise.resolve(42),{retries:3}).then(console.log)"132- npx mocha --reporter spec test/retry.test.js133134## References135- [tenacity](https://tenacity.readthedocs.io/en/latest/)136- [async-retry](https://github.com/vercel/async-retry)137- [Azure Retry Pattern](https://learn.microsoft.com/en-us/azure/architecture/patterns/retry)