Repository navigation
Restore task spend from the lanes the live ledger counts - #302
Conversation
Planner, worker, judge, and compactor rows rebuild the cap. Main-agent chat, goal decomposition, and side questions stay out, so a restart does not count turns the running process never metered.
BaaRai
left a comment
There was a problem hiding this comment.
Thanks for restoring spend from the database: a restart should not reset the cap.
1. Please add a test for TaskLLMSpend (db/llm_usage.go:44-51). An llm_usage row with worker='judge' and this task_id must be counted; a chat row for the same task must not. The query has no test today, and the Postgres-backed tests skip without a database.
2. Please pin down what the cap means after a restart, with a test. The restore counts the runs recorded before the restart against the cap. That fits a per-task budget (ARTEX_TASK_BUDGET_TOKENS, README.md:255 and 450), so the restore itself is fine. Two things need to be explicit:
- A restored task that is already near the cap only gets the wrap-up margin. Please confirm this is intended, document it next to the budget env vars, and cover it with a test.
RestoreSpendonly adds tospent(agent/budget.go:116-124).workerRunsandworkerSpentstay at 0, soState()falls back to the default worker estimate (agent/budget.go:149-152) even when the task has real worker history. Should the restore also rebuild the per-worker averages? If not, please document that the estimate restarts from the defaults.
3. The comment on seedBudget is wrong. server/engine_budget.go:29-30 says the seed runs "the first time a ledger is created in this process". budgetFor seeds every new ledger (server/engine_budget.go:20-21), and ledgers are deleted and rebuilt inside the same process by resetSettledRun (server/engine_timeout.go:100-102, called on revive from server/goals.go:202) and by StopTask (server/engine.go:295). Please fix the comment, and add a Postgres-backed version of TestResetSettledRunRestartsBudget (server/engine_budget_test.go:66-68 expects a fresh ledger after a revive; without Postgres seedBudget returns early, so the test does not see the reseed).
… count. A task already inside the wrap-up reserve only has that reserve left. The worker estimate starts from the defaults because usage rows have no run boundary.
BaaRai
left a comment
There was a problem hiding this comment.
Thanks, the README and the seedBudget comment now match the behaviour, and the Postgres test pins the revive case near the cap.
One line is still wrong: resetSettledRun (server/engine_timeout.go) says it clears the ledger "so a revived task can plan and claim again with a fresh budget", which the reseed contradicts. Say that the next ledger is seeded from llm_usage, as the README now does.
BaaRai
left a comment
There was a problem hiding this comment.
Thanks, the comment now says the next ledger is seeded from llm_usage. Approved.
Summary
IntentMeter.Recordadds the worker call to the same task spend.llm_usagerows in theplanner,worker,judge, andcompactorlanes. Those calls reach the budget sink. Main-agent chat, goal decomposition, and side questions do not, so they no longer tighten the turn cap after a restart.Test plan
TestRestoreSpendCountsTowardCapandTestBudgetCountsMatchUsageFixture.