fix(loops): persist cost on stop; reset budget baseline on restart #172
No reviewers
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman!172
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/loop-restart-budget"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes two loop budget-accounting bugs, surfaced by loop-end messages like:
Bug A — terminal stop didn't persist the cost that triggered it
The stop path wrote only
state+last_summary(viaSetLoopState), never the refreshedcost_usd/iteration. The stored row showed cost 0 next to a "$5 budget reached" summary, so the UI contradicted itself.Fix: persist the loop (
UpdateLoop) beforeSetLoopStatein the stop branch, so the row matches the final summary.Bug B — Restart instantly re-terminated ("0 iterations, $6.76")
Restartzeroed the loop'scost_usd/iteration, but usage aggregation re-summed the previous run'schild_sessions(still linked byloop_id) on the next tick. Cost jumped back over the cap and the loop re-terminated immediately — a restarted loop could never run.Fix: add
loops.usage_baseline_at(migration v18). Only child sessions created at/after the baseline count toward the budget.Restartsets it tonow, so a restarted loop runs against a fresh budget while history is preserved. Baseline0(all existing loops) counts everything — behavior unchanged.Tests
TestEvaluateOne_StopPersistsCostThatTriggeredIt— stop persists the cost (row matches summary).TestRestart_ResetsBudgetBaselineSoOldSpendDoesNotReTrip— restart succeeds and old spend is excluded.TestRefreshUsage_ExcludesSessionsBeforeBaseline— baseline filtering.go test ./...,go vet ./...pass.Migration
v18:
ALTER TABLE loops ADD COLUMN usage_baseline_at INTEGER NOT NULL DEFAULT 0(additive, backward-compatible).Coverage ratchet: ✅ pass
Tolerance: -0.1%. Baseline stored on
gh-pages.