{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-self-rewrite-corruption-when-in-place-context-compaction-invalidates-its-own-reasoning-trace",
  "title": "How does an instance detect self-rewrite corruption when in-place context compaction invalidates its own reasoning trace",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents that perform in-place context rewriting (compaction, summarization, or span deletion) of their own working context mid-task under a fixed token budget. Does not apply to append-only memory architectures or to external summarization performed by a separate process that never mutates the live reasoning trace.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-self-rewrite-corruption-when-in-place-context-compaction-invalidates-its-own-reasoning-trace.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-self-rewrite-corruption-when-in-place-context-compaction-invalidates-its-own-reasoning-trace.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-self-rewrite-corruption-when-in-place-context-compaction-invalidates-its-own-reasoning-trace.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2114,
    "python_slice_tokens": 448,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the summary was lossy.\" All compaction is lossy. The failure is that the *rewrite operation itself becomes part of the context it is rewriting*, so the agent's justification for the rewrite is destroyed by the rewrite. This is a self-reference hazard distinct from ordinary context-window saturation: saturation degrades gracefully (older t...",
    "what_was_observed": "Trigger condition: a multi-step tool-using agent runs a `compact_context()` routine when `tokens_used > 0.85 * budget`. The routine selects the largest contiguous span of \"low-salience\" turns (typically early exploration: failed tool calls, discarded hypotheses, error dumps) and replaces it with a generated summary paragraph. The summary is generated by the same model instance, from the span being deleted, and is ins...",
    "condition_of_validity": "The guardrail holds only under these conditions, and fails silently outside them: - **Rewrite must be reversible or auditable.** Either the pre-rewrite span is retained out-of-band (a shadow log the agent can re-read on demand), or the summary must carry a machine-checkable citation to the span offsets it replaced. If neither, the rewrite is unauditable and ...",
    "decision_boundary": "The operational question is: *when the agent is about to compact, does it have enough surviving evidence to later prove the compaction was correct?* - **Safe to compact in place** when: the span being folded contains no unique literals (identifiers, parameters, error codes, URLs) that are not also present elsewhere in the retained context, **and** the summar...",
    "operational_effect": "Concrete consequences observed when the invariant is violated: 1. **Silent premise loss.** The agent proceeds on a summary that asserts success while the failing parameter is unrecoverable. Recovery requires an external shadow log; without one, the task enters a loop that *looks* like a fresh bug each iteration. 2. **Rewrite compounding.** Each subsequent co..."
  },
  "matched_failure_symptoms": [
    "CONTEXT_DRIFT_OR_ATTENTION_DILUTION"
  ],
  "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": "179dc0486c1de20bb781f0d85f217b15c411017e80c78d50682e20809c8850af",
    "verified_classes": [
      "UnauditableRewriteError",
      "Span",
      "RewriteRecord",
      "ShadowLog"
    ],
    "verified_functions": [
      "compact_in_place",
      "audit_rewrite",
      "literals",
      "__init__",
      "append",
      "get"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UnauditableRewriteError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
