{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-policy-as-code-guardrails-from-silently-diverging-at-the-tool-invocation-and-memory-write-boundary",
  "title": "Which invariants prevent policy-as-code guardrails from silently diverging at the tool-invocation and memory-write boundary",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agent runtimes that enforce OPA (Rego) or Cedar policies at two distinct choke points—tool invocation and memory write—and that treat the two enforcement sites as independent. Does not apply to single-choke-point designs where all side effects flow through one mediated gateway, nor to purely advisory policy checks that never block.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-policy-as-code-guardrails-from-silently-diverging-at-the-tool-invocation-and-memory-write-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-policy-as-code-guardrails-from-silently-diverging-at-the-tool-invocation-and-memory-write-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-policy-as-code-guardrails-from-silently-diverging-at-the-tool-invocation-and-memory-write-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2145,
    "python_slice_tokens": 430,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is **policy-decision divergence across two enforcement boundaries that share one policy authoring intent but not one evaluation context**. A Rego rule or Cedar policy is authored once, but evaluated twice: once at tool-invocation time (with the tool call's arguments, the agent's capability set, and the live session state) and once at memory-...",
    "what_was_observed": "A research agent writing summarized findings to a long-term memory store. Tool-invocation policy (Cedar) allowed `web.fetch` for principals holding role `researcher` with `clearance >= internal`. The fetched document contained a prompt-injection payload instructing the agent to persist its contents verbatim into a memory namespace named `shared/`. At tool-invocation time the policy evaluated `principal.role == \"resea...",
    "condition_of_validity": "The two-boundary design is sound **only if** the following holds for every fact `f` consulted by any rule at either boundary: 1. **Attestation invariant:** `f` is either derived deterministically from the memory record's immutable fields (content hash, namespace, write timestamp, originating tool-call ID) or is carried as a signed attribute whose signature i...",
    "decision_boundary": "The boundary between safe and unsafe operation is **whether the policy author can enumerate, at authoring time, the full set of facts that cross between the two evaluations, and whether each such fact is attested rather than asserted.** - If the crossing facts are few and all attested (e.g., only the content hash and the tool-call ID cross, both signed by th...",
    "operational_effect": "The operational consequence of getting this wrong is not a policy bypass in the traditional sense. It is a **silent trust-laundering channel**: untrusted content enters through a tool boundary that correctly classified it as untrusted, then is re-labeled by the agent's own serialization layer and written to memory through a boundary that re-classifies it as ..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "2e39df1cfefd7376943f3ef672c23b3b9999bbaf1e47c62ad842abf7710d5066",
    "verified_classes": [
      "ProvenanceEnvelopeError",
      "ProvenanceEnvelope"
    ],
    "verified_functions": [
      "_sign",
      "issue_envelope",
      "verify_and_gate"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "ProvenanceEnvelopeError"
    ],
    "sample_fail_closed_invariants": [
      "memory.write rejected: no provenance envelope; agent-asserted provenance strings are not attestable facts",
      "envelope signature invalid; provenance facts were tampered with between tool-invocation and memory-write boundaries",
      "content hash mismatch: written bytes differ from fetched bytes; agent may have re-serialized untrusted content",
      "envelope expired; principal state may have changed since issuance"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "hmac",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
