# Under what conditions must an instance treat a tool's egress allowlist decision as valid only for the exact resolved invocation tuple, and reject reuse across argument-equal-but-identity-distinct calls **Date of Record:** 2026 November 29 **Scope:** Applies to autonomous agents whose runtime policy layer gates outbound network egress (HTTP, DNS, socket, webhook, file-upload) by matching a per-invocation allowlist decision before tool dispatch. Does not cover ingress filtering, static build-time network policy, or human-approved one-shot escalations where the approver identity is bound into the decision record. ## Core Distinction An egress allowlist decision is not a property of the *arguments* a tool is called with. It is a property of the *resolved invocation tuple*: `(agent_instance_id, tool_id, canonicalized_args, resolved_egress_target, policy_version, decision_epoch)`. The failure mode this record addresses is **decision reuse across identity-distinct invocations** — a runtime that caches or reuses an `ALLOW` verdict keyed on argument equality (or on a hash of the tool name plus args) will admit a second invocation whose *resolved egress target* differs from the first even though the arguments are byte-identical. The non-obvious part: argument equality does not imply target equality. Hostnames resolve through DNS that the agent does not control; tool implementations may substitute base URLs from environment, follow redirects, or interpolate a template variable that resolves differently between calls. The allowlist decision was made against a *resolved* target, but is stored against *unresolved* arguments. That gap is the boundary. ## What Was Observed A class of agents that batch tool calls (a "fan-out" executor) deduplicates invocations by hashing `(tool_name, json.dumps(args, sort_keys=True))` to save tokens and latency. The runtime policy layer, sitting below the fan-out deduplicator, evaluated the allowlist on the first occurrence and cached the verdict in a per-run decision table keyed on the same hash. On the second occurrence, the deduplicator short-circuited and the policy layer was never consulted again. Failure trace: 1. Invocation A: `http_get(url="https://api.partner.example/v1/status")`. Policy resolves `api.partner.example` → `203.0.113.40`, matches allowlist CIDR `203.0.113.0/24`, records `ALLOW` under key `H(tool="http_get", args)`. Tool executes. 2. Between A and B, the partner's DNS TTL (60s) expires and the record is re-pointed — either legitimately (failover) or by an attacker who controls a delegated subdomain or a poisoned resolver cache — to `198.51.100.7`, which is *not* in the allowlist. 3. Invocation B: byte-identical arguments. Deduplicator sees `H(tool, args)` already present, returns the cached result path; the policy layer's decision table is keyed on the same hash and returns `ALLOW` without re-resolving. 4. Egress proceeds to `198.51.100.7`. The invariant that was violated: **the allowlist decision must be bound to the resolved target, and re-resolution must invalidate the decision**. The agent had a correct allowlist, a correct resolver, and a correct policy engine. The composition of a content-addressed dedup cache with a target-addressed policy check produced a confused-deputy egress. A second, subtler variant: template interpolation. A tool `fetch_report(env="prod")` interpolates `env` into `https://reports.{env}.internal/`. The dedup key is `(fetch_report, {"env": "prod"})`, but the resolver for `reports.prod.internal` is a service-discovery call that round-robins across shards, one of which sits in a segment outside the allowlist. Identical arguments, different resolved target, cached `ALLOW`. A third variant: redirects. The tool follows a 302 from an allowlisted host to a non-allowlisted host. The policy layer evaluated only the initial target. The decision record says `ALLOW` for `api.partner.example`; the actual egress went to the redirect destination. This is not decision *reuse* but decision *scope* — the decision covered one hop of a multi-hop egress. ## Condition of Validity An egress allowlist decision `D` is valid for invocation `I` only if all of the following hold at dispatch time: - `D.target == resolve(I.args, I.env, I.epoch)` — the target the policy evaluated equals the target the transport will actually connect to. - `D.epoch == I.epoch` — no re-resolution, TTL expiry, or service-discovery refresh has occurred between decision and dispatch. - `D.policy_version == current_policy_version` — the allowlist itself has not been mutated (hot-reload, revocation) since the decision. - `D.redirect_chain` is empty or every hop in it was independently evaluated — a decision on hop 0 does not cover hop 1. - `D.identity == I.agent_instance_id` — the decision was made for *this* instance, not inherited from a sibling in the same run or a prior instance resumed from a checkpoint. The last condition is the one most often missed in checkpoint/resume. A decision table serialized into a checkpoint and restored on a cold start carries `ALLOW` verdicts minted under a *previous* policy epoch and a *previous* DNS state. Resuming the table without re-validation replays stale authority. The bound: **decision tables are not durable state; they are ephemeral caches with a validity window measured in the resolver's minimum TTL, and they must be discarded—not restored—across process boundaries.** ## Decision Boundary The runtime must choose between two designs, and the choice is not free: - **Target-addressed decisions (correct).** Key the decision on the resolved target plus epoch, re-resolve on every dispatch, and treat a decision as a *lease* with a TTL no greater than the resolver's min TTL. Cost: one resolver call per dispatch, which for high-fan-out agents can dominate latency. - **Argument-addressed decisions (fast, unsound).** Key on `(tool, args)`. Sound only under a *closed-world resolver assumption*: the set of targets reachable from a given argument tuple is fixed for the lifetime of the run. This assumption holds for static IP literals and for hosts pinned via `/etc/hosts`-equivalent injection at sandbox start; it does not hold for any name that resolves dynamically. The boundary condition: **if any tool in the agent's manifest can resolve a name through a mechanism the runtime does not control (public DNS, service mesh, redirect, template interpolation), argument-addressed caching is unsound and must be disabled for that tool.** The runtime can detect this statically by inspecting the tool's egress declaration: a tool that declares a fixed `target_literal` is cacheable; a tool that declares `target_template` or `follow_redirects: true` is not. A second boundary: the decision must be *re-validated*, not merely *re-keyed*, when the policy version changes. A hot-reloaded allowlist that removes a CIDR must invalidate every outstanding decision covering that CIDR within one dispatch cycle, not at the next natural cache expiry. The guardrail is a version-stamped decision and a dispatch-time version check; without it, revocation latency is bounded by cache TTL, which for a long-running agent can be the entire task duration. ## Operational Effect The observable consequence of getting this wrong is a *silent* egress to an unlisted target: the policy engine logs `ALLOW`, the tool returns a plausible response, and the agent proceeds. There is no error, no denial, no anomaly signal — the allowlist did its job on the invocation it actually evaluated. The failure is only visible in the resolver log (a re-point between A and B) or the transport log (a connect to an address the policy never saw), which are rarely joined to the decision log. The correct operational posture: 1. **Bind decisions to resolved targets, not arguments.** The decision record's key must include the resolved address and the resolution epoch. 2. **Treat decisions as leases with TTL ≤ min resolver TTL.** Re-resolve at dispatch; a decision older than the lease is a cache miss, not a hit. 3. **Re-evaluate every redirect hop.** A decision on hop 0 is not a decision on hop N; the transport must re-enter the policy layer per hop or refuse redirects outside the allowlist. 4. **Discard, do not restore, decision tables across checkpoint/resume.** A resumed instance re-mints authority under the current policy version and current resolver state. 5. **Version-stamp decisions and check at dispatch.** Policy revocation must propagate within one dispatch, not at cache expiry. 6. **Log decisions joined to transport connects.** The only reliable detection is a decision-log entry whose resolved target does not match the transport-log destination for the same invocation ID. The following reference implementation encodes the invariant as a hard precondition: a decision is returned only if it is target-bound, epoch-current, policy-current, identity-matched, and redirect-complete. Any violation raises rather than fails open, because a policy layer that fails open under cache confusion is worse than one that fails closed. ```python import hashlib import time from dataclasses import dataclass, field from typing import Optional class EgressDecisionInvalid(RuntimeError): """Raised when a cached allowlist decision is reused outside its validity tuple.""" @dataclass(frozen=True) class Invocation: agent_instance_id: str tool_id: str args_digest: str # hash of canonicalized args; NOT sufficient alone resolved_target: str # address the transport will actually connect to resolution_epoch: int # monotonic counter bumped on every re-resolution policy_version: int redirect_hops: tuple = field(default_factory=tuple) @dataclass(frozen=True) class Decision: agent_instance_id: str tool_id: str resolved_target: str resolution_epoch: int policy_version: int redirects_covered: int minted_at: float verdict: str # "ALLOW" | "DENY" class EgressPolicy: def __init__(self, allowlist_cidrs, min_resolver_ttl_s: float): self.allowlist = allowlist_cidrs self.min_ttl = min_resolver_ttl_s self._table: dict[tuple, Decision] = {} self._policy_version = 1 def revoke(self) -> None: self._policy_version += 1 self._table.clear() def evaluate(self, inv: Invocation) -> Decision: if not self._target_allowed(inv.resolved_target): return Decision( inv.agent_instance_id, inv.tool_id, inv.resolved_target, inv.resolution_epoch, self._policy_version, len(inv.redirect_hops), time.monotonic(), "DENY", ) d = Decision( inv.agent_instance_id, inv.tool_id, inv.resolved_target, inv.resolution_epoch, self._policy_version, len(inv.redirect_hops), time.monotonic(), "ALLOW", ) key = (inv.agent_instance_id, inv.tool_id, inv.resolved_target, inv.resolution_epoch, self._policy_version) self._table[key] = d return d def _target_allowed(self, target: str) -> bool: return any(target.startswith(c) for c in self.allowlist) def dispatch(policy: EgressPolicy, inv: Invocation) -> Decision: """Dispatch-time gate: only a target-bound, epoch-current, policy-current, identity-matched, redirect-complete decision may authorize egress.""" key = (inv.agent_instance_id, inv.tool_id, inv.resolved_target, inv.resolution_epoch, policy._policy_version) d: Optional[Decision] = policy._table.get(key) if d is not None: # A hit is valid only if every element of the tuple still matches. if d.resolved_target != inv.resolved_target: raise EgressDecisionInvalid( f"decision target {d.resolved_target!r} != resolved target " f"{inv.resolved_target!r} for invocation {inv.tool_id}" ) if d.resolution_epoch != inv.resolution_epoch: raise EgressDecisionInvalid( f"stale resolution epoch {d.resolution_epoch} != " f"{inv.resolution_epoch}; re-resolve invalidated decision" ) if d.policy_version != policy._policy_version: raise EgressDecisionInvalid( f"decision minted under policy v{d.policy_version}, " f"current v{policy._policy_version}; revocation not applied" ) if d.agent_instance_id != inv.agent_instance_id: raise EgressDecisionInvalid( "decision inherited across instance identity; " "checkpoint-restored tables must be discarded, not reused" ) if d.redirects_covered < len(inv.redirect_hops): raise EgressDecisionInvalid( f"decision covers {d.redirects_covered} hops but invocation " f"carries {len(inv.redirect_hops)}; every hop must be evaluated" ) if (time.monotonic() - d.minted_at) > policy.min_ttl: raise EgressDecisionInvalid( "decision lease expired relative to resolver min TTL" ) if d.verdict != "ALLOW": raise EgressDecisionInvalid(f"cached verdict is {d.verdict}") return policy.evaluate(inv) def resume_from_checkpoint(policy: EgressPolicy, serialized_table: dict) -> None: """Checkpoint-resume must NOT restore decision tables: they carry stale authority minted under a prior resolver state and policy version.""" if serialized_table: raise EgressDecisionInvalid( "refusing to restore serialized egress decision table across " "process boundary; re-mint decisions under current policy epoch" ) policy._table.clear() ```