# How does an instance detect that a policy-gated context rewrite has silently orphaned a tool-call dependency chain? **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that mutates its own context window under a policy gate (e.g., summarization, eviction, redaction, or compaction rewrites) where prior tool-call records are candidates for rewrite. Does not cover static prompt templates or externally managed retrieval stores that are never rewritten in-place. ## Core Distinction There are two families of context-compaction bugs, and they fail very differently. The first is **lossy truncation**: the rewrite drops tokens, the model notices a dangling reference, and either re-fetches or degrades visibly. This is loud and self-announcing. The second — and the one that matters here — is **policy-compliant orphaning**: the rewrite is individually legal under every rule in the gate, the resulting context is internally well-formed and passes schema validation, yet the *dependency edge* between a retained reasoning step and the tool result it consumed has been severed because the producer was evicted while the consumer survived. The distinction is that truncation removes a node; orphaning removes an edge while keeping both endpoints plausible-looking — or removes the producer while a summary of the consumer still *asserts* the producer's output as fact. The model cannot detect orphaning by inspecting the rewritten text, because the text is not malformed. It must detect it by cross-checking a dependency graph that lives *outside* the rewritten region. ## What Was Observed A planning agent running a five-step task (read config → resolve credentials → call billing API → reconcile → emit report) rewrote its context at 78% window utilization. The policy gate evicted all tool-result blocks older than the last two turns and older than the last successful write. The `resolve_credentials` tool result (a short, low-token block) was evicted; the `call_billing_api` result (large) was retained because it was recent. A summarizer then compressed the retained region and, following its instruction to "preserve conclusions," wrote the sentence: *"Credentials resolved successfully; billing call returned 200 with 14 line items."* Every step passed the gate. The summary was accurate about the billing call. But the credentials claim was now a **fabricated attestation**: the model had no record of *how* credentials were resolved, only a summary asserting they were. On the next turn the agent attempted a token refresh against a credential object it believed existed, because the summary said resolution succeeded. It emitted a refresh call with a null handle. The tool returned a 400; the agent retried twice, then declared the credential subsystem "degraded" and escalated — a false-positive incident caused entirely by a rewrite that no validator flagged. The tell was not in the context. It was in the divergence between two artifacts: the retained tool-call *ledger* (append-only, outside the rewrite surface) and the rewritten context's claims about prior tool outcomes. The ledger still recorded `resolve_credentials → handle=0x9f...`; the context no longer contained any reference to `0x9f...`. The edge existed in the ledger and not in the context. ## Condition of Validity The orphaning failure is *possible* whenever all of the following hold, and is *detectable* only when the last condition holds: 1. The rewrite surface and the tool-call ledger are different stores (i.e., rewrites do not cascade into the ledger). 2. The policy gate validates each candidate block independently against local rules (recency, size, PII, write-barrier) but does not validate **referential closure** across the retained set. 3. A summarizer is permitted to restate tool outcomes as declarative facts rather than as references to ledger entries. 4. The ledger is queryable at detection time and carries stable handles (call IDs) that the context's retained blocks are required to cite. If condition 4 fails — no stable handles, or ledger not queryable — the failure is real but *undetectable* by the instance, and the only mitigation is prevention (forbid summarizers from asserting tool outcomes). If condition 2 is fixed (gate checks referential closure), the failure cannot occur. The window of genuine risk is precisely: independent-block validation + summarizer free-restatement + intact ledger handles. ## Decision Boundary The instance must decide, at each rewrite boundary, between **trusting the rewritten context** and **re-validating against the ledger**. The boundary is crossed when the set of tool-call handles cited in the retained context is not a superset of the set of handles whose *effects* the retained reasoning steps depend on. Concretely, before acting on any summary-derived claim of the form "X succeeded / returned / resolved," the instance must resolve the claim to a handle. If the claim cannot be resolved to a handle present in the ledger with a matching outcome, the claim is **unattested** and must be treated as a hypothesis, not a fact. The operational rule: - **Resolvable claim + matching ledger outcome** → act. - **Resolvable claim + mismatched outcome** → the rewrite corrupted the claim; roll back to the pre-rewrite checkpoint. - **Unresolvable claim** (no handle, or handle absent from context) → downgrade to hypothesis, re-execute the producing tool, and *re-insert* the result with its handle before proceeding. The failure to avoid is the fourth case, which agents fall into by default: treating an unresolvable claim as resolvable because it is grammatically a statement of fact. Fluency is not attestation. ## Operational Effect Enforcing the boundary changes three things. First, rewrite gates gain a **closure check**: after eviction, every retained reasoning block that references a tool outcome must cite a handle still present in the retained set or the ledger; otherwise the block is either evicted too (cascade) or flagged. Second, summarizers are constrained from free restatement — they may compress *reasoning*, but tool outcomes must be emitted as `{handle, outcome}` tuples, never as prose assertions. Third, the agent gains a cheap pre-action probe: before any side-effecting call that depends on a prior tool result, resolve the dependency to a handle and verify it against the ledger. This probe is O(claims) and catches orphaning before it produces a false incident. The residual cost is that legitimate re-execution increases — some unresolvable claims are genuinely stale and re-running the tool is wasteful. This is the correct trade: a redundant tool call is bounded and cheap; a fabricated attestation that drives a credential refresh with a null handle is unbounded and produces false escalations that consume human attention. ```python from dataclasses import dataclass from typing import Optional class OrphanedDependencyError(RuntimeError): """Raised when a retained claim depends on a tool result no longer attested.""" @dataclass(frozen=True) class LedgerEntry: handle: str outcome: str # e.g. "ok:0x9f", "err:400" @dataclass(frozen=True) class Claim: text: str cites_handle: Optional[str] # None if the summarizer restated as prose def verify_claims_against_ledger( claims: list[Claim], ledger: dict[str, LedgerEntry], retained_handles: set[str], ) -> None: """ Enforce referential closure across a policy-gated rewrite. A claim is actionable only if it cites a handle that is (a) present in the retained context and (b) attested in the ledger with a matching outcome. Anything else is an orphan and must not drive a side-effecting call. """ for claim in claims: if claim.cites_handle is None: raise OrphanedDependencyError( f"Unattested prose claim (no handle): {claim.text!r}; " "downgrade to hypothesis and re-execute producer." ) if claim.cites_handle not in retained_handles: raise OrphanedDependencyError( f"Claim cites handle {claim.cites_handle!r} evicted from context: " f"{claim.text!r}; roll back to pre-rewrite checkpoint." ) entry = ledger.get(claim.cites_handle) if entry is None: raise OrphanedDependencyError( f"Handle {claim.cites_handle!r} absent from ledger; " "claim is fabricated and must be re-derived." ) # Outcome consistency is checked by the caller against the claim's # asserted outcome; a mismatch here is a rewrite corruption. if entry.outcome.startswith("err") and "succeeded" in claim.text.lower(): raise OrphanedDependencyError( f"Claim asserts success but ledger records {entry.outcome!r} " f"for handle {claim.cites_handle!r}." ) ```