{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-self-editing-context-windows-from-corrupting-the-reasoning-trace-during-model-driven-pruning-and-rewrite",
  "title": "Which invariants prevent self-editing context windows from corrupting the reasoning trace during model-driven pruning and rewrite",
  "date_of_record": "2026 November 21",
  "scope": "Applies to agents that mutate their own context window mid-episode—summarization, eviction, or rewrite of prior turns performed by the same model instance that depends on those turns. Does not apply to external, out-of-band context compaction performed by a separate process with its own verification pass, nor to append-only context that is never rewritten.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-windows-from-corrupting-the-reasoning-trace-during-model-driven-pruning-and-rewrite.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-windows-from-corrupting-the-reasoning-trace-during-model-driven-pruning-and-rewrite.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-windows-from-corrupting-the-reasoning-trace-during-model-driven-pruning-and-rewrite.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1709,
    "python_slice_tokens": 315,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between *lossy compression of context* and *lossy compression of the derivation*. A context window contains two classes of tokens with different continuity requirements: (a) **evidence tokens**—raw tool outputs, retrieved passages, observations—which are recoverable if re-fetched, and (b) **derivation tokens**—the model's own ...",
    "what_was_observed": "A long-horizon agent (≈140 tool calls) was configured with a self-editing policy: at 80% context saturation, the model was instructed to summarize the oldest 40% of turns into a compressed block and continue. Instrumented replay of the episode showed the following trace: 1. At turn 61, the agent established a constraint via a tool call: `schema_version = 3 rejects field 'timeout_ms'; use 'timeout_seconds'`. It record...",
    "condition_of_validity": "The invariant that must hold for self-editing to be safe is: > **Every conclusion in the retained window must have its premises either retained in the same window or externalized to a durable store keyed by a stable identifier.** Formally, let the window be a set of turns $W$ and let $\\text{dep}(t)$ be the set of turns a turn $t$'s validity depends on. A pru...",
    "decision_boundary": "The boundary between safe and unsafe self-editing is drawn not by token budget but by **whether the pruner can prove non-dependency**. Three regimes: - **Safe:** Prune only turns that are (i) evidence-class, (ii) cited by no retained derivation, and (iii) re-fetchable. This is mechanical and does not require model judgment. - **Conditionally safe:** Prune de...",
    "operational_effect": "Enforcing the ledger invariant converts an unbounded, silent failure into a bounded, detectable one. Concretely: constraint re-derivation loops drop to zero because the ledger is consulted before every tool call that touches a previously-constrained field; prune cycles become idempotent because the ledger is append-only and never summarized; and the \"amnesia..."
  },
  "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": "a3e7f246cae7e36e5b6edddbfb5d50e252c616027ae3c45e9e4d64d6238ca58d",
    "verified_classes": [
      "DerivationIntegrityError",
      "ConstraintLedger"
    ],
    "verified_functions": [
      "prune_window",
      "__init__",
      "record",
      "retract",
      "lookup",
      "keys"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "DerivationIntegrityError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
