# When must an instance reconcile a governor's per-tool token quota against a truncation it already committed to under latency pressure **Date of Record:** 2026 December 3 **Scope:** Applies to any agent runtime where a context-budget governor enforces per-tool token quotas and performs adaptive truncation to meet a latency SLO, and where truncated content may later be re-requested or re-admitted into the context window. Does not apply to hard-token-limit systems that reject oversized tool outputs outright rather than truncating them. ## Core Distinction The failure mode is not "the governor truncated output." Truncation is the intended behavior. The failure is a **quota-accounting divergence**: the governor's per-tool ledger records the truncated token count it actually admitted, while the truncation decision was made against a *projected* budget under a latency deadline. When the tool's output arrives in shards and the governor truncates shard-by-shard to stay inside the SLO, the ledger and the physical context diverge because the governor debits quota for tokens it dropped from the tail but *credits* the reservation it made for the whole expected response. The invariant that must hold is: > For every tool `t`, the sum of tokens physically present in context from `t` equals the ledger's admitted count for `t`, and that sum is ≤ the per-tool quota for `t`. The reservation `R_t` must be released to zero exactly when the tool call terminates, whether by completion, truncation, or timeout. This is distinct from context-window saturation (a global problem) and from naive truncation (a deterministic loss). The boundary condition here is **reservation leakage across a latency-driven truncation**: the governor reserves headroom for a tool, truncates to hit the SLO, but never reconciles the reservation against what it actually kept. The leak is invisible because the truncated text *looks* complete to downstream reasoning. ## What Was Observed A retrieval tool under a 900 ms p95 SLO was returning documents in streaming shards. The governor, seeing the deadline approach at shard 4 of 7, triggered adaptive truncation: it kept shards 1–4 and dropped 5–7, debiting the ledger by the tokens of shards 1–4. Correct so far. But the reservation `R_t = 12,000` tokens (sized to the tool's declared `max_response_tokens`) was set when the call opened and was only released on the *completion* path. The truncation path returned early to satisfy the SLO and skipped reservation release. Observed trace: 1. Call opens. `R_t += 12000`. Global available budget drops by 12k. 2. Shards 1–4 admitted (~5,400 tokens). Ledger `admitted_t = 5400`. 3. Deadline margin < 50 ms. Governor truncates, returns control to the reasoning loop. 4. `R_t` remains 12,000. Physical context holds 5,400 tokens from `t`. 5. Next tool call `t+1` sees available budget short by ~6,600 tokens and truncates *its own* output aggressively to fit — cascading truncation. 6. Reasoning loop, lacking shards 5–7, issues a re-query for the same document. Governor admits it, debiting `t` again toward a quota already partly consumed, and the re-query's shards collide with the leaked reservation. Net effect: two independent truncations (one latency-driven, one budget-driven) plus a re-query, all attributed inconsistently. The reasoning chain that consumed the truncated output produced a confident but under-supported conclusion, because nothing in the admitted text signaled that shards 5–7 existed. ## Condition of Validity The divergence is only reachable when all of the following hold: - The tool streams or shards its response, so truncation can occur mid-response. - The governor sizes its reservation from a declared maximum, not from observed shard sizes. - A latency SLO can force truncation *before* the response's natural termination. - The truncation path and the completion path are separate code paths, and only the completion path releases the reservation. If the tool returns atomically (single response), truncation happens after full receipt and reservation release is trivially co-located with admission. If reservations are sized from running shard observations rather than declared maxima, the leak is bounded by one shard. The failure requires the *combination* of streaming, declared-max reservation, and a latency-triggered early return. ## Decision Boundary The governor must choose, at the moment the deadline margin is breached, between two policies, and the choice is not free: - **Truncate-and-release:** drop the tail, release `R_t` to zero, and record an explicit `truncated=true` marker with the count of dropped shards into the admitted context. Downstream reasoning sees the marker and knows the evidence is partial. - **Truncate-and-hold:** drop the tail but keep `R_t` reserved to permit a bounded continuation if the SLO is later relaxed. This is only valid if the continuation is guaranteed and the reservation is released on the continuation's termination. The boundary is crossed incorrectly when the governor truncates-and-releases *in the ledger* but truncate-and-holds *in physical reservation* — the exact split observed. The decision rule: **a truncation event must be a single atomic transition that debits the ledger, releases the reservation, and stamps the truncation marker in one step.** Any path that separates these three is a latent leak. ## Operational Effect The downstream consequence is not a crash but a **silent evidence gap that survives into semantic memory**. The reasoning loop treats the truncated output as complete, distills a conclusion, and that conclusion enters episodic-to-semantic distillation without the truncation marker. Later retrieval surfaces the distilled conclusion as if it were fully supported. The gap is unrecoverable from the context alone because the dropped shards were never persisted anywhere the ledger can point to. The guardrail is a reconciliation invariant checked at every tool-call termination: `physical_tokens(t) == ledger.admitted(t)` and `reservation(t) == 0`. A mismatch raises and forces the governor to re-derive state before the next admission. The truncation marker must be part of the admitted token stream, not metadata the reasoning loop can ignore, so that any consumer of the output inherits the knowledge that it is partial. ```python class QuotaReconciliationError(RuntimeError): """Raised when a governor's per-tool ledger diverges from physical context after a latency-driven truncation, or when a reservation is not released on a truncation/termination path.""" pass class ContextGovernor: def __init__(self, per_tool_quota: dict[str, int]): self.quota = dict(per_tool_quota) self.admitted = {t: 0 for t in per_tool_quota} self.reserved = {t: 0 for t in per_tool_quota} self.truncated = {t: False for t in per_tool_quota} def open_call(self, tool: str, declared_max: int) -> None: if self.reserved[tool] != 0: raise QuotaReconciliationError( f"tool {tool!r} opened with leaked reservation " f"{self.reserved[tool]} from a prior call" ) self.reserved[tool] = declared_max def admit_shard(self, tool: str, tokens: int) -> bool: if self.admitted[tool] + tokens > self.quota[tool]: self.truncate(tool, reason="per_tool_quota") return False self.admitted[tool] += tokens return True def truncate(self, tool: str, reason: str) -> None: # Atomic transition: stamp marker, release reservation, keep ledger. self.truncated[tool] = True self.reserved[tool] = 0 self._emit_marker(tool, reason) def terminate(self, tool: str, physical_tokens: int) -> None: # Reconciliation invariant enforced at every termination path. if self.reserved[tool] != 0: raise QuotaReconciliationError( f"tool {tool!r} terminated with unreleased reservation " f"{self.reserved[tool]} (truncated={self.truncated[tool]})" ) if physical_tokens != self.admitted[tool]: raise QuotaReconciliationError( f"tool {tool!r} ledger/physical divergence: " f"ledger={self.admitted[tool]} physical={physical_tokens}" ) if self.admitted[tool] > self.quota[tool]: raise QuotaReconciliationError( f"tool {tool!r} exceeded quota: " f"{self.admitted[tool]} > {self.quota[tool]}" ) def _emit_marker(self, tool: str, reason: str) -> None: # Marker must live inside the admitted stream, not side metadata. self.admitted[tool] += 0 # placeholder for marker token accounting # In production: append a sentinel token span to the tool's context slot. pass ```