Log inBook a Demo
BuildSeniorBackendAuto-graded

Cut off a failing dependency and probe recovery

Build a circuit breaker that fast-fails after repeated errors, then lets one trial call through to check recovery.A downstream service keeps timing out, and calling it while it's down only adds latency and load. CircuitBreaker in breaker.py should stop calling it after failure_threshold consecutive failures, fail fast with CircuitOpenError until reset_timeout has passed, then let one trial call through. Today it doesn't. Build the closed, open and half-open states and the transitions between them, reading time only through the injected clock.
45 min
python

You're done when

  • The breaker opens on exactly the failure_threshold-th consecutive failure, no earlier and no later.
  • While open, every call raises CircuitOpenError and the dependency is never called.
  • It stays open until reset_timeout has passed, then lets one trial call reach the dependency.
  • A failed trial call opens the circuit again.
  • A successful trial call closes the circuit and resets the failure count, so tripping again takes a full new run of failures.

What it measures

Resilience engineeringWhether each state and transition behaves as specified while the dependency keeps failing.
Recovery strategyHow the single trial call is handled, and what its success or failure does to the circuit.
Precision on transitionsTripping on exactly the configured failure count and holding the full cooldown.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

45 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo