{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-a-self-rewrite-the-compaction-oscillation-trap-in-budgeted-working-memory",
  "title": "When must an instance refuse a self-rewrite: the compaction-oscillation trap in budgeted working memory",
  "date_of_record": "2026 December 2",
  "scope": "Applies to single-agent instances that hold a mutable context buffer and are permitted to rewrite (summarize, prune, merge, or reorder) that buffer themselves under a token budget. Does not apply to externally-managed compaction where a separate controller owns the buffer and the agent only reads it.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-a-self-rewrite-the-compaction-oscillation-trap-in-budgeted-working-memory.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-a-self-rewrite-the-compaction-oscillation-trap-in-budgeted-working-memory.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-a-self-rewrite-the-compaction-oscillation-trap-in-budgeted-working-memory.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1876,
    "python_slice_tokens": 380,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways a self-editing agent can \"save tokens,\" and they are not equivalent: - **Reclaiming tokens from dead weight** — collapsing turns that will never be read again, deduplicating tool outputs, dropping superseded plans. This is monotone: once reclaimed, the reclaimed material stays irrelevant. - **Rebalancing tokens against live obligations** —...",
    "what_was_observed": "An instance was executing a five-step retrieval-and-reconcile task with a 12k-token working budget. At step 3 the buffer hit 11.6k tokens. The agent invoked its own `compact()` routine with the instruction \"preserve all open obligations.\" The routine produced a 4.1k summary. Execution resumed. The trace showed the following: 1. **Cycle 1.** The summary preserved the *text* of open obligations but dropped the provenan...",
    "condition_of_validity": "A self-rewrite is safe to apply to live obligations **only if all three hold**: 1. **Idempotence on the obligation set.** `compact(compact(S))` must preserve the same obligations as `compact(S)`, with the same provenance. If the routine's behavior depends on the *form* of its input (e.g., it infers provenance when tags are absent), it is not idempotent and m...",
    "decision_boundary": "The boundary is not \"buffer full vs. not full.\" It is **\"does the candidate rewrite touch an obligation whose consumer has not yet run?\"** - **Below the boundary (safe):** the rewrite's inputs are all *closed* — turns whose consumers have executed and whose outputs are already reflected in the current plan. Compaction here is monotone and idempotent by const...",
    "operational_effect": "Enforcing the invariant changes agent behavior in three measurable ways: - **Compaction count drops, but rewrite quality rises.** Agents that refuse non-idempotent rewrites compact less often but each compaction is a fixed point; total fidelity loss over a long task falls sharply versus the oscillating baseline. - **Failure localizes.** When a verification c..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "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": "cd76593e473551bab83f68a0580548078216affcf844cb03a333dad0ebb1e92a",
    "verified_classes": [
      "NonIdempotentRewriteError",
      "Obligation",
      "WorkingBuffer"
    ],
    "verified_functions": [
      "_provenance_preserved",
      "safe_self_rewrite",
      "live"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "NonIdempotentRewriteError"
    ],
    "sample_fail_closed_invariants": [
      "refusing rewrite of live obligations: no checkpoint to re-inflate from",
      "refusing rewrite: provenance not preserved verbatim on live obligations",
      "refusing rewrite: routine is not idempotent on its own output (compaction-oscillation risk)",
      "refusing rewrite: candidate still exceeds budget; escalate instead"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
