PROMPT 05 Backoff And Closing
# Implementation Prompt 05: Backoff and Closing States **Goal:** Implement :backoff state with exponential backoff and reconnection, and :closing state for graceful shutdown. **Test Strategy:** TDD with rgr. All tests green, no warnings. --- ## Context: What You're Building You're implementing the final two states of the Connection state machine: - **:backoff**: Exponential backoff with scheduled reconnection after failures - **:closing**: Terminal shutdown state that ignores all operations except final cleanup These states handle connection resilience and graceful termination. --- ## Required Reading: State Transitions From STATE_TRANSITIONS.md, these are the exact transitions to implement: ### :backoff State | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :backoff | `{:state_timeout, :reconnect}` | - | Spawn new transport; wait for transport_up | :initializing | | :backoff | `{:call, from}, {:request, method, params, opts}` | - | Reply with backoff error | :backoff | | :backoff | `{:call, from}, :stop` | - | Reply `:ok`; exit(normal) | - | | :backoff | `{:state_timeout, :tombstone_sweep}` | - | Sweep expired tombstones; reschedule sweep | :backoff | ### :closing State | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :closing | `{:info, {:retry_send, _}}` | - | Ignore (retries cleared) | :closing | | :closing | `{:state_timeout, {:request_timeout, _}}` | - | Ignore (requests cleared) | :closing | | :closing | `{:state_timeout, :tombstone_sweep}` | - | Ignore (shutting down) | :closing | | :closing | `{:call, from}, _` | - | Reply with shutdown error | :closing | | :closing | `{:info, _}` | - | Ignore | :closing | **Note**: :closing is reached via `{:stop_and_reply, :normal, ...}` so most clauses are defensive. --- ## Key Requirements from ADRs ### ADR-0002: Backoff Delay Management **Exponential increase on failure:**
fill the variables
This prompt has 8 variables. Pro fills them into a ready-to-paste prompt for you — no manual find-and-replace.
{:state_timeout, :reconnect}{:call, from}{:request, method, params, opts}{:state_timeout, :tombstone_sweep}{:info, {:retry_send, _}{:state_timeout, {:request_timeout, _}{:info, _}{:stop_and_reply, :normal, ...}
Unlock with Pro →when to use it
Community prompt sourced from the open-source GitHub repo nshkrdotcom/mcp_client (MIT). A "PROMPT 05 Backoff And Closing" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
businesscommunitygeneral
source
nshkrdotcom/mcp_client · MIT