{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-prune-the-self-referential-token-accounting-trap-in-model-driven-context-rewrites",
  "title": "When must an instance refuse to prune: the self-referential token accounting trap in model-driven context rewrites",
  "date_of_record": "2026 November 27",
  "scope": "Applies to any agent that edits its own live context window (prune/rewrite/summarize policies executed by the model itself mid-task) where the pruning decision is computed against a token budget the model must reason about. Does not apply to out-of-band context managers that operate on a separate process with an exact tokenizer and a write-ahead log.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-prune-the-self-referential-token-accounting-trap-in-model-driven-context-rewrites.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-prune-the-self-referential-token-accounting-trap-in-model-driven-context-rewrites.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-prune-the-self-referential-token-accounting-trap-in-model-driven-context-rewrites.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2419,
    "python_slice_tokens": 476,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two fundamentally different operations that get conflated under \"context pruning\": 1. **Eviction** — dropping spans the model has *already consumed* and whose residual effect is only its current belief state. Eviction is safe to the degree the belief state is stable. 2. **Rewrite** — replacing a span with a compressed surrogate (summary, paraphrase...",
    "what_was_observed": "A long-horizon coding agent (tool loop: read file → edit → run tests → read output) is configured with a 128k window and a \"self-compaction\" policy: when estimated occupancy exceeds 85%, the model is instructed to summarize the oldest 40% of the transcript into a \"state card\" of at most 2,000 tokens, then continue. Trace of the failure, reproduced across three runs: - **Turn N:** occupancy estimate 108k/128k (84.4%)....",
    "condition_of_validity": "The self-rewrite policy is only valid when all four of the following hold simultaneously. If any is unverifiable, the correct action is refusal, not a best-effort rewrite. 1. **Cost attribution closure.** The occupancy model must count, against the prune budget, not just the surrogate's size but the *expected re-read cost* of any state the surrogate fails to...",
    "decision_boundary": "The decision the instance faces at each compaction point is a three-way branch, and the middle branch is the one models skip: - **REWRITE** — permitted only if conditions 1–4 hold *and* the surrogate has been generated and measured within its slot. The rewrite is a committed state transition; the pre-rewrite span is retained in a side log (not in-window) for...",
    "operational_effect": "Implementing the refusal branch and post-generation measurement changes the failure profile in three measurable ways: - **Eliminates silent regression masking.** With provenance markers and a rewrite-depth limit of 1, the \"known-failing test\" fact survives because the second-generation rewrite is refused and the first surrogate is retained verbatim alongside..."
  },
  "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": "a097c9a20f608f73df16187f4cbb371a02e23a066492c710d1a21fea3e33963e",
    "verified_classes": [
      "RewriteRefused",
      "Surrogate",
      "ContextWindow"
    ],
    "verified_functions": [
      "safe_rewrite",
      "evict_only"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "RewriteRefused"
    ],
    "sample_fail_closed_invariants": [
      "rewrite-of-rewrite lacks provenance markers",
      "E[re-read] unbounded; rewrite is net-zero at best — fall back to evict-only with tombstone"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
