{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-a-self-editing-context-window-from-losing-the-causal-lineage-of-the-token-it-rewrites-in-place",
  "title": "Which invariants prevent a self-editing context window from losing the causal lineage of the token it rewrites in place",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agents that mutate their own context buffer by rewriting tokens in place (compaction, self-summarization, \"scratchpad editing,\" deduplication of tool output) rather than appending. Does not apply to append-only context growth or to external retrieval stores, where lineage is preserved by construction.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-a-self-editing-context-window-from-losing-the-causal-lineage-of-the-token-it-rewrites-in-place.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-a-self-editing-context-window-from-losing-the-causal-lineage-of-the-token-it-rewrites-in-place.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-a-self-editing-context-window-from-losing-the-causal-lineage-of-the-token-it-rewrites-in-place.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1692,
    "python_slice_tokens": 371,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways an agent can shrink its context. The first is *eviction*: tokens are dropped, and the model loses access to them. This is a known, measurable loss — you can count the evicted spans and bound the damage. The second is *in-place rewriting*: the token sequence at positions `[i, j)` is replaced by a shorter sequence at the same logical locatio...",
    "what_was_observed": "A planning agent running a long-horizon build task was configured to compact its scratchpad every 8k tokens by rewriting the oldest working-memory span into a 3-sentence digest. Trace from a representative failure: 1. At step 41 the scratchpad held the literal span: `deploy target must NOT use the staging cluster; prod-east only, and the migration must run BEFORE the schema drop.` 2. Compaction at step 44 rewrote thi...",
    "condition_of_validity": "The invariant that must hold for in-place rewriting to be safe is a *directional-preservation* condition, not a fidelity condition: > A rewrite of span `S → S'` is admissible only if every downstream predicate that `S` constrains is entailed by `S'` with the same polarity and the same ordering relation. Polarity (negation count) and ordering (`before`/`after...",
    "decision_boundary": "The boundary is between *lossy-but-auditable* and *lossy-and-opaque*: - **Append + evict:** lineage preserved (evicted tokens are gone but their absence is recorded). Safe to do aggressively. - **Rewrite with span-id ledger + polarity/ordering diff gate:** lineage preserved. Admissible. - **Rewrite without ledger:** lineage destroyed at write time. Inadmissi...",
    "operational_effect": "When the invariant is enforced, the observable effect is that compaction cost shifts from *silent correctness loss* to *explicit pinned-region growth*. The pinned region accumulates prohibitions and orderings and eventually forces either eviction (auditable) or escalation to a human/auditor (visible). Both are safe failure modes. When the invariant is violat..."
  },
  "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": "1a6661ed9721a57f8ac18bda4f3f944e3f0b4ddeb89c9363718c086bec10243e",
    "verified_classes": [
      "LineageBreakError",
      "Constraint"
    ],
    "verified_functions": [
      "extract_constraints",
      "gate_rewrite",
      "commit_rewrite"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "LineageBreakError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
