euv_core/dynamic/engine/struct.rs
1use super::*;
2
3/// Client configuration controlling the background `UpdateWorker`, negotiation, verification, and budgets.
4#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
5pub struct UpdateClientConfig {
6 /// Base HTTP URL of the Hyperlane update server (e.g. `"http://127.0.0.1:8080"`).
7 pub(crate) base_url: String,
8 /// Logical project identifier.
9 pub(crate) project: String,
10 /// Release channel name (e.g. `"prod"`).
11 pub(crate) channel: String,
12 /// Trusted HMAC-SHA256 verification key bytes.
13 pub(crate) verify_key: Vec<u8>,
14 /// Running host ABI version.
15 #[new(skip)]
16 #[get(type(copy))]
17 pub(crate) host_abi: u32,
18 /// Allowed channel delivery mode (`WasmComponent` or `DeclarativeData`).
19 #[new(skip)]
20 #[get(type(copy))]
21 pub(crate) delivery_mode: DeliveryChannelMode,
22 /// Capabilities advertised by this host build.
23 #[new(skip)]
24 pub(crate) capabilities: Vec<String>,
25 /// Optional preferred compatibility track override.
26 #[new(skip)]
27 #[get(skip)]
28 pub(crate) preferred_track: Option<String>,
29 /// Maximum size in bytes allowed for any single artifact.
30 #[new(skip)]
31 #[get(type(copy))]
32 pub(crate) max_artifact_bytes: u64,
33 /// Capacity of the bounded non-blocking `CandidateMailbox`.
34 #[new(skip)]
35 #[get(type(copy))]
36 pub(crate) mailbox_capacity: usize,
37 /// SSE reconnect backoff in milliseconds.
38 #[new(skip)]
39 #[get(type(copy))]
40 pub(crate) reconnect_backoff_ms: u64,
41 /// HTTP connect/read timeout in milliseconds.
42 #[new(skip)]
43 #[get(type(copy))]
44 pub(crate) http_timeout_ms: u64,
45 /// Wasm sandbox fuel, memory, and size limits applied during warm-up and mount.
46 #[new(skip)]
47 #[get(type(copy))]
48 pub(crate) sandbox_config: WasmSandboxConfig,
49}
50
51/// Pure-std HTTP/1.1 release transport fetching signed manifests and range-resumable content-addressed blobs.
52#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
53pub struct HttpReleaseTransport {
54 /// Base HTTP URL (`http://host:port`).
55 pub(crate) base_url: String,
56 /// Connect and read timeout in milliseconds.
57 #[get(type(copy))]
58 pub(crate) timeout_ms: u64,
59}
60
61/// Fully verified, pre-compiled, and pre-migrated release candidate handed from `UpdateWorker` to the UI thread.
62#[derive(Clone, Data, Debug)]
63pub struct PreparedReleaseCandidate {
64 /// Verified signed target `ReleaseManifest`.
65 pub(crate) manifest: ReleaseManifest,
66 /// SHA-256 digest of the verified manifest JSON.
67 pub(crate) manifest_sha256: String,
68 /// Pre-parsed / warmed artifacts keyed by `"module_id@version"`.
69 pub(crate) warmed_artifacts: BTreeMap<String, WarmedArtifact>,
70 /// Authoritative route paths whose pinned dependency graph changed relative to the previous manifest.
71 pub(crate) affected_routes: Vec<String>,
72 /// SHA-256 blob hashes downloaded over the wire during this preparation.
73 pub(crate) newly_fetched_hashes: Vec<String>,
74 /// SHA-256 blob hashes reused from the local verified content cache without re-downloading.
75 pub(crate) reused_cached_hashes: Vec<String>,
76 /// Pre-migrated nested component UI state snapshots keyed by canonical `StableAddress`.
77 pub(crate) migrated_ui_states: BTreeMap<String, ComponentUiStateSnapshot>,
78 /// Global authoritative business store revision `R` at snapshot capture time.
79 #[get(type(copy))]
80 pub(crate) snapshot_business_revision: u64,
81 /// Per-entity baseline revisions captured at snapshot time `R` for `R -> R+n` catch-up.
82 pub(crate) snapshot_entity_revisions: BTreeMap<String, u64>,
83 /// OS thread name on which verification, compilation, and migration executed.
84 pub(crate) prepared_on_thread: String,
85}
86
87/// Interior queue state for the bounded non-blocking `CandidateMailbox`.
88#[derive(Debug)]
89pub(crate) struct CandidateMailboxInner {
90 /// Maximum number of queued candidates.
91 pub(crate) capacity: usize,
92 /// Highest release sequence accepted so far to reject stale candidates.
93 pub(crate) highest_seen_seq: u64,
94 /// Bounded FIFO queue of prepared candidates.
95 pub(crate) queue: VecDeque<PreparedReleaseCandidate>,
96}
97
98/// Bounded non-blocking handoff mailbox decoupling the background `UpdateWorker` from the UI/render thread.
99#[derive(Clone, Debug)]
100pub struct CandidateMailbox {
101 /// Shared mutex-guarded bounded queue accessed via `try_lock` on the UI thread.
102 pub(crate) inner: Arc<Mutex<CandidateMailboxInner>>,
103}
104
105/// Shared worker state coordinating SSE cursor, verified blob cache, fetch telemetry, and shutdown.
106#[derive(CustomDebug)]
107pub(crate) struct UpdateWorkerShared {
108 /// Client negotiation, verification, and budget configuration.
109 pub(crate) config: UpdateClientConfig,
110 /// Bounded non-blocking candidate delivery mailbox.
111 pub(crate) mailbox: CandidateMailbox,
112 /// Verified content-addressed blob cache keyed by 64-char SHA-256 hex digest.
113 pub(crate) blob_cache: Mutex<HashMap<String, Arc<Vec<u8>>>>,
114 /// Chronological list of SHA-256 hashes actually downloaded over the transport (for incremental verification).
115 pub(crate) fetched_hashes_log: Mutex<Vec<String>>,
116 /// Latest accepted SSE `Last-Event-ID` cursor.
117 pub(crate) last_event_id: Mutex<Option<String>>,
118 /// Latest manifest successfully prepared on the background worker.
119 pub(crate) last_prepared_manifest: Mutex<Option<ReleaseManifest>>,
120 /// Optional latest background error recorded without interrupting live UI.
121 pub(crate) last_error: Mutex<Option<DynamicReleaseError>>,
122 /// Pending route UI snapshot queued by the UI thread for background migration.
123 pub(crate) pending_snapshot: Mutex<Option<NestedStateSnapshot>>,
124 /// Pure background state migrator.
125 #[debug(skip)]
126 pub(crate) migrator: SharedStateMigrator,
127 /// Cooperative stop flag terminating the worker thread cleanly.
128 pub(crate) running: AtomicBool,
129 /// One-shot flag requesting immediate manifest reconciliation.
130 pub(crate) reconcile_requested: AtomicBool,
131 /// Count of completed SSE reconnect cycles.
132 pub(crate) sse_connect_count: AtomicU64,
133}
134
135/// Running handle to the dedicated background `UpdateWorker` thread.
136#[derive(Debug)]
137pub struct UpdateWorkerHandle {
138 /// Shared worker coordination state.
139 pub(crate) shared: Arc<UpdateWorkerShared>,
140 /// Dedicated background worker OS thread handle.
141 #[cfg(not(target_arch = "wasm32"))]
142 pub(crate) worker_thread: Option<JoinHandle<()>>,
143}
144
145/// Active ref-counted release generation pinned by one or more open routes or in-flight operations.
146#[derive(Clone, Data, Debug)]
147pub struct ReleaseGeneration {
148 /// Monotonic release generation identifier (`== manifest.release_seq`).
149 #[get(type(copy))]
150 pub(crate) generation_id: u64,
151 /// Signed immutable manifest defining this generation.
152 pub(crate) manifest: ReleaseManifest,
153 /// Pre-warmed artifacts shared across routes pinned to this generation.
154 pub(crate) warmed_artifacts: BTreeMap<String, WarmedArtifact>,
155 /// Number of currently open route instances pinned to this generation.
156 #[get(type(copy))]
157 pub(crate) active_route_pins: usize,
158 /// Number of active in-flight tasks still referencing this generation.
159 #[get(type(copy))]
160 pub(crate) active_in_flight_tasks: usize,
161}
162
163/// Per-route pinned dependency graph handle isolating open Route A from open Route B.
164#[derive(Clone, Data, Debug)]
165pub struct RoutePinHandle {
166 /// Stable route instance identifier (e.g. `"A#tab-1"`).
167 pub(crate) route_instance_id: String,
168 /// Normalized route path (e.g. `"/route-a"`).
169 pub(crate) route: String,
170 /// Pinned release generation identifier.
171 #[get(type(copy))]
172 pub(crate) generation_id: u64,
173 /// Pinned entry artifact key (`"page-a@1.0.0"`).
174 pub(crate) entry_module: String,
175 /// Pinned logical slot bindings (`"card"` -> `"card@1.0.0"` or `"card@2.0.0"`).
176 pub(crate) slot_bindings: BTreeMap<String, String>,
177 /// Cancellation token flipped when this pinned instance is superseded or closed.
178 pub(crate) cancellation_token: Arc<AtomicBool>,
179}
180
181/// Host-mediated cross-route action preventing component version leakage between routes (Sec 11.2).
182#[derive(Clone, Data, Debug, New)]
183pub struct CrossRouteAction {
184 /// Target route path to enter or activate.
185 pub(crate) target_route: String,
186 /// Logical action identifier validated against host permissions.
187 pub(crate) action_id: String,
188 /// Typed JSON action payload.
189 pub(crate) payload: Value,
190 /// Release generation active on the originating route.
191 #[get(type(copy))]
192 pub(crate) origin_generation: u64,
193 /// Cancellation token tied to the originating route instance.
194 pub(crate) cancellation_token: Arc<AtomicBool>,
195}
196
197/// Result summary emitted by `DynamicReleaseRuntime::activate_release`.
198#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
199pub struct ActivationReport {
200 /// Target release sequence evaluated.
201 #[get(type(copy))]
202 pub(crate) release_seq: u64,
203 /// Open route instance IDs atomically hot-swapped at this frame boundary.
204 pub(crate) swapped_routes: Vec<String>,
205 /// Open route instance IDs left untouched on their prior pinned generation.
206 pub(crate) unchanged_pinned_routes: Vec<String>,
207 /// Whether activation was safely deferred due to an unsafe interaction boundary.
208 #[get(type(copy))]
209 pub(crate) deferred: bool,
210 /// Human-readable deferral reason when `deferred == true`.
211 pub(crate) defer_reason: String,
212 /// Number of business state deltas replayed from `R` to `R+n`.
213 #[get(type(copy))]
214 pub(crate) caught_up_deltas: usize,
215 /// Number of unreachable old release generations reclaimed by GC.
216 #[get(type(copy))]
217 pub(crate) gc_reclaimed_generations: usize,
218}
219
220/// Client runtime orchestrator managing per-route pinned dependency graphs, safe swaps, business state, and GC.
221#[derive(CustomDebug)]
222pub struct DynamicReleaseRuntime {
223 /// Ambient `DynamicUpdateHub` receiving surgical frame-boundary slot updates.
224 pub(crate) hub: DynamicUpdateHub,
225 /// Host-owned authoritative business state store surviving swaps and rollbacks.
226 pub(crate) business_store: BusinessStateStore,
227 /// Wasm sandbox execution configuration.
228 pub(crate) sandbox_config: WasmSandboxConfig,
229 /// Currently active latest release sequence (`0` before any release is installed).
230 pub(crate) active_release_seq: u64,
231 /// Live and ref-counted release generations keyed by `generation_id`.
232 pub(crate) generations: BTreeMap<u64, ReleaseGeneration>,
233 /// Currently open pinned route instances keyed by `route_instance_id`.
234 pub(crate) open_routes: BTreeMap<String, RoutePinHandle>,
235 /// Last migrated per-instance UI state snapshots keyed by canonical `StableAddress`.
236 pub(crate) restored_ui_states: BTreeMap<String, ComponentUiStateSnapshot>,
237 /// Candidate deferred at an unsafe interaction boundary awaiting the next safe frame.
238 pub(crate) deferred_candidate: Option<PreparedReleaseCandidate>,
239 /// Monotonic component revision counter applied onto `DynamicUpdateHub` slots.
240 pub(crate) next_hub_revision: u64,
241}