Skip to main content

State

Struct State 

Source
pub struct State {
    pub store: Mutex<Store>,
    pub root: PathBuf,
    pub sessions: Mutex<HashMap<MergeSessionId, ApiMergeSession>>,
    pub policy_ceiling: Option<Policy>,
}

Fields§

§store: Mutex<Store>§root: PathBuf

Filesystem root of the store. Held alongside the Store itself so handlers that need to read store-level files (e.g. users.json for actor auth) don’t have to round- trip through the lock.

§sessions: Mutex<HashMap<MergeSessionId, ApiMergeSession>>

In-memory merge sessions, keyed by MergeSessionId. Sessions are ephemeral by design (#134 foundation): they live for the lifetime of the server process and are GC’d on commit. A future slice can persist them to disk so a session survives process restarts. For now an agent that gets unlucky with a restart re-runs merge/start and gets a fresh session.

§policy_ceiling: Option<Policy>

Optional server-imposed ceiling on the effect policy honored by /v1/run and /v1/replay. None (the default, used by single-tenant lex serve) runs the caller’s request policy as-is — the operator is the caller there, so that’s intended. When Some, the request policy is clamped via [clamp_policy] so it can only narrow the ceiling, never widen it.

Any embedder that exposes this API to untrusted callers — a hosted, multi-tenant gateway like lex-hub — MUST set this. Without it the request body can grant itself [proc] (arbitrary subprocess spawn), [fs_*] over /, and unrestricted [net]: arbitrary code execution as the server process. See lex-hub#6.

NOTE: an empty scope list means “any path/host” in the runtime, so a ceiling that puts fs_read/fs_write/net in allow_effects MUST also populate the matching scope list (allow_fs_read, …) or it re-opens the wildcard. Granting none of those kinds is the safe default.

Implementations§

Source§

impl State

Source

pub fn open(root: PathBuf) -> Result<Self>

Source

pub fn open_with_ceiling( root: PathBuf, policy_ceiling: Option<Policy>, ) -> Result<Self>

Like State::open but installs a policy_ceiling that /v1/run and /v1/replay clamp the caller’s request policy against. Embedders exposing this API to untrusted callers must use this constructor (or set the field directly).

Source

pub fn new_with_tenant(tenant_id: &str, store_root: PathBuf) -> Result<Self>

Construct a per-tenant State by prefixing store_root with the tenant id. Single-tenant lex serve is unaffected — it calls State::open directly.

tenant_id is restricted to [A-Za-z0-9_-]{1,64}: anything else (path separators, .., NUL, absolute paths, dotfiles, empty string) is rejected before touching the filesystem. Without this PathBuf::join("/etc") would silently replace store_root, and PathBuf::join("../foo") would escape the tenant root.

Source

pub fn new_with_tenant_and_ceiling( tenant_id: &str, store_root: PathBuf, policy_ceiling: Option<Policy>, ) -> Result<Self>

Multi-tenant constructor that also installs a policy ceiling for /v1/run / /v1/replay. The path-traversal guard from new_with_tenant and the effect ceiling are the two halves a hosted gateway needs.

Auto Trait Implementations§

§

impl !Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more