| name | circuit-breaker-rollback |
| description | Implement circuit breaker patterns, canary deployment gates, hallucination telemetry checkers, and automated rollback for agent skill deployments. Stop cascading failures before they propagate across the swarm. |
| origin | Netflix Hystrix concept, Martin Fowler Circuit Breaker pattern, YAMTAM rules 56–57 |
| license | Apache-2.0 |
| version | 1.0.0 |
| compatibility | claude-sonnet-4-6, claude-opus-4-7 |
Circuit Breaker & Automated Rollback
Isolate failing agents/tools automatically before errors cascade. Deploy new skills to 1% canary traffic, roll back if quality drops.
When to Use
- Agent or tool returning repeated errors that are slowing the entire swarm
- Deploying a new skill and wanting automatic rollback if it degrades quality
- Protecting downstream agents from an upstream agent stuck in an error loop
- Implementing the YAMTAM circuit-breaker-law (rule 56) and canary-deployment-law (rule 57)
Do NOT use for
- Single requests where retrying once is fine
- Tools that must always be called regardless of prior failures (e.g., audit logging)
Circuit Breaker
class CircuitBreaker {
constructor(opts = {}) {
this.threshold = opts.threshold ?? 5;
this.cooldown = opts.cooldown ?? 60000;
this.state = 'CLOSED';
this.failures = 0;
this.lastFailure = 0;
this.openCount = 0;
}
async call(fn) {
if (this.state === 'OPEN') {
const elapsed = Date.now() - this.lastFailure;
if (elapsed < this._cooldownMs()) throw new Error('CIRCUIT_OPEN');
this.state = 'HALF_OPEN';
}
try {
const result = await fn();
this.();
result;
} (e) {
.(e);
e;
}
}
() {
. = ;
. = ;
}
() {
.++;
. = .();
immediate = e. === || e. === ;
(immediate || . >= .) {
. = ;
.++;
}
}
() {
[, , ][.(. - , )];
}
}
breaker = ({ : });
breaker.( (agentId, command));
Canary Deployment
class CanaryGate {
constructor(opts = {}) {
this.rate = opts.rate ?? 0.01;
this.windowMs = opts.windowMs ?? 30 * 60 * 1000;
this.baseline = opts.baseline ?? { errorRate: 0.02, latencyP95: 500 };
this.canaryStats = { calls: 0, errors: 0, latencies: [] };
}
shouldUseCanary() {
return Math.random() < this.rate;
}
record(isError, latencyMs) {
this.canaryStats.calls++;
if (isError) this.canaryStats.errors++;
this.canaryStats.latencies.push(latencyMs);
}
shouldRollback() {
{ calls, errors, latencies } = .;
(calls < ) ;
errorRate = errors / calls;
p95 = latencies.( a-b)[.(latencies. * )];
errorRate > .. + ||
p95 > .. * ;
}
}
Hallucination Telemetry Checker
async function checkHallucination(skillOutput, referenceOutput) {
const similarity = cosineSimilarity(
await embed(skillOutput),
await embed(referenceOutput)
);
return { score: similarity, hallucinated: similarity < 0.85 };
}
const { hallucinated, score } = await checkHallucination(canaryResult, baselineResult);
if (hallucinated) {
canaryGate.rollback();
secureLogger.logAction('canary', 'hallucination-detected', 'BLOCK', { score });
}
Sovereign State Reconstruction (Lớp 96)
async function emergencyRollback() {
const lastGoodRoot = readFileSync('releases/logs/audit.jsonl.root', 'utf8').trim();
const snapshotPath = `releases/snapshots/${lastGoodRoot.slice(0,16)}.tar.gz`;
const actual = sha256(readFileSync(snapshotPath));
if (actual !== lastGoodRoot) throw new Error('SNAPSHOT_TAMPERED');
execSync(`tar -xzf ${snapshotPath} -C /workspaces/yana-ai/`);
secureLogger.logAction('system', 'emergency-rollback', 'PASS', { root: lastGoodRoot });
}
Anti-Fake-Pass Checklist