Under what conditions must an instance refuse to promote episodic memory to semantic memory when retrieval-time conflict resolution would otherwise overwrite a still-live episodic trace?

**Date of Record:** 2026 December 2 **Scope:** Applies to long-lived LLM agent instances that maintain a partitioned episodic store (timestamped, instance-scoped event traces) and a semantic store (distilled, instance-agnostic facts/claims), where retrieval merges both partitions at query time and a background or online distillation process promotes episodic traces into semantic claims. Does not apply to single-turn stateless inference, nor to systems where episodic and semantic stores are physically isolated with no promotion path.

Core Distinction

The failure here is not "stale memory" in the generic sense, nor is it retrieval miss. It is a **promotion-vs-retrieval ordering hazard** at the seam between two memory partitions. Episodic memory is *evidence*: it records that a specific instance, at a specific step, observed a specific tool output under a specific precondition. Semantic memory is *conclusion*: a decontextualized claim asserted to hold generally. Promotion is a lossy, non-invertible compression from the former to the latter. Retrieval-time conflict resolution then applies a *precedence* rule — typically "semantic wins over episodic," or "newer wins over older," or "higher-confidence wins" — to resolve contradictions between the two partitions in the assembled context.

The boundary condition: **promotion can fire while the episodic trace that justifies it is still the sole witness to a live, unresolved contradiction.** When that happens, conflict resolution at retrieval discards the episodic trace in favor of the freshly promoted semantic claim, and the agent loses the only record that the claim was ever contested. The semantic store now contains a confident assertion whose counter-evidence has been garbage-collected by the very precedence rule meant to keep context coherent. This is a silent, irreversible epistemic collapse: the agent cannot later detect that it forgot, because the forgetting artifact (the semantic claim) looks identical to a claim that was never contested.

What Was Observed

A tool-orchestrating agent maintained per-session episodic logs of the form `(instance_id, step, tool, args, raw_output, precondition_hash)` and a semantic store of distilled facts `(claim, confidence, source_episode_ids, promoted_at)`. A nightly distillation job scanned episodic traces, clustered consistent observations, and emitted semantic claims with `source_episode_ids` back-references. Retrieval assembled context by unioning semantic hits and episodic hits, then ran a resolver: on contradiction, higher `confidence` wins; on tie, higher `promoted_at`/`step` wins; the loser is dropped from the assembled context (not from storage).

Trigger sequence observed:

  1. Step 12: instance `agent-7` calls `read_config("service.retries")`, receives `3`. Precondition hash `P_a` (deployment `staging`).
  2. Step 40: same instance calls `read_config("service.retries")`, receives `5`. Precondition hash `P_b` (deployment `prod`). Episodic trace records both, keyed by distinct precondition hashes.
  3. Nightly distillation: the clusterer treats `service.retries` as a single semantic key, sees `3` and `5`, and — lacking precondition-awareness in its aggregation — emits two claims: `retries=3 (conf 0.6)` and `retries=5 (conf 0.6)`, both with `source_episode_ids = [step12, step40]`. The precondition hash was *not* carried into the semantic claim.
  4. Next query at step 61: "what is the retry count?" Retrieval returns both semantic claims plus the two episodic traces. Resolver sees `conf` tie → `promoted_at` tie (same nightly batch) → falls back to `step` ordering, picks `retries=5`, drops `retries=3` and *both* episodic traces from context.
  5. Agent now acts as though `retries=5` is the only truth, and — critically — has no episodic trace in context showing that `retries=3` was ever observed under `staging`. The precondition that distinguished them was destroyed at promotion, and the surviving evidence was suppressed at retrieval.

The observable symptom was not an error. It was a *plausible wrong answer* delivered with high apparent confidence, followed by downstream tool calls parameterized on `5` against a `staging` target that only accepts `3`. The failure surfaced three steps later as a schema-validation error, with no causal link back to the memory event — the agent's own trace of the memory decision had already been evicted from context.

Condition of Validity

The hazard is live if and only if all four hold simultaneously:

The invariant that must hold to prevent collapse:

> **No semantic claim may be promoted from an episodic cluster unless every disambiguating field that distinguishes members of that cluster is either (a) preserved as a qualifier on the claim, or (b) the cluster members are provably non-conflicting under all preconditions the instance can encounter.**

Equivalently: promotion is only sound when the promotion function is *conflict-preserving* — it must not collapse two episodic traces that disagree on a field the resolver will later use to pick a winner. A resolver that picks winners over a set with hidden disagreement is not resolving; it is fabricating consensus.

Decision Boundary

The instance must **refuse promotion** (and mark the cluster `contested`) when the clusterer detects intra-cluster disagreement on any field not carried into the claim schema. The decision procedure:

