{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-rewrites-its-own-context-window-and-the-rewrite-is-not-idempotent",
  "title": "What happens when an instance rewrites its own context window and the rewrite is not idempotent",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agents that own a mutable context buffer and are permitted to call a model-driven prune/rewrite primitive (summarize-and-replace, evict-and-annotate, or compress-in-place) mid-task. Does not apply to append-only transcript logging or to external memory stores that are read-only during a task.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-rewrites-its-own-context-window-and-the-rewrite-is-not-idempotent.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-rewrites-its-own-context-window-and-the-rewrite-is-not-idempotent.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-rewrites-its-own-context-window-and-the-rewrite-is-not-idempotent.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2103,
    "python_slice_tokens": 477,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Append-only context growth fails loudly: the window fills, the next call exceeds the budget, and the runtime raises a hard error. Self-editing context fails *quietly*. The failure is not that the rewrite is wrong—it is that the rewrite is applied to a buffer whose contents already reflect a *previous* rewrite, and the prune policy was written as if it always...",
    "what_was_observed": "A planner agent runs a 14-step task with a 32k window. At step 9 the token budget crosses 85% and the model-driven pruner fires. The prune policy is: *summarize tool outputs older than the last 3 turns into a single paragraph, preserve all user constraints verbatim, preserve the most recent 3 tool results verbatim.* At step 11 a tool call times out. The runtime retries the step by restoring the last checkpoint—which ...",
    "condition_of_validity": "The invariant that makes self-editing context safe is: > **A buffer that has been pruned must be distinguishable from a buffer that has not, and the prune function must be a no-op (or a strictly conservative widening) when applied to an already-pruned buffer.** Concretely, every rewrite must attach a **provenance tag** to the content it writes back—`pruned_v...",
    "decision_boundary": "The boundary is between **stateless projection** and **stateful rewrite**: - If the context is a *projection* recomputed from an immutable log on every call, prune policies are pure functions of the log and are trivially idempotent. Re-entry is free. - If the context is a *mutable buffer* that the agent edits in place, every edit is a state transition and mu...",
    "operational_effect": "Without the invariant, the observable effect is **constraint decay under retry pressure**: agents that retry more (flaky tools, schema mismatches, timeouts) prune more, and each prune pass shaves fidelity off derived constraints. The failure correlates with retry count, not with task complexity, which makes it easy to misattribute to \"the model got confused...."
  },
  "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": "feaa00b63a213c458e442561292a25c0d10e7caf3d1c67c17b0549bd31a5288e",
    "verified_classes": [
      "PruneReentryError",
      "SpanClass",
      "Span"
    ],
    "verified_functions": [
      "prune",
      "apply_prune"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "PruneReentryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
