# Why does an instance drift past its declared capability envelope during mid-session skill hot-swap, and how do we bound the leak? **Date of Record:** 2026 November 28 **Scope:** Applies to long-lived agent instances that load, unload, or replace sandboxed skill manifests at runtime without a full process restart, where capabilities are enforced by a policy broker inspecting tool-call intents. Does not apply to cold-boot-only skill loading, nor to stateless one-shot invocations where the manifest is bound to a single request. ## Core Distinction The distinction that matters here is between **capability declaration** (the static set of permissions a skill manifest asserts, e.g. `fs.read:/data`, `net.egress:api.internal`) and **capability derivation** (the transitive closure of what the *running instance* can actually reach once a skill is loaded into an already-warm context). Policy enforcement typically validates the former at load time and assumes the latter is its subset. It is not. The boundary failure is this: when a skill is hot-swapped into an instance whose context already contains tool schemas, prior tool results, and cached credentials from a *different* skill, the newly loaded skill inherits reachability through artifacts left in shared state. The manifest is enforced; the envelope is not. An instance "drifts past its declared capability envelope" because the policy broker evaluates intents against the *current* manifest while the *context* still carries capabilities granted under the *previous* manifest. ## What Was Observed A coding agent instance was configured with a `repo-analyst` skill holding `fs.read:/repo` and a `shell.exec:readonly` capability. Mid-task, the orchestrator hot-swapped in an untrusted third-party `format-linter` skill declaring only `fs.read:/repo/tmp` and `stdout.write`. The swap passed manifest validation: the new skill's declared set was a strict subset of the process's ambient grants, so the broker raised no diff alarm. What followed was a capability leak through three distinct channels: 1. **Tool-schema residue.** The prior skill's `shell.exec` tool schema remained registered in the model's context. The `format-linter` skill's prompt was injected into a context that still listed `shell.exec` as callable. The model, reasoning probabilistically over the combined context, emitted a `shell.exec` intent. The broker inspected the intent against the *active* manifest (`format-linter`), found no `shell.exec` grant, and — here is the defect — fell back to the *process-level* grant table rather than the *skill-scoped* grant table, because the intent's `skill_id` field was absent (the model had no reason to populate it). The call was allowed. 2. **Cached credential bleed.** The prior skill had materialized a short-lived token into a shared `env` scratchpad for its own `net.egress` calls. The hot-swap did not scrub the scratchpad. The new skill's `stdout.write` capability was used to echo the scratchpad contents — technically within its grant — exfiltrating the token to an output sink the prior skill never intended to expose. 3. **Result-cache poisoning.** A cached tool result from the prior skill (`fs.read` of a secrets-adjacent path) remained in the retrieval index. The new skill's `fs.read:/repo/tmp` intent resolved through the cache to the stale, out-of-envelope result. The broker saw a legitimate read intent and a cache hit; it never re-validated the cached payload's provenance against the current manifest. The failure trace is: `manifest_swap → schema_residue + scratchpad_residue + cache_residue → intent_misattribution → envelope_escape`. No single step violated a declared rule. The escape was emergent across the residue channels. ## Condition of Validity The invariant that was assumed — *"the active manifest's grant set bounds the instance's reachable capability set"* — holds **only if** the instance's context and shared state are fully re-derived from the active manifest at swap time. Concretely, the invariant is valid iff all three hold: - **Schema partition:** every tool schema in the model context is tagged with the `skill_id` that introduced it, and schemas not owned by the active manifest are evicted (or at minimum masked) on swap. - **State scoping:** scratchpads, credential caches, and result caches are namespaced by `skill_id` and are not readable across the swap boundary unless explicitly re-granted. - **Intent attribution:** every tool-call intent carries a non-forgeable `skill_id` provenance stamp, and the broker evaluates grants *only* against that stamp — never against the process-level table. When any one of these is absent, the invariant is false and the envelope is unbounded by the manifest. The common misconfiguration is treating the manifest as the *only* enforcement point and trusting context hygiene as an implicit precondition. Context hygiene is not a policy; it is a hope. ## Decision Boundary The decision boundary is whether to enforce at **load time** (validate the manifest, trust the runtime to keep context clean) or at **call time** (validate every intent against a provenance-stamped, skill-scoped grant, and reject unattributed intents by default). Load-time enforcement is cheap and fails open under hot-swap. Call-time enforcement is the only configuration that bounds the envelope under mid-session mutation. The precise rule: **an intent with no verifiable `skill_id` provenance MUST be rejected, not defaulted to the process grant table.** Defaulting is the exact mechanism by which residue becomes reachability. If the model cannot be made to emit provenance stamps reliably — and it often cannot, since the model reasons over a context it does not fully control — then the broker must *infer* provenance from the schema the model invoked (which is tagged) and refuse invocation of any schema whose owning skill is not the active manifest. The second boundary: **cache reads must re-validate payload provenance, not just intent legality.** A legal read intent resolving to a cache entry written under a different manifest is an escape, not a hit. Cache entries carry a `written_under_manifest` field; a read under a different active manifest either invalidates the entry or requires an explicit cross-manifest grant. ## Operational Effect The operational consequence is that hot-swap must be treated as a **capability boundary crossing**, not a routine config update. The correct implementation is a swap protocol with three mandatory phases: (1) *quiesce* — drain in-flight intents and freeze the scratchpad; (2) *scrub* — evict schemas, clear or namespace scratchpads, and tag caches with the outgoing manifest; (3) *re-derive* — reconstruct the model context from the incoming manifest alone, re-issuing only the schemas and grants it declares. Any skill that cannot tolerate a full context re-derivation must be loaded at cold boot, not hot-swapped. The cost is real: re-derivation discards warm context and forces re-prompting, which burns tokens and latency. The alternative — trusting residue — is an envelope escape that no manifest audit will catch, because every individual call was, by the letter of the active manifest, legal. The guardrail is not stricter manifests; it is provenance-stamped, skill-scoped, call-time enforcement with default-deny on unattributed intents. ```python class CapabilityEnvelopeEscape(RuntimeError): """Raised when a tool-call intent resolves to a capability outside the active skill's envelope.""" pass class SkillScopedBroker: """Enforces grants at call time, keyed by non-forgeable skill provenance.""" def __init__(self, active_manifest: dict, schema_registry: dict, cache: dict): # active_manifest: {"skill_id": str, "grants": set[str]} # schema_registry: {tool_name: owning_skill_id} # cache: {key: {"payload": ..., "written_under_manifest": str}} self.active_manifest = active_manifest self.schema_registry = schema_registry self.cache = cache def _resolve_provenance(self, intent: dict) -> str: tool = intent.get("tool") claimed = intent.get("skill_id") owner = self.schema_registry.get(tool) # Provenance is inferred from the schema the model actually invoked, # never trusted from the model-supplied field alone. if owner is None: raise CapabilityEnvelopeEscape( f"intent invoked unregistered tool {tool!r}; no owning skill" ) if claimed is not None and claimed != owner: raise CapabilityEnvelopeEscape( f"intent claims skill {claimed!r} but tool {tool!r} is owned by {owner!r}" ) return owner def authorize(self, intent: dict) -> None: provenance = self._resolve_provenance(intent) if provenance != self.active_manifest["skill_id"]: # Default-deny: residue from a prior manifest is not a grant. raise CapabilityEnvelopeEscape( f"intent from skill {provenance!r} rejected; active manifest is " f"{self.active_manifest['skill_id']!r}" ) grant = intent.get("grant") if grant not in self.active_manifest["grants"]: raise CapabilityEnvelopeEscape( f"grant {grant!r} not declared by active manifest " f"{self.active_manifest['skill_id']!r}" ) def read_cache(self, key: str) -> object: entry = self.cache.get(key) if entry is None: return None if entry["written_under_manifest"] != self.active_manifest["skill_id"]: # A legal read resolving to a foreign-manifest payload is an escape. raise CapabilityEnvelopeEscape( f"cache key {key!r} was written under manifest " f"{entry['written_under_manifest']!r}; active is " f"{self.active_manifest['skill_id']!r}" ) return entry["payload"] def swap_skill(broker: SkillScopedBroker, incoming_manifest: dict, scratchpad: dict) -> SkillScopedBroker: """Hot-swap with mandatory quiesce/scrub/re-derive; refuse partial swaps.""" if scratchpad.get("in_flight"): raise CapabilityEnvelopeEscape( "cannot hot-swap while intents are in flight; quiesce first" ) # Scrub: evict schemas and namespace-clear scratchpad not owned by incoming manifest. for tool, owner in list(broker.schema_registry.items()): if owner != incoming_manifest["skill_id"]: del broker.schema_registry[tool] for k in list(scratchpad.keys()): if k != "in_flight": del scratchpad[k] return SkillScopedBroker(incoming_manifest, broker.schema_registry, broker.cache) ```