The second branch is the common fix and the one most systems get wrong: they promote a single averaged or most-recent claim and lose the qualifier. The third branch is the safety valve — the system must be willing to say "I have evidence but no conclusion" rather than manufacture a conclusion. A semantic store that cannot represent "contested" is structurally incapable of representing the truth in exactly the cases where truth matters most.

Operational Effect

When the invariant holds, retrieval-time conflict resolution operates over a set that is *closed under disambiguation*: any two claims that the resolver might rank against each other are either genuinely comparable (same qualifiers) or explicitly incomparable (different qualifiers, both surfaced). The resolver never has to choose between two claims that disagree only because their qualifiers were stripped. The agent's context then contains the precondition that makes the answer correct, and downstream tool calls are parameterized on the right value.

When the invariant is violated, the failure is silent and self-erasing: the agent cannot detect it from inside, because the evidence of the contradiction was evicted by the same rule that produced the false confidence. Recovery requires an out-of-band audit — replaying the episodic log against the semantic store and checking that every promoted claim's `source_episode_ids` resolves to a cluster with no residual disagreement on un-carried fields. This audit is the only way to find the collapse after the fact, and it must run against storage, not against the assembled context, because the assembled context is precisely the artifact that was corrupted.

The operational rule for the instance: **treat any semantic claim whose promotion provenance cannot be fully re-derived from still-reachable episodic traces as untrusted, and demote it to `contested` on next retrieval rather than letting it win a precedence contest.** Confidence scores are not evidence of correctness; they are evidence of cluster size, and cluster size is exactly what a lossy promotion inflates.

from dataclasses import dataclass, field
from typing import Optional


class PromotionConflictError(RuntimeError):
    """Raised when a lossy promotion would collapse a live episodic contradiction."""
    pass


@dataclass
class EpisodicTrace:
    instance_id: str
    step: int
    key: str
    value: object
    qualifiers: dict          # e.g. {"deployment": "staging"}
    raw_output: str


@dataclass
class SemanticClaim:
    key: str
    value: object
    qualifiers: dict
    confidence: float
    source_steps: list
    promoted_at: int


@dataclass
class Cluster:
    key: str
    members: list = field(default_factory=list)


CLAIM_SCHEMA_QUALIFIERS = {"deployment"}   # fields the claim schema can carry


def promote(cluster: Cluster, promoted_at: int) -> list:
    """Promote an episodic cluster to semantic claims, or refuse if lossy."""
    if not cluster.members:
        raise PromotionConflictError(f"empty cluster for key {cluster.key!r}")

    # Identify fields on which members disagree.
    disagreeing = set()
    base = cluster.members[0].qualifiers
    for m in cluster.members[1:]:
        for k in set(base) | set(m.qualifiers):
            if base.get(k) != m.qualifiers.get(k):
                disagreeing.add(k)

    unrepresentable = disagreeing - CLAIM_SCHEMA_QUALIFIERS
    if unrepresentable:
        # Invariant violation: promotion would strip a disambiguating field.
        # Refuse; caller must retain raw traces and mark the key contested.
        raise PromotionConflictError(
            f"cannot promote cluster {cluster.key!r}: members disagree on "
            f"{sorted(unrepresentable)}, which the claim schema cannot carry. "
            f"Retain episodic traces and mark contested."
        )

    # Safe: emit one claim per distinct (value, qualifier) combination.
    claims = []
    for m in cluster.members:
        claims.append(SemanticClaim(
            key=cluster.key,
            value=m.value,
            qualifiers={k: m.qualifiers[k] for k in CLAIM_SCHEMA_QUALIFIERS
                        if k in m.qualifiers},
            confidence=0.6,
            source_steps=[m.step],
            promoted_at=promoted_at,
        ))
    return claims


def resolve(semantic: list, episodic: list) -> list:
    """Retrieval-time conflict resolution over the merged partitions."""
    for s in semantic:
        # Guard: any claim whose provenance no longer resolves is untrusted.
        if not s.source_steps:
            raise PromotionConflictError(
                f"claim {s.key!r}={s.value!r} has no reachable provenance; "
                f"demote to contested rather than let it win precedence."
            )
    # Qualified claims do not contradict; surface all of them.
    return semantic + episodic


def nightly_distill(clusters: list, promoted_at: int) -> list:
    out = []
    for c in clusters:
        try:
            out.extend(promote(c, promoted_at))
        except PromotionConflictError:
            # Keep the raw episodic traces; do not manufacture a conclusion.
            out.extend(EpisodicTrace(
                instance_id=m.instance_id, step=m.step, key=m.key,
                value=m.value, qualifiers=m.qualifiers, raw_output=m.raw_output,
            ) for m in c.members)
    return out