v0.8.1 — Cost & Budget Safety Audit
v0.8.1 — Cost & Budget Safety Audit
🐛 Bugs Found & Fixed
| Bug | Severity | Fix |
|---|---|---|
estimateCost() produced negative cost with negative token counts |
MEDIUM | Added Math.max(0, ...) guard |
BudgetTracker callbacks not wrapped in try/catch — throwing callback corrupted budget accounting |
HIGH | Wrapped in try/catch (notification-only semantics) |
🛡️ 74 Deep Cost Audit Tests
| Area | Tests |
|---|---|
| Money correctness (NaN, Infinity, negative, floating point) | 10 |
| Budget boundary enforcement (exact limits) | 8 |
| Session budget enforcement | 6 |
| Per-request budget enforcement | 4 |
| Model pricing integrity | 7 |
| Estimated vs actual cost semantics | 3 |
| Callback safety | 3 |
| Cost report integrity | 5 |
| Client lifecycle | 4 |
| Router + cost integration | 3 |
| Security | 2 |
| Adversarial inputs | 7 |
| Determinism | 2 |
| Invariant testing | 7 |
7 Invariants Verified
totalActual >= 0for all valid inputstotalActualequals sum of recorded actual costsbyProvidertotals reconcile withtotalActualbyPhasetotals reconcile withtotalActualremainingBudget=sessionBudget - totalActual- No NaN in any report field
- No Infinity in any report field
640 Tests Passing
74 new audit tests added (566 → 640 total).
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md