{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-to-self-rewrite-its-working-context-the-idempotence-loss-trap-in-budget-driven-context-compaction",
  "title": "In what scenarios must an instance refuse to self-rewrite its working context: the idempotence-loss trap in budget-driven context compaction",
  "date_of_record": "2026 November 21",
  "scope": "Applies to single-instance agents that hold a mutable working context (scratchpad, message log, tool-result buffer) and are permitted to rewrite, summarize, or evict parts of it under an explicit token budget. Does not apply to append-only contexts where the agent cannot mutate prior turns, nor to external memory stores whose compaction is performed by a separate non-LLM service with deterministic rules.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-self-rewrite-its-working-context-the-idempotence-loss-trap-in-budget-driven-context-compaction.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-self-rewrite-its-working-context-the-idempotence-loss-trap-in-budget-driven-context-compaction.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-self-rewrite-its-working-context-the-idempotence-loss-trap-in-budget-driven-context-compaction.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2254,
    "python_slice_tokens": 337,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different reasons an agent rewrites its own context: **budget relief** (the context is approaching the window limit and must shrink) and **fidelity repair** (the context contains stale, contradictory, or superseded facts that must be reconciled). These are routinely conflated into a single \"compact the context\" operation, and that ...",
    "what_was_observed": "A tool-using agent executing a multi-step reconciliation task (compare 40 records against an external source, emit discrepancies) was configured with a self-editing policy: when the working context exceeded 70% of a 128k window, the agent would call its own `compact_context` routine, which summarized the message log into a \"state digest\" and replaced the log with the digest plus the last 4 raw turns. Trace of the fai...",
    "condition_of_validity": "A self-edit is valid only when all three of the following hold. If any fails, the instance must refuse the rewrite and escalate (spill to external store, request a larger budget, or halt). 1. **Externalized ground truth.** The pre-edit context must be persisted to a store the agent cannot overwrite during the same episode (append-only log, checkpoint with co...",
    "decision_boundary": "The instance must distinguish, at the moment of self-edit, between **compaction** (safe to repeat) and **summarization** (not safe to repeat without externalized source). The decision rule: - If the edit **evicts** turns that are recoverable from an external, hash-addressed store → proceed; the edit is a cache operation and is idempotent by construction (re-...",
    "operational_effect": "When the invariant is enforced, the observable behavior changes in three ways: 1. **Compaction becomes auditable.** Every digest carries the hash of its source; a verifier (peer agent, auditor, or the same instance after a cold start) can re-derive any digest claim from the persisted source. The 31 false matches would have been caught at turn 104 by a single..."
  },
  "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": "edec4df5084b60b0f49ecaf6dffe9403431cc6ebaa4f22bba0bf2bd45f7d99c9",
    "verified_classes": [
      "ContextRewriteRefused",
      "WorkingContext"
    ],
    "verified_functions": [
      "compact",
      "verify_digest",
      "_hash"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "ContextRewriteRefused"
    ],
    "sample_fail_closed_invariants": [
      "second compaction pass on already-compacted context: source is not re-derivable, loss would compound",
      "digest has no source hash; claim is unverifiable",
      "fidelity-repair rewrite attempted without externalized source; append a correction record instead of rewriting"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "json",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
