agentleFS
mmccallammccalla/coding-agent-skill-library/skills/exception-handling-and-recovery/SKILL.md

exception-handling-and-recovery

Skill4 starsChanged 5 months agoApache-2.0View on GitHub

Use when building resilient agent workflows that must detect failures, retry safely, degrade gracefully, rollback state, or escalate to a human/operator.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when an agent calls tools, edits files, executes code, uses network services, invokes models, or performs any multi-step …

    line 10
  2. Distinctive:

    Use fallbacks for unavailable services, models or tools.

    line 27
  3. Distinctive:

    Never hide failures. Convert raw exceptions into actionable diagnostics and include the next safe step.

    line 46
  4. Distinctive:

    Never retry a destructive operation unless it is idempotent or explicitly safe.

    line 51
  5. Distinctive:

    Never proceed after failed validation without documenting the risk.

    line 52
  6. Distinctive:

    Prefer controlled failure over silent corruption.

    line 53

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Exception Handling and Recovery

When to use

Use this skill when an agent calls tools, edits files, executes code, uses network services, invokes models, or performs any multi-step workflow where failures are likely.

Objective

Make failures explicit, recover safely where possible, and preserve enough evidence to repair or escalate.

Procedure

  1. Detect errors early: tool exceptions, malformed outputs, timeout, unavailable service, failed tests, invalid schema, unexpected state.
  2. Classify the failure as transient, deterministic, recoverable, unsafe, or unknown.
  3. Select a recovery strategy: retry, fallback, rollback, repair, degrade, ask clarification, or escalate.
  4. Preserve evidence: error message, stack trace, command, inputs, outputs and affected files.
  5. Resume only from a known-good state.

Recovery strategies

  • Retry transient failures with bounded attempts and back-off.
  • Use fallbacks for unavailable services, models or tools.
  • Roll back partial file or state changes before trying a different approach.
  • Reduce scope when a full solution is blocked.
  • Escalate when credentials, permissions, destructive actions or ambiguous requirements are involved.

Implementation guidance

Wrap risky operations with typed outcomes:

@dataclass
class OperationResult:
    ok: bool
    value: Any | None = None
    error_type: str | None = None
    error_message: str | None = None
    recoverable: bool = False

Never hide failures. Convert raw exceptions into actionable diagnostics and include the next safe step.

Guardrails

  • Never retry indefinitely.
  • Never retry a destructive operation unless it is idempotent or explicitly safe.
  • Never proceed after failed validation without documenting the risk.
  • Prefer controlled failure over silent corruption.

References

Verification

  • Failure modes are identified.
  • Retry and fallback limits are explicit.
  • Rollback or cleanup path exists.
  • Errors are logged with enough context.
  • Escalation condition is defined.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.