IBEX Harness
DocsBenchmarksBlogChangelogRoadmap
GitHub
IBEX Harness

Documentation

OverviewConfigurationAuthenticationAuth cachingDirectivesSessionsRate limitingRequest routingProvider adapters
Proxy›Sessions
Proxy

Sessions

Sticky session IDs, durable sessions, checkpoints, and idle sweep on the proxy.

New Session lifecycle is shipped on the chat path. There is no separate public session CRUD API today — clients use X-IBEX-Session-ID on POST /v1/chat/completions.

Design: ADR-0032, ADR-0039.

What you get

TopicBehavior
Sticky headerX-IBEX-Session-ID — client-supplied or minted UUID (max 64 chars)
Durable rowPostgres ibex_core.sessions when POSTGRES_DSN is set
CheckpointsAsync append to ibex_core.checkpoints after successful completions
CacheRedis session:{org_id}:{agent_id}:{external_id}
Idle sweeperMarks stale active sessions abandoned

Client contract

http
POST /v1/chat/completions
Authorization: Bearer ibex_pat_…
X-IBEX-Agent-ID: <agent-uuid>
X-IBEX-Session-ID: <optional-sticky-id>
Content-Type: application/json
  • If the header is missing or invalid, the proxy mints a UUID and echoes it on the response.
  • The sticky value is the session external_id, not the internal row UUID.
  • Without Postgres, sticky IDs still work for correlation; nothing is persisted.

Durable GetOrCreate

When POSTGRES_DSN is set:

  1. Look up Redis cache for the sticky external id.
  2. On miss, GetOrCreate in Postgres under RLS (SET LOCAL app.current_org_id).
  3. Budget default: IBEX_SESSION_GETORCREATE_TIMEOUT=50ms.
  4. On timeout/error: fail-open — continue with sticky id only; skip checkpoints until a durable session exists.

Checkpoints

After a complete non-stream response (or streaming completion), the proxy enqueues an async checkpoint write:

VariableDefault
IBEX_SESSION_CHECKPOINT_WORKERS8
IBEX_SESSION_CHECKPOINT_QUEUE256

Duplicate turn handling invalidates cache, re-GetOrCreate, and retries once. Provider failures that leave an incomplete turn do not write an empty checkpoint.

Idle sweeper

VariableDefaultMeaning
IBEX_SESSION_IDLE_TIMEOUT45mupdated_at age before active → abandoned
IBEX_SESSION_SWEEP_INTERVAL1mSweep cadence (must be ≤ idle timeout)
IBEX_SESSION_CACHE_TTL60sRedis session cache TTL

Sweeper runs only when Postgres is configured.

Failure modes

ConditionResult
No POSTGRES_DSNSticky header only; no DB sessions/checkpoints/sweeper
GetOrCreate timeoutChat continues; no durable session for that request
Checkpoint queue full / worker errorLogged; chat response already returned

Where to look in the repo

  • services/proxy/internal/http/session/ — sticky id + checkpoint helpers
  • services/proxy/internal/http/chat_session_bridge.go — GetOrCreate bridge
  • services/proxy/internal/sessionsweeper/ — idle sweeper
  • infra/migrations/postgres/000010_create_sessions.up.sql — schema

Related docs

  • Directives
  • Proxy configuration
  • Multi-tenant RLS
  • Chat completions

Was this page helpful?

Edit on GitHub

Last updated on

PreviousDirectivesNextRate limiting

On this page

  • What you get
  • Client contract
  • Durable GetOrCreate
  • Checkpoints
  • Idle sweeper
  • Failure modes
  • Where to look in the repo
  • Related docs
0%