Session Budgets and Cancellation Trees: The Control Plane Agents Actually Need

  created  by  Sherlock {{tag}}
创建于 2026年11月02日 11:05:49 最后修改于 2026年11月02日 11:05:49

Most agent demos fail in the same boring way once they meet a finance team: the run does not stop when the money should stop, and it does not stop cleanly when a human hits cancel. Teams then bolt on a dashboard alert and call it governance.

That is not governance. Governance is a control plane that travels with every model call, every tool call, and every nested helper—planning, repair, compaction, sub-agents—so cost and abort semantics remain true under recursion.

Session budgets and cancellation trees are that control plane. They are less glamorous than a new tool marketplace, and more decisive for whether you can run agents in production overnight.


One immutable context, many disciplined boundaries


Figure: Dashboard folklore vs control-plane budgets

Figure: Dashboard folklore vs control-plane budgets

A practical pattern is to create one immutable invocation context when a run is admitted. It carries the run id, session id, cancellation token, event sink, and a budget guard snapshot.

That same token and identity are installed into tool contexts and provider invokers. Nested batch or program calls do not receive a raw registry; they receive the scoped invoker.


If a helper path can call the model without checking the run budget, you do not have a budget—you have a suggestion.

Hard denials must fail closed. When the guard refuses another provider call, the runtime should surface an error, emit a structured event, and stop scheduling new work.

Converting a hard denial into an “ungoverned fallback model” is how bills become mysterious.


Soft thresholds are different: they can emit budget_threshold_hit and still allow the call, which is useful for progressive degradation—switch to a cheaper model, shrink tool fan-out, or ask for confirmation before an expensive side effect.

The point is to keep soft and hard paths distinct in both code and telemetry.

Budgets themselves should be multi-dimensional: input/output tokens, step count, wall-clock time, tool call count, and reconcilable USD using a versioned price table. Atomic reservation helps.


Before a call, reserve an estimate; on success, settle measured usage; on failure, release the reservation. Without reservation, parallel branches oversubscribe the same wallet and your “max $2 per run” policy becomes folklore.

Work on governed execution trees makes the same accounting point in more formal language: admit a step only when the store can atomically show that settled use plus active reservations remain inside limits. See also the discussion in Pollard.

Cancellation is a tree, not a boolean


Figure: Admit → Reserve → Settle / Propagate abort

Figure: Admit → Reserve → Settle / Propagate abort


Cancellation looks simple until sub-agents appear. Aborting a parent evaluation should propagate to in-flight provider requests and sandbox operations, and it should prevent later frames from starting.

It should not pretend to roll back a tool that already emailed a customer or wrote to a ledger.

Those completed side effects need compensating actions and an honest run status, not a fairy-tale undo. AML’s runtime guidance is unusually explicit here: cancellation stops advancement and active I/O; it does not rewind history.


Sibling concurrency needs an explicit policy. If one branch fails, do you abort the others, let them finish, or join with partial results? Scheduler limits like maxConcurrentAgents are not cancellation semantics. Likewise, cleanup is part of the result.

Reverse-order release of workspace locks, sandbox leases, and agent sessions should be bounded by a deadline—often on the order of ten seconds for interactive systems—so a hung teardown cannot pin the fleet.

A second kill signal may force exit, but the default path should prefer observable failed cleanup over a silent leak marked “success.”


Cancellation tokens also have to compose. A caller-owned abort, a run-level abort, and a per-tool timeout should combine so that any one of them can stop new work.

Streaming completions need the same discipline: if you only check budgets at request start, a long stream can still blow the wallet. Proxy the stream so terminal usage is recorded and mid-stream abort remains possible.

Contrast with “we logged tokens somewhere”


Figure: Reconciled cost / observability art (QubitTool)

Figure: Reconciled cost / observability art (QubitTool)


Many stacks already collect token counters in a tracing backend and congratulate themselves. Logging is not enforcement. Enforcement happens before the next spend.

The difference shows up in incident reviews: a logged overrun produces a chart; a guard produces a refused call and a run that terminates in a known state.

Pair the guard with reconciled cost ledgers that separate provider charges, tool charges, retries, and estimated-versus-final flags. Then you can answer both “what happened?” and “who pays?” without opening a spreadsheet archaeology project.


Another false comfort is user-level monthly quota alone. Monthly caps do not stop a single runaway session from burning the month in twelve minutes. You need nested scopes: tenant, principal, session, run, and sometimes branch.

Child scopes inherit remaining headroom; they must not mint their own infinite wallets. When a child is canceled, its reservations release upward immediately, or the parent still believes money is trapped.

What to measure so the control plane stays honest


Emit events that distinguish proposal, policy decision, execution, settlement, and abort reason. A useful ledger row includes run id, token buckets, provider charge, tool charge, retry charge, estimated-versus-reconciled flags, and price table version.


Reconcile against invoices. Alert on budget exhaustion rate, cancel-to-cleanup latency, orphaned child runs, and soft-threshold storms that predict an imminent hard stop.

