Skip to content

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

Merged
BaaRai merged 2 commits into
mainfrom
integr/705-planner-budget
Nov 30, 2026
Merged

BaaRai merged 2 commits into
mainfrom
integr/705-planner-budget

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Summary

Ships the #705 fix from #714 by @brixtonpham in 0.7.1, rebased on current main with three review corrections. The cherry-pick keeps the contributor's authorship; the correction commit is mine.

#705: a task could exhaust its run budget while planner rounds kept starting, and an agent-driven set_goals could revive a timed-out task indefinitely. The report reached 18.4M tokens against a 250k cap. This branch:

  • starts a normal planner round only when the remaining budget covers the planner estimate plus the next worker (BudgetState.Plan replaces Dispatch at the round gate);
  • meters each planner round (PlannerMeter), clamps its turns, blocks intent/goal mutations on forced wrap-up or exhaustion, and stops retrying once ErrTaskBudgetExhausted is raised;
  • skips the final planner round once lifetime spend passes the task budget plus the wrap-up reserve, and cancels in-flight calls immediately instead of draining for the full grace window;
  • refuses automatic agent revival of timed-out, settling or budget-exhausted tasks, while explicit operator revival still works when no budget is exhausted.

Review corrections on top

  1. Operator chat revival (server/server.go). fix(server,agent): enforce planner run budgets and stop revive loops (#705) #714 routed the Main Agent chat through reviveTaskFromAgent, which refuses a timed-out task by logging only: 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.
  2. A real regression test (server/engine_budget_test.go). TestBudgetStopReservesPlannerRoundCost pre-marked the wrap-up before calling budgetStop, so it passed because wrap-up was already set, not because the reservation worked. It now calls budgetStop from Plan alone. I verified the test fails when the gate is reverted to st.Dispatch and passes with st.Plan.
  3. README documents the planner+worker reservation, the skipped final judgment past the hard ceiling, and which revivals are refused.

Verification

  • go build ./... and go vet ./...: PASS.
  • go test -count=1 ./agent ./server on disposable PostgreSQL 16: agent 35.3s, server 125.3s, PASS.
  • go test -race -count=1 ./agent ./server: agent 31.7s, server 222.8s, PASS.
  • TestHardExhaustedBudgetSkipsFinalPlannerRound, TestBudgetStopReservesPlannerRoundCost, TestReviveGuardsPreventTimeoutSettlingAndBudgetLoops: PASS.
  • Mutation check: reverting the round gate to st.Dispatch makes TestBudgetStopReservesPlannerRoundCost fail, so the test is not self-fulfilling any more.
  • gofmt clean on all 11 committed Go blobs (checked on the committed blobs, not the CRLF worktree).

Known limit, documented rather than changed

With a token-only budget and MaxTurns = 0, a normal round's turn allowance stays unlimited, so it can consume the wrap-up reserve before the provider's hard ceiling stops it. The effect is that the final judgment is skipped more often, not unbounded spend. Documented in the README; a token-to-turn estimate would be a separate change.

Not included

The recommended, non-blocking items from the review: a 409 status for refusal paths, a dedicated cancellation cause, and the turn-cap change above. #714 itself will be closed in favour of this branch once merged.

Ships in 0.7.1; the changelog entry is in this branch.

brixtonpham and others added 2 commits November 30, 2026 22:38
Review of #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.
@BaaRai
BaaRai merged commit 0529f6b into main Nov 30, 2026
8 checks passed
esp0xdeadbeef pushed a commit to esp0xdeadbeef/ARTEX that referenced this pull request Nov 30, 2026
upstream: Merge pull request BaaRai#726 from BaaRai/integr/705-planner-budget
overlay:  nix overlay: refresh npm-deps and vendor hashes for upstream 0529f6b

files: flake.nix flake.lock nix .github/workflows/update-flake-lock.yml .github/workflows/sync-upstream.yml scripts/sync-upstream.sh
esp0xdeadbeef pushed a commit to esp0xdeadbeef/ARTEX that referenced this pull request Nov 30, 2026
upstream: Merge pull request BaaRai#726 from BaaRai/integr/705-planner-budget
overlay:  sync-upstream: extend our previous sync commit instead of replacing it

files: flake.nix flake.lock nix .github/workflows/update-flake-lock.yml .github/workflows/sync-upstream.yml scripts/sync-upstream.sh
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.

2 participants