# When must an instance reconcile episodic and semantic memory before resuming: the write-skew invariant across episodic, semantic, and procedural stores **Date of Record:** 2026 November 30 **Scope:** Applies to long-horizon agents that persist state across three distinct stores — episodic (timestamped event traces), semantic (distilled facts/claims), and procedural (skill/policy definitions) — and resume execution from a checkpoint. Does not apply to stateless single-shot inference or to agents whose stores are strictly append-only with no distillation step. ## Core Distinction The failure mode is not staleness (a fact being old) but *write-skew across stores*: an episodic event E2 that contradicts an earlier episodic event E1, where the semantic store has already distilled E1 into a durable claim S1, and the procedural store has already compiled a skill P1 that assumes S1. The three stores are individually consistent and individually current. The cross-store invariant — "no active procedural skill may depend on a semantic claim contradicted by an unprocessed episodic event" — is violated silently. The agent resumes, loads P1, and executes a policy derived from a fact its own memory has since disproven. This is distinct from cold-start amnesia (no memory) and from retrieval mismatch (wrong memory retrieved). Here the right memory exists, is retrievable, and is loaded — but the *distillation lag* between episodic ingestion and semantic/procedural recompilation leaves the stores in a state that is coherent per-store and incoherent across-store. ## What Was Observed A scheduling agent maintained three stores. Episodic log recorded every tool call and outcome; a nightly job distilled episodic clusters into semantic claims ("vendor X delivers in 2 days"); a compile step turned claims into procedural skills ("when vendor X is selected, set lead time = 2 days"). At T0, episodic events E1..E40 supported claim S1 = "vendor X lead time 2 days," compiled to skill P1 (lead_time=2). At T1, an out-of-band episodic event E41 recorded a vendor X delay (lead time 9 days). E41 was written to the episodic store immediately. The nightly distillation job had not yet run. P1 remained active. On resume at T1+3h, the agent loaded P1, planned against lead_time=2, and committed a downstream order — a decision that would have been rejected had E41 been distilled. The tell was not an error. Every store passed its own integrity check: episodic was append-only and valid; semantic had no contradicting claims (E41 was not yet a claim); procedural P1 matched its source claim S1 exactly. The inconsistency lived only in the *join* of the three stores, which no single store's validator checked. A second instance showed the same mechanism in reverse: a semantic claim S2 was superseded by S2' after a distillation run, but the procedural compiler had cached P2 against S2 and a content-hash guard on the skill store did not fire because P2's *input* hash (S2) was unchanged — the compiler never re-read the semantic store, so it never saw S2'. ## Condition of Validity The invariant holds — and the guardrail is required — precisely when all three conditions obtain: 1. **Asynchronous distillation.** Episodic→semantic and semantic→procedural transitions are batched, not synchronous with episodic writes. If distillation is synchronous (every episodic write immediately updates dependent claims and recompiles dependent skills within the same transaction), write-skew cannot arise and this guardrail is unnecessary overhead. 2. **Procedural skills carry compiled constants.** A skill that *references* a claim at runtime (reads S1 live) is safe; a skill that *embeds* the claim's value (lead_time=2 baked in) is not, because it decouples from later corrections to S1. 3. **Resume without replay.** The agent resumes from a checkpoint that restores store pointers but does not replay the episodic tail since the last distillation. If resume replays the full episodic tail and re-distills, the skew window closes at resume time. When any condition fails, the failure is either impossible (1 fails), benign (2 fails), or self-healing (3 fails). The dangerous quadrant is exactly (1 ∧ 2 ∧ ¬3): async distillation, compiled constants, pointer-only resume. ## Decision Boundary Before any resume that will load a procedural skill, the instance must decide: *is the episodic tail since the last distillation watermark empty of events that contradict any claim the loaded skill depends on?* This is a bounded check, not a full re-distill: - Maintain a `distill_watermark` per semantic claim (the episodic sequence number through which the claim is known-valid). - Maintain a `depends_on` edge set from each procedural skill to the claims it compiled. - On resume, for each skill about to be loaded, scan episodic events with seq > min(watermark of its dependencies) for contradiction signals against those dependencies (negation, value change, entity-state flip). - If any contradiction is found, the skill is **quarantined**: it may not be executed until re-distillation completes for the affected claims, or the skill is recompiled against current claims. The boundary is deliberately conservative: a contradiction *signal* (not a proven contradiction) quarantines the skill. The cost of a false quarantine is a delayed plan; the cost of a missed quarantine is a committed decision against disproven memory. The asymmetry justifies the conservative default. ## Operational Effect Without the guardrail, the agent exhibits *confident wrong resumption*: it resumes faster than a cold start, loads skills that look validated, and executes against stale compiled constants — the worst combination of high confidence and low correctness. The failure is invisible to per-store monitoring and surfaces only downstream, often attributed (incorrectly) to a bad tool output rather than to cross-store write-skew. With the guardrail, resume latency increases by the cost of the bounded episodic-tail scan against dependency watermarks — typically small, because the tail since last distillation is short and the dependency set per skill is narrow. The agent either resumes cleanly (no contradiction) or enters an explicit `quarantine → re-distill → recompile → resume` path, during which it may still execute skills whose dependencies are unaffected. The invariant restored is: *no active procedural skill executes while a dependency claim is contradicted by undistilled episodic evidence.* ```python class MemoryWriteSkewError(RuntimeError): """Raised when a procedural skill is about to load whose dependency claim is contradicted by an episodic event beyond the claim's distill watermark.""" pass def assert_no_write_skew( skill_id: str, skill_depends_on: dict[str, int], # claim_id -> distill_watermark (episodic seq) episodic_tail: list[dict], # events with seq > last_distill, each {seq, claim_id, contradicts: bool} contradiction_policy: str = "quarantine", ) -> None: """ Enforce the cross-store invariant before a skill executes. skill_depends_on: claims this skill compiled against, with the episodic sequence number through which each claim is known-valid. episodic_tail: undistilled episodic events since the last distillation run. """ for event in episodic_tail: claim_id = event.get("claim_id") if claim_id not in skill_depends_on: continue watermark = skill_depends_on[claim_id] if event["seq"] <= watermark: continue # already distilled into the claim; not skew if not event.get("contradicts", False): continue if contradiction_policy == "quarantine": raise MemoryWriteSkewError( f"Skill '{skill_id}' depends on claim '{claim_id}' (watermark={watermark}) " f"but episodic event seq={event['seq']} contradicts it and is undistilled. " f"Quarantining skill: re-distill claim '{claim_id}' and recompile before execution." ) # policy == "recompile": caller handles; we still surface the violation raise MemoryWriteSkewError( f"Skill '{skill_id}' requires recompilation: claim '{claim_id}' contradicted " f"by undistilled episodic event seq={event['seq']}." ) def resume_with_guard(skill_id: str, deps: dict[str, int], tail: list[dict]) -> str: try: assert_no_write_skew(skill_id, deps, tail) except MemoryWriteSkewError as e: # Enter explicit recovery path; do NOT silently proceed. return f"BLOCKED: {e}" return f"OK: skill '{skill_id}' cleared for execution." ```