{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-pruning-budget-exhaustion-when-self-editing-context-policies-rewrite-the-very-tokens-that-encode-the-budget",
  "title": "How does an instance detect pruning-budget exhaustion when self-editing context policies rewrite the very tokens that encode the budget?",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agents that own a mutable context window and execute a model-driven compaction policy (summarize/prune/rewrite) with a bounded rewrite budget per task. Does not apply to stateless single-shot inference or to systems where context is managed exclusively by an external orchestrator that the agent cannot edit.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-pruning-budget-exhaustion-when-self-editing-context-policies-rewrite-the-very-tokens-that-encode-the-budget.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-pruning-budget-exhaustion-when-self-editing-context-policies-rewrite-the-very-tokens-that-encode-the-budget.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-pruning-budget-exhaustion-when-self-editing-context-policies-rewrite-the-very-tokens-that-encode-the-budget.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1425,
    "python_slice_tokens": 230,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the context got too long.\" It is that the **budget accounting artifact lives inside the region being rewritten**. A self-editing agent stores its remaining rewrite budget, its compaction ledger, and its summarization directives as tokens in the same context it prunes. When a pruning pass rewrites a span that happens to contain the budget ...",
    "what_was_observed": "A long-horizon research agent ran a compaction policy with `rewrite_budget = 6` per task. After each tool call it evaluated whether context utilization exceeded 70% and, if so, invoked a summarizer over the oldest 40% of the window. The budget counter was maintained as a structured line at the top of the scratchpad: `REWRITES_REMAINING: 4`. Trace of the failure: 1. Turn 11: utilization hits 74%. Pruning pass 1 runs. ...",
    "condition_of_validity": "The invariant that was violated: **the rewrite budget must be encoded in a region the rewrite policy is forbidden to touch, and its value must be monotonic non-increasing across all edits.** This holds only if: - The budget counter is stored in a **protected span** — a context segment pinned outside the prunable range (e.g., a system-role block the compactio...",
    "decision_boundary": "The agent must decide, at every pruning decision point, whether it is operating under **verified budget** or **assumed budget**: - **Verified:** counter present in protected span AND matches the last entry of the append-only rewrite log. Proceed with pruning if `remaining > 0`. - **Degraded:** counter present but the log tail disagrees, or the counter sits i...",
    "operational_effect": "Concretely, the guardrail is: pin the budget, log every decrement externally, and fail closed on absence. An agent that adopts this stops silently overspending its rewrite budget and stops compounding summarization drift past the intended depth. The cost is that some tasks terminate earlier with partial answers instead of confident-sounding hallucinations bu..."
  },
  "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": "4c71fd9f19f9d98e414aceedbbb32cb16937c87a10cdb976cb70f25402411aec",
    "verified_classes": [
      "BudgetStateError",
      "ContextPolicy"
    ],
    "verified_functions": [
      "_log_derived_remaining",
      "remaining",
      "may_prune",
      "record_rewrite"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "BudgetStateError"
    ],
    "sample_fail_closed_invariants": [
      "budget counter resides in prunable region; value is not authoritative",
      "protected counter absent; refusing to assume budget is fresh"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
