Files
myWiki/concepts/circuit-breaker-pattern.md

40 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Circuit Breaker Pattern熔断器模式"
created: 2026-06-29
updated: 2026-06-29
type: concept
tags: [safety, loop-engineering, reliability, pattern]
sources: [[prompt-to-loop-engineering-2026]]
confidence: high
---
# Circuit Breaker Pattern
> 在 [[loop-engineering|Loop Engineering]] 中,熔断器是 [[loop-contract|Loop Contract]] 的 BUDGET 维度固化为硬约束的安全机制——连续失败 N 次即跳闸。
## 核心参数
- **max_consecutive_failures**:连续失败次数上限。一旦连续报错 N 次,系统立即跳闸并回退代码,将当前运行栈日志打包成工单转交人工
- **max_runtime_min**:墙上时间上限。超时无条件熔断,不等待当前操作完成
## 设计原理
熔断器来自分布式系统设计模式,在自主 Agent 循环中承担 **安全预算执行者** 角色:
1. **失败计数**:跟踪连续失败次数
2. **阈值触发**:达到 max_consecutive_failures → OPEN 状态(拒绝所有操作)
3. **优雅降级**:回退代码 → 打包日志 → 转交人工,而非静默丢失
## 与看门狗的分工
| 机制 | 监控对象 | 触发条件 | 响应 |
|------|---------|---------|------|
| [[circuit-breaker-pattern|熔断器]] | 任务级失败 | 连续失败 N 次 | 跳闸 + 回退 |
| [[watchdog-pattern|看门狗]] | 进程级异常 | CPU 满载 + 无 I/O | SIGKILL |
## 相关概念
- [[loop-contract|Loop Contract]]
- [[watchdog-pattern|看门狗]]
- [[loop-engineering|Loop Engineering]]