Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    Repair Circuit Breaker State Races

    by Mariusz Wrzeszczynski

    1

    Repair circuit-breaker state races across closed, open, and half-open transitions without changing resilience policy.

    Secure checkout via Stripe

    0 installsSecurity scanned

    See it in action

    You say

    Our Java payment client has a custom circuit breaker with CLOSED, OPEN, and HALF_OPEN states. Only one half-open probe is allowed, but two callers can pass the check, and a slow success from the first generation sometimes closes the breaker after the second probe has already failed and reopened it. Repair locally with a fake clock, controlled futures, and barriers. Preserve thresholds, reset timeout, retries, fallback behavior, and per-process scope; do not call the payment service.

    Your agent does

    State race found. Two callers observe an expired open interval and both enter half-open, while a success from the previous epoch can still close the newer breaker. The repair makes transition and probe admission generation-aware, rejects stale completions, preserves all thresholds and fallback behavior, and validates timer, failure, success, timeout, and reset orderings with a fake clock.

    What you get

    Enforce single-owner probe permits to prevent duplicate half-open requests.Reject stale success callbacks from previous breaker generations.Synchronize manual resets with in-flight probe completions safely.Implement deterministic state-machine testing using controlled clocks.

    About this skill

    The problem

    Circuit breakers often suffer from race conditions where stale callbacks, non-atomic transitions, or duplicate probes corrupt the internal state. This leads to breakers staying open after recovery, closing due to outdated successes, or admitting multiple probes despite a single-probe contract.

    What it does

    • Enforces a strict generation-based contract to reject stale callbacks and timer updates.
    • Makes half-open probe admission atomic within the existing repository concurrency model.
    • Fixes state leaks where cancellation or timeouts leave the breaker in an inconsistent generation.
    • Replaces flaky wall-clock sleeps in tests with deterministic clocks and barriers.
    • Implements generation-aware metrics to track transition reasons and rejected callbacks.

    Frameworks & tools

    Works with custom or wrapped state machines in environments using Read, Edit, and Bash tools. Applicable to languages with async/concurrent primitives like Node.js, Go, or Java.

    Why this beats prompting it yourself

    General prompts often miss the nuances of epoch-based state management, leading to "fixes" that just narrow the race window. This skill applies a formal ownership register to every transition, ensuring that only the current breaker generation can mutate state.

    Use cases

    • Preventing a stale success from closing a breaker that has already moved to a new failure epoch.
    • Stopping multiple probes from firing simultaneously during a half-open state.
    • Ensuring manual resets do not race with in-flight probe completions or old timers.
    • Converting non-deterministic circuit breaker tests into reliable, clock-controlled assertions.

    Known limitations

    Does not modify thresholds, retry budgets, or fallback policies. Will not introduce distributed coordination if no existing contract exists in the repository.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Frequently Asked Questions

    Popular in AI Agents & LLM Ops