Skip to main content

Workstream

Struct Workstream 

Source
pub struct Workstream {
    pub id: WorkstreamId,
    pub name: String,
    pub session_ids: Vec<String>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    pub metadata: Map<String, Value>,
}
Expand description

A durable named grouping of sessions, scoped to a single daemon instance (DOC-48 §2.1).

Why: the domain object that finally gives a workstream daemon-owned identity (DOC-48 §1.1) — previously the in-memory SessionRegistry was the sole record and a restart discarded it. What: id is immutable; name and metadata are mutable; session_ids is append-only (never removed, per §2.1); created_at is immutable, updated_at reflects last activity. state is deliberately NOT a field — call Self::state with the store’s active pointer to compute it. Test: model_tests::workstream_serde_round_trip, model_tests::new_workstream_starts_idle_with_no_sessions.

Fields§

§id: WorkstreamId

Unique, immutable identifier assigned at creation.

§name: String

Human-readable name; mutable (future rename support, Phase C).

§session_ids: Vec<String>

Sessions bound to this workstream. Append-only — never remove an entry (§2.1).

§created_at: DateTime<Utc>

When the workstream was created (first workstream.create call).

§updated_at: DateTime<Utc>

Last activity: state inferred, name changed, session attached, activated/deactivated, or closed.

§metadata: Map<String, Value>

Reserved for future use (tags, description, the closed flag). Empty by default; #[serde(default)] keeps pre-existing records without this key deserializable.

Implementations§

Source§

impl Workstream

Source

pub fn new(name: impl Into<String>) -> Self

Create a new workstream with the given name, no bound sessions, and empty metadata.

Why: the one constructor every creation path (the future workstream.create RPC, and this ticket’s store/tests) funnels through, so id/created_at/updated_at are never hand-assembled inconsistently. What: assigns a fresh WorkstreamId, stamps created_at == updated_at == now, and starts with empty session_ids/metadata. Test: model_tests::new_workstream_starts_idle_with_no_sessions.

Source

pub fn is_closed(&self) -> bool

Whether this workstream is marked closed via the reserved metadata flag (§3.2).

Why: closure itself (workstream.close, #3294/#3295) is out of this ticket’s scope, but the domain model must already agree on where that future verb will record its effect, so state inference is correct from day one rather than needing a schema migration later. What: true iff metadata["closed"] is present and == true. Test: model_tests::state_is_closed_when_metadata_flag_set.

Source

pub fn state( &self, active_workstream_id: Option<WorkstreamId>, ) -> WorkstreamState

Compute this workstream’s state given the store’s persisted active pointer (DOC-48 §2.2/§3.2).

Why: state must never be read from a stored field — the pointer is the single source of truth for which workstream is active, and session liveness never gates this (§3.3: “it does NOT determine active/idle state”). What: Active iff active_workstream_id == Some(self.id) (checked FIRST, matching §3.2’s literal ordering); otherwise Closed if Self::is_closed, else Idle. Test: model_tests::state_is_active_iff_pointer_matches, model_tests::state_is_closed_when_metadata_flag_set, model_tests::state_defaults_to_idle.

Source

pub fn touch(&mut self)

Stamp updated_at to now.

Why: every mutation the store performs on a record (rename, session bind, activation change, close) must refresh liveness per §2.1’s updated_at semantics; centralising it here keeps every call site in lock-step. What: sets updated_at = Utc::now(). Test: model_tests::touch_updates_timestamp.

Source

pub fn mark_closed(&mut self)

Mark this workstream closed via the reserved metadata flag (DOC-48 §4.4, SPEC-WS-04~draft).

Why: workstream.close (#3295) is the sole call site that flips a workstream irreversible-closed; centralising the mutation here keeps the reserved metadata["closed"] key private to this module rather than leaking its literal string to the store/RPC layers. Idempotent — closing an already-closed workstream re-sets the same flag and simply refreshes updated_at, since the spec never requires re-close to error. What: sets metadata["closed"] = true, then calls Self::touch. Test: model_tests::mark_closed_sets_flag_and_touches.

Trait Implementations§

Source§

impl Clone for Workstream

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Workstream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Workstream

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Workstream

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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