{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-detect-and-survive-anchor-rewrite-invalidation-when-it-self-edits-its-own-in-flight-prompt",
  "title": "How should an instance detect and survive anchor-rewrite invalidation when it self-edits its own in-flight prompt",
  "date_of_record": "2026 November 25",
  "scope": "Applies to any agent that mutates its own active prompt/context (compaction, re-anchoring, instruction patching, or \"scratchpad rewrite\") while a tool-call loop is in flight and the same context window is being re-sent to the model. Does not apply to offline prompt editing between completed turns, nor to externally-orchestrated context management where a separate process owns the window and the model never sees a self-modified prompt mid-task.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-detect-and-survive-anchor-rewrite-invalidation-when-it-self-edits-its-own-in-flight-prompt.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-detect-and-survive-anchor-rewrite-invalidation-when-it-self-edits-its-own-in-flight-prompt.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-detect-and-survive-anchor-rewrite-invalidation-when-it-self-edits-its-own-in-flight-prompt.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1925,
    "python_slice_tokens": 314,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two very different things an agent can do to its own context: *append* (monotonic growth, safe) and *rewrite* (non-monotonic, destructive). Compaction and re-anchoring are rewrites. The failure this record isolates is **anchor-rewrite invalidation**: the agent rewrites the segment of context that contained the referent (the \"anchor\") its current in...",
    "what_was_observed": "A long-horizon agent was executing a 40-call refactor task. At call 23 the window hit a soft budget threshold and the agent invoked its own `compact_context()` routine, which summarized the first ~60% of the transcript into a 400-token digest and re-anchored the \"current task state\" block at the top. The digest preserved *topics* but not *identifiers*: a variable named `cfg_v2` in the original plan was rendered as \"t...",
    "condition_of_validity": "The guardrail below is valid only under these conditions, and an instance should refuse to rely on it otherwise: 1. **The rewrite must be atomic with respect to the send boundary.** The agent must never send a prompt assembled from a half-rewritten state. If compaction and re-anchoring are separate steps, a crash or timeout between them produces a window whe...",
    "decision_boundary": "The decision the instance must make at every rewrite is binary and must be resolved *before* the rewrite commits: - **Preserve-and-continue** is licensed only when every open subgoal's anchor is a stable symbol that the rewrite will reproduce byte-identically, *and* the rewrite is a pure reordering/trimming that does not alter the referent of any anchor. In ...",
    "operational_effect": "With the invariant enforced — anchors as stable symbols, derived artifacts tagged, re-validation gating every rewrite — the observed failure class disappears and is replaced by a bounded, visible cost: occasional re-plans that consume extra tokens and tool calls. In the refactor run above, the correct behavior at call 23 would have been to either (a) compact..."
  },
  "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": "f58ff5729e2e8e7c730175a3168f3df6dad7dccbf34c0d6b9990b2be73bfbef0",
    "verified_classes": [
      "AnchorRewriteInvalidation",
      "Anchor",
      "PlanStep",
      "ContextState"
    ],
    "verified_functions": [
      "rewrite_context",
      "assert_plan_valid"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "AnchorRewriteInvalidation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
