PROMPT 04 Ready Failures And Retry
# Implementation Prompt 04: Ready State - Failures and Retry Logic **Goal:** Implement :ready state failure handling, transport busy retry, oversized frames, and transport down handling (reset notifications were removed from MVP). > **Update (2025-11-07):** Use `:erlang.send_after/3` for retry timers (message form `{:retry_send, id, frame}`) and ignore any legacy instructions about `{:info, {:retry_send, ...}}`. Reset notifications are intentionally out-of-scope for MVP; the remaining references in this prompt are historical context only. **Test Strategy:** TDD with rgr. All tests green, no warnings. --- ## Context: What You're Building You're implementing the failure paths and retry logic for :ready state: 1. **Transport busy retry**: When send returns `:busy`, schedule retry with exponential backoff + jitter 2. **Transport down**: Fail all in-flight and in-retry requests, transition to :backoff 3. **Oversized frames**: Close transport, transition to :backoff 4. **Reset notifications**: (Removed for MVP; keep this slot empty until a negotiated capability exists) 5. **Stop during retry**: Clear retry timers, prevent double replies This is where **concurrent retry correctness** is critical (per-ID retry tracking). --- ## Required Reading: State Transitions From STATE_TRANSITIONS.md, these are the exact transitions to implement: ### :ready State - Retry Path | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :ready | `{:call, from}, {:request, method, params, opts}` | send returns `:busy` | Generate ID; track in `retries` map with attempt count; schedule retry with jitter; reply `{:ok, id}` | :ready | | :ready | `{:info, {:retry_send, id}}` | retry exists, attempts < max | Increment attempts; retry send; if `:ok` → promote to requests with timeout; if `:busy` → reschedule retry; if error → fail request | :ready | | :ready | `{:info, {:retry_send, id}}` | retry exists, attempts ≥ max | Reply backpressure error; tombstone; clear retry | :ready | | :ready | `{:info, {:retry_send, id}}` | retry cleared (stop) | Ignore | :ready | ### :ready State - Failure Paths | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :ready | `{:info, {:transport, :down, reason}}` | - | Tombstone all requests; **fail/clear retries**; do not re-arm set_active; schedule backoff | :backoff | | :ready | `{:info, {:transport, :frame, binary}}` | byte_size > max | Log error; close transport (no set_active); **fail/clear retries**; schedule backoff | :backoff | | :ready | `{:call, from}, :stop` | - | Tombstone all requests; **fail/clear retries**; reply `:ok`; close transport; exit(normal) | - | ### Retry Tracking Structure (from ADR-0007)
fill the variables
This prompt has 8 variables. Pro fills them into a ready-to-paste prompt for you — no manual find-and-replace.
{:retry_send, id, frame}{:info, {:retry_send, ...}{:call, from}{:request, method, params, opts}{:ok, id}{:info, {:retry_send, id}{:info, {:transport, :down, reason}{:info, {:transport, :frame, binary}
Unlock with Pro →when to use it
Community prompt sourced from the open-source GitHub repo nshkrdotcom/mcp_client (MIT). A "PROMPT 04 Ready Failures And Retry" 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
roleplaycommunitygeneral
source
nshkrdotcom/mcp_client · MIT