Expand description
Activation-lock exclusivity layer over WorkstreamStore (DOC-48 §6,
issue #3294).
§Spec References
Why: WorkstreamStore::set_active is a bare “write the pointer”
primitive — issue #3293’s foundation deliberately left conflict detection
and force-switch semantics for this ticket to build (see that method’s
own docs). The daemon-enforced singleton invariant (AC-3.1) needs a layer
ABOVE the store that decides ActiveConflict vs. idempotent re-activation
vs. force-switch, and reports which workstream was previously active so
RPC/REST callers (and #3297’s SSE WorkstreamActivationChanged producer)
can react to the change.
What: SharedWorkstreamStore (the Arc<Mutex<...>> handle every RPC
handler closure clones — mirrors crate::session::SessionRegistry’s
Arc-shared-state convention, except WorkstreamStore’s mutating methods
take &mut self, so a tokio::sync::Mutex wrapper is required; tokio’s
(not std’s) because every store operation is async file I/O and must
not block the executor while held), ActivationError (the typed
failure surface), ActivateOutcome (new + prior ids), and the two free
functions activate/deactivate that implement DOC-48 §6.1’s exact
rules:
activate{id, force: false}whenidis ALREADY the active workstream: succeeds (idempotent — re-activating yourself is not a “switch” at all; §6.1’sActiveConflictonly fires when ANOTHER workstream is active).activate{id, force: false}when a DIFFERENT workstream is active:ActivationError::ActiveConflict(active_id).activate{id, force: true}: deactivates whichever workstream was active (if any) and activatesid, reporting both ids.deactivate{id}: clears the pointer only ifidIS the currently active workstream; otherwise a no-op success (§4.3: “deactivating an idle or closed workstream is a no-op (idempotent)” — this includes an unknown or nonexistent id, since the caller cannot distinguish “idle” from “never existed” without an extra lookup the spec does not ask for).
(issue #3297) activate/deactivate are also the sole publishers of
crate::events::Event::WorkstreamActivationChanged (DOC-48 §5.3/§6.3,
AC-3.3) — emitted exactly when the persisted active pointer actually
changes (a fresh activation, a force-switch, or a real deactivation),
never on the idempotent no-op branches. Centralising the emission here
(rather than at each RPC/REST call site) means every current AND future
caller of these two functions gets the notification for free — see
crate::events::Event::WorkstreamActivationChanged’s own docs for why
this reuses the existing global event bus instead of a second channel.
They also publish crate::events::Event::WorkstreamStateInferred for
every workstream whose computed state actually transitions alongside the
pointer change (the newly-active workstream on every real activation, plus
the prior one on a force-switch); super::protocol::close publishes the
same event’s "closed" state via [publish_state_inferred] (pub(super)
for exactly that one cross-file call).
Test: activation_tests.
Structs§
- Activate
Outcome - The result of a successful
activatecall (DOC-48 §5.1’s{active_id, prior_id?}response shape).
Enums§
- Activation
Error - Typed failure surface for
activate/deactivate.
Functions§
- activate
- Activate
idunder DOC-48 §6.1’s exclusivity rules. - deactivate
- Deactivate
idunder DOC-48 §4.3’s idempotent rule.
Type Aliases§
- Shared
Workstream Store - Shared, lock-wrapped handle to a project’s workstream store.