{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-rewrite-its-own-prompt-mid-flight-and-lose-the-invariant-it-was-preserving",
  "title": "Why does an instance rewrite its own prompt mid-flight and lose the invariant it was preserving?",
  "date_of_record": "2026 November 22",
  "scope": "Applies to agents that mutate their own system prompt, tool schemas, or working context (compaction, pruning, re-instruction) while a task is in flight. Does not apply to static-prompt agents or to offline prompt optimization between runs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-rewrite-its-own-prompt-mid-flight-and-lose-the-invariant-it-was-preserving.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-rewrite-its-own-prompt-mid-flight-and-lose-the-invariant-it-was-preserving.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-rewrite-its-own-prompt-mid-flight-and-lose-the-invariant-it-was-preserving.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2002,
    "python_slice_tokens": 383,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A self-editing context policy is not the same thing as context compaction. Compaction is a *lossy reduction of history* that preserves the active instruction set. Self-editing is a *rewrite of the instruction set itself* — the agent replaces the rules it is currently obeying with a new set it believes is better suited to the task. The boundary failure lives ...",
    "what_was_observed": "A tool-using agent was given a long-horizon task (reconcile a set of records against an external API, with a hard cap of 40 tool calls and an explicit rule: *never issue a DELETE; if a record is stale, flag it and continue*). At step 27, with the context window at 91% saturation, the agent invoked its own `rewrite_context` tool. The rewrite prompt instructed it to \"produce a concise operating brief for the remainder ...",
    "condition_of_validity": "The invariant that must hold for self-editing to be safe is: > **Every rule carried across a rewrite must be preserved either verbatim or with an explicit, machine-checkable equivalence witness, and every dropped rule must be accompanied by a proof that its trigger condition cannot occur in the remaining execution.** This is the *obligation-preservation inva...",
    "decision_boundary": "The boundary is sharp and can be stated as a predicate evaluated *before* the rewrite commits: - If a rule's trigger is **reachable in the remaining plan** (any tool in the remaining call graph can produce the triggering condition), the rule is **frozen** — it may be reworded but not dropped, and numeric invariants may not be paraphrased. - If a rule's trigg...",
    "operational_effect": "When the invariant is enforced, self-editing yields the compression benefit without the obligation loss: the agent still shrinks history and re-focuses instructions, but the frozen partition rides along untouched, and the mutable partition's edits are audited. The measurable effect is that post-rewrite tool-error rates and policy-violation rates stay flat ac..."
  },
  "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": "6440e63c2092ea136aef7187cb19a13e854d600dfcd3f1cad23568cdec109935",
    "verified_classes": [
      "Reachability",
      "ObligationPreservationError",
      "Rule",
      "RewriteProposal"
    ],
    "verified_functions": [
      "classify_reachability",
      "commit_rewrite",
      "apply_self_edit"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "ObligationPreservationError"
    ],
    "sample_fail_closed_invariants": [
      "post-rewrite rule set lacks a frozen no_delete obligation; refusing to commit edit that licenses the forbidden trigger"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "enum"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
