space-data-module-sdk 0.10.3 → 0.10.4

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.
@@ -422,6 +422,39 @@ worker bundles and the browser capability probe.
422
422
 
423
423
  ### Explicit pool size, partial spawns, supervision hooks
424
424
 
425
+ `createBrowserModuleHarness` accepts `wasiThreadProbeTimeoutMs`, the browser
426
+ pool arming deadline in milliseconds. It forwards the value as
427
+ `createWasiThreadSpawn`'s `probeTimeoutMs`. The default is 1500. An explicit
428
+ value must be a positive finite number; invalid values throw an `Error` before
429
+ the artifact is loaded. The option applies to the initial context and each
430
+ fresh command invocation. It has no effect on Node's on-demand pool startup.
431
+
432
+ After harness creation, the read-only `harness.wasiThreadPoolReport` property
433
+ returns a frozen `{ requested, armed }` snapshot. Counts refer to pool workers
434
+ and exclude the calling thread. With `wasiThreadPoolSize`, `requested` is that
435
+ explicit size, including when threading is unavailable. Without an explicit
436
+ size, it is the browser's selected pool size. Non-threaded artifacts return
437
+ `null`. Node reports its explicit cap (or `null` without one) and the number
438
+ of workers started on demand.
439
+
440
+ For an explicit browser pool, fewer armed workers do not throw. Workers that
441
+ miss the deadline are terminated before the harness returns; successfully
442
+ armed workers remain available. The host uses the report to decide whether
443
+ the capacity meets its needs. A guest must handle declined spawns to execute
444
+ successfully with fewer workers. After a command invocation, the property
445
+ reports that invocation's arming counts, even though its pool is terminated.
446
+ These are startup counts, not a live-worker health report.
447
+
448
+ ```js
449
+ const harness = await createBrowserModuleHarness({
450
+ wasmSource,
451
+ enableBrowserWasiThreads: true,
452
+ wasiThreadPoolSize: 8,
453
+ wasiThreadProbeTimeoutMs: 10000,
454
+ });
455
+ const { requested, armed } = harness.wasiThreadPoolReport;
456
+ ```
457
+
425
458
  `createWasiThreadSpawn` options added in 0.8.22:
426
459
 
427
460
  | Option | Effect |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "space-data-module-sdk",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Module SDK for building, validating, signing, and deploying WebAssembly modules on the Space Data Network.",
6
6
  "type": "module",
@@ -429,6 +429,7 @@ async function instantiateBrowserModule(options = {}) {
429
429
  // the module will actually ask for. Ignored by the Node lazy path.
430
430
  requestedThreads: options.maxThreads,
431
431
  poolSize: options.wasiThreadPoolSize,
432
+ probeTimeoutMs: options.wasiThreadProbeTimeoutMs,
432
433
  hostcallChannel: options.threadHostcallChannel,
433
434
  requiresHostcalls: needsHostBridge,
434
435
  enableBrowserThreads: options.enableBrowserWasiThreads,
@@ -485,8 +486,14 @@ async function instantiateBrowserModule(options = {}) {
485
486
  * @param {number} [options.wasiThreadSpawnWaitMs] - How long a guest spawn that
486
487
  * finds every pooled thread busy waits for one to finish before
487
488
  * pthread_create fails (createWasiThreadSpawn `spawnWaitMs`, default 250).
489
+ * @param {number} [options.wasiThreadProbeTimeoutMs] - Positive finite browser
490
+ * pool arming deadline in milliseconds (default 1500).
488
491
  */
489
492
  export async function createBrowserModuleHarness(options = {}) {
493
+ if (options.wasiThreadProbeTimeoutMs !== undefined &&
494
+ (!Number.isFinite(options.wasiThreadProbeTimeoutMs) || options.wasiThreadProbeTimeoutMs <= 0)) {
495
+ throw new Error("wasiThreadProbeTimeoutMs must be a positive finite number.");
496
+ }
490
497
  let wasmSource = options.wasmSource;
491
498
  const signaturePolicy = resolveModuleSignaturePolicy(options);
492
499
  // Bytes THIS function materializes itself (Response/URL fetch, or the
@@ -596,6 +603,7 @@ export async function createBrowserModuleHarness(options = {}) {
596
603
  wasiThreadWorkerUrl: options.wasiThreadWorkerUrl,
597
604
  wasiThreadSpawnWaitMs: options.wasiThreadSpawnWaitMs,
598
605
  wasiThreadPoolSize: options.wasiThreadPoolSize,
606
+ wasiThreadProbeTimeoutMs: options.wasiThreadProbeTimeoutMs,
599
607
  });
600
608
  const { instance, bridge, wasi, memory, threadHost } = activeContext;
601
609
  let lastCommandContext = null;
@@ -862,6 +870,7 @@ export async function createBrowserModuleHarness(options = {}) {
862
870
  wasiThreadWorkerUrl: options.wasiThreadWorkerUrl,
863
871
  wasiThreadSpawnWaitMs: options.wasiThreadSpawnWaitMs,
864
872
  wasiThreadPoolSize: options.wasiThreadPoolSize,
873
+ wasiThreadProbeTimeoutMs: options.wasiThreadProbeTimeoutMs,
865
874
  });
866
875
  lastCommandContext = commandContext;
867
876
  let exitError = null;
@@ -974,6 +983,10 @@ export async function createBrowserModuleHarness(options = {}) {
974
983
  // spawn host so callers can observe real thread activity
975
984
  // (spawnCount/distinctOsThreadCount).
976
985
  get threadHost() { return lastCommandContext?.threadHost ?? threadHost; },
986
+ get wasiThreadPoolReport() {
987
+ const report = (lastCommandContext?.threadHost ?? threadHost)?.spawnReport();
988
+ return report ? Object.freeze({ requested: report.poolSize, armed: report.armed }) : null;
989
+ },
977
990
  callHost,
978
991
  invokeDirect,
979
992
  invoke,
package/src/index.d.ts CHANGED
@@ -2156,6 +2156,11 @@ export function createBrowserWasiShim(options?: {
2156
2156
  };
2157
2157
  }): BrowserWasiShim;
2158
2158
  export interface BrowserModuleHarness {
2159
+ /** Pool workers requested and armed; excludes the calling thread. Null for non-threaded artifacts.
2160
+ * Command calls report the most recent invocation, including after its pool is terminated.
2161
+ * Node starts workers on demand; requested is null without an explicit pool size.
2162
+ */
2163
+ readonly wasiThreadPoolReport: Readonly<{ requested: number | null; armed: number }> | null;
2159
2164
  runtime: {
2160
2165
  kind: "browser";
2161
2166
  profile: string;
@@ -2234,6 +2239,8 @@ export function createBrowserModuleHarness(options?: {
2234
2239
  wasiThreadSpawnWaitMs?: number;
2235
2240
  // Explicit wasi-threads pool size (createWasiThreadSpawn poolSize).
2236
2241
  wasiThreadPoolSize?: number;
2242
+ /** Positive finite browser pool arming deadline in milliseconds. Default 1500. */
2243
+ wasiThreadProbeTimeoutMs?: number;
2237
2244
  // Request-isolated BroadcastChannel descriptor a nested pthread hostcall
2238
2245
  // dispatches over; supplied by createWorkerModuleHarness for the in-worker
2239
2246
  // harness instance, not something a top-level caller usually sets by hand.