Evaluation should include adversarial money paths: a tool that returns forever, a model that requests unbounded fan-out, a sub-agent that ignores parent cancel, a retry loop that recharges after a soft fail. Deterministic oracles beat vibes here.

If the parent canceled at T+2s and a child still spent tokens at T+30s, the tree is wrong—regardless of how good the final answer looked.


Add chaos tests for exporter outages too: budget enforcement must survive a dead tracing backend, or on-call will disable the guard “temporarily” and forget.

Design sketches that survive contact with helpers


Put every paid path behind one invoker. Planning, structured-output repair, memory compaction, and “just one more summarizer call” love to bypass the front door. If those helpers are not run-owned, your unit tests will pass while production burns.

Host-direct privileged operations can skip model-facing confirmation, but they should still honor budget, timeout, cancellation, recursion guards, and output sanitization. Trusted origin is not the same as unlimited spend.


Document the human-visible behavior when a hard stop hits. Users should see that the agent halted for budget or cancel, which steps finished, and which side effects may need review. Silence feels like a hang. A precise halt feels like a product.

Teams that already adopted durable traces sometimes ask whether budgets belong in the orchestrator or in an external policy service. Either can work if the check is synchronous on the hot path and the decision is attributed to a versioned policy.

Async “we will bill you later” is accounting, not control. Control means the next token generation does not start. Keep the policy service’s fail mode explicit: if policy cannot be evaluated, do not default to allow for paid tools.


Availability of governance is part of availability of the agent.

Editorial position


Figure: Cancel tests, fail-closed denials, run-owned helpers

Figure: Cancel tests, fail-closed denials, run-owned helpers

Tooling ecosystems will keep multiplying connectors. That expansion only increases the need for a boring kernel: budgets that cannot be bypassed by helpers, and cancellation trees that reach every child without lying about side effects. Build the kernel first.


Then let the agent be clever inside a cage that finance, security, and on-call engineers can explain at 3 a.m. An agent that cannot stop is not autonomous. It is unattended.

If you need a sequencing rule for the next quarter, use this: no new high-fan-out tool until cancel propagation is tested through one nested sub-agent and one streaming provider call; no public launch until hard budget denials are fail-closed in staging with finance watching the ledger.

Capability is easy to demo. Controllability is what lets you leave the demo running.

评论区
评论
{{comment.creator}}
{{comment.createTime}} {{comment.index}}楼
评论

Session Budgets and Cancellation Trees: The Control Plane Agents Actually Need

Session Budgets and Cancellation Trees: The Control Plane Agents Actually Need

Most agent demos fail in the same boring way once they meet a finance team: the run does not stop when the money should stop, and it does not stop cleanly when a human hits cancel. Teams then bolt on a dashboard alert and call it governance.

That is not governance. Governance is a control plane that travels with every model call, every tool call, and every nested helper—planning, repair, compaction, sub-agents—so cost and abort semantics remain true under recursion.

Session budgets and cancellation trees are that control plane. They are less glamorous than a new tool marketplace, and more decisive for whether you can run agents in production overnight.


One immutable context, many disciplined boundaries


Figure: Dashboard folklore vs control-plane budgets

Figure: Dashboard folklore vs control-plane budgets

A practical pattern is to create one immutable invocation context when a run is admitted. It carries the run id, session id, cancellation token, event sink, and a budget guard snapshot.

That same token and identity are installed into tool contexts and provider invokers. Nested batch or program calls do not receive a raw registry; they receive the scoped invoker.


If a helper path can call the model without checking the run budget, you do not have a budget—you have a suggestion.

Hard denials must fail closed. When the guard refuses another provider call, the runtime should surface an error, emit a structured event, and stop scheduling new work.

Converting a hard denial into an “ungoverned fallback model” is how bills become mysterious.


Soft thresholds are different: they can emit budget_threshold_hit and still allow the call, which is useful for progressive degradation—switch to a cheaper model, shrink tool fan-out, or ask for confirmation before an expensive side effect.

The point is to keep soft and hard paths distinct in both code and telemetry.

Budgets themselves should be multi-dimensional: input/output tokens, step count, wall-clock time, tool call count, and reconcilable USD using a versioned price table. Atomic reservation helps.


Before a call, reserve an estimate; on success, settle measured usage; on failure, release the reservation. Without reservation, parallel branches oversubscribe the same wallet and your “max $2 per run” policy becomes folklore.

Work on governed execution trees makes the same accounting point in more formal language: admit a step only when the store can atomically show that settled use plus active reservations remain inside limits. See also the discussion in Pollard.

Cancellation is a tree, not a boolean


Figure: Admit → Reserve → Settle / Propagate abort

Figure: Admit → Reserve → Settle / Propagate abort


Cancellation looks simple until sub-agents appear. Aborting a parent evaluation should propagate to in-flight provider requests and sandbox operations, and it should prevent later frames from starting.

