Infer MCP sessions from a sliding window

What does this MR do and why?

Infer MCP sessions from a sliding window

MCP is stateless - session ids were removed from the specification in the 2026-07-28 revision - so there is nothing on a tools/call request to group calls by. A session is inferred from caller identity plus a 15 minute idle window capped at 30 minutes, held in Redis, and recorded as an ai_governance_sessions row.

The window is evaluated in Ruby rather than left to the Redis TTL, so a key outliving its window cannot silently extend a session.

The OAuth application behind the request is the only agent identity that survives statelessness. It is client-declared and never verified, so it is mapped onto a known slug and is attribution only, never authorization.

Nothing calls this yet.

Changelog: added EE: true

References

Screenshots or screen recordings

Before After

How to set up and validate locally

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

##Queryies -- create_session INSERT INTO ai_governance_sessions (namespace_id, project_id, user_id, external_xid, source, status, session_started_at, agent_type, created_at, updated_at) VALUES ($1, $2, $3, $4, 3, 1, $5, $6, $7, $8) RETURNING id

-- resume / resume_after_lost_claim SELECT "ai_governance_sessions".* FROM "ai_governance_sessions" WHERE "ai_governance_sessions"."id" = $1 LIMIT 1 -- Index Scan using ai_governance_sessions_pkey (primary key lookup)

-- mint, lost-claim path DELETE FROM ai_governance_sessions WHERE id = $1 -- Delete via primary key

All three are single-row primary-key operations. The INSERT checks two partial unique indexes, both namespace_id-led: i_ai_governance_sessions_on_namespace_source_external_xid and i_ai_governance_sessions_on_namespace_workflow

Edited by Harsimar Sandhu

Merge request reports

Loading
Loading