euv_core/dynamic/engine/struct.rs
1use super::*;
2
3/// Proxy-aware on-device hot-update connection configuration bridging direct, reverse-proxy, and HTTP forward-proxy transports.
4#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
5pub struct HotUpdateProxyConfig {
6 /// Target update server base URL (direct `http://127.0.0.1:8787` or reverse proxy `https://proxy.host/euv`).
7 pub(crate) server_url: String,
8 /// Optional explicit HTTP forward proxy URL (`http://proxy.local:7890`).
9 #[get(skip)]
10 #[serde(default)]
11 pub(crate) proxy_url: Option<String>,
12 /// Optional proxy credentials (`"user:pass"`, `"Basic ..."`, or `"Bearer ..."`).
13 #[get(skip)]
14 #[serde(default)]
15 pub(crate) proxy_auth: Option<String>,
16 /// Release channel name (e.g. `"prod"` or `"dev"`).
17 pub(crate) channel: String,
18 /// Whether verified incoming candidates apply automatically without manual prompt.
19 #[get(type(copy))]
20 pub(crate) auto_apply: bool,
21 /// Fallback manifest polling interval in seconds when SSE is unavailable.
22 #[get(type(copy))]
23 pub(crate) poll_fallback_secs: u64,
24 /// Optional persistent disk cache directory for verified OTA blobs and active/previous manifests.
25 #[get(skip)]
26 #[serde(default)]
27 pub(crate) cache_dir: Option<PathBuf>,
28}
29
30/// Reactive live status snapshot published by `DynamicUpdateHub` for connected hot-update clients.
31#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
32pub struct HotUpdateLiveStatus {
33 /// Whether a live hot-update transport (background SSE worker or browser `EventSource`) is active.
34 #[get(type(copy))]
35 pub(crate) connected: bool,
36 /// Whether the underlying SSE stream has an established live HTTP 200 connection to the server.
37 #[get(type(copy))]
38 pub(crate) sse_live: bool,
39 /// Configured target update server base URL.
40 pub(crate) server_url: String,
41 /// Optional configured HTTP forward proxy or reverse-proxy URL (empty when direct).
42 pub(crate) proxy_url: String,
43 /// Active release channel name (e.g. `"prod"`).
44 pub(crate) channel: String,
45 /// Highest applied release sequence number (`0` before any hot update is applied).
46 #[get(type(copy))]
47 pub(crate) active_release_seq: u64,
48 /// SHA-256 hex digest of the active applied release manifest.
49 pub(crate) active_manifest_sha256: String,
50 /// Number of verified releases atomically applied during this session.
51 #[get(type(copy))]
52 pub(crate) applied_count: u64,
53 /// Whether the active release was restored offline from persistent disk cache.
54 #[get(type(copy))]
55 pub(crate) restored_from_cache: bool,
56 /// Whether a verified candidate is currently deferred awaiting a safe interaction boundary.
57 #[get(type(copy))]
58 pub(crate) pending_safe_boundary: bool,
59 /// Latest non-fatal background transport or verification diagnostic message (empty when healthy).
60 pub(crate) last_error: String,
61}
62
63/// Client configuration controlling the background `UpdateWorker`, negotiation, verification, and budgets.
64#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
65pub struct UpdateClientConfig {
66 /// Base HTTP URL of the Hyperlane update server (e.g. `"http://127.0.0.1:8080"`).
67 pub(crate) base_url: String,
68 /// Logical project identifier.
69 pub(crate) project: String,
70 /// Release channel name (e.g. `"prod"`).
71 pub(crate) channel: String,
72 /// Trusted HMAC-SHA256 verification key bytes.
73 pub(crate) verify_key: Vec<u8>,
74 /// Optional explicit HTTP forward proxy URL (`http://proxy:port`).
75 #[new(skip)]
76 #[get(skip)]
77 pub(crate) proxy_url: Option<String>,
78 /// Optional forward-proxy `Proxy-Authorization` credential (`"user:pass"` or `"Basic ..."`).
79 #[new(skip)]
80 #[get(skip)]
81 pub(crate) proxy_auth: Option<String>,
82 /// Running host ABI version.
83 #[new(skip)]
84 #[get(type(copy))]
85 pub(crate) host_abi: u32,
86 /// Allowed channel delivery mode (`WasmComponent` or `DeclarativeData`).
87 #[new(skip)]
88 #[get(type(copy))]
89 pub(crate) delivery_mode: DeliveryChannelMode,
90 /// Capabilities advertised by this host build.
91 #[new(skip)]
92 pub(crate) capabilities: Vec<String>,
93 /// Optional preferred compatibility track override.
94 #[new(skip)]
95 #[get(skip)]
96 pub(crate) preferred_track: Option<String>,
97 /// Maximum size in bytes allowed for any single artifact.
98 #[new(skip)]
99 #[get(type(copy))]
100 pub(crate) max_artifact_bytes: u64,
101 /// Capacity of the bounded non-blocking `CandidateMailbox`.
102 #[new(skip)]
103 #[get(type(copy))]
104 pub(crate) mailbox_capacity: usize,
105 /// SSE reconnect backoff in milliseconds.
106 #[new(skip)]
107 #[get(type(copy))]
108 pub(crate) reconnect_backoff_ms: u64,
109 /// HTTP connect/read timeout in milliseconds.
110 #[new(skip)]
111 #[get(type(copy))]
112 pub(crate) http_timeout_ms: u64,
113 /// Wasm sandbox fuel, memory, and size limits applied during warm-up and mount.
114 #[new(skip)]
115 #[get(type(copy))]
116 pub(crate) sandbox_config: WasmSandboxConfig,
117 /// Optional persistent disk cache directory for verified OTA blobs and active/previous manifests.
118 #[new(skip)]
119 #[get(skip)]
120 pub(crate) cache_dir: Option<PathBuf>,
121}
122
123/// Pure-std HTTP/1.1 release transport fetching signed manifests and range-resumable content-addressed blobs.
124#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
125pub struct HttpReleaseTransport {
126 /// Base HTTP URL (`http://host:port` or reverse-proxy prefix `http://proxy:port/prefix`).
127 pub(crate) base_url: String,
128 /// Connect and read timeout in milliseconds.
129 #[get(type(copy))]
130 pub(crate) timeout_ms: u64,
131 /// Optional explicit HTTP forward proxy URL (`http://proxy:port`).
132 #[new(skip)]
133 #[get(skip)]
134 pub(crate) proxy_url: Option<String>,
135 /// Optional forward-proxy `Proxy-Authorization` credential.
136 #[new(skip)]
137 #[get(skip)]
138 pub(crate) proxy_auth: Option<String>,
139}
140
141/// Fully verified, pre-compiled, and pre-migrated release candidate handed from `UpdateWorker` to the UI thread.
142#[derive(Clone, Data, Debug)]
143pub struct PreparedReleaseCandidate {
144 /// Verified signed target `ReleaseManifest`.
145 pub(crate) manifest: ReleaseManifest,
146 /// SHA-256 digest of the verified manifest JSON.
147 pub(crate) manifest_sha256: String,
148 /// Pre-parsed / warmed artifacts keyed by `"module_id@version"`.
149 pub(crate) warmed_artifacts: BTreeMap<String, WarmedArtifact>,
150 /// Authoritative route paths whose pinned dependency graph changed relative to the previous manifest.
151 pub(crate) affected_routes: Vec<String>,
152 /// SHA-256 blob hashes downloaded over the wire during this preparation.
153 pub(crate) newly_fetched_hashes: Vec<String>,
154 /// SHA-256 blob hashes reused from the local verified content cache without re-downloading.
155 pub(crate) reused_cached_hashes: Vec<String>,
156 /// Pre-migrated nested component UI state snapshots keyed by canonical `StableAddress`.
157 pub(crate) migrated_ui_states: BTreeMap<String, ComponentUiStateSnapshot>,
158 /// Global authoritative business store revision `R` at snapshot capture time.
159 #[get(type(copy))]
160 pub(crate) snapshot_business_revision: u64,
161 /// Per-entity baseline revisions captured at snapshot time `R` for `R -> R+n` catch-up.
162 pub(crate) snapshot_entity_revisions: BTreeMap<String, u64>,
163 /// OS thread name on which verification, compilation, and migration executed.
164 pub(crate) prepared_on_thread: String,
165}
166
167/// Restored offline hot-update candidate paired with its verified on-disk content-addressed blobs.
168#[derive(Debug)]
169pub(crate) struct PersistedReleaseRestore {
170 /// Warmed release candidate restored from `active_manifest.json` or `previous_manifest.json`.
171 pub(crate) candidate: PreparedReleaseCandidate,
172 /// Verified SHA-256 blobs loaded from `cache_dir/blobs/` to pre-seed worker cache.
173 pub(crate) blobs: HashMap<String, Arc<Vec<u8>>>,
174}
175
176/// Interior queue state for the bounded non-blocking `CandidateMailbox`.
177#[derive(Debug)]
178pub(crate) struct CandidateMailboxInner {
179 /// Maximum number of queued candidates.
180 pub(crate) capacity: usize,
181 /// Highest release sequence accepted so far to reject stale candidates.
182 pub(crate) highest_seen_seq: u64,
183 /// Bounded FIFO queue of prepared candidates.
184 pub(crate) queue: VecDeque<PreparedReleaseCandidate>,
185}
186
187/// Bounded non-blocking handoff mailbox decoupling the background `UpdateWorker` from the UI/render thread.
188#[derive(Clone, Debug)]
189pub struct CandidateMailbox {
190 /// Shared mutex-guarded bounded queue accessed via `try_lock` on the UI thread.
191 pub(crate) inner: Arc<Mutex<CandidateMailboxInner>>,
192}
193
194/// Shared worker state coordinating SSE cursor, verified blob cache, fetch telemetry, and shutdown.
195#[derive(CustomDebug)]
196pub(crate) struct UpdateWorkerShared {
197 /// Client negotiation, verification, and budget configuration.
198 pub(crate) config: UpdateClientConfig,
199 /// Bounded non-blocking candidate delivery mailbox.
200 pub(crate) mailbox: CandidateMailbox,
201 /// Verified content-addressed blob cache keyed by 64-char SHA-256 hex digest.
202 pub(crate) blob_cache: Mutex<HashMap<String, Arc<Vec<u8>>>>,
203 /// Chronological list of SHA-256 hashes actually downloaded over the transport (for incremental verification).
204 pub(crate) fetched_hashes_log: Mutex<Vec<String>>,
205 /// Latest accepted SSE `Last-Event-ID` cursor.
206 pub(crate) last_event_id: Mutex<Option<String>>,
207 /// Latest manifest successfully prepared on the background worker.
208 pub(crate) last_prepared_manifest: Mutex<Option<ReleaseManifest>>,
209 /// Optional latest background error recorded without interrupting live UI.
210 pub(crate) last_error: Mutex<Option<DynamicReleaseError>>,
211 /// Pending route UI snapshot queued by the UI thread for background migration.
212 pub(crate) pending_snapshot: Mutex<Option<NestedStateSnapshot>>,
213 /// Pure background state migrator.
214 #[debug(skip)]
215 pub(crate) migrator: Arc<dyn StateMigrator>,
216 /// Cooperative stop flag terminating the worker thread cleanly.
217 pub(crate) running: AtomicBool,
218 /// One-shot flag requesting immediate manifest reconciliation.
219 pub(crate) reconcile_requested: AtomicBool,
220 /// Count of completed SSE reconnect cycles.
221 pub(crate) sse_connect_count: AtomicU64,
222 /// Whether the background SSE stream is currently connected with an active HTTP 200 session.
223 pub(crate) sse_live: AtomicBool,
224 /// Lock-free attention flag set ONLY when a ready candidate is pushed or background error state changes.
225 pub(crate) ui_attention_flag: Arc<AtomicBool>,
226}
227
228/// Running handle to the dedicated background `UpdateWorker` thread.
229#[derive(Debug)]
230pub struct UpdateWorkerHandle {
231 /// Shared worker coordination state.
232 pub(crate) shared: Arc<UpdateWorkerShared>,
233 /// Dedicated background worker OS thread handle.
234 #[cfg(not(target_arch = "wasm32"))]
235 pub(crate) worker_thread: Option<JoinHandle<()>>,
236}
237
238/// Active ref-counted release generation pinned by one or more open routes or in-flight operations.
239#[derive(Clone, Data, Debug)]
240pub struct ReleaseGeneration {
241 /// Monotonic release generation identifier (`== manifest.release_seq`).
242 #[get(type(copy))]
243 pub(crate) generation_id: u64,
244 /// Signed immutable manifest defining this generation.
245 pub(crate) manifest: ReleaseManifest,
246 /// Pre-warmed artifacts shared across routes pinned to this generation.
247 pub(crate) warmed_artifacts: BTreeMap<String, WarmedArtifact>,
248 /// Number of currently open route instances pinned to this generation.
249 #[get(type(copy))]
250 pub(crate) active_route_pins: usize,
251 /// Number of active in-flight tasks still referencing this generation.
252 #[get(type(copy))]
253 pub(crate) active_in_flight_tasks: usize,
254}
255
256/// Per-route pinned dependency graph handle isolating open Route A from open Route B.
257#[derive(Clone, Data, Debug)]
258pub struct RoutePinHandle {
259 /// Stable route instance identifier (e.g. `"A#tab-1"`).
260 pub(crate) route_instance_id: String,
261 /// Normalized route path (e.g. `"/route-a"`).
262 pub(crate) route: String,
263 /// Pinned release generation identifier.
264 #[get(type(copy))]
265 pub(crate) generation_id: u64,
266 /// Pinned entry artifact key (`"page-a@1.0.0"`).
267 pub(crate) entry_module: String,
268 /// Pinned logical slot bindings (`"card"` -> `"card@1.0.0"` or `"card@2.0.0"`).
269 pub(crate) slot_bindings: BTreeMap<String, String>,
270 /// Cancellation token flipped when this pinned instance is superseded or closed.
271 pub(crate) cancellation_token: Arc<AtomicBool>,
272}
273
274/// Host-mediated cross-route action preventing component version leakage between routes (Sec 11.2).
275#[derive(Clone, Data, Debug, New)]
276pub struct CrossRouteAction {
277 /// Target route path to enter or activate.
278 pub(crate) target_route: String,
279 /// Logical action identifier validated against host permissions.
280 pub(crate) action_id: String,
281 /// Typed JSON action payload.
282 pub(crate) payload: Value,
283 /// Release generation active on the originating route.
284 #[get(type(copy))]
285 pub(crate) origin_generation: u64,
286 /// Cancellation token tied to the originating route instance.
287 pub(crate) cancellation_token: Arc<AtomicBool>,
288}
289
290/// Result summary emitted by `DynamicReleaseRuntime::activate_release`.
291#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
292pub struct ActivationReport {
293 /// Target release sequence evaluated.
294 #[get(type(copy))]
295 pub(crate) release_seq: u64,
296 /// Open route instance IDs atomically hot-swapped at this frame boundary.
297 pub(crate) swapped_routes: Vec<String>,
298 /// Open route instance IDs left untouched on their prior pinned generation.
299 pub(crate) unchanged_pinned_routes: Vec<String>,
300 /// Whether activation was safely deferred due to an unsafe interaction boundary.
301 #[get(type(copy))]
302 pub(crate) deferred: bool,
303 /// Human-readable deferral reason when `deferred == true`.
304 pub(crate) defer_reason: String,
305 /// Number of business state deltas replayed from `R` to `R+n`.
306 #[get(type(copy))]
307 pub(crate) caught_up_deltas: usize,
308 /// Number of unreachable old release generations reclaimed by GC.
309 #[get(type(copy))]
310 pub(crate) gc_reclaimed_generations: usize,
311}
312
313/// Client runtime orchestrator managing per-route pinned dependency graphs, safe swaps, business state, and GC.
314#[derive(CustomDebug)]
315pub struct DynamicReleaseRuntime {
316 /// Ambient `DynamicUpdateHub` receiving surgical frame-boundary slot updates.
317 pub(crate) hub: DynamicUpdateHub,
318 /// Host-owned authoritative business state store surviving swaps and rollbacks.
319 pub(crate) business_store: BusinessStateStore,
320 /// Wasm sandbox execution configuration.
321 pub(crate) sandbox_config: WasmSandboxConfig,
322 /// Currently active latest release sequence (`0` before any release is installed).
323 pub(crate) active_release_seq: u64,
324 /// Live and ref-counted release generations keyed by `generation_id`.
325 pub(crate) generations: BTreeMap<u64, ReleaseGeneration>,
326 /// Currently open pinned route instances keyed by `route_instance_id`.
327 pub(crate) open_routes: BTreeMap<String, RoutePinHandle>,
328 /// Last migrated per-instance UI state snapshots keyed by canonical `StableAddress`.
329 pub(crate) restored_ui_states: BTreeMap<String, ComponentUiStateSnapshot>,
330 /// Candidate deferred at an unsafe interaction boundary awaiting the next safe frame.
331 pub(crate) deferred_candidate: Option<PreparedReleaseCandidate>,
332 /// Monotonic component revision counter applied onto `DynamicUpdateHub` slots.
333 pub(crate) next_hub_revision: u64,
334}