Skip to main content

Module session

Module session 

Source
Expand description

Thread / Session split (issue #5261).

codewhale’s Session was really a thread. The new split is:

  • Thread — durable, persisted, owns the append-only Journal and the leafId cursor. One row in state.threads, one directory on disk.
  • Session — ephemeral, per-turn / per-engine-lifetime, owns the in-memory TurnContext plus the live approval/sandbox posture for this SessionId. Many sessions can attach to one thread over time, but only one Session drives a turn for a given ThreadId at a time.

The thread manager (ThreadManager in crate::lib) already can start a session with no TUI attached (spawn_thread_with_history); this file formalizes the types that make that first-class and moves the former crates/tui/src/core/session.rs state (model, reasoning_effort, AppendLog, PrefixStabilityManager, frozen_prefix, messages_revision) into crates/core so both TUI and headless share it.

Structs§

Session
Ephemeral session within a thread (one engine lifetime / one turn’s live posture). The TUI’s EngineHandle and the headless exec both hold a Session that points at the same ThreadId but with different SessionIds.
Thread
Durable thread (the former Session). One per conversation, persisted in state.threads. The only new field vs the old Session is leaf_id — the journal cursor — plus the typed ThreadId. All other fields keep their persisted JSON shape unchanged.

Functions§

session_for_thread
Split helper: derive a Session from an existing Thread without cloning the journal. Headless and TUI call the same constructor so the request shape stays identical.