1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! `session.create`'s validate-then-mint-then-bind step (DOC-48 §4.1/§4.2,
//! issue #3298; atomicity fix per PR #3354 code-critic HIGH finding 1),
//! split out of `protocol.rs` purely to keep that production file under the
//! crate's 500-SLOC cap — a child module of `protocol` (declared via
//! `#[path = ...] mod protocol_workstream;`), so it shares full access to
//! `protocol`'s private items exactly as if this function were still
//! defined there.
//!
//! Why: `SessionRegistry` has no delete/rollback, so `create` must NOT mint
//! a session until the workstream target (if any) has been fully validated
//! — the first cut minted first and could then fail the bind, stranding an
//! orphaned, caller-invisible session in the registry on every rejected
//! bind (code-critic HIGH 1, PR #3354). This helper drives
//! `crate::workstreams::protocol::resolve_validate_bind`, which validates
//! every caller-triggerable failure mode (malformed/unknown/closed
//! `workstream_id`) BEFORE invoking the mint closure, all under one store
//! lock (TOCTOU-free — see that function's docs).
//!
//! What: [`mint_bound_session`] resolves+validates the effective workstream
//! target, mints the session via the caller's closure only once validation
//! passes, persists the bind, stamps it onto the registry via
//! `SessionRegistry::bind_workstream` (publishing `Event::SessionAdded`),
//! and returns the POST-bind `Session` snapshot as `Value` — so the
//! response always reflects the binding it just made, never a stale
//! pre-bind snapshot.
//!
//! Test: `super::workstream_binding_tests::*`, in particular
//! `create_rejected_bind_leaves_no_phantom_session` (the regression the
//! critic required).
use ;
use crateRpcError;
use crateSharedWorkstreamStore;
use SessionRegistry;
/// Validate the workstream target, mint the session (only after validation
/// passes), persist + stamp its binding, and return its snapshot.
pub async