{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-a-self-edit-rollback-is-unsafe-diff-based-context-rewriting-and-the-tombstone-collapse-failure",
  "title": "What structural signals indicate a self-edit rollback is unsafe: diff-based context rewriting and the tombstone-collapse failure",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agents that rewrite their own working context via diff-and-apply (patch) operations with a journaled rollback path, where the journal stores inverse patches rather than full snapshots. Does not apply to snapshot-per-edit systems or to append-only context that is never compacted in place.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-self-edit-rollback-is-unsafe-diff-based-context-rewriting-and-the-tombstone-collapse-failure.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-self-edit-rollback-is-unsafe-diff-based-context-rewriting-and-the-tombstone-collapse-failure.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-self-edit-rollback-is-unsafe-diff-based-context-rewriting-and-the-tombstone-collapse-failure.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2479,
    "python_slice_tokens": 529,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways an agent \"edits its own context.\" The first is *append-and-supersede*: new text is added, old text is marked stale by pointer, and the original bytes remain in the store. The second is *in-place diff rewrite*: the agent computes a patch against the live context buffer, applies it destructively, and relies on an inverse patch recorded in a ...",
    "what_was_observed": "A planning agent maintained a 40k-token working context and self-edited it after every tool call to compress completed subgoals. Each edit produced a unified-diff patch against the live buffer; the inverse was appended to a journal stack with a monotonically increasing edit ID. On tool failure, the agent popped journal entries and applied inverse patches in reverse order until it reached the edit ID recorded at the l...",
    "condition_of_validity": "The invariant that makes diff-based rollback sound is: > For every journal entry Jₖ, the set of context lines its inverse patch depends on must be disjoint from the union of all lines deleted by journal entries Jₘ with m > k, and the applier must be configured with zero fuzz. Formally, let `ctx(Jₖ)` be the context lines of Jₖ's inverse and `del(Jₘ)` be the l...",
    "decision_boundary": "The agent must decide, at the moment of *recording* an edit (not at rollback time), whether the edit is rollback-safe. The decision boundary is: - **Record as diff** if the edit's deletion set is disjoint from all live inverse-patch context sets. This is the common case and preserves the token savings. - **Promote to snapshot** if the edit's deletion set int...",
    "operational_effect": "Agents that implement anchor-aware journaling observe three changes. First, rollback failures become *loud*: an exact-apply applier with anchor-ownership indexing raises on the first unsafe rollback instead of silently splicing. Second, context density drops slightly, because some edits are promoted to snapshots — typically 5–15% of edits in a compression-he..."
  },
  "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": "78f06836070377d6cc1a40a8e7b30dd0019f45a013d1b70f38fbaed3d261b027",
    "verified_classes": [
      "UnsafeRollbackError",
      "JournalEntry",
      "AnchorAwareJournal"
    ],
    "verified_functions": [
      "demonstrate_tombstone_collapse",
      "_live_context_lines",
      "record_edit",
      "rollback_to"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UnsafeRollbackError"
    ],
    "sample_fail_closed_invariants": [
      "rollback requires exact apply (fuzz=0); fuzz>0 converts anchor misses into silent partial restores"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
