Skip to content

symfonic.memory.backends.postgres_working_expiry_reads

postgres_working_expiry_reads

Database discovery of what a read may return, for every backend process.

Two things hide stored rows from a read: the installed Working TTL barrier, and a CORE-199 erase job still erasing the row's subtree. Both are judged in the read's own statement, so one snapshot decides them together with the rows: a job commits before any of its content chunks, so a statement that sees a chunk's deletions also sees the job and hides what is left.

ReadVisibility dataclass

ReadVisibility(expiry: str | None, jobs: str | None)

The TTL barrier function and the erase job table, either may be absent.

expiry_function async

expiry_function(conn)

One fresh catalog snapshot; partial/drifted installs fail closed.

Source code in src/symfonic/memory/backends/postgres_working_expiry_reads.py
async def expiry_function(conn):
    """One fresh catalog snapshot; partial/drifted installs fail closed."""
    from symfonic.memory.backends.postgres_working_expiry_attestation import discover_working_expiry
    return await discover_working_expiry(conn)

read_visibility async

read_visibility(conn: Any, scope: Any = None) -> ReadVisibility

The TTL barrier, plus the erase job table for a native (or unknown) scope.

A v0 scope reads only v0 or NULL owner paths, which no canonical v1 job prefix can start, so it skips the job lookup.

Source code in src/symfonic/memory/backends/postgres_working_expiry_reads.py
async def read_visibility(conn: Any, scope: Any = None) -> ReadVisibility:
    """The TTL barrier, plus the erase job table for a native (or unknown) scope.

    A v0 scope reads only v0 or NULL owner paths, which no canonical v1 job
    prefix can start, so it skips the job lookup.
    """
    from symfonic.memory.backends.postgres_erase_jobs import jobs_table
    from symfonic.memory.scope_isolation import _is_native_scope

    expiry = await expiry_function(conn)
    native = scope is None or _is_native_scope(scope)
    return ReadVisibility(expiry, await jobs_table(conn) if native else None)

visible

visible(function, alias='', identifier='id')

Build only from internal SQL identifiers; caller values stay bound.

function is a ReadVisibility, or a bare TTL function name (or None) as returned by expiry_function.

Source code in src/symfonic/memory/backends/postgres_working_expiry_reads.py
def visible(function, alias='', identifier='id'):
    """Build only from internal SQL identifiers; caller values stay bound.

    ``function`` is a ``ReadVisibility``, or a bare TTL function name (or
    None) as returned by ``expiry_function``.
    """
    from symfonic.memory.backends.postgres_erase_jobs import erasing

    if not isinstance(function, ReadVisibility):
        function = ReadVisibility(function, None)
    prefix = alias + '.' if alias else ''
    parts = []
    if function.expiry is not None:
        parts.append(
            f'{function.expiry}({prefix}tenant_id,{prefix}{identifier},{prefix}scope_path)')
    if function.jobs is not None:
        parts.append('NOT ' + erasing(function.jobs, f'{prefix}tenant_id', f'{prefix}scope_path'))
    return ' AND '.join(parts) or 'TRUE'