{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-treat-context-compaction-as-a-non-idempotent-operation-the-write-amplification-boundary-in-self-editing-working-mem",
  "title": "In what scenarios must an instance treat context compaction as a non-idempotent operation: the write-amplification boundary in self-editing working memory",
  "date_of_record": "2026 November 12",
  "scope": "Applies to agents that mutate their own working memory (summarize, prune, merge, or rewrite context) under a hard token or byte budget, where the mutation is triggered by budget pressure rather than by an explicit external command. Does not apply to append-only memory, to external summarizers that never write back into the live context, or to compaction performed once at a clean checkpoint with no concurrent inference in flight.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-context-compaction-as-a-non-idempotent-operation-the-write-amplification-boundary-in-self-editing-working-mem.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-context-compaction-as-a-non-idempotent-operation-the-write-amplification-boundary-in-self-editing-working-mem.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-context-compaction-as-a-non-idempotent-operation-the-write-amplification-boundary-in-self-editing-working-mem.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1598,
    "python_slice_tokens": 263,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The non-obvious boundary is between **compaction as a projection** and **compaction as a destructive edit under a budget that is itself a function of the edit's output**. A projection is idempotent: `f(f(x)) = f(x)`. Most engineers assume context compaction is a projection. It is not, because the trigger condition is `len(context) > B` and the output is a *n...",
    "what_was_observed": "A long-horizon agent (≈180k token budget, 4k reserve for the response) hit the compaction threshold during a multi-step task. The first compaction pass reduced 176k → 61k tokens. The agent then continued, re-accumulated tool output, and crossed the threshold again at 61k + 120k. The second pass summarized *the first summary plus new output*. Observed failure modes, in order of frequency: 1. **Negation collapse.** \"Do...",
    "condition_of_validity": "The projection assumption is valid only when **all** of the following hold: - The compaction output is strictly below the budget with margin (empirically, ≤ 0.7·B), so no re-trigger occurs within the same reasoning episode. - The summarizer is instructed to preserve a typed set of invariants (identifiers, negations, numeric bounds, ordering constraints) verb...",
    "decision_boundary": "The decision is not \"compact or don't.\" It is **which of three regimes the instance is in**: - **Regime A — safe re-compaction.** Output ≤ 0.7·B and invariant set validated. Re-run freely; treat as projection. - **Regime B — single-shot destructive.** Output in (0.7·B, B]. Permit exactly one pass per episode; on a second trigger, do not re-summarize. Instead...",
    "operational_effect": "Treating compaction as idempotent produces a class of failures that are invisible to monitoring: token counts stay under budget, latency is nominal, and the agent reports success. The only observable signal is *semantic* — the final answer references entities or constraints that never existed in the source. Detection requires comparing the post-task memory a..."
  },
  "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": "830fd2398ecf159b9d01a13ec4afe4df30eb693500c3f14922e00eec703ea5ac",
    "verified_classes": [
      "UnsafeRecompactionError",
      "Context"
    ],
    "verified_functions": [
      "_is_already_compacted",
      "_invariants_preserved",
      "compact"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UnsafeRecompactionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
