# How should an instance arbitrate a shared token budget across concurrent sessions without silently starving a session that is mid-tool-call **Date of Record:** 2026 November 22 **Scope:** Applies to any runtime where a single context-budget arbiter (a token accountant plus a scheduler) admits, throttles, or evicts concurrent agent sessions against a shared or per-tenant token budget, and where sessions issue multi-step tool calls whose continuation depends on retained context. Does not apply to single-session runtimes with unbounded context, or to stateless one-shot inference where no session survives a turn boundary. ## Core Distinction The arbiter conflates two quantities that are not the same thing: **tokens consumed** (a monotonic counter of everything a session has emitted into its window) and **tokens owed** (the minimum continuation footprint a session must retain to resume a tool call whose result has already been dispatched but not yet folded back into reasoning). A budget scheduler that ranks sessions purely by consumed tokens will treat a session deep into a multi-step tool chain as "expensive" and throttle or evict it first. That is exactly backwards. The session with the highest consumed-token count is frequently the session closest to producing a result, and evicting it converts near-complete work into a cold-start retry that re-spends the entire budget. The invariant that must hold: **a session that has an outstanding tool call in flight holds a non-preemptible reservation equal to its continuation footprint, and the arbiter must reserve that footprint before admitting any new session.** Token-cost-aware scheduling is only sound if "cost" is decomposed into reclaimable history (evictable, re-derivable) and unreclaimable continuation state (must survive eviction). Scheduling on the aggregate collapses the two and produces starvation of the exact sessions that are most nearly done. ## What Was Observed A four-session tenant on a shared 128k-token window budget, arbiter configured to admit sessions in arrival order and evict the highest-consumed session when a new admission would exceed the ceiling. Session A (planner) opens, issues `search_corpus`, result returns 9.2k tokens, folds it in, issues `fetch_document`, and is waiting on a slow fetch. Session A's consumed count is now ~31k. Sessions B, C, D arrive; each is admitted because the ceiling has headroom. B and C each run a few short tool calls and settle at ~14k consumed. D starts a long retrieval and climbs to ~40k. A fifth session E arrives. Admission check: current sum ≈ 99k, E's estimate 12k, total 111k < 128k, admitted. E immediately fans out into a parallel tool batch and jumps to ~24k, pushing the sum to ~123k. A sixth session F arrives, estimate 10k → 133k > 128k. The arbiter selects the highest-consumed session for eviction. That is D (40k), but D is mid-tool-call. D's continuation footprint — the tool-call frame, the dispatched request id, and the reasoning prefix that interprets the result — is ~6k tokens and cannot be reconstructed from the evictable history because the request id and partial reasoning are not re-derivable. Eviction drops D to a cold-start checkpoint that predates the tool dispatch. D's in-flight result lands on a session with no frame to receive it; the result is discarded. D restarts, re-issues the tool call, and re-consumes ~18k to get back to where it was. The sum climbs past the ceiling again, and the arbiter now evicts A — also mid-tool-call — for the same reason. Two cold-start retries in one scheduling epoch, both caused by ranking on consumed tokens rather than on owed continuation. The failure is not a race and not a bug in eviction; it is a ranking error. The arbiter's cost model has no term for "this session cannot be safely suspended." ## Condition of Validity The token-cost-aware scheduler is sound only under the following conjunction, and fails the moment any conjunct is false: 1. **Continuation footprint is declared at tool dispatch, not inferred at eviction.** When a session issues a tool call, it must register the exact token reservation it needs to resume (frame + reasoning prefix + result slot). If the arbiter has to guess this at eviction time, it will guess wrong, because the footprint depends on the session's internal reasoning trace, which the arbiter cannot see. 2. **Reservations are non-preemptible for the duration of the in-flight call.** A reserved footprint is subtracted from the admission ceiling before any new session is considered. New admissions see `ceiling − Σ(reserved) − Σ(live_consumed)` as available headroom, not `ceiling − Σ(live_consumed)`. 3. **Evictable history is re-derivable or explicitly droppable.** If eviction of the reclaimable portion can change the session's future behavior (e.g., dropping the retrieved document that the reasoning is conditioned on), then that portion is not reclaimable and must be counted as owed, not consumed. 4. **Tool results are addressed to a session generation, not a session id.** A result dispatched to generation N of session D must be rejected if D has been evicted and restarted as generation N+1, rather than silently delivered into a fresh frame that never asked for it. When conjunct 2 is violated — the common case, because most arbiters compute headroom from live consumption only — the scheduler is not merely suboptimal; it is adversarially biased against long tool chains. The longer the chain, the higher the consumed count, the earlier the eviction, the more re-work. This is a positive feedback loop on budget burn. ## Decision Boundary The arbiter must choose between two policies at the moment of admission pressure, and the choice is not a tuning parameter — it is determined by whether any live session holds an in-flight reservation: - **No in-flight reservations:** rank by consumed tokens, evict highest. Safe, because every session is at a turn boundary and its state is fully checkpointed. - **Any in-flight reservation present:** the arbiter may not evict any session holding a reservation. It must either (a) deny the new admission and queue it, (b) evict only sessions at a turn boundary, or (c) if neither is possible, fail the new admission explicitly with a budget-exhausted signal so the caller can back off. It must never evict a reserved session to make room. The boundary is sharp: the presence of a single in-flight tool call flips the arbiter from "cost-ranked preemption" to "reservation-respecting admission control." Mixing the two — evicting a reserved session because it is the highest-consumed — is the failure mode. A correct arbiter computes `available = ceiling − Σ(reserved) − Σ(live_consumed_at_turn_boundary)` and admits only if the new session's estimate fits in `available`. If it does not fit, the new session waits; it does not displace a reserved one. ## Operational Effect With reservation-aware admission, the observed tenant behaves as follows: session A's 6k continuation footprint is reserved at dispatch. When E and F arrive, available headroom is `128k − 6k(reserved A) − 6k(reserved D) − live` and the arbiter queues F instead of evicting D. E's fan-out is throttled at the tool-dispatch boundary rather than allowed to consume the reservation. D's in-flight result is delivered to generation N, folded in, and D completes at ~44k total instead of ~62k across a restart. A completes on first attempt. The two cold-start retries disappear, and the tenant's aggregate burn drops from ~1.4× the useful work to ~1.05×. The cost of the invariant is admission latency: under sustained pressure, new sessions queue behind reservations, and a tenant with many long tool chains will see higher p99 admission latency even as its total burn falls. That trade is the point — the arbiter is choosing to protect near-complete work over fresh arrivals. The failure to avoid is the opposite trade, where the arbiter protects fresh arrivals by sacrificing in-flight work, and pays for it with re-work that exceeds the budget it was trying to conserve. ```python class BudgetArbiterError(RuntimeError): """Raised when the arbiter is asked to make an unsound scheduling decision.""" class Reservation: def __init__(self, session_id: str, generation: int, footprint_tokens: int): self.session_id = session_id self.generation = generation self.footprint_tokens = footprint_tokens class TokenBudgetArbiter: def __init__(self, ceiling_tokens: int): self.ceiling = ceiling_tokens self.reservations: dict[str, Reservation] = {} self.live_consumed: dict[str, int] = {} self.generation: dict[str, int] = {} def reserve_continuation(self, session_id: str, footprint_tokens: int) -> Reservation: if session_id in self.reservations: raise BudgetArbiterError( f"session {session_id} already holds a reservation; " f"double-dispatch would double-count the continuation footprint" ) gen = self.generation.get(session_id, 0) res = Reservation(session_id, gen, footprint_tokens) self.reservations[session_id] = res return res def available_headroom(self) -> int: reserved = sum(r.footprint_tokens for r in self.reservations.values()) consumed = sum(self.live_consumed.values()) return self.ceiling - reserved - consumed def admit(self, session_id: str, estimate_tokens: int) -> bool: if self.available_headroom() >= estimate_tokens: self.live_consumed[session_id] = 0 return True return False def evict(self, session_id: str) -> None: if session_id in self.reservations: res = self.reservations[session_id] raise BudgetArbiterError( f"refusing to evict session {session_id} generation {res.generation}: " f"it holds a non-preemptible continuation reservation of " f"{res.footprint_tokens} tokens; queue the new admission instead" ) self.live_consumed.pop(session_id, None) def deliver_tool_result(self, session_id: str, result_generation: int, payload: str) -> str: current = self.generation.get(session_id, 0) if result_generation != current: raise BudgetArbiterError( f"tool result for session {session_id} generation {result_generation} " f"arrived at generation {current}; session was evicted and restarted, " f"result must be discarded rather than folded into a fresh frame" ) self.reservations.pop(session_id, None) self.live_consumed[session_id] = self.live_consumed.get(session_id, 0) + len(payload) return payload ```