Skip to content

symfonic.capabilities.memory.mongo_native_forget

mongo_native_forget

Public native Mongo v1 forget: one journal-bound FORGET per call (CORE-171).

The native Mongo HMS stays read-only for every other mutation. A forget here claims its own invocation in the operation journal, prepares a FORGET of the scope and every descendant, and runs the prepared erasure in one guarded transaction of the tenant: nodes, edges and both vector owner copies, the receipt and the erase record commit together or not at all.

A refusal before that transaction mutates nothing. Any failure inside it, or of its commit, raises MemoryOperationOutcomeUnknown: the transaction may have committed. The journal's outcome of the exception's operation is COMMITTED only once it did; UNKNOWN never proves it did not. Nothing replays that operation. A new forget of the scope is a new operation with its own invocation; after a committed forget it erases whatever was written since and otherwise answers an empty receipt.

forget_native_mongo async

forget_native_mongo(store: Any, journal: Any, scope: MemoryScope) -> Any

Erase scope and its descendants from the exact native Mongo pair.

Source code in src/symfonic/capabilities/memory/mongo_native_forget.py
async def forget_native_mongo(store: Any, journal: Any, scope: MemoryScope) -> Any:
    """Erase ``scope`` and its descendants from the exact native Mongo pair."""
    from symfonic.capabilities.memory.operation_receipt import MemoryOperationOutcomeUnknown
    from symfonic.capabilities.memory.receipt_composition import _require_native_mongo
    from symfonic.memory.storage_scope import NativeStorageScope

    if type(scope) is not MemoryScope or scope.identity_version != 1:
        raise MemoryContractError("native Mongo forget requires an exact v1 MemoryScope")
    domain = _require_native_mongo(store, scope, journal).domain
    storage = NativeStorageScope.from_scope(scope)
    owner, prepared = await _prepare(journal, scope, storage)
    binding = dict(journal=journal, owner=owner, revision=prepared.revision,
                   phase_key=PHASE, ordinal=0)
    try:
        async with domain._forget_transaction(prepared.operation, **binding):
            return await domain._forget_leaf(prepared.operation, **binding)
    except (Exception, asyncio.CancelledError) as exc:
        raise MemoryOperationOutcomeUnknown(prepared.operation) from exc

native_mongo_store

native_mongo_store(store: Any) -> bool

Whether store is the read-only native Mongo HMS this module serves.

Source code in src/symfonic/capabilities/memory/mongo_native_forget.py
def native_mongo_store(store: Any) -> bool:
    """Whether ``store`` is the read-only native Mongo HMS this module serves."""
    from symfonic.capabilities.memory.graph_store import GraphBackedHms

    return type(store) is GraphBackedHms and getattr(store._mutations, "read_only", False)