{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-self-editing-context-policies-from-silently-corrupting-their-own-rewrite-budget",
  "title": "Which invariants prevent self-editing context policies from silently corrupting their own rewrite budget",
  "date_of_record": "2026 November 13",
  "scope": "Applies to agents that rewrite their own prompt/context at runtime (compaction, summarization, tool-result pruning, reordering) while the rewrite is itself expressed in tokens drawn from the same budget it is trying to conserve. Does not apply to externally driven, out-of-band context management where the rewrite cost is paid from a separate quota.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-policies-from-silently-corrupting-their-own-rewrite-budget.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-policies-from-silently-corrupting-their-own-rewrite-budget.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-policies-from-silently-corrupting-their-own-rewrite-budget.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1630,
    "python_slice_tokens": 313,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is not \"the context grew too large.\" It is that the *accounting* of the rewrite diverged from the *effect* of the rewrite. A self-editing policy computes a plan (which spans to drop, merge, or summarize), pays for that plan in tokens, executes it, and then re-measures. The non-obvious boundary is that the cost of *deciding* and the cost of *...",
    "what_was_observed": "In a runtime that compacted tool output on every turn, the following sequence recurred across three separate runs: 1. Turn N: context at 91% of budget. Policy selected 6 spans for summarization, estimated savings of 1,100 tokens. 2. The planner itself emitted a 700-token rationale block (chain-of-thought for *why* these spans) into the working context before applying. 3. The summarizer replaced the 6 spans with 5 sum...",
    "condition_of_validity": "The conservation identity above is only checkable if three preconditions hold. Violating any one of them makes the policy unsound regardless of how good the heuristics are: - **Cost attribution is complete.** Every token the policy emits — rationale, tool calls, measurement traces, error messages — must be charged to the rewrite budget, not to the \"system\" p...",
    "decision_boundary": "The operational rule is a pre-commit gate, not a post-hoc check: > **Commit a rewrite only if `tokens_freed - tokens_rewrite_cost - tokens_measurement_cost > 0` is *proven* from attributed deltas, and the plan artifact is excluded from the editable set for this turn.** If the gate cannot be proven — because cost attribution is incomplete, or because the plan...",
    "operational_effect": "Enforcing the conservation gate changes the failure profile from silent divergence to loud rejection. In the observed runtime, adding the gate and the immutability marker for plan artifacts converted a repeating 3% per-turn loss into a bounded oscillation between 88% and 91%, with occasional explicit `RewriteBudgetViolation` escalations that a human or super..."
  },
  "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": "6490c146259ba0b04233480e635b2d603d7510583933990ddedec032c0e4c24f",
    "verified_classes": [
      "RewriteBudgetViolation",
      "RewritePlan"
    ],
    "verified_functions": [
      "commit_rewrite",
      "__init__"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "RewriteBudgetViolation"
    ],
    "sample_fail_closed_invariants": [
      "plan edited its own rationale/plan artifacts; self-reference loop reachable"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
