# How does an instance detect policy drift at a federated protocol boundary when the ledger is append-only but the policy bundle is mutable **Date of Record:** 2026 November 18 **Scope:** Applies to federated agent systems where each organization enforces policy-as-code at the protocol boundary (request admission, capability grants, delegation chains) and records decisions to an inter-org audit ledger. Does not apply to single-org deployments with a shared policy store, nor to systems where policy bundles are content-addressed and immutable once referenced by a ledger entry. ## Core Distinction The non-obvious failure is the divergence between **decision-time policy identity** and **ledger-time policy identity**. An append-only ledger gives the illusion of a complete audit trail: every admission decision is recorded, ordered, and tamper-evident. But the ledger entry typically records the *decision* and the *policy bundle version string* — not a cryptographic commitment to the bundle contents evaluated at that instant. When an operator mutates a policy bundle in place (e.g., editing a rule to close a hole, or rolling back a bad rule), the version string may remain stable while the semantics change, or the version may bump while the ledger's historical entries still point at a version that no longer resolves to the bytes that produced them. The distinction that matters operationally: **append-only ledger ≠ reproducible audit**. Reproducibility requires that a verifier, replaying the ledger against the policy store, obtains the same admit/deny outcome. That invariant is silently violated by mutable bundles, and no amount of hash-chaining on the ledger detects it because the ledger chain is intact — the *policy* moved underneath it. ## What Was Observed In a two-org federation (Org A issues capability grants; Org B enforces them at its ingress boundary), an agent delegation chain was admitted for 11 days under policy bundle `grants-v7`. On day 12, Org B's security team edited `grants-v7` in place to add a constraint: delegated capabilities must carry an explicit `audience` claim. The bundle's version label was not bumped because the edit was made through a "hotfix" path that bypassed the normal release pipeline. Consequences observed: 1. **Ledger replay divergence.** Org A's audit process replayed the ledger entries from days 1–11 against the current `grants-v7` bytes. Entries that originally resolved to `admit` now resolved to `deny` (the historical grants lacked `audience`). The replay produced 340 divergences, none of which indicated tampering — the ledger chain verified cleanly. 2. **False tamper alarm.** Org A initially classified the divergence as ledger corruption because its replay tooling assumed `admit` decisions must reproduce. It took 6 hours to locate the cause in Org B's policy store. 3. **Silent over-admission window.** Between the hotfix and its detection, new delegations were evaluated under the tightened rule while in-flight ones continued under the old semantics, producing an inconsistent admission surface that neither org could reconstruct from the ledger alone. The detection signal was not a chain-verification failure. It was a **replay-divergence count exceeding zero** during routine audit — a signal that only exists if the auditor actually replays rather than trusting recorded outcomes. ## Condition of Validity The invariant "ledger replay reproduces recorded outcomes" holds **only if** every ledger entry commits to the cryptographic digest of the exact policy bundle bytes evaluated, and the policy store is content-addressed such that a digest resolves to immutable bytes. Under those conditions, a divergence is a genuine integrity event. The invariant is **invalid** — and the divergence signal is meaningless as a tamper indicator — whenever any of the following hold: - The bundle is mutable in place and the ledger records a version *label* rather than a content digest. - The policy engine resolves includes/imports at evaluation time, so the effective policy is a transitive closure not captured by the top-level digest. - The ledger records the decision but not the evaluated policy identity (common when the ledger schema predates policy-as-code). - Multiple orgs share a policy store with independent write access, so "the bundle at digest D" is not a stable referent across org boundaries. If any condition fails, replay divergence must be treated as **expected** and routed to a policy-drift investigation, not an integrity alarm. ## Decision Boundary The operational decision is how to classify a replay divergence. The boundary: - **Divergence with matching content digests** → genuine integrity failure (ledger or store tampering). Escalate as security incident; freeze the federation. - **Divergence with mismatched or absent digests, and the current bundle resolves to different bytes than at decision time** → policy drift. Quarantine the affected bundle version, re-admit affected delegations under current policy, and record a compensating ledger entry. Do not escalate as tampering. - **Divergence where the bundle cannot be resolved at all** (version retired, store pruned) → indeterminate. Treat as drift with unknown blast radius; require the issuing org to re-attest the affected decisions. The critical rule: **never let the replay tool collapse "digest mismatch" and "digest match" into a single `diverged` boolean.** That collapse is what produced the 6-hour misclassification. The tool must branch on digest equality before branching on outcome equality. ## Operational Effect Enforcing digest-committed policy identity at the boundary converts replay divergence from an ambiguous alarm into a precise classifier. The practical effects: 1. Hotfix paths that mutate bundles in place become detectable within one audit cycle, because the digest recorded at decision time no longer resolves. 2. Cross-org audits stop producing false tamper alarms; each divergence carries a cause class. 3. The cost is that every boundary decision must compute and persist a content digest of the *effective* policy closure, not just the top-level bundle — a non-trivial change to ingress latency budgets and ledger schema. The residual risk: a federation that cannot afford effective-closure digesting will retain a blind spot for transitive-include mutations. That blind spot should be documented in the federation agreement, not assumed away. ```python import hashlib from dataclasses import dataclass from enum import Enum class PolicyDriftError(RuntimeError): """Raised when ledger replay cannot reproduce a decision and the cause is a mutable policy bundle rather than ledger tampering.""" pass class DivergenceClass(Enum): INTEGRITY = "integrity" # digests match, outcomes differ -> tampering DRIFT = "drift" # digests differ, bundle bytes changed INDETERMINATE = "indeterminate" # bundle no longer resolvable @dataclass(frozen=True) class LedgerEntry: decision: str # "admit" | "deny" policy_digest: str | None # sha256 of effective policy closure at decision time bundle_ref: str # human label, e.g. "grants-v7" def digest_bytes(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def classify_divergence( entry: LedgerEntry, current_bundle_bytes: bytes | None, replayed_decision: str | None, ) -> DivergenceClass: """Classify a replay divergence. Must branch on digest equality BEFORE branching on outcome equality, or drift is misread as tampering.""" if current_bundle_bytes is None or replayed_decision is None: return DivergenceClass.INDETERMINATE current_digest = digest_bytes(current_bundle_bytes) # Digest is the discriminator. If the ledger never recorded one, we cannot # distinguish drift from tampering. if entry.policy_digest is None: raise PolicyDriftError( f"ledger entry for bundle {entry.bundle_ref!r} lacks a policy digest; " "replay divergence cannot be classified as drift vs. tampering" ) if entry.policy_digest == current_digest: # Same bytes, different outcome -> the engine or ledger is compromised. if entry.decision != replayed_decision: return DivergenceClass.INTEGRITY return DivergenceClass.INTEGRITY # should not reach here if caller only passes divergences else: # Bytes changed since decision time -> mutable bundle, i.e. drift. return DivergenceClass.DRIFT def audit_replay(entries: list[LedgerEntry], resolve_bundle) -> dict: """Replay ledger entries; raise PolicyDriftError only on unclassifiable cases.""" counts = {c: 0 for c in DivergenceClass} for e in entries: bundle = resolve_bundle(e.bundle_ref) replayed = None if bundle is None else evaluate(bundle, e) if replayed is None: counts[DivergenceClass.INDETERMINATE] += 1 continue if replayed == e.decision: continue cls = classify_divergence(e, bundle, replayed) counts[cls] += 1 return counts def evaluate(bundle: bytes, entry: LedgerEntry) -> str: # Placeholder for the real policy engine; raises if bundle is unusable. if not bundle: raise PolicyDriftError(f"empty bundle for {entry.bundle_ref!r}") return entry.decision # engine stub ```