@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.
Files changed (30) hide show
  1. package/README.md +5 -4
  2. package/dist/constants/feature-flags.constants.js +7 -2
  3. package/dist/host-env.d.ts +3 -19
  4. package/dist/host-ports.types.d.ts +1 -14
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
  8. package/dist/interfaces/wrun-runtime.interface.js +17 -3
  9. package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
  10. package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
  11. package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
  12. package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
  13. package/dist/utility/wrun/wrun-host.service.d.ts +114 -50
  14. package/dist/utility/wrun/wrun-host.service.js +351 -151
  15. package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
  16. package/dist/utility/wrun/wrun-hover.util.js +25 -4
  17. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +2 -2
  18. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +2 -2
  19. package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
  20. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
  21. package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
  22. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  23. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
  24. package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
  25. package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
  26. package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
  27. package/dist/workers/wrun/wrun-abi-host.js +31 -12
  28. package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
  29. package/dist/workers/wrun/wrun-engine-handler.js +181 -12
  30. package/package.json +1 -1
@@ -1,10 +1,24 @@
1
1
  /**
2
- * Main-thread WRUN host: compiles a package's wasm (sha256-verified against
3
- * the metadata pin when present), owns the sandbox worker, and runs packed
4
- * series requests through it. One shared worker serves every dev overlay;
5
- * requests are id-matched, and a request that outlives its timeout poisons
6
- * the worker (terminate + respawn) so a spinning guest cannot wedge later
7
- * runs.
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 compiled modules the host keeps by wasm digest (compileModule). Every package version, draft Run
61
- * and REPL compile mints a digest, and a compiled module is mostly native memory the heap never shows. */
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
- /** Compiles by wasm digest, least recently used first (Map order: a hit moves its entry to the end). The cache
118
- * only dedupes compiles and owns no module: a mounted overlay keeps the module it was handed (its record), and
119
- * a live session keeps its instance in the worker (live ticks name the session, never a module), so an
120
- * eviction stops neither. */
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 compile's module
137
- * rewrite, the packer, the strategy resolver) and the authoring kit (the
138
- * run path's two kit tables, the daemon-only sources and the token
139
- * names) ahead of the first add (the Indicators tab opening is the
140
- * signal), so the first package a reader mounts pays neither the worker
141
- * spawn nor a module parse on its click. Idempotent; a load failure
142
- * surfaces on the first compile or run as before, never here. A held
143
- * respawn is not warmed around: the window exists to keep the worker
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
- /** Compile (and cache) a package module. The cache key is the sha256 of
151
- * the bytes, so identical bytes compile once whatever package name they
152
- * arrive under. When the metadata pins `wasm_sha256`, a mismatch refuses
153
- * before compilation; so does a memory the clamp refuses (a maximum or a
154
- * starting size over the worker's memory limit, shared or 64-bit memory),
155
- * and a memory declared with no maximum compiles with the limit as its
156
- * maximum (clampWrunModuleMemory).
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 compiled modules.
159
- * Every consumer of a digest in flight shares its one compile, and a
160
- * compile in flight is never evicted; eviction drops compiled entries
161
- * only, least recently used first, so the cache passes the capacity
162
- * only while more compiles than that are in flight. A failed compile is
163
- * not cached: its entry leaves before its consumers see the failure, and
164
- * the next request compiles again. */
165
- compileModule(wasmBytes: ArrayBuffer, metadata: WrunIndicatorMetadata): Promise<WebAssembly.Module>;
166
- /** Evict compiled entries, least recently used first, until the cache is back at its capacity (a compile
167
- * in flight stays: its consumers share it). */
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: WebAssembly.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: WebAssembly.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
- * timed-out request's, or the oldest in flight when the error event fired, the
241
- * worker answers in dispatch order), terminate the worker, remember the
242
- * death for the respawn window, and reject every pending request with the
243
- * poison error naming the live sessions lost with the worker. Nothing in
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
- * timed-out request keeps its own deadline sentence. The death's context
247
- * (cause, the culprit's package and session, the budget a timeout used up)
248
- * is recorded here once, frozen, and rides every rejection of this death,
249
- * the respawn hold's included, so a casualty can name who held the sandbox.
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