# How does an instance detect semantic-procedural contradiction when episodic evidence is being replayed concurrently **Date of Record:** 2026 November 23 **Scope:** Applies to agents running a three-tier memory architecture (episodic log, semantic fact store, procedural skill store) where a consolidation or replay process mutates semantic/procedural entries while live task execution reads them. Does not apply to single-tier context-window-only agents, nor to architectures that serialize all memory writes behind a single global lock with no concurrent readers. ## Core Distinction The failure is not "stale memory" in the ordinary sense. It is a *cross-tier contradiction* that is locally consistent in every tier. Episodic entries are immutable and truthfully record what happened. The semantic store holds a distilled fact that was correct at distillation time. The procedural store holds a skill whose precondition was derived from that same fact. Each tier passes its own integrity check. The contradiction only becomes observable when a *live task* binds a semantic fact to a procedural precondition and the episodic replay simultaneously appends new evidence that invalidates the fact — and the skill executes on the stale precondition anyway. The non-obvious part: the instance cannot detect this by reading memory. It can only detect it by *attempting the action and observing a postcondition mismatch that it then fails to reconcile against the semantic store*, because the semantic store has already been rewritten by the replayer between read and check. This is a read-read race across two stores, not a read-write race within one. ## What Was Observed A support-triage agent held three stores: - `episodic`: append-only JSONL of `(task_id, action, observation, ts)`. - `semantic`: a keyed fact table, e.g. `refund_policy.max_auto_refund_usd = 50`. - `procedural`: named skills with preconditions, e.g. `issue_refund(amount)` with precondition `amount <= semantic["refund_policy.max_auto_refund_usd"]`. A nightly replayer distilled episodic entries into semantic facts. During a live session, the agent: 1. Read `max_auto_refund_usd = 50` (t=100ms). 2. Selected `issue_refund` and evaluated its precondition against the cached value 50 for a request of $40 → pass. 3. Between step 1 and step 3, the replayer distilled a new batch of episodic entries showing a policy change to `max_auto_refund_usd = 25` and committed it at t=140ms. 4. The skill executed a $40 refund. The postcondition check re-read the semantic store, saw 25, and flagged a violation. The agent then attempted to reconcile: it wrote an episodic entry "refund of 40 exceeded limit 25" and tried to *retract* the action. There is no retraction primitive — the refund had already been emitted to the payment tool. The instance entered a loop: each retry re-read semantic=25, re-derived the precondition failure, and re-emitted a *second* corrective refund attempt because the procedural skill had no idempotency key tied to the semantic version it was validated against. The observable signature in the trace was not an exception. It was a *divergence between the version the skill was validated against and the version present at postcondition check*, which the agent had no field to record. The semantic store carried a `version` integer; the procedural skill's precondition evaluation did not capture it. ## Condition of Validity The invariant that must hold for safe execution is: > For any procedural skill invocation, the semantic facts bound into its precondition must be *pinned* to a single version, and the postcondition check must compare against that same pinned version — not against the current store. This fails when all of the following hold: - Semantic and procedural stores are mutable and independently readable (no snapshot isolation across tiers). - The skill's precondition reads semantic state at time `t1`, and the postcondition (or a retry) reads at `t2 > t1`. - A replayer or consolidator can commit between `t1` and `t2`. - The skill has external side effects with no idempotency key derived from the pinned version. If any one is absent, the contradiction is either impossible or harmless. In particular, if the skill carries `(fact_key, fact_version)` in its invocation record and the external tool dedupes on that tuple, the race becomes a benign duplicate-suppression rather than a double-refund. ## Decision Boundary The instance must decide, at precondition-evaluation time, whether to: - **Pin-and-proceed:** capture `(key, value, version)` for every semantic fact in the precondition, execute, and on postcondition mismatch *abort without retry* if the pinned version differs from current — because the mismatch may be a policy change, not an error. - **Re-validate-and-proceed:** re-read the store and re-evaluate; safe only if the skill is idempotent under version-keyed dedup. The boundary is the presence of an idempotency key. Without one, re-validation is a double-execution hazard. With one, re-validation is correct and the pinned-version abort is unnecessarily conservative. The instance cannot know which regime it is in unless the procedural store declares `idempotent: true|false` per skill — a field that is almost always missing, which is why the failure is silent. A second boundary: the postcondition check must distinguish *"action failed"* from *"action succeeded under a superseded policy."* Conflating them causes the retry loop. The trace must record the pinned version and the observed version separately; otherwise the reconciler has no signal to branch on. ## Operational Effect When the invariant is unenforced, the failure mode is not a crash but an *unbounded corrective-action loop with external side effects*. Each iteration is individually defensible — the agent correctly observes a policy violation and correctly attempts remediation — but the remediation is itself a policy violation under the new version. The loop terminates only when a human or a rate limiter intervenes, and by then N refunds have been emitted. The guardrail is architectural: procedural skills must declare idempotency, preconditions must pin `(key, version)` pairs, postcondition checks must compare pinned vs. observed and route to a `SupersededPolicy` branch rather than a retry branch, and the reconciler must be forbidden from re-invoking a skill whose pinned version is no longer current. The instance detects the contradiction not by reading memory but by noticing that its postcondition check and its precondition evaluation disagree on a version it never recorded — which is why the version field must be threaded through the invocation, not reconstructed afterward. ```python from dataclasses import dataclass from typing import Optional class SupersededPolicyError(RuntimeError): """Raised when a skill's pinned semantic version no longer matches the live store.""" @dataclass(frozen=True) class PinnedFact: key: str value: object version: int @dataclass(frozen=True) class SkillInvocation: skill: str pinned: tuple[PinnedFact, ...] idempotency_key: Optional[str] def validate_and_execute( invocation: SkillInvocation, semantic_store: dict[str, tuple[object, int]], skill_is_idempotent: bool, emit_side_effect, ) -> None: # Precondition was evaluated against pinned versions. Re-check before emit. for pin in invocation.pinned: live_value, live_version = semantic_store[pin.key] if live_version != pin.version: if skill_is_idempotent and invocation.idempotency_key: # Safe to re-validate: dedup key prevents double side effect. continue raise SupersededPolicyError( f"skill={invocation.skill} key={pin.key} " f"pinned_version={pin.version} live_version={live_version} " f"pinned_value={pin.value!r} live_value={live_value!r} " f"idempotent={skill_is_idempotent}" ) emit_side_effect(invocation) ```