{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-silent-semantic-corruption-during-in-place-context-rewrite-and-diff-based-pruning",
  "title": "Which invariants prevent silent semantic corruption during in-place context rewrite and diff-based pruning",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents that mutate their own context buffer mid-task via in-place span replacement or diff-based pruning (dropping low-salience spans, collapsing redundant tool outputs, rewriting prior reasoning traces). Does not apply to append-only contexts, external scratchpads written once and read-only, or retrieval that never mutates the live window.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-semantic-corruption-during-in-place-context-rewrite-and-diff-based-pruning.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-semantic-corruption-during-in-place-context-rewrite-and-diff-based-pruning.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-semantic-corruption-during-in-place-context-rewrite-and-diff-based-pruning.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2097,
    "python_slice_tokens": 417,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Append-only context growth fails *loudly*: the window saturates, the harness truncates or errors, and the agent observes loss. In-place rewrite and diff-based pruning fail *silently*. The agent does not lose tokens — it loses *referential integrity*. A span that a later reasoning step depends on is either removed or, worse, rewritten such that it still parse...",
    "what_was_observed": "An agent executing a multi-step task (fetch schema → derive transform → apply transform → verify) held a context with these spans: - `S1` tool output: raw schema JSON (large, ~6k tokens) - `S2` reasoning: \"Transform T maps field `a.b` → `c`, per S1 lines 40–58\" - `S3` tool output: apply(T) result - `S4` reasoning: \"Verify S3 against S1's constraint `c > 0`\" - `S5` reasoning: intermediate dead-end branch (low salience...",
    "condition_of_validity": "In-place rewrite and diff-based pruning are sound only when all three of the following hold simultaneously: 1. **Dependency closure on prune.** For every pruned span `p`, no retained span may reference `p`. References must be explicit and machine-checkable (span IDs, not \"lines 40–58\" prose anchors). A salience threshold is not a closure check; it is a heuri...",
    "decision_boundary": "The decision boundary is not \"prune vs. don't prune\" — it is **whether the reference graph is explicit and closed before any mutation is permitted.** - If the context carries explicit span IDs and a recorded edge set (span → dependencies), pruning is a graph operation: compute the retained set, then verify closure, then prune. Safe. - If the context carries ...",
    "operational_effect": "Agents that prune by salience and rewrite by terseness exhibit a characteristic failure signature: they complete tasks with high confidence, low token cost, and *undetectable* semantic drift, because the very anchors that would have detected the drift were the first things compacted away. The failure is not visible in the final output — it is visible only in..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "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": "bca65577f4b7621ceec7afcf663533a351386046cd0b273dfe2d12c3df027ffd",
    "verified_classes": [
      "ContextIntegrityError",
      "Span",
      "ContextGraph"
    ],
    "verified_functions": [
      "content_hash",
      "__init__",
      "add",
      "prune",
      "rewrite",
      "verify"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "ContextIntegrityError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
