AI Denial-of-Service & Economic Abuse
Defend against denial-of-wallet, context stuffing, recursive tool loops, and retry storms using strict input/output token caps, `max_steps` agent limits, wall-clock timeouts, retry jitter, circuit breakers, and per-tenant cost quotas.
Module detail
Best time to learn: Immediately after implementing token budgets, truncation, retries, tool-call limits, queues, and rate limiting.
Prerequisites - Token counting and context budgets. - API rate limiting. - Async concurrency and queue basics. - Agent step and tool-call budgets.
### Threat model
AI workloads have variable and sometimes multiplicative costs. One user action may trigger retrieval, reranking, several model calls, tools, retries, and media processing.
Study: - Denial of wallet and cost amplification. - Context stuffing and oversized input. - Repeated tool invocation and recursive agent loops. - Retry storms and provider failure amplification. - Expensive retrieval/reranking patterns. - Per-user, per-tenant, and per-model quotas. - Concurrency limits, queue backpressure, and circuit breakers. - Abuse signals and anomaly detection.
### Labs
- Cost model (1h): Estimate cost per request across input/output tokens, retrieval, reranking, tools, and media.
- Adversarial load (1h): Simulate oversized prompts, repeated requests, and tool loops against your own local test system.
- Budget enforcement (2h): Add request, token, tool-call, wall-clock, and concurrency budgets with deterministic rejection behavior.
- Recovery test (1h): Simulate provider timeouts and retries; verify retry caps, jitter, circuit breaking, and queue recovery.
### Project integration
- Project 1: Token and conversation budgets, maximum response tokens, request timeout, and per-session limits.
- Project 3: Maximum steps, tool calls, parallel tasks, execution time, and approval waits.
- Production API: Per-user and per-tenant quotas, backpressure, and cost alerts.
### Measurable completion criteria
- Each request has a bounded token, time, and cost budget.
- Agent loops terminate at a deterministic limit.
- Retries cannot amplify an outage indefinitely.
- Load tests show controlled degradation and recovery.
- Cost and abuse metrics are available without logging sensitive prompt contents.
------------------------------------------------------------------------
Study days for this domain
11- 10Add tool timeoutsW2S2M5D1R01 R10
- 11SSE Streaming & CancellationW2S0M5R01 R03 R08 R09
- 12Implement token countingW2M5R03 R04
- 13Implement request rate limitsW3M5R03 R25
- 29Build a bounded agent loop from scratch with three tools and…W5S3M5R24 R41
- 42Add inference request sizeW7M4M5R03 R26
- 44Deep SSRF DefenseW8S0M5R03 R04 R10
- 45Test retry stormsW8M5R03 R25
- 78Streaming, Budgets & Load ResilienceW13S5M5D4R03 R08 R16 R17 R27
- 85Agent State Machine & Sandboxed Code DiagnosisW15S3M5D2D3R02 R21 R24 R41
- 92Run availability and economic abuseW16S9M5D1D8R03 R04