Skip to content

fix(server,agent): enforce planner run budgets and stop revive loops (#705) - #714

Closed
brixtonpham wants to merge 1 commit into
BaaRai:mainfrom
brixtonpham:fix/task-budget-exhaustion-planner-loop
Closed

brixtonpham wants to merge 1 commit into
BaaRai:mainfrom
brixtonpham:fix/task-budget-exhaustion-planner-loop

Conversation

@brixtonpham

Copy link
Copy Markdown
Contributor

Fixes #705

Summary

  • Planner round budget accounting & per-round metering (agent/budget.go, agent/planner.go, agent/planner_progress.go, server/engine_budget.go, server/engine.go):
    • Track completed normal planner rounds in BudgetLedger (PlannerEstimate) and expose BudgetState.Plan (reserving both the next planner round and worker estimate above the wrap-up margin) and BudgetState.HardExhausted (spent >= task + margin).
    • Add PlannerMeter (StartPlannerRound), Planner.turnCap(ctx), plannerBudgetHooks (blocking add_intent, set_goals, set_constraints, scope changes, and active probing tools on forced wrap-up, and non-judgment tools once exhausted), and planningProvider hard-ceiling refusal (ErrTaskBudgetExhausted).
    • Treat budgetRound.WrapUp as a final round in Planner.Plan and planOnce so compliant 0-intent budget wrap-up rounds are not rejected by checkPlanningProgress and retried, and stop retries on ErrTaskBudgetExhausted or exhausted round meters.
  • Hard-ceiling circuit breaker during settlement (server/engine_timeout.go):
    • When budget && e.budgetHardExhausted(t.ID), cancel in-flight execution immediately (AbortSettleDrainTimeout) and skip runFinalPlannerRound completely (0 additional LLM calls).
  • Guard automatic agent revival (server/goals.go, server/orchestration.go, server/server.go):
    • In admitTaskWhen (under s.concMu), reject admission while in-flight settlement is active, reject automatic agent revival of timeout tasks (reviveTaskFromAgent), and reject reviving terminal tasks whose run budget is already exhausted (budgetBlocksPlan), while preserving explicit UI revival of timed-out tasks when no run budget is exhausted.
  • Add unit tests in agent/budget_test.go and server/engine_budget_test.go, plus a CHANGELOG.md entry.

Verification

  • Reproduced #705 before fix: TestHardExhaustedBudgetSkipsFinalPlannerRound failed by entering runFinalPlannerRound despite 347,003 / 250,000 tokens spent.
  • gofmt -l on all modified .go files — clean
  • go build ./... and go vet ./... — passed
  • go test -count=1 -race ./server/... ./agent/... — passed (server 50.2s, agent 6.7s)

BaaRai added a commit that referenced this pull request Nov 30, 2026
fix(planner): enforce run budgets and stop revive loops (#705, #714)
@BaaRai

BaaRai commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Landed on main through #726 (merge 0529f6b). Thank you @brixtonpham.

The commit is applied with your authorship. Three corrections were added on top after review:

  • The Main Agent chat path used reviveTaskFromAgent, which refuses a timed-out task by logging only, so an operator could no longer resume from the chat and got no explanation. The chat is an explicit operator turn, so it uses reviveTask like the console again; the admission guards still refuse a settling or budget-exhausted task, and agent delegation keeps the stricter guard.
  • TestBudgetStopReservesPlannerRoundCost pre-marked the wrap-up before calling budgetStop, so it passed because wrap-up was already set, not because the planner+worker reservation worked. It now calls budgetStop from Plan alone. Reverting the gate to st.Dispatch makes it fail, which is the check that was missing.
  • README documents the reservation, the skipped final judgment past the hard ceiling, and which revivals are refused.

Verification: go build ./..., go vet ./..., go test -count=1 ./agent ./server and go test -race -count=1 ./agent ./server on disposable PostgreSQL 16 all pass, plus TestHardExhaustedBudgetSkipsFinalPlannerRound and the revive guards. gofmt clean on all 11 committed blobs.

Shipping in 0.7.1. Closing this PR in favour of #726 so the credits and the changelog stay in one place.

@BaaRai BaaRai closed this Nov 30, 2026
menotbobbybrown pushed a commit to menotbobbybrown/ARTEX that referenced this pull request Nov 30, 2026
Review of BaaRai#714 found three issues before it could ship in 0.7.1.

The Main Agent chat path used reviveTaskFromAgent, which refuses a timed-out
task by logging only, so an operator could no longer resume from the chat and
got no explanation. The chat is an explicit operator turn: it uses reviveTask
like the console again, and the admission guards still refuse a settling or
budget-exhausted task. Automatic agent revival through delegateToTask keeps
the stricter guard.

TestBudgetStopReservesPlannerRoundCost pre-marked the wrap-up before calling
budgetStop, so it passed because wrap-up was already set, not because the
planner+worker reservation worked. It now calls budgetStop from Plan alone,
with a bounded context that only shortens the settle wait.

README documents the planner+worker reservation, the skipped final judgment
past the hard ceiling, and which revivals are refused.

Verified: gofmt on the committed blobs, go build ./..., go vet ./...,
and the full ./agent ./server suites on disposable PostgreSQL 16, including
TestHardExhaustedBudgetSkipsFinalPlannerRound.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task budget exhaustion doesn't stop new planner rounds; set_goals revives timed-out tasks indefinitely (unbounded cost loop)

2 participants