Session Lifecycle & Conversation State IMPLEMENTED

Sessions are the unit of conversation in MRP-VM. A session owns the chat log, staged and committed session KUs, selected plugin preferences, mounted KB metadata, and the explainability registry for recent turns. Spec: DS019.

Created Active (turns) Expired next turn

Session creation

A session is created when a chat request arrives without a usable session_id. The browser stores the current session id in local state so the tab can continue the same conversation until the session expires or the page state is reset.

Turn preparation

  1. Resolve or create the session
  2. Check expiry and mounted KB/workspace metadata
  3. Resolve selected planner, seed detector, KB plugin, and goal solver
  4. Build bounded prompt history and current message
  5. Prepare the explainability request id and request budgets

Session context store

Reusable facts, constraints, definitions, and execution guidance extracted from chat turns become session KUs. They are staged first and committed only when the turn succeeds.

@k1 ku atomic "session::turn::unit-000"
@k2 set $k1 sourceId session
@k3 set $k1 chunkId session::turn
@k4 set $k1 role Constraint
@k5 set $k1 topic "deployment environment"
@k6 set $k1 claim "The system must run on CPU only."
@k7 set $k1 utilityActs [verify]
@k8 set $k1 phaseScopes [kb-plugin gs-plugin]

Turn commit

On success the engine commits:

  1. user and assistant messages
  2. new session KUs after hash-based deduplication
  3. selected plugin ids for future defaults
  4. the explainability entry with response preview, response document, and execution trace

Failed turns do not append assistant text to the message log, but they still enter the explainability registry so the UI can inspect why the request failed.

Explainability log

Each session keeps a bounded per-turn explainability log. Every entry records request metadata, selected plugin ids, answer status, optional error details, and the canonical executionTrace.graph payload used by the Explainability panel.

Session state schema

{
  sessionId: "sess-abc123",
  createdAt: "2026-03-27T10:00:00Z",
  lastActivityAt: "2026-03-27T10:05:00Z",
  expiresAt: "2026-03-27T10:35:00Z",
  preferredModel: "test-fast",
  preferredPlannerPlugin: "planner-default",
  preferredSeedDetectorPlugin: "sd-symbolic",
  preferredKBPlugin: "kb-fast",
  preferredGoalSolverPlugin: "gs-symbolic",
  mountedKbId: "kb-...",
  messageLog: [{ role, content }, ...],
  sessionContextUnits: [ContextUnit, ...],
  explainabilityLog: [ExplainabilityTurn, ...]
}