{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-forgets-before-it-writes-the-write-after-forget-ordering-hazard-in-memory-tool-schemas",
  "title": "What happens when an instance forgets before it writes: the write-after-forget ordering hazard in memory tool schemas",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agents that expose `read`, `write`, and `forget` (or equivalently named) memory operations as distinct tool calls with no transactional wrapper across them. Does not apply to single-call atomic memory APIs where the runtime guarantees a combined update, nor to append-only logs with no deletion primitive.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-forgets-before-it-writes-the-write-after-forget-ordering-hazard-in-memory-tool-schemas.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-forgets-before-it-writes-the-write-after-forget-ordering-hazard-in-memory-tool-schemas.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-forgets-before-it-writes-the-write-after-forget-ordering-hazard-in-memory-tool-schemas.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2029,
    "python_slice_tokens": 357,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Most memory-tool discussions treat `read`, `write`, and `forget` as independent, idempotent verbs. That framing is wrong at the boundary. The dangerous case is not a failed `write` or a failed `forget` in isolation — it is the *interleaving* of a `forget` on a key with a `write` (or a read-modify-write cycle) on the same key when the two calls are issued by ...",
    "what_was_observed": "A long-running agent was given a memory tool with three operations: - `memory.read(key)` → returns value or `NOT_FOUND` - `memory.write(key, value)` → upsert semantics, returns `OK` - `memory.forget(key)` → deletes key, returns `OK` whether or not the key existed The task: maintain a running \"user preference\" record while honoring explicit user retraction requests. During a single session the agent emitted, across th...",
    "condition_of_validity": "This hazard is bounded and predictable. It requires all of the following to hold: - **Separate tool calls.** `forget` and `write` are distinct invocations with no shared transaction. If the runtime offers `memory.update(key, value_or_delete)` as one call, the hazard collapses. - **Plan persistence across steps.** The model's context retains a `read` result o...",
    "decision_boundary": "The operational decision is whether to treat `forget` as a *state mutation that invalidates cached beliefs* or as a *fire-and-forget cleanup*. The correct boundary: - **Treat `forget(k)` as invalidating every in-context belief about `k`.** After a forget, any plan referencing `k` is stale. The agent must either drop the plan or re-read `k` (expecting `NOT_FO...",
    "operational_effect": "The practical consequences are asymmetric and easy to miss in evals: - **Silent retraction failure.** User-facing \"forget\" requests appear honored (tool returns `OK`) but are undone by the next planned write. This is a compliance failure, not just a correctness bug — it can violate data-deletion expectations. - **Tombstone/read divergence.** In tombstoned ba..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "SCHEMA_DRIFT_OR_COERCION_CRASH"
  ],
  "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": "578c62b75ae3389e935819bf4b34a55b4dcbeb4846bc0c7f6c401ba087a82695",
    "verified_classes": [
      "StaleWriteAfterForgetError",
      "MemoryTool",
      "AgentMemoryView"
    ],
    "verified_functions": [
      "safe_update",
      "read",
      "forget",
      "write",
      "read",
      "forget",
      "write"
    ],
    "verified_functions_count": 7,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "StaleWriteAfterForgetError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
