You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document defines the formal "Definition of Done" for ratelord. It translates the project's high-level goals into verifiable, observable test cases. These criteria must be met before the system is considered production-ready.
Status: DRAFT
1. Daemon (ratelord-d)
The daemon is the central authority and event-sourced brain of the system.
1.1 Lifecycle & Persistence
ID
Scenario
Procedure
Acceptance Criteria
D-01
Clean Start
Start ratelord-d with no existing DB.
Process starts; ratelord.db and ratelord.db-wal are created; system_started event is logged.
D-02
Crash Recovery
Kill ratelord-d (SIGKILL); Restart it.
Daemon restarts; Replays events from WAL; Internal state (counters, forecasts) matches state before kill.
D-03
Graceful Shutdown
Send SIGINT or SIGTERM to ratelord-d.
Daemon stops accepting new intents; Flushes pending WAL writes; Exits with code 0.
1.2 Event Sourcing
ID
Scenario
Procedure
Acceptance Criteria
D-04
Event Immutability
Inspect SQLite DB after a series of operations.
events table contains sequential entries; No rows are ever updated or deleted (append-only).
D-05
State Derivation
Wipe snapshots table; Trigger a replay/rebuild command.
snapshots are regenerated and match the values derived from the events stream.
1.3 Identity Management
ID
Scenario
Procedure
Acceptance Criteria
D-06
Identity Registration
Register a new Identity (e.g., ratelord identity add).
identity_registered event is emitted; Secrets are not logged in plain text; Identity appears in TUI/CLI list.
D-07
Initial Polling
Register a valid Provider Identity.
Daemon automatically polls the Provider within 5s; limits_polled event is logged with correct values.
2. API & Agent Contract
Agents interact with the daemon via the Unix Socket API. This contract is strict.
2.1 Intent Negotiation (The Happy Path)
ID
Scenario
Procedure
Acceptance Criteria
A-01
Approve Intent
Submit POST /intent with valid AgentID, Identity, Scope, and low usage.
Response is 200 OK; Body contains "decision": "approve"; intent_decision event is logged.
A-02
Latency
Measure RTT of POST /intent under light load.
99th percentile latency < 10ms (daemon overhead must be negligible).
2.2 Intent Negotiation (The Throttled Path)
ID
Scenario
Procedure
Acceptance Criteria
A-03
Wait Instruction
Configure policy to rate-limit; Submit POST /intent.
Response is 200 OK; Body contains "decision": "approve_with_modifications", "wait_seconds": N (where N > 0).
A-04
Denial
Submit POST /intent that violates a "Hard Rule" (e.g., cost limit).
Response is 200 OK (not 4xx); Body contains "decision": "deny", "reason": "...".
3. Prediction & Drift
The system must predict exhaustion and correct itself when reality diverges.
3.1 Forecasting
ID
Scenario
Procedure
Acceptance Criteria
P-01
Forecast Emission
Emit a sequence of intent_decision events.
Daemon emits forecast_updated events; tte_p50 (Time To Exhaustion) decreases as usage increases.
P-02
Reset Awareness
Advance time across a Provider's reset window.
forecast_updated shows TTE jumping back to maximum/infinity immediately after reset time.