容错性原则 logo

容错性原则

Organization
microwind
容错性原则

设计系统使其在部分组件失败时仍能继续提供服务,优雅地处理和恢复错误。

Overview

Publishermicrowind
Repositoryai-skills
Skill name容错性原则
Stars
93
Forks
25
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by microwind on GitHub. Read the source before you install it.

Installation

Install the 容错性原则 AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/microwind/ai-skills/tree/main/design-principles/fault-tolerance-principle
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/microwind/ai-skills.git /tmp/ai-skills
mkdir -p .claude/skills
cp -r /tmp/ai-skills/design-principles/fault-tolerance-principle .claude/skills/microwind-41
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable 容错性原则 in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads 容错性原则 on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so 容错性原则 is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

容错性原则 (Fault Tolerance Principle)

概述

容错性:系统在部分组件发生故障时,仍能继续正确地提供服务。故障是必然的,系统设计必须考虑故障场景。

核心思想:

  • Design for failure —— 为故障而设计
  • 故障是常态,不是例外
  • 故障应该被检测、隔离和恢复

容错模式

1. 断路器模式 (Circuit Breaker)

java
// ✅ 断路器:防止故障蔓延
public class CircuitBreaker {
    private int failureCount = 0;
    private int threshold = 5;
    private long lastFailureTime;
    private long resetTimeout = 30_000;  // 30秒

    enum State { CLOSED, OPEN, HALF_OPEN }
    private State state = State.CLOSED;

    public <T> T execute(Supplier<T> action, Supplier<T> fallback) {
        if (state == State.OPEN) {
            if (System.currentTimeMillis() - lastFailureTime > resetTimeout) {
                state = State.HALF_OPEN;  // 尝试恢复
            } else {
                return fallback.get();  // 直接走降级
            }
        }

        try {
            T result = action.get();
            if (state == State.HALF_OPEN) {
                state = State.CLOSED;  // 恢复正常
                failureCount = 0;
            }
            return result;
        } catch (Exception e) {
            failureCount++;
            lastFailureTime = System.currentTimeMillis();
            if (failureCount >= threshold) {
                state = State.OPEN;  // 打开断路器
            }
            return fallback.get();
        }
    }
}

// 使用
CircuitBreaker breaker = new CircuitBreaker();
String result = breaker.execute(
    () -> externalService.call(),     // 正常调用
    () -> "默认值"                     // 降级方案
);

2. 舱壁模式 (Bulkhead)

python
# ✅ 资源隔离:一个服务出问题不影响其他服务
from concurrent.futures import ThreadPoolExecutor

class BulkheadService:
    def __init__(self):
        # 不同服务使用独立的线程池
        self.order_pool = ThreadPoolExecutor(max_workers=10, thread_name_prefix="order")
        self.payment_pool = ThreadPoolExecutor(max_workers=5, thread_name_prefix="payment")
        self.notification_pool = ThreadPoolExecutor(max_workers=3, thread_name_prefix="notify")

    def process_order(self, order_data):
        # 支付服务卡住不会耗尽订单服务的线程
        return self.order_pool.submit(self._do_process, order_data)

    def process_payment(self, payment_data):
        return self.payment_pool.submit(self._do_payment, payment_data)

3. 重试与退避

typescript
// ✅ 指数退避重试
async function withRetry<T>(
    fn: () => Promise<T>,
    maxRetries: number = 3,
    baseDelay: number = 1000
): Promise<T> {
    for (let attempt = 0; attempt <= maxRetries; attempt++) {
        try {
            return await fn();
        } catch (error) {
            if (attempt === maxRetries) throw error;

            // 指数退避 + 随机抖动
            const delay = baseDelay * Math.pow(2, attempt) + Math.random() * 1000;
            await new Promise(resolve => setTimeout(resolve, delay));
        }
    }
    throw new Error('Unreachable');
}

// 使用
const data = await withRetry(() => fetch('/api/data').then(r => r.json()));

4. 超时控制

java
// ✅ 所有外部调用必须有超时
public class HttpClient {
    public String get(String url) {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setConnectTimeout(3000);  // 连接超时 3 秒
        conn.setReadTimeout(5000);     // 读取超时 5 秒
        return readResponse(conn);
    }
}

Fail-Fast vs Fail-Safe

Fail-Fast(快速失败):
- 尽早发现错误并报告
- 适用于编程错误、配置错误
- 例:参数验证失败立即抛异常

Fail-Safe(安全失败):
- 发生错误时继续运行
- 适用于运行时可恢复的故障
- 例:缓存失败走数据库

容错检查清单

□ 所有外部调用有超时设置
□ 关键调用有断路器保护
□ 不同服务间有资源隔离(舱壁)
□ 有重试机制(带指数退避和抖动)
□ 有降级方案(核心功能不依赖非核心服务)
□ 有死信队列处理失败消息
□ 错误日志包含足够的上下文信息
□ 定期进行故障注入测试(Chaos Engineering)

与其他原则的关系

原则关系
可用性容错是保障可用性的技术手段
关注点分离隔离故障域需要清晰的边界
封装故障处理逻辑封装在基础设施中

总结

核心:为故障而设计,检测、隔离、恢复。

关键模式:断路器、舱壁、重试退避、超时控制、优雅降级。

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the 容错性原则 AI skill do?

设计系统使其在部分组件失败时仍能继续提供服务,优雅地处理和恢复错误。

Why use 容错性原则 on TypingMind?

Because you install it once and use it with any model. 容错性原则 is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install 容错性原则 in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/microwind/ai-skills/tree/main/design-principles/fault-tolerance-principle. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use 容错性原则?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with 容错性原则?

As many as you like. As long as a model supports skills, you can use 容错性原则 with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the 容错性原则 AI skill free?

Yes. It is published on GitHub by microwind under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