v0.9.1 — Reservation Accounting Audit
v0.9.1 — Hard Budget Enforcement Audit
🐛 Bugs Found & Fixed (3 real production bugs)
| Bug | Severity | Root Cause | Fix |
|---|---|---|---|
reserve() accepted NaN amounts |
HIGH | NaN < 0 is false, bypassed guard |
Added !Number.isFinite() check |
settle() with negative/NaN cost corrupted totals |
HIGH | No input validation on actualCost |
Clamps negative/NaN to 0, Infinity to session budget |
settle() with Infinity didn't exhaust budget |
MEDIUM | Math.max(0, Infinity) = Infinity but isBudgetExhausted used >= which Infinity satisfies, yet Infinity wasn't clamped |
Now correctly caps Infinity at session budget |
🛡️ 55 Adversarial Reservation Tests
| Area | Tests |
|---|---|
| Lifecycle (reserve→settle, reserve→release) | 2 |
| Double settlement/release safety | 5 |
| Settle after release / release after settle | 2 |
| Reservation ID collision | 3 |
| Negative/NaN/Infinity amounts | 4 |
| Over-settlement (actual > reserved) | 3 |
| Under-settlement with random cycles | 2 |
| Concurrent reservations (1000+ calls) | 5 |
| Floating point attacks | 3 |
| Retry accounting | 2 |
| Fallback accounting | 1 |
| Client isolation | 2 |
| Memory safety (leak prevention) | 3 |
| Security (no secrets) | 2 |
| API abuse (rapid cycles) | 3 |
| Cost report reconciliation | 4 |
| Fuzz testing (1000 scenarios) | 1 |
| Performance (100K+ ops) | 2 |
| Callback safety | 2 |
731 Tests Passing
55 new adversarial tests added (676 → 731 total).
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md