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: WorkstreamIdUnique, immutable identifier assigned at creation.
name: StringHuman-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
impl Workstream
Sourcepub fn new(name: impl Into<String>) -> Self
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.
Sourcepub fn is_closed(&self) -> bool
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.
Sourcepub fn state(
&self,
active_workstream_id: Option<WorkstreamId>,
) -> WorkstreamState
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.
Sourcepub fn touch(&mut self)
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.
Sourcepub fn mark_closed(&mut self)
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
impl Clone for Workstream
Source§impl Debug for Workstream
impl Debug for Workstream
Source§impl<'de> Deserialize<'de> for Workstream
impl<'de> Deserialize<'de> for Workstream
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Workstream
impl RefUnwindSafe for Workstream
impl Send for Workstream
impl Sync for Workstream
impl Unpin for Workstream
impl UnsafeUnpin for Workstream
impl UnwindSafe for Workstream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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