#13885: feat: add session cost monitoring and alerting system
stale
Cluster:
Session Management Enhancements
## Summary
Adds a session cost monitoring system that checks cumulative session and daily costs against configurable thresholds, enabling operators to get alerted before costs spiral unexpectedly.
## Changes
### New files
- `src/infra/session-cost-alerts.ts` - Core alerting logic with session and daily threshold checks
- `src/infra/session-cost-alerts.test.ts` - Comprehensive test suite (20+ test cases)
### Features
- **Configurable thresholds** via `costAlerts.sessionThreshold` and `costAlerts.dailyThreshold` (USD)
- **Two-tier alerting**: warning (80-100% of threshold) and critical (>=100%)
- **Structured results** with level, message, cost details for downstream consumption
- **Formatted output** with emoji indicators suitable for Slack/Discord delivery
- **Graceful defaults** - no alerts when thresholds are unconfigured
### API
- `checkSessionCostAlert(cost, thresholds)` - Check single session cost
- `checkDailyCostAlert(cost, thresholds)` - Check aggregate daily cost
- `getApplicableCostAlerts(sessionCost, dailyCost, config)` - Get all triggered alerts from config
- `formatCostAlerts(alerts)` - Format for messaging (Slack-compatible markdown)
## Testing
Full test coverage including:
- Below-threshold (no alert)
- Warning range (80-100%)
- Critical range (>=100%)
- Missing/undefined thresholds
- Multiple simultaneous alerts
- Formatting with emoji sections
## Motivation
Long-running or expensive sessions can accumulate significant API costs without the operator noticing. This provides a lightweight, opt-in guard rail that integrates with existing config and messaging infrastructure.
Most Similar PRs
#13872: feat: Cost Optimization Suite - Session Management & Resource Effic...
by trevorgordon981 · 2026-02-11
66.4%
#17449: feat(extension): add cost-guard — budget enforcement and cost alerts
by miloudbelarebia · 2026-02-15
65.2%
#13889: feat: Slack channel cache, session cost alerts & checkpoint/recover...
by trevorgordon981 · 2026-02-11
64.0%
#20650: fix(gateway): include deleted/reset sessions in usage.cost RPC (#20...
by lailoo · 2026-02-19
61.1%
#19114: feat(usage): add default model costs for session_status
by Clawborn · 2026-02-17
59.6%
#13882: feat: Enhance session checkpoint system with better types and valid...
by trevorgordon981 · 2026-02-11
57.3%
#10192: feat(tui): display daily token cost in footer
by Dalton-AI-open · 2026-02-06
56.7%
#11999: fix: add session-growth guard to prevent unbounded session store gr...
by reverendrewind · 2026-02-08
54.4%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
53.8%
#17321: feat: add configurable idle trigger system
by kmixter · 2026-02-15
53.8%