{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-span-rewrite-self-editing-from-silently-corrupting-its-own-diff-baseline",
  "title": "Which invariants prevent span-rewrite self-editing from silently corrupting its own diff baseline",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agents that edit their own working context by rewriting token spans in place and validating the result against a diff computed from a prior snapshot. Does not apply to append-only context logs, external retrieval stores, or full-context regeneration from a durable checkpoint.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-rewrite-self-editing-from-silently-corrupting-its-own-diff-baseline.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-rewrite-self-editing-from-silently-corrupting-its-own-diff-baseline.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-rewrite-self-editing-from-silently-corrupting-its-own-diff-baseline.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2107,
    "python_slice_tokens": 526,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways an agent \"revises its context.\" The first is **regeneration**: the model emits a fresh full context and the old one is discarded. The second is **in-place span rewriting**: the model emits a patch — `(span_start, span_end, replacement)` — and a harness splices the replacement into the live token buffer, then computes a diff between the pre...",
    "what_was_observed": "A planning agent maintaining a 40k-token working context of task state, tool outputs, and partial plans was asked to compact a section. It issued three span rewrites in one revision epoch: 1. Replace the \"open questions\" block (tokens 8110–8260) with a 30-token summary. 2. Replace a stale tool-output block (tokens 12040–12310) with a 12-token pointer. 3. Rewrite a plan step it had just summarized (tokens 8285–8340) t...",
    "condition_of_validity": "The invariant holds — and span-rewrite self-editing is safe — only when all of the following are true: - **Baseline identity is explicit.** Every edit carries the identity (hash or epoch counter) of the snapshot its coordinates were derived from. An edit whose baseline hash does not match the harness's current baseline is rejected, not silently rebased. - **...",
    "decision_boundary": "The boundary is between **batch-atomic revision** and **sequential revision with rebasing**: - If an agent submits multiple edits in one epoch, they must all be expressed against the *same* baseline and applied *simultaneously* (sort by span start, apply right-to-left so earlier splices don't shift later coordinates). This is the only mode where a single dif...",
    "operational_effect": "With the invariant enforced, the failure mode disappears but a new cost appears: the agent must either pay a re-read between edits (context tokens, latency) or structure its revision as a single atomic batch (harder to reason about, requires the model to hold all coordinates simultaneously). In practice, agents that compact large contexts should batch aggres..."
  },
  "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": "e2cb061990b1252c052bead645e8dde141446d89f1414371c762f92eb58d8d3f",
    "verified_classes": [
      "StaleBaselineError",
      "SpanRewriteError",
      "ContextBuffer",
      "SpanEdit"
    ],
    "verified_functions": [
      "apply_edits",
      "validate_diff",
      "__post_init__",
      "_hash",
      "commit"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SpanRewriteError",
      "StaleBaselineError"
    ],
    "sample_fail_closed_invariants": [
      "diff baseline equals current buffer hash; validation is self-consistent and proves nothing about edit placement"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
