Skip to content

symfonic.memory.backends.postgres_receipt_adapter

postgres_receipt_adapter

Operation-scoped receipt route for an exact raw graph-only PostgreSQL HMS.

A raw GraphBackedHms(PostgresGraphBackend) keeps its read-only v1 admission: this adapter never declares native storage on the raw backend and exposes no DELETE, DISCARD or FORGET. Caller-identified WRITE and exact selected FLUSH run through a domain-owned receipt store built around the raw backend's exact pool, so claims, manifests and receipts commit atomically.

PostgresOperationReceiptAdapter

PostgresOperationReceiptAdapter(store: Any)

Durable WRITE and selected FLUSH for one exact raw HMS pool only.

Source code in src/symfonic/memory/backends/postgres_receipt_adapter.py
def __init__(self, store: Any) -> None:
    from symfonic.capabilities.memory.graph_store import GraphBackedHms
    from symfonic.memory.backends.postgres_operation_receipt import PostgresReceiptDomain

    self._domain = PostgresReceiptDomain(_exact_pool(store))
    self._store = GraphBackedHms(self._domain.graph)
    self._writer = self._domain.writer_for(self._store)

flush async

flush(operation: MemoryOperation, *, write: MemoryOperation) -> Any

Publish only the canonical FLUSH of the caller-persisted WRITE.

The preflight refuses before a receipt is reserved; the bound source is re-read and compared again inside the publication transaction.

Source code in src/symfonic/memory/backends/postgres_receipt_adapter.py
async def flush(self, operation: MemoryOperation, *, write: MemoryOperation) -> Any:
    """Publish only the canonical FLUSH of the caller-persisted WRITE.

    The preflight refuses before a receipt is reserved; the bound source is
    re-read and compared again inside the publication transaction.
    """
    from symfonic.memory.backends.postgres_receipt_selected import (
        bound_write_selected,
        require_selected_write,
    )

    if (
        type(operation) is not MemoryOperation
        or operation.verb is not MemoryOperationVerb.FLUSH
        or operation.selected_manifest is None
    ):
        raise MemoryContractError("raw PostgreSQL FLUSH requires an exact selected manifest")
    _require_v1(operation.scope)
    require_selected_write(operation, write, await self._durable_manifest(write))
    with bound_write_selected(self._domain, operation, write):
        return await self._writer.flush(operation.scope, operation=operation)

operation_for_write

operation_for_write(operation_id: str, request: Any) -> MemoryOperation

Bind the actual records to the caller's persisted operation ID.

Source code in src/symfonic/memory/backends/postgres_receipt_adapter.py
def operation_for_write(self, operation_id: str, request: Any) -> MemoryOperation:
    """Bind the actual records to the caller's persisted operation ID."""
    _require_v1(request.scope)
    return self._writer.operation_for_write(operation_id, request)

reconcile_write async

reconcile_write(operation: MemoryOperation) -> Any

The exact committed claim manifest, or None; never adopts IDs.

Source code in src/symfonic/memory/backends/postgres_receipt_adapter.py
async def reconcile_write(self, operation: MemoryOperation) -> Any:
    """The exact committed claim manifest, or ``None``; never adopts IDs."""
    _require_v1(getattr(operation, "scope", None))
    return await self._domain.reconcile_write(operation)

selected_flush_operation async

selected_flush_operation(operation_id: str, write: MemoryOperation) -> MemoryOperation

FLUSH identity bound to the accepted WRITE and its durable manifest.

Reads the committed manifest, not an in-process receipt, so a fresh process holding only the restored WRITE identity selects the same claims. Siblings and later writes are outside the manifest.

Source code in src/symfonic/memory/backends/postgres_receipt_adapter.py
async def selected_flush_operation(
    self, operation_id: str, write: MemoryOperation,
) -> MemoryOperation:
    """FLUSH identity bound to the accepted WRITE and its durable manifest.

    Reads the committed manifest, not an in-process receipt, so a fresh
    process holding only the restored WRITE identity selects the same
    claims. Siblings and later writes are outside the manifest.
    """
    from symfonic.memory.backends.postgres_receipt_selected import (
        operation_for_selected_write,
    )

    return operation_for_selected_write(
        operation_id, write, await self._durable_manifest(write),
    )