Skip to main content

Overview

IDManager maintains auto-incrementing ID sequences for LangChat’s Supabase tables. It handles concurrent inserts gracefully by using a retry-with-conflict-resolution strategy. This is an internal component — you don’t interact with it directly under normal use.
from langchat.adapters.database.id_manager import IDManager

How it works

  1. On initialization, IDManager reads the current maximum ID from each table
  2. IDs are assigned from an in-memory counter
  3. When two concurrent requests try to insert with the same ID, the retry logic increments and retries automatically
  4. This avoids database sequences while maintaining consistent IDs

Constructor

IDManager(
    supabase_client,
    initial_value: int = 1,
    retry_attempts: int = 3,
)
supabase_client
Client
Supabase client instance.
initial_value
int
default:"1"
Starting ID value for new tables.
retry_attempts
int
default:"3"
Number of retry attempts on ID conflict before raising an error.

Methods

insert_with_retry()

Insert a record with automatic ID assignment and conflict retry.
def insert_with_retry(
    self,
    table: str,
    data: dict,
) -> dict | None
Used internally by session.save_message() and metrics recording. You only need this if building a custom adapter.