actrone-memory
    Preparing search index...

    Class PostgresL1Store

    Postgres-backed hot session store (L1).

    Pairs with PgVectorL2Store so both memory tiers live in a Postgres you already run, instead of adding Redis and a vector database. Takes an injected pg-compatible client, so this package keeps no hard pg dependency.

    Redis gives TTL and list trimming for free; Postgres does not, so this store implements both explicitly:

    • Expiry is an expires_at column. Reads filter on it and writes opportunistically delete the session's expired rows, so an abandoned session cannot accumulate forever with no background job scheduled.
    • Retention is enforced on append by deleting everything older than the newest maxTurns rows for that session, mirroring Redis LTRIM.

    Ordering uses a bigserial rather than the timestamp, because two turns appended in the same clock tick would otherwise have no defined order, and prompt assembly depends on recent turns coming back oldest-first. Expiry is computed by the server (now() + make_interval(...)), never from the application clock, so retention does not depend on two machines agreeing on the time.

    Mirrors the Python actrone_memory.l1.postgres_store.PostgresStore and passes the same published conformance suite (actrone-memory/testing).

    Implements

    Index
    • Create the turns table, the summary-lock table and their indexes. Call once at startup.

      Returns Promise<void>

    • Recent turns, oldest → newest, capped at n (defaults to all retained).

      Parameters

      • agentId: string
      • sessionId: string
      • Optionaln: number

      Returns Promise<Turn[]>

    • Claim the right to summarise this session, fleet-wide.

      One statement, so the check and the claim cannot interleave between processes: the upsert only overwrites a row whose window has already elapsed, and RETURNING is empty for the losers.

      Parameters

      • agentId: string
      • sessionId: string
      • ttlSeconds: number

      Returns Promise<boolean>