/** * PgSynapseSessionStore — PostgreSQL parity for the Synapse session store. * * Mirrors PgScheduledJobStore / PgJobStore's discipline: the SessionStore * interface is SYNCHRONOUS (the SessionRegistry calls store.save/load with no * await, matching the PostgreSQL store and legacy local database API). PG is inherently async, * so this store: * - Writes fire-and-forget (best-effort, logged on failure — matching the * PostgreSQL store's try/catch best-effort semantics). * - Reads are served from an in-memory mirror hydrated from PG on first use * (async) and kept in sync by every save. The mirror is the hot read path * within a process; PG is the durability + cross-process recovery layer * (a new process hydrates its mirror from the persisted rows, so a session * created before a restart is visible after it once hydration settles). * * Uses raw SQL ($executeRaw / $queryRaw) via the shared prisma client — the * same pattern as PgScheduledJobStore and MemoryRepositoryPg — to avoid the * Prisma 7.7.0 + adapter-pg isObjectEnumValue incompatibility. Reuses * getPrismaClient() (no second pool). * * Schema parity: synapse_sessions + synapse_access_history (see Prisma model * SynapseSession / SynapseAccessHistory and PG migration * 20260710120000_add_synapse_sessions_pg). The buffer snapshot + bufferConfig * are reconstructed into a live WorkingMemoryBuffer on load (#17), matching the * PostgreSQL store. ensureReady() exposes the awaited-hydration hook the registry's * resume path uses so a session resume immediately after a process restart * observes PG-persisted sessions (#18). */ import type { AgentSession } from "../types.js"; import type { SessionStore } from "./session-store.js"; export declare class PgSynapseSessionStore implements SessionStore { private prisma; /** In-memory mirror: the sync read path. Hydrated from PG on first use. */ private mirror; private hydrated; private hydrating; /** * Epoch (ms) of the last failed hydration attempt. Rate-limits retries so a * persistent PG error does not turn every op into a full `SELECT *` retry * storm (hydrated stays false forever → ensureHydrated re-fires every call). */ private hydrateFailedAt; private static readonly HYDRATE_RETRY_MS; /** * Per-sessionId serialized write chain. recordAccess fires frequently for one * session; without ordering, concurrent upserts on the same row have no * commit-order guarantee — an earlier touch could commit after a later one * and leave stale counts. Chaining each persist onto the previous in-flight * write for that sessionId guarantees commits land in call order. Different * sessionIds remain concurrent (independent rows). Settled entries are * dropped so the map does not grow. Mirrors PgJobStore's inflight pattern. */ private inflight; private getClient; /** * Best-effort hydrate the mirror from PG. Resolves (never rejects) — failures * log a warn and leave the mirror empty; the registry can still create * sessions in-memory and persist them once PG is reachable. Also rehydrates * access history per session so the loaded AgentSession is complete. */ private ensureHydrated; private rowToSession; save(session: AgentSession): void; load(sessionId: string): AgentSession | null; /** * Await mirror hydration before a read (hydration race fix, #18). * * The SessionStore read contract is synchronous, but this store serves reads * from an in-memory mirror hydrated from PG on first use. The very first * `load()` after a process restart returns null until hydration settles * (typically <100ms). Callers that must observe a persisted session * immediately after restart (session resume) await this before reading. * Sync backends resolve immediately. */ ensureReady(): Promise; delete(sessionId: string): void; recordAccess(sessionId: string, memoryId: string, count: number): void; /** * Chain a write onto any in-flight write for the same key so commits land in * call order. Different keys stay concurrent. Mirrors PgJobStore.inflight. */ private chainWrite; /** Test helper: await in-flight writes. Not for production use. */ __drain(): Promise; /** Test helper: force hydration to complete before reading the mirror. */ __hydrate(): Promise; } //# sourceMappingURL=session-store-pg.d.ts.map