Repository navigation
Conversation
`agent_close` only set the in-memory handle's flag. The durable row kept the status of the child's last run, so a later turn — which builds a fresh pool and has no handle at all — read `completed` and resumed the child. `_resume_from_registry` already refuses a `closed` row, but nothing ever wrote one. Observed in a live acceptance turn: `agent_close` returned success, then `agent_send` to the same id came back `delivery: "resumed"`. - `close` now writes `closed` onto the row before cancelling. - `_settle_child` keeps it `closed` instead of overwriting it with the `cancelled` that the close-triggered cancel produces. That overwrite would have restored exactly the resumable state this fix removes. - `shutdown` still marks handles closed, but that is the turn ending rather than the user giving up: those rows settle as `cancelled` and stay resumable. A `pool_gone` flag keeps the two apart — without it, the existing "interrupted by shutdown is not terminal" test fails, correctly. Tests: close writes the row; closing a running child is not settled as cancelled; a fresh pool still finds the row closed and unresumable. Signed-off-by: Wang Tai <i@wangtai.me>
The tree-wide token budget is gone. It answered the wrong question: it
stopped a task partway through, left children at `budget_exhausted` waiting
for a human to click resume, and never once fired in a real product run —
`budgetTokens` is not sent by any of the three products, so the gate that
was written to protect them had never executed.
What it was costing: a live acceptance turn of four sub-agents spent
934,882 tokens (~¥0.24). Stopping that at a limit would have thrown away
most of a cent's worth of completed work and left the user with a
half-finished refactor, which is a worse outcome than the spend.
- `TreeBudget` / `SessionBudgetExceeded` / `budget.py` → `TreeSpend` /
`spend.py`: `record(usage, agent=...)` and `report() -> {spent, by_agent}`.
No limit field, no exception, no way to add one.
- `AgentPool(budget=...)` → `AgentPool(spend=...)`; `spawn` no longer refuses
when the tree is "exhausted" (there is nothing to exhaust), and the
`budgetExceeded` field on `child_completed` is gone with it.
- `stream.done.treeUsage` is now `{spent, byAgent}` and always present, since
the figure is for display. A host cannot tell "no limit" from "spent
nothing" any more because there is no limit to tell apart.
- `budgetTokens` keeps its older, separate job: capping the parent run's own
loop via `BudgetLimit`. That path is untouched.
Why not fix the enforcement timing instead (charge per round so the wall
lands earlier)? Because the wall itself is the problem. A turn that runs
long had more work, not a failure; cost control belongs before a turn starts
or on a period budget, not inside one already half done.
R6's per-turn bill is the replacement surface, and it needed no change: it
reads the same usage numbers, which the tree counter still records.
Verified: 2612 py tests, 1646 agent-shell tests, tsc clean, doc gates green.
Signed-off-by: Wang Tai <i@wangtai.me>
Signed-off-by: Wang Tai <i@wangtai.me>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two runtime fixes carried since 0.12.0. No new features.
1. A closed child stays closed (
fbcc10c3)agent_closeonly set the in-memory handle's flag. The durable row kept its last run's status, so a later turn — which builds a fresh pool and has no handle at all — readcompletedand resumed a child the user had explicitly closed._resume_from_registryalready refused aclosedrow; nothing ever wrote one.Observed in a live acceptance turn:
agent_closereturned success, thenagent_sendto the same id came backdelivery: "resumed".closewritesclosedbefore cancelling._settle_childkeeps itclosedrather than overwriting with thecancelledthat the close-triggered cancel produces.shutdownstill leaves rows resumable: a turn ending is not the user giving up. Apool_goneflag separates the two.2. The tree token budget is removed (
18f7b7c1)It answered the wrong question. Evidence:
budgetTokens, so the gate written to protect them had never executed.TreeBudget/SessionBudgetExceeded/budget.py→TreeSpend/spend.py:record(usage, agent=...)+report() -> {spent, by_agent}. No limit, no exception, no way to add one.stream.done.treeUsageis now{spent, byAgent}and always present.budgetTokensitself is untouched — it keeps its older job of capping the parent run's own loop viaBudgetLimit. So aremaxParallel(orchestration_budget_exceeded) andmaxRounds(budget_exhausted); neither is a token limit.R6's per-turn bill needed no change: it reads the same usage numbers, which the counter still records.
Breaking change
TreeBudget,TreeBudgetReport,SessionBudgetExceededwere exported fromsteerable_agent_runtimesince 0.10. Removed per the repo's pre-stable convention; the migration note is inagent-runtime/py/README.md→ "Upgrading from 0.10".Verification
tsc --noEmitcleancheck_docs_drift/check_doc_anchorsgreenMade with Cursor