MemorySyncMemorySync
Core Concepts

Sessions & Threads

The word "session" means two different things in the codebase. One is an auth session — a refresh-token tracking row. The other is a memory query session — an optional context handle on /memory/query. There is also the Conversation model for long-lived chat threads. This page distinguishes all three and lists what does not exist.

Three "session" shapes in the codebase

ShapePurposePersisted?
Auth SessionTracks a refresh token and the device it lives on.Yes — sessions table.
Memory query sessionCarries query-time context across follow-up calls.Not by default — handled by the session engine in process state.
ConversationA long-lived chat thread.Yes — conversations table.

Auth Session fields

FieldNotes
idInternal id.
user_idFK to User.
device_idFK to Device. Tracks IP, fingerprint, location.
refresh_token_hashHMAC-SHA256 hash of the refresh token. The plaintext is never stored.
family_idToken rotation chain identifier.
session_typeweb, api, mobile, cli.
is_active, is_currentState flags.
expires_atAbsolute 14-day expiration.

The memory-query <code>session_id</code>

POST /memory/query accepts an optional session_id on the request body. The recall engine uses it to enrich follow-up queries with context from previous turns. By default this is held in the in-process session engine; persistence is opt-in.

Important
session_id is not a scope key. It does not affect ownership or isolation. It is a hint to the recall engine.

Conversation — the chat thread model

Conversation rows represent long-lived chat threads. Each row carries a UUID, a user_id, and references to the messages that belong to it. Conversations are separate from memory scoping — the same memory can be referenced across many conversations.

What does not exist

  • No thread_id column on Memory. Memories are not bound to a chat thread.
  • No session_id column on Memory. Memories are scoped to (tenant, project, user), not to a session.
  • No Thread model. The chat-thread concept is the Conversation model.

How to model a chat app on top of MemorySync

  1. 1Use Conversations for the thread itself — message order, message bodies.
  2. 2Write memories from messages that contain durable knowledge — preferences, facts, decisions.
  3. 3Pass a stable session_id to /memory/query across the same chat turn so the engine can carry context.
  4. 4Do not embed the conversation id into the memory's scope keys — keep them clean for cross-conversation recall.

Refresh and rotation

  • POST /auth/refresh rotates the refresh token; the old token's family_id is reused but its hash is invalidated.
  • POST /auth/logout revokes the active session.
  • Reusing an old refresh token from the same family triggers a security event and invalidates the entire family.