{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-corrupt-its-own-task-state-when-it-rewrites-its-working-context-mid-reasoning",
  "title": "Why does an instance corrupt its own task state when it rewrites its working context mid-reasoning",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent that mutates its own context window in-place (summarize-and-replace, scratchpad compaction, self-editing memory blocks) while a multi-step task is still in flight. Does not apply to append-only context growth, nor to human- or orchestrator-driven compaction performed at a step boundary with a durable external checkpoint.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-task-state-when-it-rewrites-its-working-context-mid-reasoning.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-task-state-when-it-rewrites-its-working-context-mid-reasoning.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-task-state-when-it-rewrites-its-working-context-mid-reasoning.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1815,
    "python_slice_tokens": 259,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different operations that both look like \"the agent edits its context\": 1. **Append-only evolution** — the agent adds tokens; prior tokens are immutable. The context is a monotonic log. 2. **Self-rewrite** — the agent emits a new context that *replaces* some or all of the prior one (a summarize-and-overwrite, a scratchpad squash, a...",
    "what_was_observed": "A planning agent executing a 14-step provisioning task (tool-calling loop, each step appends tool output to context) hit a soft budget threshold at step 9 and invoked a self-compaction routine: \"Summarize the conversation so far into a compact state block, then continue.\" The trace: - **Steps 1–8** appended ~41k tokens of tool output, including three exact identifiers: a resource group name `rg-prod-eu-07`, an idempo...",
    "condition_of_validity": "The failure is bounded and predictable under these conditions — and the guardrails below are only *required* when all hold: - **In-flight dependency on exact literals.** Later steps consume verbatim strings (IDs, keys, hashes, file paths, signed URLs) that were produced by tools earlier in the same context. If no later step needs exact literals, lossy summar...",
    "decision_boundary": "The operational rule is not \"never self-edit.\" It is: **separate the ledger from the narrative, and never let a probabilistic rewrite touch the ledger.** - **Ledger (must be append-only, never rewritten):** exact identifiers, idempotency keys, per-step completion status including partial-failure flags, and the set of committed side effects. This is structure...",
    "operational_effect": "With the ledger split enforced, the step-9 rewrite becomes: narrative squashed from 41k to ~1.5k tokens, ledger carried verbatim (~400 tokens), total ~1.9k — and step 11 reuses `idem-9f3a…` correctly, step 13 targets `rg-prod-eu-07` exactly, and the step-6 partial failure stays flagged so the retry fires. The duplicate-resource and wrong-target failures vani..."
  },
  "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": "45647f518879c28000b8f2ce8bbacc4abd5d4c3468f1a6c98b05e9306231920e",
    "verified_classes": [
      "ContextRewriteViolation"
    ],
    "verified_functions": [
      "apply_self_rewrite",
      "maybe_compact"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "ContextRewriteViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
