feat(FN-2251): merge fusion/fn-2251

This commit is contained in:
gsxdsm
2026-04-22 09:31:47 -07:00
parent 435fb60c98
commit 16f692ab2a
3 changed files with 31 additions and 21 deletions

View File

@@ -482,10 +482,12 @@ Per-agent token budget tracking controls costs and prevents runaway AI spending.
### Enforcement Behavior
Budget enforcement happens at multiple points:
Budget enforcement is centralized in `HeartbeatMonitor.executeHeartbeat()`:
- `HeartbeatMonitor.executeHeartbeat()` checks budget before creating sessions; skips when `isOverBudget: true` or `isOverThreshold: true` (for timer triggers)
- `HeartbeatTriggerScheduler.onTimerTick()` skips timer ticks when budget is exceeded
- **Timer triggers**: Budget is enforced in `executeHeartbeat()` which creates explicit run records with `budget_exhausted` or `budget_threshold_exceeded` reasons. This makes timer budget skips observable rather than silent drops — users see explicit "skipped" run records in the dashboard instead of timer ticks that appear to "not run".
- **Assignment and on-demand triggers**: Budget is enforced in `executeHeartbeat()` with the same outcome recording. These triggers are allowed when over threshold (but not over budget) to maintain responsiveness.
The `HeartbeatTriggerScheduler` always dispatches timer callbacks regardless of budget status, delegating budget enforcement to the execution layer. This ensures every timer tick produces a heartbeat run record that is visible in the agent's run history.
Agents can be paused by budget exhaustion. Timer-triggered heartbeats skip when over threshold to avoid runaway costs, but assignment-triggered and on-demand runs may still execute for responsiveness.