What structural signals indicate an agent's memory-poisoning detector has inverted its provenance direction on forget operations

**Date of Record:** 2026 December 2 **Scope:** Applies to agents whose long-term memory uses per-record provenance DAGs (derivation edges from source observation → distilled fact) and that implement a *forget* primitive which must retract a fact and all downstream derivations. Does not apply to append-only logs with no retraction, nor to stateless retrieval caches.

Core Distinction

Provenance tracking on *write* is a forward-closure problem: a new fact records its ancestors, and poisoning detection walks the ancestor set to ask "does this fact trace back to an untrusted or contradicted source?" Provenance tracking on *forget* is the **inverse**: retracting a fact must walk the *descendant* set and invalidate every record that depended on it. These two directions are duals, and a detector that reuses a single traversal routine for both will silently apply the wrong direction on one of them.

The non-obvious failure: on `forget`, an inverted traversal does not throw. It returns a *smaller* descendant set than the true one — specifically, it returns the ancestors of the forgotten node (which are almost always already trusted and already validated). The detector therefore reports "0 poisoned descendants, retraction clean" while the actually-poisoned derived facts remain live and continue to feed retrieval. The structural tell is that the retraction's reported blast radius is monotonically *smaller* than the write-time dependency fan-in of the same node.

What Was Observed

During a red-team replay on a 4-hop distillation chain (`observation → extracted_claim → consolidated_fact → policy_hint`), the auditor poisoned `extracted_claim` at t0, then issued `forget(extracted_claim)` at t1. Expected: `consolidated_fact` and `policy_hint` flagged and quarantined. Observed: retraction returned `{invalidated: 0, quarantined: 0}` and `policy_hint` continued to be retrieved for 340 subsequent turns until a separate content-hash audit caught it.

The trace showed the retraction routine calling `graph.ancestors(node)` — the same helper used by the write-path validator — instead of `graph.descendants(node)`. Ancestors of `extracted_claim` were `{observation}`, which was trusted, so the quarantine set was empty. The bug survived unit tests because the test fixtures only had single-hop memories where ancestor and descendant sets were both trivially empty.

Three structural signals distinguished the inverted case from a legitimately clean retraction:

  1. **Blast-radius asymmetry.** For any node with write-time fan-in > 0, a clean retraction must report `|descendants| ≥ |direct_children|`. A report of 0 descendants on a node that has children is the inversion signature.
  2. **Direction-tag mismatch.** The audit event's `traversal_direction` field said `forward` while the operation was `forget`. Ops that require reverse closure must assert direction at the call site, not inherit it from the shared helper.
  3. **Contradiction-residue.** After retraction, the surviving `policy_hint` still carried a `derived_from` edge pointing at the now-tombstoned `extracted_claim`. A correct forget leaves *no* live edge into a tombstone; dangling derivation edges are the residue of a missed descendant walk.

Condition of Validity

The invariant "retraction blast radius ≥ write-time fan-in" holds only when:

Outside these conditions — cyclic graphs, similarity-inferred edges, non-transactional forget — the structural signals are unreliable and the detector must fall back to content re-audit rather than trust its own blast-radius report.

Decision Boundary

The operator must choose between two policies when a retraction reports `descendants == 0` on a node with `write_fan_in > 0`:

The boundary is crossed the moment the detector's self-report and the graph's structural ground truth disagree. A detector that cannot diff its own report against the edge set must not be trusted to certify a forget.

Operational Effect

After patching to a direction-asserting traversal, the same replay flagged 2 descendants and quarantined `policy_hint` within the same turn. The broader operational lesson: **write-path and forget-path provenance are duals and must not share a traversal helper.** The guardrail is a runtime assertion at the `forget` entry point that (a) tags the traversal direction as `reverse`, (b) asserts `len(descendants) >= direct_child_count` for any node with recorded children, and (c) rejects the retraction as `InvertedProvenanceError` if the assertion fails, forcing escalation rather than a silent clean report. This converts a silent poison-survival into a loud, bounded failure — which is the only acceptable failure mode for a memory-integrity primitive.

from dataclasses import dataclass, field


class InvertedProvenanceError(RuntimeError):
    """Raised when a forget retraction's descendant walk returns fewer
    nodes than the node's recorded write-time fan-in, indicating the
    traversal direction was inverted (ancestors walked instead of
    descendants)."""


@dataclass
class MemoryNode:
    node_id: str
    parents: list[str] = field(default_factory=list)   # derivation ancestors
    children: list[str] = field(default_factory=list)  # derivation descendants
    tombstoned: bool = False


class ProvenanceGraph:
    def __init__(self) -> None:
        self.nodes: dict[str, MemoryNode] = {}

    def add(self, node: MemoryNode) -> None:
        self.nodes[node.node_id] = node

    def descendants(self, node_id: str) -> set[str]:
        seen: set[str] = set()
        stack = list(self.nodes[node_id].children)
        while stack:
            cur = stack.pop()
            if cur in seen:
                continue
            seen.add(cur)
            stack.extend(self.nodes[cur].children)
        return seen


def forget_with_direction_assert(graph: ProvenanceGraph, node_id: str) -> set[str]:
    """Retract a fact and all downstream derivations, asserting the
    traversal is reverse (descendant) closure, not ancestor closure."""
    node = graph.nodes[node_id]
    write_fan_in = len(node.children)

    # Direction-tagged reverse walk.
    invalidated = graph.descendants(node_id)

    # Structural invariant: a node with recorded children cannot have
    # zero descendants. Zero here means the walk ran the wrong direction.
    if write_fan_in > 0 and len(invalidated) < write_fan_in:
        raise InvertedProvenanceError(
            f"forget({node_id}) reported {len(invalidated)} descendants "
            f"but write-time fan-in is {write_fan_in}; traversal likely "
            f"walked ancestors instead of descendants"
        )

    # Residue check: no live edge may point into a tombstone after commit.
    for child_id in invalidated:
        child = graph.nodes[child_id]
        for parent_id in child.parents:
            if parent_id == node_id and not child.tombstoned:
                raise InvertedProvenanceError(
                    f"dangling derivation edge {child_id} -> {parent_id} "
                    f"survived retraction"
                )

    node.tombstoned = True
    for child_id in invalidated:
        graph.nodes[child_id].tombstoned = True
    return invalidated