@orangecharts/wrun-chart-host 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/constants/feature-flags.constants.js +7 -2
- package/dist/host-env.d.ts +3 -19
- package/dist/host-ports.types.d.ts +1 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
- package/dist/interfaces/wrun-runtime.interface.js +17 -3
- package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
- package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
- package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
- package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
- package/dist/utility/wrun/wrun-host.service.d.ts +114 -50
- package/dist/utility/wrun/wrun-host.service.js +351 -151
- package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-hover.util.js +25 -4
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +2 -2
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +2 -2
- package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
- package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
- package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
- package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
- package/dist/workers/wrun/wrun-abi-host.js +31 -12
- package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
- package/dist/workers/wrun/wrun-engine-handler.js +181 -12
- package/package.json +1 -1
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Main-thread WRUN host:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Main-thread WRUN host: loads a package's module into the sandbox worker,
|
|
3
|
+
* owns that worker, and runs packed series requests through it. One shared
|
|
4
|
+
* worker serves every dev overlay; requests are id-matched, and a request
|
|
5
|
+
* that outlives its clock poisons the worker (terminate + respawn) so a
|
|
6
|
+
* spinning guest cannot wedge later runs.
|
|
7
|
+
*
|
|
8
|
+
* Modules (the shared engine protocol, wrun-chart-host 0.6.0): the main
|
|
9
|
+
* thread never hashes and never compiles a module. `loadModule` keeps a
|
|
10
|
+
* private copy of the package's bytes and posts them (`module-load`); the
|
|
11
|
+
* worker hashes them, checks the sheet's `wasm_sha256` pin, clamps the
|
|
12
|
+
* memory, prepares and compiles them (wrun-engine-handler.ts) and answers the
|
|
13
|
+
* module's key, digest and imports, which the opaque handle carries. Every
|
|
14
|
+
* full run and live-start names the module by key and carries the bytes
|
|
15
|
+
* again (copied, never transferred), so a respawned worker compiles them
|
|
16
|
+
* anew; nothing here tracks which keys the worker holds. Each request has
|
|
17
|
+
* two clocks of WRUN_RUN_TIMEOUT_MS: the start ceiling from the post (the
|
|
18
|
+
* wait behind other requests, the compile and the instantiation), then the
|
|
19
|
+
* run deadline from the worker's `{ id, running: true }`, posted once the
|
|
20
|
+
* module is instantiated, when the request executes; a terminal answer
|
|
21
|
+
* settles a request in either phase.
|
|
8
22
|
*
|
|
9
23
|
* Isolation: a death of the shared worker (the run timeout, or an error
|
|
10
24
|
* event with a request in flight) rejects every pending request with
|
|
@@ -37,7 +51,7 @@
|
|
|
37
51
|
* carries the engine's StrategyOutput, which rides beside the rows
|
|
38
52
|
* (`attachWrunStrategy`) exactly like the handle set.
|
|
39
53
|
*/
|
|
40
|
-
import type { WrunIndicatorMetadata, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
54
|
+
import type { WrunIndicatorMetadata, WrunModuleHandle, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
41
55
|
import { attachWrunLive, WrunLiveOrderError, wrunLiveOf } from '../../interfaces/wrun-runtime.interface.js';
|
|
42
56
|
import { type WrunInputRow } from './wrun-pack.util.js';
|
|
43
57
|
import { WrunWorkerPoisonError } from './wrun-registry-errors.util.js';
|
|
@@ -57,8 +71,8 @@ export declare function assertWrunBrowserSources(metadata: WrunIndicatorMetadata
|
|
|
57
71
|
* below bounds ONE package's deaths geometrically; this window bounds the
|
|
58
72
|
* worker's deaths whatever mix of packages (or overrides) causes them. */
|
|
59
73
|
export declare const WRUN_WORKER_RESPAWN_WINDOW_MS = 60000;
|
|
60
|
-
/** How many
|
|
61
|
-
* and
|
|
74
|
+
/** How many module handles the host keeps (loadModule): every package version, draft Run and REPL compile mints a
|
|
75
|
+
* key, and the engine worker keeps an LRU of the same size of the compiled modules behind them. */
|
|
62
76
|
export declare const WRUN_MODULE_CACHE_CAPACITY = 16;
|
|
63
77
|
/** Why the shared worker died: the run timeout, or the Worker's error event (the worker factory's death test). */
|
|
64
78
|
export type WrunHostDeathReason = WrunWorkerPoisonError['reason'];
|
|
@@ -113,11 +127,14 @@ export { attachWrunLive, wrunLiveOf };
|
|
|
113
127
|
export declare class WrunBrowserHost {
|
|
114
128
|
private worker;
|
|
115
129
|
private pending;
|
|
130
|
+
/** One counter numbers loads, runs and live-ends: a retired incarnation's late answer names an id no entry holds. */
|
|
116
131
|
private requestSeq;
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
132
|
+
/** The order requests enter the `run` phase in (`PendingRequest.runOrder`). */
|
|
133
|
+
private runSeq;
|
|
134
|
+
/** Loads by module, least recently used first (Map order: a hit moves its entry to the end). The cache only
|
|
135
|
+
* dedupes loads and owns no module: a mounted overlay keeps the handle it was handed (its record), and a live
|
|
136
|
+
* session keeps its instance in the worker (live ticks name the session, never a module), so an eviction stops
|
|
137
|
+
* neither; a handle's bytes stay behind it whatever the cache lets go, and its runs carry them. */
|
|
121
138
|
private moduleCache;
|
|
122
139
|
/** Live sessions the current worker holds (installed by an ok live-start,
|
|
123
140
|
* dropped by live-end, a sessionLost answer, or the worker's death). */
|
|
@@ -133,41 +150,61 @@ export declare class WrunBrowserHost {
|
|
|
133
150
|
* the first death, so the first spawn ever never opens a window. */
|
|
134
151
|
private lastRespawnAt;
|
|
135
152
|
private respawnHeldUntil;
|
|
136
|
-
/** Spin the sandbox worker and load the shared host (the
|
|
137
|
-
*
|
|
138
|
-
* run path's two kit tables, the daemon-only
|
|
139
|
-
* names) ahead of the first add (the Indicators tab
|
|
140
|
-
* signal), so the first package a reader mounts pays
|
|
141
|
-
* spawn nor a module parse on its click. Idempotent; a
|
|
142
|
-
* surfaces on the first
|
|
143
|
-
* respawn is not warmed around: the window exists to keep the
|
|
144
|
-
* down. */
|
|
153
|
+
/** Spin the sandbox worker and load the shared host (the packer, the
|
|
154
|
+
* strategy resolver; the worker holds its own for the module rewrite) and
|
|
155
|
+
* the authoring kit (the run path's two kit tables, the daemon-only
|
|
156
|
+
* sources and the token names) ahead of the first add (the Indicators tab
|
|
157
|
+
* opening is the signal), so the first package a reader mounts pays
|
|
158
|
+
* neither the worker spawn nor a module parse on its click. Idempotent; a
|
|
159
|
+
* load failure surfaces on the first module load or run as before, never
|
|
160
|
+
* here. A held respawn is not warmed around: the window exists to keep the
|
|
161
|
+
* worker down. */
|
|
145
162
|
warm(): void;
|
|
146
163
|
/** The active quarantine of a package, if its hold is still running. */
|
|
147
164
|
quarantineOf(metadata: Pick<WrunIndicatorMetadata, 'id' | 'wasm_sha256'>): WrunHostQuarantine | undefined;
|
|
148
165
|
/** Forget every quarantine and the respawn window (specs only). */
|
|
149
166
|
resetGuardsForTests(): void;
|
|
150
|
-
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
167
|
+
/** Load (and cache) a package module: the worker hashes the bytes, refuses a
|
|
168
|
+
* digest other than the sheet's `wasm_sha256` pin with the words this host
|
|
169
|
+
* always used, refuses a memory the clamp refuses (a maximum or a starting
|
|
170
|
+
* size over the worker's memory limit, shared or 64-bit memory), stamps
|
|
171
|
+
* the limit as the maximum of a memory declared without one, exports every
|
|
172
|
+
* mutable global for the live lane's snapshot and restore, and compiles
|
|
173
|
+
* (wrun-engine-handler.ts `compileWrunModuleBytes`). This thread keeps a
|
|
174
|
+
* private copy of the bytes behind the handle and hashes and compiles
|
|
175
|
+
* nothing. A load needs the worker: during a held respawn every load
|
|
176
|
+
* rejects with the held death, a cached one too, and its start ceiling
|
|
177
|
+
* bounds the wait and the compile.
|
|
157
178
|
*
|
|
158
|
-
* The cache is an LRU of WRUN_MODULE_CACHE_CAPACITY
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* in flight
|
|
179
|
+
* The cache is an LRU of WRUN_MODULE_CACHE_CAPACITY handles, keyed by the
|
|
180
|
+
* sheet's pin and ABI when it pins one (its identity before and after the
|
|
181
|
+
* load), else by the bytes object and the ABI until the worker names the
|
|
182
|
+
* digest, then by the module's key; the first handle of a key stays the
|
|
183
|
+
* one every caller shares. A hit serves only bytes equal to the ones its
|
|
184
|
+
* entry loads: other bytes under the key (a pin claimed by bytes it was
|
|
185
|
+
* not verified from, a reused buffer whose content changed) go to the
|
|
186
|
+
* worker, which checks them against the pin, beside the cached entry and
|
|
187
|
+
* never in its place. Every caller of a load in flight shares its one
|
|
188
|
+
* post, and a load in flight is never evicted; eviction drops loaded
|
|
189
|
+
* entries only, least recently used first, so the cache passes the
|
|
190
|
+
* capacity only while more loads than that are in flight. A failed load is
|
|
191
|
+
* not cached: its entry leaves before its callers see the failure, and the
|
|
192
|
+
* next request loads again. Async, as the compile was: every failure (a
|
|
193
|
+
* detached buffer included) is a rejection, and nothing here awaits before
|
|
194
|
+
* the entry is cached. */
|
|
195
|
+
loadModule(wasmBytes: ArrayBuffer | Uint8Array, metadata: WrunIndicatorMetadata): Promise<WrunModuleHandle>;
|
|
196
|
+
/** A load answered: its entry leaves the key it waited under (an unpinned sheet's provisional key; none for a load
|
|
197
|
+
* that verified other bytes beside a cached entry) for the module's own key. A handle already loaded under that key
|
|
198
|
+
* stays the one every caller shares. */
|
|
199
|
+
private cacheLoadedModule;
|
|
200
|
+
/** Post one `module-load` of the private bytes (copied, never transferred: the handle keeps them for its runs) and
|
|
201
|
+
* mint the handle from the worker's answer. */
|
|
202
|
+
private requestModuleLoad;
|
|
203
|
+
/** Evict loaded entries, least recently used first, until the cache is back at its capacity (a load in flight
|
|
204
|
+
* stays: its callers share it). */
|
|
168
205
|
private trimModuleCache;
|
|
169
206
|
runSeries(input: {
|
|
170
|
-
module:
|
|
207
|
+
module: WrunModuleHandle;
|
|
171
208
|
metadata: WrunIndicatorMetadata;
|
|
172
209
|
rows: readonly WrunInputRow[];
|
|
173
210
|
initArgs: readonly number[];
|
|
@@ -189,7 +226,7 @@ export declare class WrunBrowserHost {
|
|
|
189
226
|
* key (see the worker's ownership rule). */
|
|
190
227
|
startLiveSeries(input: {
|
|
191
228
|
sessionKey: string;
|
|
192
|
-
module:
|
|
229
|
+
module: WrunModuleHandle;
|
|
193
230
|
metadata: WrunIndicatorMetadata;
|
|
194
231
|
rows: readonly WrunInputRow[];
|
|
195
232
|
initArgs: readonly number[];
|
|
@@ -233,22 +270,49 @@ export declare class WrunBrowserHost {
|
|
|
233
270
|
* reason and the package's strikes (the heal ladder reads them). Returns
|
|
234
271
|
* the lane the pending entry remembers. */
|
|
235
272
|
private admit;
|
|
273
|
+
/** A full run or a live-start: the module rides the request, its key (the worker reuses the module it holds under
|
|
274
|
+
* it) and the host's private copy of its bytes (copied by structured clone, never transferred: a worker that does
|
|
275
|
+
* not hold the key, a respawned one or one that let it go, compiles them). The packed request's own `abi` stays
|
|
276
|
+
* the run's sheet's. */
|
|
277
|
+
private dispatchWithModule;
|
|
236
278
|
private dispatch;
|
|
279
|
+
/**
|
|
280
|
+
* Post one request under a pending entry: the respawn hold first (a held death refuses it, nothing posted), then
|
|
281
|
+
* the worker, the entry in its `start` phase with the start ceiling armed (the wait behind other requests, the
|
|
282
|
+
* module's compile and its instantiation, bounded as the dispatch clock bounded the hold before 0.6.0), then the
|
|
283
|
+
* post. A request the structured clone refuses fails alone (its entry and clock go with it).
|
|
284
|
+
*/
|
|
285
|
+
private post;
|
|
286
|
+
/** A phase's clock: a request that outlives it means the worker is stuck (a guest spinning, a compile that never
|
|
287
|
+
* ends), so the worker is poisoned and replaced and later requests start clean. */
|
|
288
|
+
private armClock;
|
|
289
|
+
/** One answer from the worker. `running` moves its request to the `run` phase on a fresh clock (a second one, one
|
|
290
|
+
* for a load or for no pending request changes nothing); a terminal answer settles its request in either phase;
|
|
291
|
+
* an answer for no pending request (an untracked live-end's, a retired incarnation's) is dropped. */
|
|
292
|
+
private receive;
|
|
293
|
+
/** A run's terminal answer: the package answered (an overridden quarantine is cleared by the success, and an
|
|
294
|
+
* opened session is one the worker now holds), a lost session, a live-order refusal, or a failure. */
|
|
295
|
+
private settleRun;
|
|
237
296
|
private ensureWorker;
|
|
238
297
|
/**
|
|
239
298
|
* The shared worker died: quarantine the package that was running (the
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* flight means nothing to quarantine (a worker that dies idle is only a
|
|
299
|
+
* culprit, `culpritOf`), terminate the worker, remember the death for the
|
|
300
|
+
* respawn window, and reject every pending request (loads included) with
|
|
301
|
+
* the poison error naming the live sessions lost with the worker. Nothing
|
|
302
|
+
* in flight means nothing to quarantine (a worker that dies idle is only a
|
|
245
303
|
* death for the window). `message` is what every casualty reads; the
|
|
246
|
-
*
|
|
247
|
-
* (cause, the culprit's package and
|
|
248
|
-
* is recorded here once, frozen, and rides every
|
|
249
|
-
* the respawn hold's included, so a casualty can
|
|
304
|
+
* culprit of a timeout keeps its own deadline sentence. The death's
|
|
305
|
+
* context (cause, the culprit's package, session and phase, the budget a
|
|
306
|
+
* timeout used up) is recorded here once, frozen, and rides every
|
|
307
|
+
* rejection of this death, the respawn hold's included, so a casualty can
|
|
308
|
+
* name who held the sandbox.
|
|
250
309
|
*/
|
|
251
310
|
private poisonWorker;
|
|
311
|
+
/** Who held the worker when it died: the request in the `run` phase, the hog holding the worker's synchronous turn
|
|
312
|
+
* (the expired request itself when it was running, else the first that started running), else the expired
|
|
313
|
+
* request (nothing ran: its own wait and compile used its ceiling up), else, for an error event, the oldest
|
|
314
|
+
* request in flight. */
|
|
315
|
+
private culpritOf;
|
|
252
316
|
/** Put (or keep) a package on the ladder: a death while its previous hold
|
|
253
317
|
* runs, or inside the reset grace after it, is a repeat and doubles the
|
|
254
318
|
* hold (capped); a later death starts over at the base hold. Records past
|