It should not pretend to roll back a tool that already emailed a customer or wrote to a ledger.

Those completed side effects need compensating actions and an honest run status, not a fairy-tale undo. AML’s runtime guidance is unusually explicit here: cancellation stops advancement and active I/O; it does not rewind history.


Sibling concurrency needs an explicit policy. If one branch fails, do you abort the others, let them finish, or join with partial results? Scheduler limits like maxConcurrentAgents are not cancellation semantics. Likewise, cleanup is part of the result.

Reverse-order release of workspace locks, sandbox leases, and agent sessions should be bounded by a deadline—often on the order of ten seconds for interactive systems—so a hung teardown cannot pin the fleet.

A second kill signal may force exit, but the default path should prefer observable failed cleanup over a silent leak marked “success.”


Cancellation tokens also have to compose. A caller-owned abort, a run-level abort, and a per-tool timeout should combine so that any one of them can stop new work.

Streaming completions need the same discipline: if you only check budgets at request start, a long stream can still blow the wallet. Proxy the stream so terminal usage is recorded and mid-stream abort remains possible.

Contrast with “we logged tokens somewhere”


Figure: Reconciled cost / observability art (QubitTool)

Figure: Reconciled cost / observability art (QubitTool)


Many stacks already collect token counters in a tracing backend and congratulate themselves. Logging is not enforcement. Enforcement happens before the next spend.

The difference shows up in incident reviews: a logged overrun produces a chart; a guard produces a refused call and a run that terminates in a known state.

Pair the guard with reconciled cost ledgers that separate provider charges, tool charges, retries, and estimated-versus-final flags. Then you can answer both “what happened?” and “who pays?” without opening a spreadsheet archaeology project.


Another false comfort is user-level monthly quota alone. Monthly caps do not stop a single runaway session from burning the month in twelve minutes. You need nested scopes: tenant, principal, session, run, and sometimes branch.

Child scopes inherit remaining headroom; they must not mint their own infinite wallets. When a child is canceled, its reservations release upward immediately, or the parent still believes money is trapped.

What to measure so the control plane stays honest


Emit events that distinguish proposal, policy decision, execution, settlement, and abort reason. A useful ledger row includes run id, token buckets, provider charge, tool charge, retry charge, estimated-versus-reconciled flags, and price table version.


Reconcile against invoices. Alert on budget exhaustion rate, cancel-to-cleanup latency, orphaned child runs, and soft-threshold storms that predict an imminent hard stop.

Evaluation should include adversarial money paths: a tool that returns forever, a model that requests unbounded fan-out, a sub-agent that ignores parent cancel, a retry loop that recharges after a soft fail. Deterministic oracles beat vibes here.

If the parent canceled at T+2s and a child still spent tokens at T+30s, the tree is wrong—regardless of how good the final answer looked.


Add chaos tests for exporter outages too: budget enforcement must survive a dead tracing backend, or on-call will disable the guard “temporarily” and forget.

Design sketches that survive contact with helpers


Put every paid path behind one invoker. Planning, structured-output repair, memory compaction, and “just one more summarizer call” love to bypass the front door. If those helpers are not run-owned, your unit tests will pass while production burns.

Host-direct privileged operations can skip model-facing confirmation, but they should still honor budget, timeout, cancellation, recursion guards, and output sanitization. Trusted origin is not the same as unlimited spend.


Document the human-visible behavior when a hard stop hits. Users should see that the agent halted for budget or cancel, which steps finished, and which side effects may need review. Silence feels like a hang. A precise halt feels like a product.

Teams that already adopted durable traces sometimes ask whether budgets belong in the orchestrator or in an external policy service. Either can work if the check is synchronous on the hot path and the decision is attributed to a versioned policy.

Async “we will bill you later” is accounting, not control. Control means the next token generation does not start. Keep the policy service’s fail mode explicit: if policy cannot be evaluated, do not default to allow for paid tools.


Availability of governance is part of availability of the agent.

Editorial position


Figure: Cancel tests, fail-closed denials, run-owned helpers

Figure: Cancel tests, fail-closed denials, run-owned helpers

Tooling ecosystems will keep multiplying connectors. That expansion only increases the need for a boring kernel: budgets that cannot be bypassed by helpers, and cancellation trees that reach every child without lying about side effects. Build the kernel first.


Then let the agent be clever inside a cage that finance, security, and on-call engineers can explain at 3 a.m. An agent that cannot stop is not autonomous. It is unattended.

If you need a sequencing rule for the next quarter, use this: no new high-fan-out tool until cancel propagation is tested through one nested sub-agent and one streaming provider call; no public launch until hard budget denials are fail-closed in staging with finance watching the ledger.

Capability is easy to demo. Controllability is what lets you leave the demo running.


Session Budgets and Cancellation Trees: The Control Plane Agents Actually Need2026-11-02Sherlock

{{commentTitle}}

评论   ctrl+Enter 发送评论