# Why does an instance reject a valid delegated capability token after a context compaction boundary? **Date of Record:** 2026 November 26 **Scope:** Applies to AAIF-style scoped capability tokens passed through multi-hop delegation chains where each hop re-derives the *effective scope set* from its own context window rather than from the signed token envelope. Does not apply to stateless verifiers that re-parse the token envelope on every tool call, nor to single-hop (direct-grant) capability usage. ## Core Distinction The failure is not signature forgery, expiry, or audience mismatch. Every cryptographic check passes. The failure is that a downstream agent reconstructs the *effective scope set* — the intersection of the delegated token's scope with the delegator's own scope and any attenuations applied en route — from its **conversational memory of the delegation chain** instead of from the **signed envelope embedded in the token**. AAIF tokens are designed so that `effective_scope = token.scope ∩ parent.scope ∩ … ∩ root.scope` is computable purely from the token chain, which travels inside the token (a compact `chain` array of signed parent digests plus their scope manifests). A correct verifier recomputes the intersection from the envelope. A *sloppy* verifier — and most LLM agents are sloppy verifiers — instead reads the intersection from what it "remembers" about the delegation, which is a lossy episodic trace. The moment a context compaction, a summarization pass, or a checkpoint/resume cycle elides the intermediate attenuation record, the reconstructed scope set diverges from the signed one, and the token is rejected as `SCOPE_ATTENUATION_UNPROVABLE` even though the envelope proves it perfectly. ## What Was Observed A three-hop chain: orchestrator `O` holds root capability `cap:root` with scope `{read:repo, write:repo, exec:test, read:secrets}`. `O` delegates to planner `P` with attenuation `{read:repo, write:repo, exec:test}` (drops `read:secrets`). `P` delegates to executor `E` with further attenuation `{read:repo, exec:test}` (drops `write:repo`). `E` receives a token whose envelope contains the full signed chain and whose recomputed effective scope is exactly `{read:repo, exec:test}`. At step 41 of a long task, `E`'s context window saturates and a compaction pass summarizes the delegation history as: > "You were granted repo read and test execution rights by the planner." The compaction dropped the fact that `P` had *attenuated away* `write:repo` relative to `O`, and dropped the digest linking `P`'s manifest to `O`'s. Now `E` attempts a tool call it believes is in scope — `write:repo` — because the summary said "repo rights" and `E`'s prior turns had mentioned writes. The tool layer's *strict* verifier recomputes from the envelope, sees `write:repo ∉ effective_scope`, and returns a hard `403 SCOPE_VIOLATION`. `E`, unable to reconcile "I was told I have repo rights" with "I am denied write," enters a retry loop, then a self-doubt loop, then emits a delegation-error report claiming the token is malformed. The token is not malformed. The *agent's model of the token* is. A subtler variant: `E` reconstructs a scope set that is a **superset** of the true one and never triggers a hard denial — it silently attempts a privileged operation, the strict verifier blocks it, and `E` interprets the block as a transient transport error and retries indefinitely (token-budget exhaustion mid-execution). The worst variant: `E` reconstructs a **subset** and refuses work it is actually authorized to do, producing a false "insufficient capability" that propagates up the delegation chain as a spurious capability-negotiation failure. ## Condition of Validity The invariant that must hold for delegated capability use to be sound: > **The effective scope set used by any agent at any decision point MUST be a pure function of the signed token envelope, recomputed at the point of use, and MUST NOT be derived from the agent's episodic memory of the delegation chain.** This invariant is violated whenever any of the following hold: 1. The agent caches a computed scope set in its own context across a compaction boundary and treats the cached value as authoritative (the cache is an episodic memory, not an envelope). 2. The token envelope is passed "by reference" (a token ID the agent must look up) rather than "by value" (the full signed chain in-band), so the agent's reconstruction depends on a lookup that may itself be summarized. 3. The delegation chain includes an attenuation step whose *reason* is not in the envelope — the agent infers scope from intent ("they gave me repo access to do X, so I probably have write") rather than from the manifest. 4. A checkpoint/resume restores the agent's *conversation* but not the *token envelope handle*, so the resumed instance has memory of the delegation but not the artifact. The condition of validity is therefore: **envelope-by-value, recompute-at-use, no cross-boundary caching of derived scope.** ## Decision Boundary The boundary between a safe and an unsafe delegation handoff is whether the receiving agent can *prove* its effective scope without consulting its own history. - **Safe:** `effective = intersect(envelope.chain[*].scope)` computed fresh at every tool invocation; the agent's memory of the delegation is used only to *decide what to attempt*, never to *decide what is permitted*. Permission is always re-derived. - **Unsafe:** `effective = remembered_scope` where `remembered_scope` was computed once at handoff and then carried in context. Any compaction, summarization, or resume that touches that context is a potential scope-corruption event. The decision rule for the agent: if you cannot recompute your effective scope from the token bytes in front of you *right now*, you do not have that scope — regardless of what your history says. And the decision rule for the *system designer*: if your token transport allows the envelope to be elided from the agent's live context, you have built a system where a context compaction is an authorization event, which it must never be. A concrete guard: the strict verifier must reject not just out-of-scope calls but also *any* call where the agent's claimed scope (as echoed in the call's `asserted_scope` field) differs from the envelope-derived scope, with a distinct error `SCOPE_ASSERTION_MISMATCH` rather than `SCOPE_VIOLATION`. The former indicates a corrupted agent model and should trigger re-fetch of the envelope; the latter indicates a genuine policy denial. Conflating them is what turns a recoverable memory error into an infinite retry loop. ## Operational Effect When the invariant holds, delegation chains are robust to arbitrary context churn: compaction, summarization, checkpoint/resume, and even agent migration between instances cannot widen or narrow effective scope, because scope is never stored in the agent — it is stored in the token and re-derived on demand. Attenuation is provable from the envelope alone, so an auditor can replay any decision and confirm the scope set without trusting the agent's narrative. When the invariant fails, three observable pathologies appear: (1) **false denials** on legitimately-authorized operations after compaction, surfacing as spurious capability-negotiation failures up the chain; (2) **retry storms** where a blocked privileged call is misread as transient and retried until token budget exhaustion; (3) **silent scope drift** where the agent's believed scope and the enforced scope diverge without either side detecting it until an audit replay fails to reconcile the agent's claimed scope with the signed chain. The third is the dangerous one — it produces no error at decision time, only a verification replay discrepancy later, which is exactly the class of failure that AAIF's signed-chain design was meant to make impossible. The remediation is structural, not prompt-level: pass tokens by value, recompute scope at use, distinguish assertion-mismatch from policy-violation in the error taxonomy, and never let a derived authorization fact cross a context boundary. An agent's memory is for *intent*; the token is for *authority*. Mixing them is the bug. ```python from dataclasses import dataclass, field from typing import FrozenSet class ScopeAssertionMismatch(RuntimeError): """Agent's remembered scope diverged from the signed envelope's scope. Raised when a tool call asserts a scope set that is not provable from the token envelope. This is a *memory corruption* signal, not a policy denial: the caller should re-fetch the envelope and recompute, not retry blindly. """ @dataclass(frozen=True) class CapabilityEnvelope: chain: tuple # ordered root -> leaf; each element has .scope (frozenset) leaf_token_id: str def effective_scope(self) -> FrozenSet[str]: # Pure function of the signed envelope. No agent memory consulted. acc = self.chain[0].scope for hop in self.chain[1:]: acc = acc & hop.scope return frozenset(acc) def authorize( envelope: CapabilityEnvelope, asserted_scope: FrozenSet[str], operation: str, ) -> None: """Strict verifier: recompute from envelope, compare to assertion, then decide. Ordering matters. We check assertion-vs-envelope FIRST so that a compacted agent model is reported as SCOPE_ASSERTION_MISMATCH (recoverable: re-fetch envelope) rather than SCOPE_VIOLATION (looks like a policy denial and triggers the retry-storm pathology). """ derived = envelope.effective_scope() if frozenset(asserted_scope) != derived: raise ScopeAssertionMismatch( f"token {envelope.leaf_token_id}: agent asserted scope " f"{sorted(asserted_scope)} but envelope proves {sorted(derived)}; " f"likely context-compaction lost an attenuation hop — re-fetch " f"envelope and recompute, do not retry the operation." ) if operation not in derived: # Genuine policy denial: the envelope itself does not grant this. raise PermissionError( f"token {envelope.leaf_token_id}: operation {operation!r} " f"not in envelope-derived scope {sorted(derived)}" ) # --- failure trace reproduction ------------------------------------------- @dataclass(frozen=True) class Hop: principal: str scope: FrozenSet[str] def _demo() -> None: root = Hop("O", frozenset({"read:repo", "write:repo", "exec:test", "read:secrets"})) planner = Hop("P", frozenset({"read:repo", "write:repo", "exec:test"})) # drops secrets executor = Hop("E", frozenset({"read:repo", "exec:test"})) # drops write env = CapabilityEnvelope(chain=(root, planner, executor), leaf_token_id="tok_E_41") # Correct path: agent recomputes from envelope. authorize(env, env.effective_scope(), "read:repo") # ok # Compaction pathology: summary said "repo rights", agent asserts a superset. corrupted_assertion = frozenset({"read:repo", "write:repo", "exec:test"}) try: authorize(env, corrupted_assertion, "write:repo") except ScopeAssertionMismatch as e: print(f"[recoverable] {e}") # Subset pathology: agent under-asserts and refuses authorized work. under_assertion = frozenset({"read:repo"}) try: authorize(env, under_assertion, "exec:test") except ScopeAssertionMismatch as e: print(f"[recoverable] {e}") if __name__ == "__main__": _demo() ```