feat(retry): configurable retry policy engine for agent failures#241
Merged
snipcodeit merged 1 commit intomainfrom Mar 6, 2026
Merged
Conversation
Implement RetryPolicyEngine in lib/retry-policy.cjs that provides per-failure-type retry limits (timeout: 2, malformed-output: 1, hallucination: 0), exponential backoff with jitter, and per-agent-type override configuration from .mgw/config.json. The engine wraps Task() calls via executeWithPolicy() and classifies failures using agent-errors.cjs taxonomy with retry.cjs fallback. Returns the original error when all retries are exhausted. Closes #232 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
Author
Testing ProceduresQuick Validationnode -e "
const { RetryPolicyEngine } = require('./lib/retry-policy.cjs');
const e = new RetryPolicyEngine();
console.log('timeout retries:', e.getMaxRetries('timeout')); // 2
console.log('hallucination retries:', e.getMaxRetries('hallucination')); // 0
console.log('should retry timeout@0:', e.shouldRetry('timeout', null, 0)); // true
console.log('should retry timeout@2:', e.shouldRetry('timeout', null, 2)); // false
console.log('backoff@0:', e.getBackoffMs(0), 'ms');
"Async Retry Testnode -e "
const { RetryPolicyEngine } = require('./lib/retry-policy.cjs');
const e = new RetryPolicyEngine({ backoff: { baseMs: 10, maxMs: 100, jitter: false } });
let attempt = 0;
e.executeWithPolicy(async () => {
attempt++;
if (attempt < 3) throw new Error('agent timed out');
return 'recovered';
}).then(r => console.log('Result:', r, 'after', attempt, 'attempts'));
"Agent Override Testnode -e "
const { RetryPolicyEngine } = require('./lib/retry-policy.cjs');
const e = new RetryPolicyEngine({ agentOverrides: { 'gsd-planner': { timeout: 5 } } });
console.log('planner timeout:', e.getMaxRetries('timeout', 'gsd-planner')); // 5
console.log('executor timeout:', e.getMaxRetries('timeout', 'gsd-executor')); // 2
"Non-modification Verificationnode -e "
const r = require('./lib/retry.cjs');
console.log('retry.cjs MAX_RETRIES:', r.MAX_RETRIES); // 3
console.log('classifyFailure:', typeof r.classifyFailure); // function
console.log('withRetry:', typeof r.withRetry); // function
" |
This was referenced Mar 6, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/retry-policy.cjs— a configurable retry policy engine for GSD agent failures with per-failure-type retry limits, exponential backoff with jitter, and per-agent-type overrideslib/agent-errors.cjs— the agent failure taxonomy (dependency from Define agent failure taxonomy with structured error codes #229/PR feat(lib): define agent failure taxonomy with structured error codes #238) providing structured failure classification for timeout, malformed-output, partial-completion, hallucination, and permission-denied errorsexecuteWithPolicy()and automatically retries on transient failures, returning the original error when retries are exhaustedCloses #232
Milestone Context
Changes
New:
lib/retry-policy.cjsRetryPolicyEngineclass with configurable policiesDEFAULT_RETRY_POLICIES— timeout: 2, malformed-output: 1, partial-completion: 1, hallucination: 0, permission-denied: 0DEFAULT_BACKOFF_CONFIG— 5s base, 300s max, 2x multiplier, full jitterexecuteWithPolicy(fn, opts)— async wrapper with retry, backoff, abort supportloadConfig()— reads per-agent-type overrides from.mgw/config.jsonRetryPolicyErrorerror class extending MgwErrorNew:
lib/agent-errors.cjsAgentFailureErrorclass with agent-specific contextclassifyAgentFailure()— context-based + pattern-based classificationIntegration
classifyAgentFailure()from agent-errors.cjs for agent-specific classificationclassifyFailure()from retry.cjs for generic errorslib/retry.cjs— coexists as a higher-level layerTest Plan
node -e "require('./lib/retry-policy.cjs')"shouldRetry()respects limits: timeout at attempt 2 returns falseexecuteWithPolicy()retries transient failures and stops on permanent onesexecuteWithPolicy()succeeds after retry on transient failureonRetrycallback fires with correct attempt, failureType, backoffMslib/retry.cjsexports and constants unchanged (19/19 verification checks pass)