`src/reflection.rs` — reflector and recovery traits
The two-piece system for deciding what to do after a tool failure: analyze, then decide.
Key items
Reflector::analyze(error, tool_name, tool_input, tool_schema, context) -> FailureAnalysis— plusReflectionError { Skipped, Internal }.FailureAnalysis { is_recoverable, root_cause, severity, correction, context };FailureSeverity— Low < Medium < High < Critical (ordered).Correction { correction_type, description, modified_input?, alternative_tool?, guidance? }andCorrectionType— InputFix, ToolChange, PrerequisiteFix, ApproachChange, Escalate.RecoveryStrategy::decide(analysis, attempt, max_attempts) -> RecoveryAction—Retry { delay },Skip,AskUser,Fail.NoopReflector— the default: everything non-recoverable, severity Medium.ReflectionContext { task, attempt (0-indexed), max_attempts }— freshly built per failure.
Behavior notes
- Variant/field pairing on
Correctionis unenforced — consultcorrection_typebefore reading fields. InputFixrequires a JSON objectmodified_input; failed corrections are logged and dropped, the retry still runs.- Defaults mean zero retries (Noop says non-recoverable);
ExponentialBackoffRecovery(inbackoff.rs) is the default strategy with 3 retries under the engine’s hard ceiling of 5. - The engine maps reflector errors to conservative
Fail— never guesses on top of a broken reflector.
Deep dive: Reflection.