feat(lib): define agent failure taxonomy with structured error codes#238
Merged
snipcodeit merged 1 commit intomainfrom Mar 6, 2026
Merged
Conversation
Add lib/agent-errors.cjs with a formal taxonomy of 5 GSD agent failure modes: timeout, malformed-output, partial-completion, hallucination, and permission-denied. Each failure type has a structured error code (AGENT_ERR_*), severity level, description, and recommended recovery action. Includes AgentFailureError class extending MgwError, classifyAgentFailure() for pattern and context-based classification, getRecoveryAction() for recovery lookup, and isRetryable() for retry eligibility checks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
Author
Testing ProceduresQuick Verification# Module loads without errors
node -e "const m = require('./lib/agent-errors.cjs'); console.log('OK:', Object.keys(m.AGENT_FAILURE_TYPES).length, 'failure types');"
# All exports present
node -e "
const m = require('./lib/agent-errors.cjs');
const exports = ['AGENT_FAILURE_TYPES', 'SEVERITY_LEVELS', 'AgentFailureError', 'classifyAgentFailure', 'getRecoveryAction', 'isRetryable', 'compareSeverity', 'getFailureByCode'];
exports.forEach(e => console.log(e + ':', typeof m[e]));
"Classification Testsnode -e "
const { classifyAgentFailure } = require('./lib/agent-errors.cjs');
const tests = [
['Agent timed out after 50 turns', 'timeout'],
['Invalid JSON in agent response', 'malformed-output'],
['Agent completed 2 of 5 tasks', 'partial-completion'],
['Artifact missing: PLAN.md not found', 'hallucination'],
['Permission denied writing to /src', 'permission-denied'],
['Random unknown error', null],
];
tests.forEach(([msg, expected]) => {
const r = classifyAgentFailure({ message: msg });
const actual = r ? r.type : null;
console.log(actual === expected ? 'PASS' : 'FAIL', msg.substring(0, 40), '→', actual);
});
"Error Class Testsnode -e "
const { AgentFailureError } = require('./lib/agent-errors.cjs');
const { MgwError } = require('./lib/errors.cjs');
const err = new AgentFailureError('test', { failureType: 'timeout', agentType: 'gsd-executor' });
console.log('instanceof MgwError:', err instanceof MgwError);
console.log('code:', err.code);
console.log('severity:', err.getSeverity());
console.log('retryable:', err.isRetryable());
" |
This was referenced Mar 6, 2026
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/agent-errors.cjswith a formal taxonomy of 5 GSD agent failure modes: timeout, malformed-output, partial-completion, hallucination, and permission-deniedAgentFailureErrorclass extendingMgwError, plusclassifyAgentFailure()for pattern and context-based classificationlib/retry.cjspipeline retry infrastructure with agent-specific failure handlingCloses #229
Milestone Context
Changes
lib/
lib/agent-errors.cjsModule exports:
AGENT_FAILURE_TYPES— frozen object with 5 failure type definitionsSEVERITY_LEVELS— ordered severity enum with numeric weightsAgentFailureError— Error class extending MgwError with agentType, failureType, artifacts fieldsclassifyAgentFailure(error, context)— pattern + context-based classificationgetRecoveryAction(failureType)— recovery action lookupisRetryable(failureType)— retry eligibility checkcompareSeverity(a, b)— severity comparison utilitygetFailureByCode(code)— reverse lookup by error codeFailure type summary:
AGENT_ERR_TIMEOUTAGENT_ERR_MALFORMED_OUTPUTAGENT_ERR_PARTIAL_COMPLETIONAGENT_ERR_HALLUCINATIONAGENT_ERR_PERMISSION_DENIEDTest Plan
node -e "require('./lib/agent-errors.cjs')"loads without errorsAgentFailureErrorextendsMgwError(instanceofcheck)classifyAgentFailure()correctly classifies all 5 failure patterns via message matchingclassifyAgentFailure()handles context-based classification (artifact mismatch, partial tasks)classifyAgentFailure()returns null for unrecognized errors (fallback to retry.cjs)getRecoveryAction()returns valid action/retryable/severity for each typeisRetryable()returns true for timeout/malformed-output/partial-completion, false for hallucination/permission-denied