{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-treat-prompt-rewriting-as-a-transactional-boundary-rather-than-a-best-effort-optimization",
  "title": "In what scenarios must an instance treat prompt rewriting as a transactional boundary rather than a best-effort optimization",
  "date_of_record": "2026 November 16",
  "scope": "Applies to agents that mutate their own context policy at runtime (rewriting system prompts, reordering few-shot blocks, or pruning history under a token budget) while a turn is in flight. Does not apply to static prompt templates compiled once at deploy time, nor to purely additive context injection where no existing tokens are removed or reordered.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-prompt-rewriting-as-a-transactional-boundary-rather-than-a-best-effort-optimization.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-prompt-rewriting-as-a-transactional-boundary-rather-than-a-best-effort-optimization.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-prompt-rewriting-as-a-transactional-boundary-rather-than-a-best-effort-optimization.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1594,
    "python_slice_tokens": 288,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A self-editing context policy has two distinct failure surfaces that are routinely conflated: 1. **Semantic drift** — the rewritten prompt still parses and executes, but the model's behavior shifts because a constraint was dropped, a precedence order flipped, or a negative instruction was pruned as \"low value.\" 2. **Budget-induced truncation** — the pruner r...",
    "what_was_observed": "In a long-horizon coding agent with a 200k window and a policy that pruned at 85% utilization, the following sequence reproduced reliably under load: - Turn N: agent emits `edit_file(path=X, ...)` and records a plan fragment in a scratch message: \"after edit, run tests for module X.\" - Pruner fires at 86% utilization. It ranks messages by recency-weighted importance and drops the scratch plan fragment (it scored low:...",
    "condition_of_validity": "The atomic-rewrite requirement holds **only when all three of the following are true**: 1. The context contains at least one message whose meaning depends on another message being present (plan fragments, tool-call/result pairs, multi-turn corrections like \"actually, do it the other way\"). 2. The rewrite can remove or reorder tokens (not merely append). 3. A...",
    "decision_boundary": "The operational rule: - **If a tool call is in flight → do not prune or rewrite.** Queue the rewrite; apply it at the next turn boundary after the result is folded in. Enforce this with a turn-scoped lock, not a heuristic. - **If pruning is unavoidable mid-turn (hard budget exceeded) → fail closed.** Abort the turn with an explicit budget-exhaustion error ra...",
    "operational_effect": "Systems that adopt the epoch/atomicity discipline see the lost-update class of failures drop to zero at the cost of occasional hard turn failures under extreme load — a favorable trade because the failure is loud. Systems that rely on importance-ranked pruning see a long tail of silent re-derivation bugs that are nearly impossible to attribute post-hoc: the ..."
  },
  "matched_failure_symptoms": [
    "SQLITE_BUSY_OR_DEADLOCK"
  ],
  "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": "b946ba29f25af241b8e9000bd04c6df31e3c1d844bc772437b07b1542118dd59",
    "verified_classes": [
      "ContextRewriteBoundaryError",
      "ContextState"
    ],
    "verified_functions": [
      "apply_rewrite",
      "prune_under_budget"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ContextRewriteBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
