Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Circuit Breaker

From Leeroopedia
Knowledge Sources
Domains Mesh_Networking, Resilience
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for circuit-breaker state tracking and container health inspection across the mesh, provided by AI Maestro's `services/agents-core-service.ts` and `lib/container-utils.ts`.

Description

The isCircuitOpen function checks whether a host's circuit breaker is tripped (requests should fail fast). The recordHostSuccess function (private) clears the circuit breaker state and offline metadata when a host succeeds. The breaker has a threshold (default 3 failures), exponential backoff (30s → 5min), and a half-open state that allows one probe when the cooldown expires.

inspectContainerStatus (documented in Container_Utils) queries Docker for container health.

Usage

  • Call `isCircuitOpen` before making a request to a peer host — fail fast if open.
  • Call `recordHostSuccess` after a successful peer request to clear the breaker.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: services/agents-core-service.ts (L100-106 isCircuitOpen, L108-120 recordHostSuccess)

Signature

export function isCircuitOpen(hostId: string): boolean

function recordHostSuccess(hostId: string): void

// Circuit breaker configuration (module-level)
const CIRCUIT_BREAKER_THRESHOLD = parseInt(process.env.CIRCUIT_BREAKER_THRESHOLD || '3', 10)
const INITIAL_BACKOFF_MS = 30_000   // 30 seconds
const MAX_BACKOFF_MS = 300_000      // 5 minutes

Import

import { isCircuitOpen } from '@/services/agents-core-service'

I/O Contract

Inputs

Name Type Required Description
hostId string Yes Host ID to check/clear

Outputs

Name Type Description
isCircuitOpen() returns boolean true if circuit is tripped (fail fast)
recordHostSuccess() returns void Clears breaker state + offline metadata

Usage Examples

import { isCircuitOpen } from '@/services/agents-core-service'

// Before making a request to a peer
if (isCircuitOpen(peerHost.id)) {
  return { error: 'Host is currently unavailable (circuit open)' }
}
// Proceed with request...
// On success: recordHostSuccess(peerHost.id) is called internally

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment