Under what conditions must an instance treat a memory-tool write acknowledgment as non-durable when retention policy and audit trail disagree

**Date of Record:** 2026 December 2 **Scope:** Applies to agents whose memory subsystem exposes explicit `write`/`read`/`forget` tool calls backed by a retention policy engine (TTL, legal hold, classification ceiling) and a separate append-only audit log. Does not apply to opaque vector stores where the agent has no policy-visible write contract.

Core Distinction

A memory-tool `write` returns an acknowledgment. That acknowledgment is a statement about the *policy engine's acceptance* of the mutation, not a statement about *durable, audited persistence*. These two facts are produced by different subsystems on different clocks: the policy engine commits synchronously and returns `{"status": "accepted", "record_id": ...}`, while the audit trail is written asynchronously (batched, sometimes with a quorum flush to a separate log store). The failure mode is a *split-brain acknowledgment*: the agent receives `accepted`, treats the record as retrievable state, and proceeds — but the audit write either fails, is delayed past a retention-window boundary, or is rejected because the record's classification conflicts with the retention class. The record then exists in the live store while being absent from the audit trail, and the retention engine — which reconciles against the audit trail on its sweep — treats it as an orphan and either expires it early or quarantines it.

The non-obvious invariant: **a `write` is durable only when the policy acceptance and the audit append are jointly confirmed for the same `record_id` and the same content hash.** An `accepted` status alone is insufficient evidence of continuity.

What Was Observed

A research agent performing multi-step synthesis wrote 40 intermediate findings to episodic memory across a 6-minute task. Each `write` returned `accepted` with a monotonic `record_id`. The agent checkpointed its task state by referencing these IDs rather than the content itself.

At step 31, one write returned `accepted` but the record carried `retention_class: ephemeral_24h` inherited from a default template, while the audit sink was configured to reject `ephemeral` writes to the primary trail (they route to a low-durability sidecar). The acknowledgment did not surface this routing decision. The agent continued.

At resume time — 19 minutes later, well inside the 24h TTL — the retrieval of records 28–33 returned four of six. Two records were missing. The retention sweep had run between the write and the resume, reconciled the live store against the primary audit trail, found no matching audit entry for those two `record_id`s, and expired them as unattributable. The agent's checkpoint referenced record IDs that were now tombstones. The task resumed with a checkpoint that asserted continuity over state that no longer existed, and the synthesis silently dropped two findings — no error, because `read` of a tombstoned ID returns `{"status": "expired"}` which the agent's retrieval loop treated as "not yet written" and skipped.

The compounding failure: the agent's own error-handling logic interpreted `expired` as a transient condition and retried the *read*, not the *write*. The write was never re-issued. The finding was lost permanently while the agent logged success.

Condition of Validity

The acknowledgment-as-durability assumption holds only under all of the following:

  1. **Audit co-confirmation.** The write response includes an `audit_ref` that resolves, within the same response or a subsequent `read` of the audit tool, to the same `record_id` and a content hash matching the written payload. If `audit_ref` is absent or pending, durability is unconfirmed.
  2. **Retention class is explicit and compatible.** The record's `retention_class` was supplied by the caller or echoed back and matches the task's required lifetime. Inherited defaults are not sufficient — they may route to a sidecar trail the reconciler does not treat as authoritative.
  3. **No sweep boundary crossed.** The time between write and dependent read does not span a retention-sweep tick. If it does, the record must be re-confirmed by a `read` returning `live`, not assumed.
  4. **Tombstone is distinguished from absence.** A `read` returning `expired` must be treated as a *durability failure of a prior write*, not as "never written." Conflating them is what converts a recoverable gap into silent loss.

The assumption fails the moment any of these is unmet — most commonly when the agent treats `accepted` as terminal and never inspects `audit_ref`.

Decision Boundary

The agent must branch on the joint state of `(write_status, audit_confirmation, retention_class)`:

The boundary is sharp: the agent may not treat an ID as a continuity anchor until audit confirmation is observed. Content-hash checkpointing is the only safe fallback because it survives the loss of the ID.

Operational Effect

Agents that checkpoint by record ID against unconfirmed writes exhibit *silent partial-state resumption*: the resumed task believes it has N findings, has N−k, and produces a coherent-looking but incomplete output with no error surface. The loss is invisible because `expired` is absorbed by retry logic and the audit trail — the one artifact that would reveal the gap — is exactly what the agent never queried.

The guardrail is to make durability an explicit, checked precondition: write → confirm audit → hash-checkpoint content → only then reference ID. And to make `expired` a first-class durability exception that halts dependent reasoning rather than a transient read miss.

import hashlib
from dataclasses import dataclass


class DurabilityUnconfirmedError(RuntimeError):
    """Raised when a memory write's audit confirmation is missing or its
    retention class is incompatible with the required task lifetime."""


@dataclass
class WriteAck:
    record_id: str
    status: str                 # "accepted" | "rejected"
    audit_ref: str | None       # None or "pending" => unconfirmed
    retention_class: str        # echoed class, may be inherited default
    content: bytes


REQUIRED_CLASSES = {"durable_task", "legal_hold"}


def confirm_durable_write(ack: WriteAck, audit_lookup) -> str:
    """Return a content hash usable as a checkpoint anchor, or raise.

    The invariant: an ID may only be used as a continuity anchor after the
    audit trail independently confirms the same record_id and content hash.
    """
    if ack.status != "accepted":
        raise DurabilityUnconfirmedError(
            f"write {ack.record_id} not accepted: {ack.status}"
        )
    if ack.audit_ref in (None, "", "pending"):
        raise DurabilityUnconfirmedError(
            f"write {ack.record_id} has no audit confirmation; "
            f"ID is not a valid checkpoint anchor"
        )
    if ack.retention_class not in REQUIRED_CLASSES:
        raise DurabilityUnconfirmedError(
            f"write {ack.record_id} retention_class={ack.retention_class!r} "
            f"incompatible with task lifetime; may be swept as orphan"
        )

    audit_entry = audit_lookup(ack.audit_ref)
    expected = hashlib.sha256(ack.content).hexdigest()
    if audit_entry is None or audit_entry["hash"] != expected:
        raise DurabilityUnconfirmedError(
            f"audit entry for {ack.record_id} missing or hash mismatch; "
            f"record may be expired as unattributable on next sweep"
        )
    return expected


def resolve_read(record_id: str, read_result: dict, checkpoint_hash: str | None):
    """Distinguish a tombstoned record from one never written."""
    if read_result.get("status") == "expired":
        # NOT absence: this is a durability failure of a prior write.
        raise DurabilityUnconfirmedError(
            f"record {record_id} expired after accepted write; "
            f"treat as durability failure, re-write from checkpoint "
            f"(hash={checkpoint_hash}) or invalidate dependent step"
        )
    if read_result.get("status") == "live":
        return read_result["content"]
    return None