Liking cljdoc? Tell your friends :D

fractal.engine.session

L4 · session lifecycle + the turn-lock (07 §2/§5). start-session! is the SOLE composition root that constructs the adapter and stashes cfg+adapter on the handle. run-turn!/run-turn-async! gate (stop/max-turns) before the CAS, then drive the step loop. commit-turn!/finalize-turn! live in session-loop (GD4).

L4 · session lifecycle + the turn-lock (07 §2/§5). start-session! is the SOLE
composition root that constructs the adapter and stashes cfg+adapter on the
handle. run-turn!/run-turn-async! gate (stop/max-turns) before the CAS, then
drive the step loop. commit-turn!/finalize-turn! live in session-loop (GD4).
raw docstring

close-session!clj

(close-session! handle)

Release a handle's store resources: stop its live dispatch and, for the sqlite store, CLOSE the JDBC connection — so the session can later be durably reopened with resume-session! (as a process restart would). Memory: just stops the dispatch. Safe from a finally/shutdown hook.

Release a handle's store resources: stop its live dispatch and, for the sqlite
store, CLOSE the JDBC connection — so the session can later be durably reopened
with resume-session! (as a process restart would). Memory: just stops the
dispatch. Safe from a finally/shutdown hook.
sourceraw docstring

compact-session!clj

(compact-session! handle)

Force compaction now: CAS the turn-lock (throw :fractal/turn-in-flight if a turn is in flight), compact under the held lock, release in a finally.

Force compaction now: CAS the turn-lock (throw :fractal/turn-in-flight if a
turn is in flight), compact under the held lock, release in a finally.
sourceraw docstring

open-turn!clj

(open-turn! handle msg)

Append the :user message (with :message/turn-id), then :turn/started carrying the same turn id + :turn/user-message-id; return the turn id (GD26).

Append the :user message (with :message/turn-id), then :turn/started carrying
the same turn id + :turn/user-message-id; return the turn id (GD26).
sourceraw docstring

resume-session!clj

(resume-session! cfg sid)
(resume-session! cfg sid opts)

^:alpha (06 §2) — durably REOPEN a persisted session (:store :sqlite only) — the cross-process payoff of persistence. Builds the store on cfg's :store/dir, FOLDS the durable event log to rebuild the view cache (create-session!'s recovery path — deterministic re-fold reproduces the same ids, 02 §9), rebuilds the SCI ctx via kernel/new-ctx, and RESTORES the live REPL vars from the latest :vars-ref (kernel/restore-vars!) so a new turn can use a var def'd before the reopen. Does NOT append :session/started — the session already exists.

^:alpha (06 §2) — durably REOPEN a persisted session (`:store :sqlite` only) —
the cross-process payoff of persistence. Builds the store on cfg's :store/dir,
FOLDS the durable event log to rebuild the view cache (create-session!'s recovery
path — deterministic re-fold reproduces the same ids, 02 §9), rebuilds the SCI
ctx via kernel/new-ctx, and RESTORES the live REPL vars from the latest :vars-ref
(kernel/restore-vars!) so a new turn can use a var def'd before the reopen. Does
NOT append :session/started — the session already exists.
sourceraw docstring

run-turn!clj

(run-turn! handle msg)

BLOCKING. Gate (stop/max-turns) → CAS the turn-lock → compact if flagged → open the turn → run the loop → release → return a TurnResult (06 §5).

BLOCKING. Gate (stop/max-turns) → CAS the turn-lock → compact if flagged →
open the turn → run the loop → release → return a TurnResult (06 §5).
sourceraw docstring

run-turn-async!clj

(run-turn-async! handle msg)

Background. Same pre-CAS gate on the caller thread; open the turn SYNCHRONOUSLY (real store-assigned id), run the loop on a daemon future. Releases busy BEFORE delivering the promise (the re-invoke race, GD27b).

Background. Same pre-CAS gate on the caller thread; open the turn
SYNCHRONOUSLY (real store-assigned id), run the loop on a daemon future.
Releases busy BEFORE delivering the promise (the re-invoke race, GD27b).
sourceraw docstring

spawn-attached!clj

(spawn-attached! parent-handle source-handle child-opts)

Phase 4 attach composition root. Materializes a FRESH derived child from a selected immutable source head (the source session is never advanced). The child's SCI ctx is restored from the source head's vars snapshot before its task turn runs. Capability is clamped by both caller and source; a caller may not drive a more-privileged source session.

Phase 4 attach composition root. Materializes a FRESH derived child from a
selected immutable source head (the source session is never advanced). The
child's SCI ctx is restored from the source head's vars snapshot before its
task turn runs. Capability is clamped by both caller and source; a caller may
not drive a more-privileged source session.
sourceraw docstring

spawn-child!clj

(spawn-child! parent-handle child-opts)

Spawn a FRESH child session that REUSES the parent's store (children are just more sessions in the SAME memory/sqlite store — the port is unchanged). The composition root for a recursion:

  • capability = inherit-and-clamp: clamp(parent-resolved, child-override) (engine-default is ROOT-ONLY, 04 §3). With no override, child = parent — so a :locked-down parent's clamp keeps lm/rlm dropped, and a :default parent's child cannot exceed :default (the escalation is closed).
  • model/provider default to the root's (cfg :child-model / :child-provider).
  • harness = :rlm, so the child gets the six fns and can itself recurse (nesting works: independent ctxs, one per session). The child's REPL ctx + adapter + leaf + cache-id (FRESH per child, 08) are stashed on its handle exactly as start-session! does. Returns the child handle; the caller (recursion/child-call) drives run-turn! on it.
Spawn a FRESH child session that REUSES the parent's store (children are just
more sessions in the SAME memory/sqlite store — the port is unchanged). The
composition root for a recursion:
- capability = inherit-and-clamp: clamp(parent-resolved, child-override)
  (engine-default is ROOT-ONLY, 04 §3). With no override, child = parent — so
  a :locked-down parent's clamp keeps lm/rlm dropped, and a :default parent's
  child cannot exceed :default (the escalation is closed).
- model/provider default to the root's (cfg :child-model / :child-provider).
- harness = :rlm, so the child gets the six fns and can itself recurse
  (nesting works: independent ctxs, one per session).
The child's REPL ctx + adapter + leaf + cache-id (FRESH per child, 08) are
stashed on its handle exactly as start-session! does. Returns the child
handle; the caller (recursion/child-call) drives run-turn! on it.
sourceraw docstring

start-session!clj

(start-session! cfg)
(start-session! cfg opts)
source

stop-session!clj

(stop-session! handle)
(stop-session! handle {:keys [wait?]})

Request stop (idempotent, safe from a finally/shutdown hook). Idle ⇒ also append :session/stopped now; in-flight ⇒ the loop appends it at the next step boundary; :wait? blocks on the turn-lock then appends :session/stopped.

Request stop (idempotent, safe from a finally/shutdown hook). Idle ⇒ also
append :session/stopped now; in-flight ⇒ the loop appends it at the next step
boundary; :wait? blocks on the turn-lock then appends :session/stopped.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close