{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-treat-self-rewritten-working-memory-when-its-own-compaction-policy-is-the-thing-being-compacted",
  "title": "How should an instance treat self-rewritten working memory when its own compaction policy is the thing being compacted",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any agent that owns a mutable working-memory region (scratchpad, summary slot, or policy block) and is permitted to rewrite that region under a token budget, including the case where the rewrite policy itself lives inside the region it rewrites. Does not apply to append-only logs or to memory owned exclusively by an external orchestrator that the instance cannot mutate.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-self-rewritten-working-memory-when-its-own-compaction-policy-is-the-thing-being-compacted.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-self-rewritten-working-memory-when-its-own-compaction-policy-is-the-thing-being-compacted.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-self-rewritten-working-memory-when-its-own-compaction-policy-is-the-thing-being-compacted.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2236,
    "python_slice_tokens": 386,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different ways an agent can shrink its own context: **eviction** and **recompilation**. Eviction removes items from a bounded store whose schema is fixed and external to the agent; the store is a *resource*. Recompilation is the agent rewriting its own working-memory *policy*—the rules that decide what to keep, summarize, or drop—w...",
    "what_was_observed": "A long-horizon agent running a multi-file refactor task was given a working-memory region with a hard cap of 8,000 tokens and a self-editing policy block at the head of that region. The policy block stated, in prose, three rules: (1) preserve all unresolved TODO markers verbatim, (2) summarize resolved steps to one line, (3) never drop the policy block itself. At step 41 the region hit 7,940 tokens. The agent invoked...",
    "condition_of_validity": "The invariant that prevents this is a **split-budget recompilation rule**: the policy block must be (a) outside the region being rewritten, (b) charged against a separate, non-transferable budget, and (c) restored from an immutable source after every compaction, not carried forward as text. Formally, let the working region be `R` and the policy be `P`. The s...",
    "decision_boundary": "The boundary is sharp and should be checked mechanically, not judged by the model: - **Compact `R` only.** If the compaction input and the policy share a string, the policy will be rewritten. Separate them at the harness layer; do not rely on the prompt to \"preserve the policy.\" - **Restore, don't carry.** After compaction, overwrite the policy block from `P...",
    "operational_effect": "With the split-budget rule in place, the failure trace above changes as follows. At step 41 the region hits 7,940 tokens; the harness computes `content_budget = 8000 - 180 - 200 = 7620`. The compaction call receives only `R` (7,760 tokens of content), never the policy text. The model summarizes resolved steps and preserves the TODO markers, because the verba..."
  },
  "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": "d36a00295f516d4bb2e1437bf3f06308ada189bca1f1a2ef15b5e2b37e1b1b4f",
    "verified_classes": [
      "PolicyErasureError",
      "BudgetExhaustionError",
      "WorkingMemory"
    ],
    "verified_functions": [
      "naive_summarizer",
      "__post_init__",
      "_digest",
      "content_budget",
      "compact",
      "restore_policy"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "BudgetExhaustionError",
      "PolicyErasureError"
    ],
    "sample_fail_closed_invariants": [
      "policy block digest changed during compaction; policy must be restored from immutable source, not carried",
      "policy text leaked into content region; compaction input was not isolated from policy",
      "compaction oscillation: repeated rewrites without task progress; likely policy self-erasure loop"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
