# 012 — SLURP Idempotency, Backpressure, and DLQ - Area: `pkg/integration/slurp_client.go`, `pkg/integration/slurp_events.go`, config - Priority: High ## Background SLURP event delivery has retries and batching but lacks idempotency keys, circuit-breaking/backpressure, and a dead-letter queue (DLQ). Under failure/load this can produce duplicates or data loss. ## Scope / Deliverables - Idempotency: - Generate a stable idempotency key per event (e.g., hash of {discussion_id, event_type, timestamp bucket}). - Send via header `Idempotency-Key` and include in body for server-side dedupe (if supported). - Backpressure & Circuit-breaker: - Add exponential backoff with jitter and max retry window. - Implement a circuit-breaker that opens on consecutive failures, stops sending for a cooldown, then half-open probes. - DLQ & Replay: - Persist failed events (JSONL or lightweight queue) with reason and next-attempt time. - Add a background replay worker with rate limiting and visibility into backlog. - Metrics & Logging: - Prometheus counters/gauges: events_generated, sent, failed, deduped, dlq_depth, circuit_state; latency histograms. - Structured logs for failures with keys. ## Acceptance Criteria / Tests - Under induced 5xx or timeouts, client opens breaker, stops flooding, writes to DLQ, then recovers and drains when service returns. - Idempotent resubmissions do not create duplicates (server returns success with same id), counters reflect dedupe. - Unit tests for backoff, breaker state transitions, DLQ persistence, and replay. ## Notes - Keep DLQ pluggable (file-based default); allow disabling via config.