@orangecharts/wrun-chart-host 0.4.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 +17 -5
- package/dist/constants/exchange-names.leaf.d.ts +8 -0
- package/dist/constants/exchange-names.leaf.js +101 -0
- package/dist/constants/feature-flags.constants.js +7 -2
- package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +15 -0
- package/dist/constants/kscript-data-interval-restrictions.constants.js +40 -0
- package/dist/constants/opra-compliance.constants.d.ts +19 -0
- package/dist/constants/opra-compliance.constants.js +19 -0
- package/dist/constants/replay-ladder.leaf.d.ts +30 -0
- package/dist/constants/replay-ladder.leaf.js +99 -0
- package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +168 -0
- package/dist/constants/scriptEditor/cme-official-scripts.constants.js +398 -0
- package/dist/constants/scriptEditor/converted-script-id.leaf.d.ts +8 -0
- package/dist/constants/scriptEditor/converted-script-id.leaf.js +10 -0
- package/dist/constants/scriptEditor/execution.constants.d.ts +4 -0
- package/dist/constants/scriptEditor/execution.constants.js +14 -0
- package/dist/constants/wrun-prefix-safe.constants.d.ts +23 -0
- package/dist/constants/wrun-prefix-safe.constants.js +26 -0
- package/dist/host-env.d.ts +301 -22
- package/dist/host-env.js +15 -0
- package/dist/host-ports.types.d.ts +853 -29
- package/dist/index.d.ts +140 -2
- package/dist/index.js +140 -2
- package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +31 -0
- package/dist/instances/script-engine-worker-ohlcv-transfer.js +164 -0
- package/dist/interfaces/market-event.interface.d.ts +231 -0
- package/dist/interfaces/market-event.interface.js +15 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +70 -134
- package/dist/interfaces/opra-realtime.interface.js +34 -59
- package/dist/interfaces/replay.interface.d.ts +285 -0
- package/dist/interfaces/replay.interface.js +1 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
- package/dist/interfaces/wrun-runtime.interface.js +17 -3
- package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +1 -0
- package/dist/kscript-data/controls/live-ohlcv-merge.util.js +93 -0
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +5 -1
- package/dist/kscript-data/controls/live-trades-merge.util.js +2 -2
- package/dist/market-data/billing.interface.d.ts +219 -0
- package/dist/market-data/billing.interface.js +58 -0
- package/dist/market-data/venue-governed.util.d.ts +2 -0
- package/dist/market-data/venue-governed.util.js +10 -0
- package/dist/market-data/venue.d.ts +122 -0
- package/dist/market-data/venue.js +1 -0
- package/dist/market-data/venues/index.d.ts +97 -0
- package/dist/market-data/venues/index.js +33 -0
- package/dist/market-data/venues/opra.contract.copy.json +35 -0
- package/dist/market-data/venues/opra.d.ts +70 -0
- package/dist/market-data/venues/opra.js +74 -0
- package/dist/replay/replayIndicatorRows.d.ts +31 -0
- package/dist/replay/replayIndicatorRows.js +117 -0
- package/dist/replay/replayLadder.d.ts +85 -0
- package/dist/replay/replayLadder.js +388 -0
- package/dist/utility/auth/server-clock.util.d.ts +81 -0
- package/dist/utility/auth/server-clock.util.js +238 -0
- package/dist/utility/chart/builtin-identity.util.d.ts +18 -0
- package/dist/utility/chart/builtin-identity.util.js +51 -0
- package/dist/utility/chart/cache-alignment.util.d.ts +454 -0
- package/dist/utility/chart/cache-alignment.util.js +926 -0
- package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +15 -0
- package/dist/utility/chart/chart-data-fetch-generation.util.js +22 -0
- package/dist/utility/chart/chart-mount-epoch.util.d.ts +17 -0
- package/dist/utility/chart/chart-mount-epoch.util.js +61 -0
- package/dist/utility/chart/chart-time-domain.util.d.ts +12 -0
- package/dist/utility/chart/chart-time-domain.util.js +23 -0
- package/dist/utility/chart/color-customization.leaf.d.ts +10 -0
- package/dist/utility/chart/color-customization.leaf.js +16 -0
- package/dist/utility/chart/footprint-tick-grid.util.d.ts +106 -0
- package/dist/utility/chart/footprint-tick-grid.util.js +167 -0
- package/dist/utility/chart/gesture-timing.leaf.d.ts +29 -0
- package/dist/utility/chart/gesture-timing.leaf.js +29 -0
- package/dist/utility/chart/governed-contract-coin.util.d.ts +22 -0
- package/dist/utility/chart/governed-contract-coin.util.js +39 -0
- package/dist/utility/chart/host-bar-placement.util.d.ts +107 -0
- package/dist/utility/chart/host-bar-placement.util.js +447 -0
- package/dist/utility/chart/index-host-tier.util.d.ts +31 -0
- package/dist/utility/chart/index-host-tier.util.js +118 -0
- package/dist/utility/chart/index-mode-admission.util.d.ts +34 -0
- package/dist/utility/chart/index-mode-admission.util.js +67 -0
- package/dist/utility/chart/indicator-error-message.util.d.ts +35 -0
- package/dist/utility/chart/indicator-error-message.util.js +44 -0
- package/dist/utility/chart/kscript-apply-fingerprint.util.d.ts +65 -0
- package/dist/utility/chart/kscript-apply-fingerprint.util.js +357 -0
- package/dist/utility/chart/kscript-chart-flush.leaf.d.ts +22 -0
- package/dist/utility/chart/kscript-chart-flush.leaf.js +13 -0
- package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +6 -0
- package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +27 -0
- package/dist/utility/chart/kscript-integration-decision.leaf.d.ts +89 -0
- package/dist/utility/chart/kscript-integration-decision.leaf.js +80 -0
- package/dist/utility/chart/kscript-live-coalesce.util.d.ts +76 -0
- package/dist/utility/chart/kscript-live-coalesce.util.js +156 -0
- package/dist/utility/chart/kscript-live-rest-pace.util.d.ts +34 -0
- package/dist/utility/chart/kscript-live-rest-pace.util.js +134 -0
- package/dist/utility/chart/kscript-live-source-identity.util.d.ts +98 -0
- package/dist/utility/chart/kscript-live-source-identity.util.js +121 -0
- package/dist/utility/chart/kscript-mounted-plot-set.leaf.d.ts +48 -0
- package/dist/utility/chart/kscript-mounted-plot-set.leaf.js +145 -0
- package/dist/utility/chart/kscript-perf-tracker.util.d.ts +243 -0
- package/dist/utility/chart/kscript-perf-tracker.util.js +522 -0
- package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +43 -0
- package/dist/utility/chart/kscript-run-interval-projection.util.js +471 -0
- package/dist/utility/chart/kscript-run-result-equality.util.d.ts +38 -0
- package/dist/utility/chart/kscript-run-result-equality.util.js +89 -0
- package/dist/utility/chart/kscript-settings-revision.leaf.d.ts +2 -0
- package/dist/utility/chart/kscript-settings-revision.leaf.js +12 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +63 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.js +68 -0
- package/dist/utility/chart/kscript-source-retention.util.d.ts +134 -0
- package/dist/utility/chart/kscript-source-retention.util.js +218 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +57 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.js +61 -0
- package/dist/utility/chart/kscript-titancharts-preparation.util.d.ts +15 -0
- package/dist/utility/chart/kscript-titancharts-preparation.util.js +376 -0
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +9 -0
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +130 -0
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +217 -0
- package/dist/utility/chart/kscript-venue-policy.util.js +324 -0
- package/dist/utility/chart/live-cadence.util.d.ts +38 -0
- package/dist/utility/chart/live-cadence.util.js +37 -0
- package/dist/utility/chart/live-feed-series-match.leaf.d.ts +13 -0
- package/dist/utility/chart/live-feed-series-match.leaf.js +21 -0
- package/dist/utility/chart/local-engine-self-heal-backoff.util.d.ts +46 -0
- package/dist/utility/chart/local-engine-self-heal-backoff.util.js +46 -0
- package/dist/utility/chart/local-engine-uninit.leaf.d.ts +21 -0
- package/dist/utility/chart/local-engine-uninit.leaf.js +22 -0
- package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +62 -0
- package/dist/utility/chart/local-kscript-source-revalidation.util.js +123 -0
- package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +214 -0
- package/dist/utility/chart/local-kscript-warmup-depth.util.js +376 -0
- package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.d.ts +85 -0
- package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.js +197 -0
- package/dist/utility/chart/local-technical-script-range.leaf.d.ts +72 -0
- package/dist/utility/chart/local-technical-script-range.leaf.js +126 -0
- package/dist/utility/chart/mixed-mode.util.d.ts +167 -0
- package/dist/utility/chart/mixed-mode.util.js +139 -0
- package/dist/utility/chart/ohlcv-row-readiness.util.d.ts +36 -0
- package/dist/utility/chart/ohlcv-row-readiness.util.js +90 -0
- package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +19 -0
- package/dist/utility/chart/opra-user-scripts-gate.util.js +32 -0
- package/dist/utility/chart/overlay-execution-guard-key.leaf.d.ts +8 -0
- package/dist/utility/chart/overlay-execution-guard-key.leaf.js +10 -0
- package/dist/utility/chart/price-precision.util.d.ts +40 -0
- package/dist/utility/chart/price-precision.util.js +70 -0
- package/dist/utility/chart/profile-block-size.util.d.ts +64 -0
- package/dist/utility/chart/profile-block-size.util.js +141 -0
- package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.d.ts +11 -0
- package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.js +29 -0
- package/dist/utility/chart/protected-kscript-empty-output.util.d.ts +28 -0
- package/dist/utility/chart/protected-kscript-empty-output.util.js +84 -0
- package/dist/utility/chart/run-interval-unservable.leaf.d.ts +9 -0
- package/dist/utility/chart/run-interval-unservable.leaf.js +20 -0
- package/dist/utility/chart/run-interval-warmup.leaf.d.ts +19 -0
- package/dist/utility/chart/run-interval-warmup.leaf.js +35 -0
- package/dist/utility/chart/titan-constants.pin.d.ts +9 -5
- package/dist/utility/chart/titan-constants.pin.js +18 -5
- package/dist/utility/chart/warmup-backfill-retry.leaf.d.ts +9 -0
- package/dist/utility/chart/warmup-backfill-retry.leaf.js +9 -0
- package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +11 -2
- package/dist/utility/chart/wrun-bar-session-facts.util.js +10 -3
- package/dist/utility/chart/wrun-run-result.util.d.ts +5 -1
- package/dist/utility/chart/wrun-run-result.util.js +20 -14
- package/dist/utility/common/data-processing.util.d.ts +138 -0
- package/dist/utility/common/data-processing.util.js +346 -0
- package/dist/utility/common/visible-timeout.util.d.ts +13 -4
- package/dist/utility/common/visible-timeout.util.js +23 -8
- package/dist/utility/exchange-format.leaf.d.ts +1 -0
- package/dist/utility/exchange-format.leaf.js +47 -0
- package/dist/utility/market-events/earnings-scope.util.d.ts +60 -0
- package/dist/utility/market-events/earnings-scope.util.js +92 -0
- package/dist/utility/market-events/market-events.util.d.ts +147 -0
- package/dist/utility/market-events/market-events.util.js +392 -0
- package/dist/utility/market-events/zoned-clock.util.d.ts +1 -0
- package/dist/utility/market-events/zoned-clock.util.js +11 -0
- package/dist/utility/options/option-venue-disclosure.util.d.ts +43 -0
- package/dist/utility/options/option-venue-disclosure.util.js +56 -0
- package/dist/utility/scriptEditor/package-semver.util.d.ts +51 -0
- package/dist/utility/scriptEditor/package-semver.util.js +120 -0
- package/dist/utility/scriptEditor/temp-script-id.util.d.ts +18 -0
- package/dist/utility/scriptEditor/temp-script-id.util.js +25 -0
- package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.d.ts +20 -0
- package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.js +81 -0
- package/dist/utility/v2/governed-tier.leaf.d.ts +103 -0
- package/dist/utility/v2/governed-tier.leaf.js +113 -0
- package/dist/utility/watchlist/import/import-request.leaf.d.ts +10 -0
- package/dist/utility/watchlist/import/import-request.leaf.js +10 -0
- package/dist/utility/wrun/sources/lanes/series.js +2 -2
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +4 -4
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +5 -6
- package/dist/utility/wrun/wrun-alert-outputs.registry.d.ts +166 -0
- package/dist/utility/wrun/wrun-alert-outputs.registry.js +219 -0
- package/dist/utility/wrun/wrun-bar-count.util.d.ts +94 -0
- package/dist/utility/wrun/wrun-bar-count.util.js +274 -0
- package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +84 -0
- package/dist/utility/wrun/wrun-chart-context-names.util.js +186 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +253 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +731 -0
- package/dist/utility/wrun/wrun-cloud-opra-stamp.util.d.ts +28 -0
- package/dist/utility/wrun/wrun-cloud-opra-stamp.util.js +45 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.js +47 -0
- package/dist/utility/wrun/wrun-deadline.util.js +2 -1
- package/dist/utility/wrun/wrun-debug-output.util.d.ts +39 -0
- package/dist/utility/wrun/wrun-debug-output.util.js +63 -0
- package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +113 -0
- package/dist/utility/wrun/wrun-declared-warmup.util.js +181 -0
- package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +43 -0
- package/dist/utility/wrun/wrun-draft-legend-note.util.js +158 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +181 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.js +357 -0
- package/dist/utility/wrun/wrun-draw-skipped.leaf.d.ts +16 -0
- package/dist/utility/wrun/wrun-draw-skipped.leaf.js +16 -0
- package/dist/utility/wrun/wrun-earnings-facts.util.d.ts +42 -0
- package/dist/utility/wrun/wrun-earnings-facts.util.js +131 -0
- package/dist/utility/wrun/wrun-first-run-depth.util.d.ts +32 -0
- package/dist/utility/wrun/wrun-first-run-depth.util.js +118 -0
- package/dist/utility/wrun/wrun-gate-plane-readers.util.d.ts +24 -0
- package/dist/utility/wrun/wrun-gate-plane-readers.util.js +31 -0
- package/dist/utility/wrun/wrun-held-lanes.util.d.ts +32 -0
- package/dist/utility/wrun/wrun-held-lanes.util.js +94 -0
- package/dist/utility/wrun/wrun-host-visible-clock.util.d.ts +2 -0
- package/dist/utility/wrun/wrun-host-visible-clock.util.js +17 -0
- package/dist/utility/wrun/wrun-host.service.d.ts +330 -0
- package/dist/utility/wrun/wrun-host.service.js +855 -0
- 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-inert-legend.util.d.ts +33 -0
- package/dist/utility/wrun/wrun-inert-legend.util.js +125 -0
- package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +155 -0
- package/dist/utility/wrun/wrun-input-requirements.leaf.js +450 -0
- package/dist/utility/wrun/wrun-integration-route.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-integration-route.util.js +59 -0
- package/dist/utility/wrun/wrun-latest-history.leaf.d.ts +8 -0
- package/dist/utility/wrun/wrun-latest-history.leaf.js +8 -0
- package/dist/utility/wrun/wrun-legend-hover.lazy.d.ts +12 -0
- package/dist/utility/wrun/wrun-legend-hover.lazy.js +96 -0
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +21 -0
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +21 -0
- package/dist/utility/wrun/wrun-live-hidden-hold.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-live-hidden-hold.util.js +13 -0
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +374 -0
- package/dist/utility/wrun/wrun-live-intake.util.js +2027 -0
- package/dist/utility/wrun/wrun-live-patch.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-live-patch.util.js +523 -0
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +619 -0
- package/dist/utility/wrun/wrun-live-tick.util.js +4974 -0
- package/dist/utility/wrun/wrun-loading-owner.util.d.ts +58 -0
- package/dist/utility/wrun/wrun-loading-owner.util.js +89 -0
- package/dist/utility/wrun/wrun-official-scope.leaf.d.ts +29 -0
- package/dist/utility/wrun/wrun-official-scope.leaf.js +36 -0
- package/dist/utility/wrun/wrun-oi-lane.util.d.ts +27 -0
- package/dist/utility/wrun/wrun-oi-lane.util.js +42 -0
- package/dist/utility/wrun/wrun-options-stop.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-options-stop.util.js +123 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +719 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +1180 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +50 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +131 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +118 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +466 -0
- package/dist/utility/wrun/wrun-overlay-metadata.util.d.ts +45 -0
- package/dist/utility/wrun/wrun-overlay-metadata.util.js +112 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +114 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +971 -0
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +858 -0
- package/dist/utility/wrun/wrun-overlay-run.util.js +11013 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +24 -9
- package/dist/utility/wrun/wrun-panel-mount.util.js +138 -43
- package/dist/utility/wrun/wrun-param-map.util.d.ts +19 -4
- package/dist/utility/wrun/wrun-param-map.util.js +40 -47
- package/dist/utility/wrun/wrun-param-values.util.d.ts +9 -3
- package/dist/utility/wrun/wrun-param-values.util.js +5 -5
- package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +93 -0
- package/dist/utility/wrun/wrun-prefix-cohort.util.js +484 -0
- package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +114 -0
- package/dist/utility/wrun/wrun-prefix-lanes.util.js +486 -0
- package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +317 -0
- package/dist/utility/wrun/wrun-prefix-proof.util.js +630 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +73 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.js +380 -0
- package/dist/utility/wrun/wrun-refusal-text.util.d.ts +15 -0
- package/dist/utility/wrun/wrun-refusal-text.util.js +40 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-replay-lane.util.d.ts +139 -0
- package/dist/utility/wrun/wrun-replay-lane.util.js +520 -0
- package/dist/utility/wrun/wrun-replay-rows.util.d.ts +21 -0
- package/dist/utility/wrun/wrun-replay-rows.util.js +172 -0
- package/dist/utility/wrun/wrun-row-source-factory.d.ts +53 -0
- package/dist/utility/wrun/wrun-row-source-factory.js +435 -0
- package/dist/utility/wrun/wrun-run-cells.util.d.ts +36 -0
- package/dist/utility/wrun/wrun-run-cells.util.js +46 -0
- package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +133 -0
- package/dist/utility/wrun/wrun-run-interval-session.util.js +121 -0
- package/dist/utility/wrun/wrun-run-interval.util.d.ts +98 -0
- package/dist/utility/wrun/wrun-run-interval.util.js +207 -0
- package/dist/utility/wrun/wrun-run-retained.util.d.ts +122 -0
- package/dist/utility/wrun/wrun-run-retained.util.js +255 -0
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +184 -0
- package/dist/utility/wrun/wrun-sandbox-row-source.js +444 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +4 -4
- package/dist/utility/wrun/wrun-series-stream.util.d.ts +86 -0
- package/dist/utility/wrun/wrun-series-stream.util.js +537 -0
- package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
- package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
- package/dist/utility/wrun/wrun-sheet-remembered.util.d.ts +21 -0
- package/dist/utility/wrun/wrun-sheet-remembered.util.js +36 -0
- package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.d.ts +7 -0
- package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.js +12 -0
- package/dist/utility/wrun/wrun-socket-row-source.js +4 -2
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +175 -3
- package/dist/utility/wrun/wrun-source-rows.util.js +294 -8
- package/dist/utility/wrun/wrun-stats-strip.util.d.ts +46 -0
- package/dist/utility/wrun/wrun-stats-strip.util.js +87 -0
- package/dist/utility/wrun/wrun-table-chrome.util.d.ts +163 -0
- package/dist/utility/wrun/wrun-table-chrome.util.js +557 -0
- package/dist/utility/wrun/wrun-text-params.util.d.ts +11 -6
- package/dist/utility/wrun/wrun-text-params.util.js +19 -30
- package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +64 -0
- package/dist/utility/wrun/wrun-transient-rerun.util.js +317 -0
- package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +10 -0
- package/dist/utility/wrun/wrun-twin-lookback.util.js +43 -0
- package/dist/utility/wrun/wrun-warmup-head-store.util.d.ts +41 -0
- package/dist/utility/wrun/wrun-warmup-head-store.util.js +120 -0
- package/dist/utility/wrun-alert-params.leaf.d.ts +24 -0
- package/dist/utility/wrun-alert-params.leaf.js +24 -0
- package/dist/utils/replay/replay-buffer-math.d.ts +148 -0
- package/dist/utils/replay/replay-buffer-math.js +684 -0
- package/dist/workers/wrun/wrun-abi-host.d.ts +203 -0
- package/dist/workers/wrun/wrun-abi-host.js +1220 -0
- package/dist/workers/wrun/wrun-engine-handler.d.ts +20 -0
- package/dist/workers/wrun/wrun-engine-handler.js +380 -0
- package/package.json +3 -3
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
22
|
+
*
|
|
23
|
+
* Isolation: a death of the shared worker (the run timeout, or an error
|
|
24
|
+
* event with a request in flight) rejects every pending request with
|
|
25
|
+
* `WrunWorkerPoisonError` naming the live sessions lost with it,
|
|
26
|
+
* quarantines the package that was running (its metadata id plus wasm
|
|
27
|
+
* digest) on the kScript self-heal ladder (30 s, doubling per repeat,
|
|
28
|
+
* capped at 5 min) so its next requests refuse at once with
|
|
29
|
+
* `WrunQuarantinedError` instead of killing the worker again, and throttles
|
|
30
|
+
* the respawn to one per window so several spinning packages (or a Retry
|
|
31
|
+
* that overrides the quarantine) cannot kill and respawn the worker on
|
|
32
|
+
* every request. A Retry or a settings save passes `overrideQuarantine`;
|
|
33
|
+
* its success clears the package's quarantine.
|
|
34
|
+
*
|
|
35
|
+
* wrun-3 (Indicator handles): the sheet's `handles` section and the other
|
|
36
|
+
* wrun-3 sheet fields are checked here before every run (the same place the
|
|
37
|
+
* string slots are), the request carries the declared handle defaults and
|
|
38
|
+
* the widened ABI, and the worker's answer carries the handle ledger's live
|
|
39
|
+
* set, which rides beside the rows it belongs to (`attachWrunHandles`) so
|
|
40
|
+
* the run-result adapter picks it up from the rows every integration route
|
|
41
|
+
* already hands it. The run's skipped draw calls (a call one bar's values
|
|
42
|
+
* could not carry, recorded instead of refusing the run) ride the same way
|
|
43
|
+
* (`attachWrunDrawSkips`), for the run's one warning row.
|
|
44
|
+
*
|
|
45
|
+
* wrun-3 (Indicator strategies): a sheet that declares `strategy` is read
|
|
46
|
+
* and resolved here before every run (the om validator's rules, then the
|
|
47
|
+
* shared host's resolver against the instance's params), the request
|
|
48
|
+
* carries the engine's declared config, the chart interval and the broker
|
|
49
|
+
* feed (the primary lane's OHLC per row, `strategyBars`, supplied by the
|
|
50
|
+
* overlay lanes from the chart's own candles), and the worker's answer
|
|
51
|
+
* carries the engine's StrategyOutput, which rides beside the rows
|
|
52
|
+
* (`attachWrunStrategy`) exactly like the handle set.
|
|
53
|
+
*/
|
|
54
|
+
import { ensureWrunChartHostSharedHost, wrunChartHostEnv } from '../../host-env.js';
|
|
55
|
+
import { abiAtLeast, attachWrunLive, WrunLiveOrderError, wrunLiveOf, wrunModuleKey, } from '../../interfaces/wrun-runtime.interface.js';
|
|
56
|
+
import { LOCAL_ENGINE_SELF_HEAL_RESET_GRACE_MS, localEngineSelfHealDelayMs, } from '../chart/local-engine-self-heal-backoff.util.js';
|
|
57
|
+
import { attachWrunStrategy, readWrunStrategySheet, wrunStrategyParamsOf } from './wrun-box-segment.util.js';
|
|
58
|
+
import { assertWrunSheetAbiCoupling, attachWrunDrawSkips, attachWrunHandles, readWrunHandleDefaults, } from './wrun-handles.util.js';
|
|
59
|
+
import { packWrunRows, unpackWrunResponse, wrunAbiVersion } from './wrun-pack.util.js';
|
|
60
|
+
import { WrunQuarantinedError, WrunWorkerPoisonError } from './wrun-registry-errors.util.js';
|
|
61
|
+
import { bindWrunHostLiveSeriesEnd } from './wrun-overlay-drivers.util.js';
|
|
62
|
+
/** Sources the kit marks daemon-only (`WRUN_DAEMON_ONLY_SOURCES`, a Set of source names; a kit that
|
|
63
|
+
* supplies per-source disclosure wording is a record read by the same key) are computed by the daemon,
|
|
64
|
+
* which owns their dependencies: the first input declaring one refuses the browser run by name. The
|
|
65
|
+
* chart's own candle classes (`ohlcv`, `time`) are served off the chart's rows and never need the kit,
|
|
66
|
+
* so a plain package dispatches synchronously; any other declared class asks the kit (`warm` loads it
|
|
67
|
+
* ahead of the first add). The table is one of the two the run path still reads from the kit: the
|
|
68
|
+
* shared host entry does not export it. */
|
|
69
|
+
export function assertWrunBrowserSources(metadata) {
|
|
70
|
+
const candidates = [];
|
|
71
|
+
for (const input of metadata.inputs) {
|
|
72
|
+
for (const source of [input.source, metadata.inputSources[input.name]?.source]) {
|
|
73
|
+
if (typeof source === 'string' && source !== 'ohlcv' && source !== 'time')
|
|
74
|
+
candidates.push([input.name, source]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (candidates.length === 0)
|
|
78
|
+
return;
|
|
79
|
+
return wrunChartHostEnv()
|
|
80
|
+
.transport.loadWrunKit()
|
|
81
|
+
.then(({ wrunIndicatorKit }) => {
|
|
82
|
+
const daemonOnlySources = wrunIndicatorKit.WRUN_DAEMON_ONLY_SOURCES;
|
|
83
|
+
if (!daemonOnlySources)
|
|
84
|
+
return;
|
|
85
|
+
for (const [name, source] of candidates) {
|
|
86
|
+
const disclosure = typeof daemonOnlySources.has === 'function'
|
|
87
|
+
? daemonOnlySources.has(source) && 'computed on your daemon, not in the tab'
|
|
88
|
+
: Reflect.get(daemonOnlySources, source);
|
|
89
|
+
if (typeof disclosure === 'string')
|
|
90
|
+
throw new Error(`Input '${name}' (${source}): ${disclosure}`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const WRUN_RUN_TIMEOUT_MS = 20_000;
|
|
95
|
+
/** One respawn of the shared worker per window (the kScript shared worker's
|
|
96
|
+
* `restartWithReseedBackoff` rule, sized for this host's 20 s run timeout
|
|
97
|
+
* instead of kScript's 90 s call timeouts): a second death inside the window
|
|
98
|
+
* after a respawn holds the next respawn until the window closes, and every
|
|
99
|
+
* request meanwhile fails fast with the death's poison error. The quarantine
|
|
100
|
+
* below bounds ONE package's deaths geometrically; this window bounds the
|
|
101
|
+
* worker's deaths whatever mix of packages (or overrides) causes them. */
|
|
102
|
+
export const WRUN_WORKER_RESPAWN_WINDOW_MS = 60_000;
|
|
103
|
+
/** `strategyBars` stride: open, high, low, close per row. */
|
|
104
|
+
const STRATEGY_BAR_STRIDE = 4;
|
|
105
|
+
/** How many module handles the host keeps (loadModule): every package version, draft Run and REPL compile mints a
|
|
106
|
+
* key, and the engine worker keeps an LRU of the same size of the compiled modules behind them. */
|
|
107
|
+
export const WRUN_MODULE_CACHE_CAPACITY = 16;
|
|
108
|
+
/** The provisional key tokens of unpinned loads: one per caller bytes object and ABI, held as long as the bytes are. */
|
|
109
|
+
const provisionalModuleKeys = new WeakMap();
|
|
110
|
+
/** An unpinned load's key until the worker names its digest: the caller's bytes object AND the ABI, so loads of one
|
|
111
|
+
* buffer for two ABIs never share (or replace) each other's entry. */
|
|
112
|
+
function provisionalModuleKey(bytes, abi) {
|
|
113
|
+
let byAbi = provisionalModuleKeys.get(bytes);
|
|
114
|
+
if (byAbi === undefined) {
|
|
115
|
+
byAbi = new Map();
|
|
116
|
+
provisionalModuleKeys.set(bytes, byAbi);
|
|
117
|
+
}
|
|
118
|
+
let key = byAbi.get(abi);
|
|
119
|
+
if (key === undefined) {
|
|
120
|
+
key = Object.freeze({ abi });
|
|
121
|
+
byAbi.set(abi, key);
|
|
122
|
+
}
|
|
123
|
+
return key;
|
|
124
|
+
}
|
|
125
|
+
/** The original bytes behind each handle this module's hosts loaded: copied at the load, never handed out, posted
|
|
126
|
+
* (copied, never transferred) with every full run and live-start. A handle no host here loaded has none: its runs
|
|
127
|
+
* carry no bytes, and a worker that does not hold its key refuses them by name. */
|
|
128
|
+
const wrunModuleBytes = new WeakMap();
|
|
129
|
+
const NO_MODULE_BYTES = new Uint8Array(0);
|
|
130
|
+
/** A caller's module bytes as a view of exactly their own range. */
|
|
131
|
+
function moduleBytesView(bytes) {
|
|
132
|
+
return ArrayBuffer.isView(bytes)
|
|
133
|
+
? new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
134
|
+
: new Uint8Array(bytes);
|
|
135
|
+
}
|
|
136
|
+
/** A private copy of a caller's module bytes, in an ordinary buffer of its own: the caller may reuse, change or
|
|
137
|
+
* transfer its buffer after the load, and a shared buffer never backs the copy (a clone of a view on shared memory
|
|
138
|
+
* shares it, so the worker's copy could rewrite the bytes this host keeps). */
|
|
139
|
+
function snapshotModuleBytes(bytes) {
|
|
140
|
+
return new Uint8Array(moduleBytesView(bytes));
|
|
141
|
+
}
|
|
142
|
+
/** Whether a caller's bytes equal a private copy: the length, then every byte. */
|
|
143
|
+
function sameModuleBytes(copy, bytes) {
|
|
144
|
+
const view = moduleBytesView(bytes);
|
|
145
|
+
if (view.byteLength !== copy.byteLength)
|
|
146
|
+
return false;
|
|
147
|
+
for (let at = 0; at < view.byteLength; at += 1) {
|
|
148
|
+
if (view[at] !== copy[at])
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
/** The client's handle for a load the worker answered: opaque, frozen, its imports in the worker's order. */
|
|
154
|
+
function wrunModuleHandleOf(response, abi) {
|
|
155
|
+
return Object.freeze({
|
|
156
|
+
key: response.key,
|
|
157
|
+
sha256: response.sha256,
|
|
158
|
+
abi,
|
|
159
|
+
imports: Object.freeze(response.imports.map(({ module, name }) => Object.freeze({ module, name }))),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** A refused load as its caller reads it: the class and the words the main thread's compile threw before 0.6.0 (a
|
|
163
|
+
* pin mismatch names the sheet's pin and the digest the worker found; an engine compile refusal is a
|
|
164
|
+
* WebAssembly.CompileError again; a clamp or rewrite refusal keeps its plain words). */
|
|
165
|
+
function wrunModuleLoadError(response, metadata) {
|
|
166
|
+
if (response.code === 'module-pin-mismatch') {
|
|
167
|
+
return new Error(`WRUN ${metadata.id}: wasm sha256 mismatch (metadata pins ${metadata.wasm_sha256}, bytes are ${response.sha256})`);
|
|
168
|
+
}
|
|
169
|
+
if (response.code === 'module-compile-failed')
|
|
170
|
+
return new WebAssembly.CompileError(response.error);
|
|
171
|
+
return new Error(response.error);
|
|
172
|
+
}
|
|
173
|
+
/** The quarantine key of a package: its metadata id plus the wasm digest the
|
|
174
|
+
* metadata pins, so a republished build (new digest) starts clean while every
|
|
175
|
+
* overlay of the same build shares one hold (two charts, two instances: a
|
|
176
|
+
* per-overlay key would let the second instance spin the worker again). An
|
|
177
|
+
* unpinned sheet (dev loader, REPL) keys by id alone. */
|
|
178
|
+
export function wrunHostQuarantineKey(metadata) {
|
|
179
|
+
return metadata.wasm_sha256 ? `${metadata.id}@${metadata.wasm_sha256}` : metadata.id;
|
|
180
|
+
}
|
|
181
|
+
/** The poison rejection every request pending at a death receives. The class
|
|
182
|
+
* is what code reads (`isWrunWorkerPoisonError`); the message keeps the
|
|
183
|
+
* host's own sentences (the culprit's deadline sentence is what the run
|
|
184
|
+
* deadline reader in runtime-diagnostics.util names the trap from, and a
|
|
185
|
+
* worker error's own message is what the legend shows); every rejection of
|
|
186
|
+
* one death carries that death's one context record. */
|
|
187
|
+
function wrunWorkerPoisonError(death, message) {
|
|
188
|
+
const error = new WrunWorkerPoisonError(death.reason, death.casualtySessionKeys, death.context);
|
|
189
|
+
error.message = message;
|
|
190
|
+
return error;
|
|
191
|
+
}
|
|
192
|
+
/** A live tick was asked of a session the worker no longer holds (never
|
|
193
|
+
* started, disposed, dropped after a failed tick, or lost to a worker
|
|
194
|
+
* poison/respawn). Callers rebuild via a fresh full run instead of treating
|
|
195
|
+
* this as a compute error. */
|
|
196
|
+
export class WrunLiveSessionLostError extends Error {
|
|
197
|
+
constructor(message) {
|
|
198
|
+
super(message);
|
|
199
|
+
this.name = 'WrunLiveSessionLostError';
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** A live tick's block was refused before evaluation because its rows run
|
|
203
|
+
* backwards against the worker session's watermark: the session survives,
|
|
204
|
+
* and the caller reseeds it from its buffers (the worker and the context
|
|
205
|
+
* disagree) instead of retrying the same block. The class is the one the
|
|
206
|
+
* ABI host throws inside the worker (`code: 'live-order'` on the wire). */
|
|
207
|
+
export { WrunLiveOrderError };
|
|
208
|
+
/** The live block accounting rides beside the rows (the registry lives with
|
|
209
|
+
* the wire types); re-exported here for the tick lane's reader. */
|
|
210
|
+
export { attachWrunLive, wrunLiveOf };
|
|
211
|
+
/**
|
|
212
|
+
* Pack a run request for the sheet's ABI. The wrun-3 sheet rules (handles,
|
|
213
|
+
* label position, text style, the strategy section) are checked first,
|
|
214
|
+
* beside the packer's own string-slot checks, so a bad sheet refuses by
|
|
215
|
+
* name before any worker hop; a wrun-3 request also carries the sheet's
|
|
216
|
+
* declared handle defaults and, for a strategy package, the engine config
|
|
217
|
+
* the sheet resolved to (full runs and live starts: the session keeps it)
|
|
218
|
+
* plus the block's broker feed (every block, live ticks included).
|
|
219
|
+
*/
|
|
220
|
+
function packWrunRunRequest(metadata, rows, initArgs, strategy, configure, textParams) {
|
|
221
|
+
assertWrunSheetAbiCoupling(metadata);
|
|
222
|
+
const sheet = readWrunStrategySheet(metadata);
|
|
223
|
+
const packed = packWrunRows(metadata, rows, initArgs, textParams);
|
|
224
|
+
if (!abiAtLeast(wrunAbiVersion(metadata), 'wrun-3'))
|
|
225
|
+
return packed;
|
|
226
|
+
// A sheet with no `handles` section sends no defaults: the ledger then refuses every draw call by name
|
|
227
|
+
// (`wrun_draw_kind_undeclared`, style, colour and delete included, the om hosts' rule), where an empty map
|
|
228
|
+
// declares the section with no kind.
|
|
229
|
+
const request = {
|
|
230
|
+
...packed.request,
|
|
231
|
+
...(metadata.handles !== undefined ? { handleDefaults: readWrunHandleDefaults(metadata) } : {}),
|
|
232
|
+
};
|
|
233
|
+
if (sheet === undefined)
|
|
234
|
+
return { request, transfer: packed.transfer };
|
|
235
|
+
if (strategy === undefined || strategy.bars.length !== rows.length) {
|
|
236
|
+
throw new Error(`Indicator ${metadata.id}: the strategy feed is missing (${strategy?.bars.length ?? 'no'} bars for ` +
|
|
237
|
+
`${rows.length} rows); a strategy package runs over the primary lane's own candles, one per input row`);
|
|
238
|
+
}
|
|
239
|
+
const strategyBars = new Float64Array(rows.length * STRATEGY_BAR_STRIDE);
|
|
240
|
+
strategy.bars.forEach((bar, row) => {
|
|
241
|
+
const at = row * STRATEGY_BAR_STRIDE;
|
|
242
|
+
strategyBars[at] = bar.open;
|
|
243
|
+
strategyBars[at + 1] = bar.high;
|
|
244
|
+
strategyBars[at + 2] = bar.low;
|
|
245
|
+
strategyBars[at + 3] = bar.close;
|
|
246
|
+
});
|
|
247
|
+
request.strategyBars = strategyBars;
|
|
248
|
+
if (configure) {
|
|
249
|
+
// The shared host's resolver: the engine's defaults, every literal as
|
|
250
|
+
// declared, every param link read from the instance's params with the
|
|
251
|
+
// engine's own value rule (an out-of-range value falls back to the
|
|
252
|
+
// default and is reported, the engine's STRATEGY_INVALID_PARAM_OVERRIDE),
|
|
253
|
+
// and the engine's inert-parameter warnings with the same text.
|
|
254
|
+
const resolution = wrunChartHostEnv()
|
|
255
|
+
.sharedHost()
|
|
256
|
+
.resolveWrunStrategySheet(sheet, {
|
|
257
|
+
params: wrunStrategyParamsOf(metadata, initArgs),
|
|
258
|
+
title: strategy.title ?? metadata.name,
|
|
259
|
+
});
|
|
260
|
+
for (const issue of resolution.issues)
|
|
261
|
+
console.warn(`[wrun] Indicator ${metadata.id}: ${issue.message}`);
|
|
262
|
+
for (const warning of resolution.warnings)
|
|
263
|
+
console.warn(`[wrun] Indicator ${metadata.id}: ${warning.message}`);
|
|
264
|
+
request.strategy = {
|
|
265
|
+
config: resolution.config,
|
|
266
|
+
...(strategy.intervalMs !== undefined ? { intervalMs: strategy.intervalMs } : {}),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return { request, transfer: [...packed.transfer, strategyBars.buffer] };
|
|
270
|
+
}
|
|
271
|
+
export class WrunBrowserHost {
|
|
272
|
+
worker = null;
|
|
273
|
+
pending = new Map();
|
|
274
|
+
/** One counter numbers loads, runs and live-ends: a retired incarnation's late answer names an id no entry holds. */
|
|
275
|
+
requestSeq = 0;
|
|
276
|
+
/** The order requests enter the `run` phase in (`PendingRequest.runOrder`). */
|
|
277
|
+
runSeq = 0;
|
|
278
|
+
/** Loads by module, least recently used first (Map order: a hit moves its entry to the end). The cache only
|
|
279
|
+
* dedupes loads and owns no module: a mounted overlay keeps the handle it was handed (its record), and a live
|
|
280
|
+
* session keeps its instance in the worker (live ticks name the session, never a module), so an eviction stops
|
|
281
|
+
* neither; a handle's bytes stay behind it whatever the cache lets go, and its runs carry them. */
|
|
282
|
+
moduleCache = new Map();
|
|
283
|
+
/** Live sessions the current worker holds (installed by an ok live-start,
|
|
284
|
+
* dropped by live-end, a sessionLost answer, or the worker's death). */
|
|
285
|
+
liveSessionKeys = new Set();
|
|
286
|
+
/** The epoch (live context generation) of the newest live-start dispatched per session key: an end naming
|
|
287
|
+
* another epoch leaves the key's bookkeeping to that newer start. */
|
|
288
|
+
liveStartEpochs = new Map();
|
|
289
|
+
/** Quarantined packages by key; a record outlives its hold by the ladder's
|
|
290
|
+
* reset grace so a repeat death escalates (pruned on the next death). */
|
|
291
|
+
quarantines = new Map();
|
|
292
|
+
lastDeath = null;
|
|
293
|
+
/** When the worker was last spawned AFTER a death (a respawn); null until
|
|
294
|
+
* the first death, so the first spawn ever never opens a window. */
|
|
295
|
+
lastRespawnAt = null;
|
|
296
|
+
respawnHeldUntil = 0;
|
|
297
|
+
/** Spin the sandbox worker and load the shared host (the packer, the
|
|
298
|
+
* strategy resolver; the worker holds its own for the module rewrite) and
|
|
299
|
+
* the authoring kit (the run path's two kit tables, the daemon-only
|
|
300
|
+
* sources and the token names) ahead of the first add (the Indicators tab
|
|
301
|
+
* opening is the signal), so the first package a reader mounts pays
|
|
302
|
+
* neither the worker spawn nor a module parse on its click. Idempotent; a
|
|
303
|
+
* load failure surfaces on the first module load or run as before, never
|
|
304
|
+
* here. A held respawn is not warmed around: the window exists to keep the
|
|
305
|
+
* worker down. */
|
|
306
|
+
warm() {
|
|
307
|
+
if (this.respawnHold() === null)
|
|
308
|
+
this.ensureWorker();
|
|
309
|
+
void wrunChartHostEnv()
|
|
310
|
+
.loadSharedHost()
|
|
311
|
+
.catch(() => undefined);
|
|
312
|
+
void wrunChartHostEnv()
|
|
313
|
+
.transport.loadWrunKit()
|
|
314
|
+
.catch(() => undefined);
|
|
315
|
+
}
|
|
316
|
+
/** The active quarantine of a package, if its hold is still running. */
|
|
317
|
+
quarantineOf(metadata) {
|
|
318
|
+
const record = this.quarantines.get(wrunHostQuarantineKey(metadata));
|
|
319
|
+
return record !== undefined && Date.now() < record.until ? record : undefined;
|
|
320
|
+
}
|
|
321
|
+
/** Forget every quarantine and the respawn window (specs only). */
|
|
322
|
+
resetGuardsForTests() {
|
|
323
|
+
this.quarantines.clear();
|
|
324
|
+
this.lastDeath = null;
|
|
325
|
+
this.lastRespawnAt = null;
|
|
326
|
+
this.respawnHeldUntil = 0;
|
|
327
|
+
}
|
|
328
|
+
/** Load (and cache) a package module: the worker hashes the bytes, refuses a
|
|
329
|
+
* digest other than the sheet's `wasm_sha256` pin with the words this host
|
|
330
|
+
* always used, refuses a memory the clamp refuses (a maximum or a starting
|
|
331
|
+
* size over the worker's memory limit, shared or 64-bit memory), stamps
|
|
332
|
+
* the limit as the maximum of a memory declared without one, exports every
|
|
333
|
+
* mutable global for the live lane's snapshot and restore, and compiles
|
|
334
|
+
* (wrun-engine-handler.ts `compileWrunModuleBytes`). This thread keeps a
|
|
335
|
+
* private copy of the bytes behind the handle and hashes and compiles
|
|
336
|
+
* nothing. A load needs the worker: during a held respawn every load
|
|
337
|
+
* rejects with the held death, a cached one too, and its start ceiling
|
|
338
|
+
* bounds the wait and the compile.
|
|
339
|
+
*
|
|
340
|
+
* The cache is an LRU of WRUN_MODULE_CACHE_CAPACITY handles, keyed by the
|
|
341
|
+
* sheet's pin and ABI when it pins one (its identity before and after the
|
|
342
|
+
* load), else by the bytes object and the ABI until the worker names the
|
|
343
|
+
* digest, then by the module's key; the first handle of a key stays the
|
|
344
|
+
* one every caller shares. A hit serves only bytes equal to the ones its
|
|
345
|
+
* entry loads: other bytes under the key (a pin claimed by bytes it was
|
|
346
|
+
* not verified from, a reused buffer whose content changed) go to the
|
|
347
|
+
* worker, which checks them against the pin, beside the cached entry and
|
|
348
|
+
* never in its place. Every caller of a load in flight shares its one
|
|
349
|
+
* post, and a load in flight is never evicted; eviction drops loaded
|
|
350
|
+
* entries only, least recently used first, so the cache passes the
|
|
351
|
+
* capacity only while more loads than that are in flight. A failed load is
|
|
352
|
+
* not cached: its entry leaves before its callers see the failure, and the
|
|
353
|
+
* next request loads again. Async, as the compile was: every failure (a
|
|
354
|
+
* detached buffer included) is a rejection, and nothing here awaits before
|
|
355
|
+
* the entry is cached. */
|
|
356
|
+
async loadModule(wasmBytes, metadata) {
|
|
357
|
+
// The hold first, before the cache: the window keeps the worker down, and a handle served from the cache now
|
|
358
|
+
// would only meet the held death at its first run.
|
|
359
|
+
const held = this.respawnHold();
|
|
360
|
+
if (held)
|
|
361
|
+
throw held;
|
|
362
|
+
const abi = wrunAbiVersion(metadata);
|
|
363
|
+
const pin = metadata.wasm_sha256 ? metadata.wasm_sha256 : undefined;
|
|
364
|
+
const cacheKey = pin !== undefined ? wrunModuleKey(pin, abi) : provisionalModuleKey(wasmBytes, abi);
|
|
365
|
+
const hit = this.moduleCache.get(cacheKey);
|
|
366
|
+
if (hit !== undefined && sameModuleBytes(hit.bytes, wasmBytes)) {
|
|
367
|
+
// A hit is the most recent use: set again, at the end of the order eviction reads from the front.
|
|
368
|
+
this.moduleCache.delete(cacheKey);
|
|
369
|
+
this.moduleCache.set(cacheKey, hit);
|
|
370
|
+
return hit.handle;
|
|
371
|
+
}
|
|
372
|
+
const bytes = snapshotModuleBytes(wasmBytes);
|
|
373
|
+
// Under a key whose entry loads other bytes, this load verifies its own beside that entry, never in its place.
|
|
374
|
+
const cacheable = hit === undefined;
|
|
375
|
+
const created = {
|
|
376
|
+
abi,
|
|
377
|
+
bytes,
|
|
378
|
+
loaded: false,
|
|
379
|
+
handle: this.requestModuleLoad(bytes, abi, pin, metadata).then((handle) => this.cacheLoadedModule(cacheable ? cacheKey : null, created, handle), (error) => {
|
|
380
|
+
if (cacheable && this.moduleCache.get(cacheKey) === created)
|
|
381
|
+
this.moduleCache.delete(cacheKey);
|
|
382
|
+
throw error;
|
|
383
|
+
}),
|
|
384
|
+
};
|
|
385
|
+
if (cacheable) {
|
|
386
|
+
this.moduleCache.set(cacheKey, created);
|
|
387
|
+
this.trimModuleCache();
|
|
388
|
+
}
|
|
389
|
+
return created.handle;
|
|
390
|
+
}
|
|
391
|
+
/** A load answered: its entry leaves the key it waited under (an unpinned sheet's provisional key; none for a load
|
|
392
|
+
* that verified other bytes beside a cached entry) for the module's own key. A handle already loaded under that key
|
|
393
|
+
* stays the one every caller shares. */
|
|
394
|
+
cacheLoadedModule(cacheKey, entry, handle) {
|
|
395
|
+
if (cacheKey !== null && this.moduleCache.get(cacheKey) === entry)
|
|
396
|
+
this.moduleCache.delete(cacheKey);
|
|
397
|
+
const known = this.moduleCache.get(handle.key);
|
|
398
|
+
if (known !== undefined && known !== entry && known.loaded) {
|
|
399
|
+
this.moduleCache.delete(handle.key);
|
|
400
|
+
this.moduleCache.set(handle.key, known);
|
|
401
|
+
return known.handle;
|
|
402
|
+
}
|
|
403
|
+
entry.loaded = true;
|
|
404
|
+
this.moduleCache.set(handle.key, entry);
|
|
405
|
+
this.trimModuleCache();
|
|
406
|
+
return handle;
|
|
407
|
+
}
|
|
408
|
+
/** Post one `module-load` of the private bytes (copied, never transferred: the handle keeps them for its runs) and
|
|
409
|
+
* mint the handle from the worker's answer. */
|
|
410
|
+
requestModuleLoad(bytes, abi, pin, metadata) {
|
|
411
|
+
return new Promise((resolve, reject) => {
|
|
412
|
+
const request = {
|
|
413
|
+
kind: 'module-load',
|
|
414
|
+
id: ++this.requestSeq,
|
|
415
|
+
abi,
|
|
416
|
+
...(pin !== undefined ? { sha256Pin: pin } : {}),
|
|
417
|
+
bytes,
|
|
418
|
+
};
|
|
419
|
+
this.post(request, [], {
|
|
420
|
+
kind: 'load',
|
|
421
|
+
// The package a compile that outlives its ceiling is held under, like a run's.
|
|
422
|
+
quarantineKey: wrunHostQuarantineKey(metadata),
|
|
423
|
+
overrideQuarantine: false,
|
|
424
|
+
reject,
|
|
425
|
+
settle: (response) => {
|
|
426
|
+
if (!response.ok) {
|
|
427
|
+
reject(wrunModuleLoadError(response, metadata));
|
|
428
|
+
}
|
|
429
|
+
else if (!('kind' in response)) {
|
|
430
|
+
reject(new Error(`WRUN ${metadata.id}: module load ${request.id} was answered as a run`));
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
const handle = wrunModuleHandleOf(response, abi);
|
|
434
|
+
wrunModuleBytes.set(handle, bytes);
|
|
435
|
+
resolve(handle);
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/** Evict loaded entries, least recently used first, until the cache is back at its capacity (a load in flight
|
|
442
|
+
* stays: its callers share it). */
|
|
443
|
+
trimModuleCache() {
|
|
444
|
+
for (const [key, entry] of this.moduleCache) {
|
|
445
|
+
if (this.moduleCache.size <= WRUN_MODULE_CACHE_CAPACITY)
|
|
446
|
+
return;
|
|
447
|
+
if (entry.loaded)
|
|
448
|
+
this.moduleCache.delete(key);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
async runSeries(input) {
|
|
452
|
+
const lane = this.admit(input.metadata, input.overrideQuarantine);
|
|
453
|
+
const sourceCheck = assertWrunBrowserSources(input.metadata);
|
|
454
|
+
if (sourceCheck)
|
|
455
|
+
await sourceCheck;
|
|
456
|
+
// The packer and the strategy resolver read the shared host (loaded once, off the boot graph;
|
|
457
|
+
// a loaded host adds no await, so a warm run dispatches in the same task as before).
|
|
458
|
+
const hostLoading = ensureWrunChartHostSharedHost();
|
|
459
|
+
if (hostLoading)
|
|
460
|
+
await hostLoading;
|
|
461
|
+
const { request: packed, transfer } = packWrunRunRequest(input.metadata, input.rows, input.initArgs, input.strategy, true, input.textParams);
|
|
462
|
+
const id = ++this.requestSeq;
|
|
463
|
+
const request = {
|
|
464
|
+
id,
|
|
465
|
+
mode: input.mode ?? 'historical',
|
|
466
|
+
...packed,
|
|
467
|
+
};
|
|
468
|
+
const response = await this.dispatchWithModule(request, transfer, lane, input.module);
|
|
469
|
+
return this.unpack(response, input.metadata, input.rows);
|
|
470
|
+
}
|
|
471
|
+
/** Full run that also opens (or replaces) a live forming-bar session under
|
|
472
|
+
* `sessionKey` in the worker: the guest stays instantiated, so later
|
|
473
|
+
* `runLiveRows` ticks execute only the new/revised rows. `epoch` is the
|
|
474
|
+
* live context generation opening the session: the worker installs the
|
|
475
|
+
* session only while that epoch is still the newest it has seen for the
|
|
476
|
+
* key (see the worker's ownership rule). */
|
|
477
|
+
async startLiveSeries(input) {
|
|
478
|
+
const lane = this.admit(input.metadata, input.overrideQuarantine);
|
|
479
|
+
const sourceCheck = assertWrunBrowserSources(input.metadata);
|
|
480
|
+
if (sourceCheck)
|
|
481
|
+
await sourceCheck;
|
|
482
|
+
// The packer and the strategy resolver read the shared host (loaded once, off the boot graph;
|
|
483
|
+
// a loaded host adds no await, so a warm run dispatches in the same task as before).
|
|
484
|
+
const hostLoading = ensureWrunChartHostSharedHost();
|
|
485
|
+
if (hostLoading)
|
|
486
|
+
await hostLoading;
|
|
487
|
+
const { request: packed, transfer } = packWrunRunRequest(input.metadata, input.rows, input.initArgs, input.strategy, true, input.textParams);
|
|
488
|
+
const id = ++this.requestSeq;
|
|
489
|
+
if (input.epoch !== undefined)
|
|
490
|
+
this.liveStartEpochs.set(input.sessionKey, input.epoch);
|
|
491
|
+
else
|
|
492
|
+
this.liveStartEpochs.delete(input.sessionKey);
|
|
493
|
+
const request = {
|
|
494
|
+
kind: 'live-start',
|
|
495
|
+
sessionKey: input.sessionKey,
|
|
496
|
+
id,
|
|
497
|
+
mode: 'live',
|
|
498
|
+
...(input.epoch !== undefined ? { epoch: input.epoch } : {}),
|
|
499
|
+
...packed,
|
|
500
|
+
};
|
|
501
|
+
const response = await this.dispatchWithModule(request, transfer, {
|
|
502
|
+
...lane,
|
|
503
|
+
session: { key: input.sessionKey, opens: true },
|
|
504
|
+
}, input.module);
|
|
505
|
+
return this.unpack(response, input.metadata, input.rows);
|
|
506
|
+
}
|
|
507
|
+
/** One live tick: evaluate only `rows` (the new/revised forming-bar rows)
|
|
508
|
+
* on the open session. Rejects with WrunLiveSessionLostError when the
|
|
509
|
+
* worker no longer holds the session. A wrun-3 session answers the
|
|
510
|
+
* handle ledger's FULL live set with every tick (the wire replaces the
|
|
511
|
+
* drawing set wholesale), attached to the returned rows; a strategy
|
|
512
|
+
* session likewise answers the whole StrategyOutput after the tick (the
|
|
513
|
+
* broker config rides the session, only the rows' broker feed ships). */
|
|
514
|
+
async runLiveRows(input) {
|
|
515
|
+
const lane = this.admit(input.metadata, input.overrideQuarantine);
|
|
516
|
+
const sourceCheck = assertWrunBrowserSources(input.metadata);
|
|
517
|
+
if (sourceCheck)
|
|
518
|
+
await sourceCheck;
|
|
519
|
+
// The packer and the strategy resolver read the shared host (loaded once, off the boot graph;
|
|
520
|
+
// a loaded host adds no await, so a warm run dispatches in the same task as before).
|
|
521
|
+
const hostLoading = ensureWrunChartHostSharedHost();
|
|
522
|
+
if (hostLoading)
|
|
523
|
+
await hostLoading;
|
|
524
|
+
// initArgs ride the session (init already ran); pack an empty block.
|
|
525
|
+
const { request: packed, transfer } = packWrunRunRequest(input.metadata, input.rows, [], input.strategy, false);
|
|
526
|
+
const id = ++this.requestSeq;
|
|
527
|
+
const request = {
|
|
528
|
+
kind: 'live-rows',
|
|
529
|
+
sessionKey: input.sessionKey,
|
|
530
|
+
id,
|
|
531
|
+
rowCount: packed.rowCount,
|
|
532
|
+
stride: packed.stride,
|
|
533
|
+
ts: packed.ts,
|
|
534
|
+
argCounts: packed.argCounts,
|
|
535
|
+
values: packed.values,
|
|
536
|
+
cellIndexes: packed.cellIndexes,
|
|
537
|
+
cellLens: packed.cellLens,
|
|
538
|
+
cellOffsets: packed.cellOffsets,
|
|
539
|
+
cells: packed.cells,
|
|
540
|
+
...(packed.strategyBars !== undefined ? { strategyBars: packed.strategyBars } : {}),
|
|
541
|
+
};
|
|
542
|
+
const response = await this.dispatch(request, transfer, {
|
|
543
|
+
...lane,
|
|
544
|
+
session: { key: input.sessionKey, opens: false },
|
|
545
|
+
});
|
|
546
|
+
return this.unpack(response, input.metadata, input.rows);
|
|
547
|
+
}
|
|
548
|
+
/** Dispose one live session. Fire-and-forget: nothing to await, and a
|
|
549
|
+
* worker that is not running holds no sessions to dispose. With `epoch`
|
|
550
|
+
* (the live context generation that opened it), only that generation's
|
|
551
|
+
* session and start: the worker judges, it knows which epoch installed
|
|
552
|
+
* (a run ending what it opened never ends a newer owner's session under
|
|
553
|
+
* the same key). Without, whatever the key holds (the teardown). */
|
|
554
|
+
endLiveSeries(sessionKey, epoch) {
|
|
555
|
+
if (epoch === undefined || this.liveStartEpochs.get(sessionKey) === epoch) {
|
|
556
|
+
this.liveSessionKeys.delete(sessionKey);
|
|
557
|
+
this.liveStartEpochs.delete(sessionKey);
|
|
558
|
+
for (const entry of this.pending.values())
|
|
559
|
+
if (entry.session?.key === sessionKey)
|
|
560
|
+
entry.session = undefined;
|
|
561
|
+
}
|
|
562
|
+
if (!this.worker)
|
|
563
|
+
return;
|
|
564
|
+
const request = {
|
|
565
|
+
kind: 'live-end',
|
|
566
|
+
id: ++this.requestSeq,
|
|
567
|
+
sessionKey,
|
|
568
|
+
...(epoch !== undefined ? { epoch } : {}),
|
|
569
|
+
};
|
|
570
|
+
// No pending entry: the ok response for an untracked id is ignored by
|
|
571
|
+
// the onmessage handler, and a failure to dispose is indistinguishable
|
|
572
|
+
// from a worker respawn (both drop the session).
|
|
573
|
+
this.worker.postMessage(request);
|
|
574
|
+
}
|
|
575
|
+
destroy() {
|
|
576
|
+
this.failAllPending(new Error('WRUN host destroyed'));
|
|
577
|
+
this.liveSessionKeys.clear();
|
|
578
|
+
this.worker?.terminate();
|
|
579
|
+
this.worker = null;
|
|
580
|
+
}
|
|
581
|
+
/** Unpack the rows against the caller's axis and hang the handle set, the
|
|
582
|
+
* run's skipped draw calls, the strategy output and the live block
|
|
583
|
+
* accounting (when the worker answered them) on that rows array. */
|
|
584
|
+
unpack(response, metadata, rows) {
|
|
585
|
+
const unpacked = unpackWrunResponse(response,
|
|
586
|
+
// The request's ts buffer was transferred with the request; re-derive
|
|
587
|
+
// the axis from the caller's rows, which the response is aligned to.
|
|
588
|
+
rows.map((row) => row.ts), metadata.outputs.length, metadata.string_slots?.length ?? 0);
|
|
589
|
+
if (response.handles !== undefined)
|
|
590
|
+
attachWrunHandles(unpacked, response.handles);
|
|
591
|
+
if (response.skipped !== undefined) {
|
|
592
|
+
attachWrunDrawSkips(unpacked, { skipped: response.skipped, skippedCount: response.skippedCount ?? 0 });
|
|
593
|
+
}
|
|
594
|
+
if (response.strategy !== undefined)
|
|
595
|
+
attachWrunStrategy(unpacked, response.strategy);
|
|
596
|
+
if (response.live !== undefined)
|
|
597
|
+
attachWrunLive(unpacked, response.live);
|
|
598
|
+
return unpacked;
|
|
599
|
+
}
|
|
600
|
+
/** The quarantine gate every request passes before any packing or worker
|
|
601
|
+
* hop: a quarantined package refuses at once (nothing posted, no worker
|
|
602
|
+
* spawned) unless the caller overrides. The refusal carries the death's
|
|
603
|
+
* reason and the package's strikes (the heal ladder reads them). Returns
|
|
604
|
+
* the lane the pending entry remembers. */
|
|
605
|
+
admit(metadata, overrideQuarantine) {
|
|
606
|
+
const quarantineKey = wrunHostQuarantineKey(metadata);
|
|
607
|
+
const quarantine = overrideQuarantine ? undefined : this.quarantineOf(metadata);
|
|
608
|
+
if (quarantine) {
|
|
609
|
+
throw new WrunQuarantinedError(quarantineKey, quarantine.until, quarantine.reason, quarantine.strikes);
|
|
610
|
+
}
|
|
611
|
+
return { quarantineKey, overrideQuarantine: overrideQuarantine === true };
|
|
612
|
+
}
|
|
613
|
+
/** A full run or a live-start: the module rides the request, its key (the worker reuses the module it holds under
|
|
614
|
+
* it) and the host's private copy of its bytes (copied by structured clone, never transferred: a worker that does
|
|
615
|
+
* not hold the key, a respawned one or one that let it go, compiles them). The packed request's own `abi` stays
|
|
616
|
+
* the run's sheet's. */
|
|
617
|
+
dispatchWithModule(request, transfer, lane, module) {
|
|
618
|
+
return this.dispatch({ ...request, moduleKey: module.key, moduleBytes: wrunModuleBytes.get(module) ?? NO_MODULE_BYTES }, transfer, lane);
|
|
619
|
+
}
|
|
620
|
+
dispatch(request, transfer, lane) {
|
|
621
|
+
return new Promise((resolve, reject) => {
|
|
622
|
+
this.post(request, transfer, {
|
|
623
|
+
...lane,
|
|
624
|
+
kind: 'run',
|
|
625
|
+
reject,
|
|
626
|
+
settle: (response, entry) => this.settleRun(entry, response, resolve, reject),
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Post one request under a pending entry: the respawn hold first (a held death refuses it, nothing posted), then
|
|
632
|
+
* the worker, the entry in its `start` phase with the start ceiling armed (the wait behind other requests, the
|
|
633
|
+
* module's compile and its instantiation, bounded as the dispatch clock bounded the hold before 0.6.0), then the
|
|
634
|
+
* post. A request the structured clone refuses fails alone (its entry and clock go with it).
|
|
635
|
+
*/
|
|
636
|
+
post(request, transfer, init) {
|
|
637
|
+
const held = this.respawnHold();
|
|
638
|
+
if (held) {
|
|
639
|
+
init.reject(held);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const worker = this.ensureWorker();
|
|
643
|
+
const entry = { ...init, phase: 'start', runOrder: 0, timer: this.armClock(request.id) };
|
|
644
|
+
this.pending.set(request.id, entry);
|
|
645
|
+
try {
|
|
646
|
+
worker.postMessage(request, transfer);
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
if (this.pending.get(request.id) === entry) {
|
|
650
|
+
this.pending.delete(request.id);
|
|
651
|
+
clearTimeout(entry.timer);
|
|
652
|
+
}
|
|
653
|
+
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
/** A phase's clock: a request that outlives it means the worker is stuck (a guest spinning, a compile that never
|
|
657
|
+
* ends), so the worker is poisoned and replaced and later requests start clean. */
|
|
658
|
+
armClock(id) {
|
|
659
|
+
return setTimeout(() => this.poisonWorker('timeout', 'WRUN worker terminated after a timed-out run', id), WRUN_RUN_TIMEOUT_MS);
|
|
660
|
+
}
|
|
661
|
+
/** One answer from the worker. `running` moves its request to the `run` phase on a fresh clock (a second one, one
|
|
662
|
+
* for a load or for no pending request changes nothing); a terminal answer settles its request in either phase;
|
|
663
|
+
* an answer for no pending request (an untracked live-end's, a retired incarnation's) is dropped. */
|
|
664
|
+
receive(message) {
|
|
665
|
+
const entry = this.pending.get(message.id);
|
|
666
|
+
if (entry === undefined)
|
|
667
|
+
return;
|
|
668
|
+
if ('running' in message) {
|
|
669
|
+
if (entry.kind !== 'run' || entry.phase === 'run')
|
|
670
|
+
return;
|
|
671
|
+
// The module is instantiated and the run executes: its own deadline replaces the start ceiling, whatever the
|
|
672
|
+
// queue, the compile and the instantiation took.
|
|
673
|
+
clearTimeout(entry.timer);
|
|
674
|
+
entry.phase = 'run';
|
|
675
|
+
entry.runOrder = ++this.runSeq;
|
|
676
|
+
entry.timer = this.armClock(message.id);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
this.pending.delete(message.id);
|
|
680
|
+
clearTimeout(entry.timer);
|
|
681
|
+
entry.settle(message, entry);
|
|
682
|
+
}
|
|
683
|
+
/** A run's terminal answer: the package answered (an overridden quarantine is cleared by the success, and an
|
|
684
|
+
* opened session is one the worker now holds), a lost session, a live-order refusal, or a failure. */
|
|
685
|
+
settleRun(entry, response, resolve, reject) {
|
|
686
|
+
const { session } = entry;
|
|
687
|
+
if (response.ok) {
|
|
688
|
+
if ('kind' in response) {
|
|
689
|
+
reject(new Error(`WRUN request ${response.id} was answered as a module load`));
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (entry.overrideQuarantine)
|
|
693
|
+
this.quarantines.delete(entry.quarantineKey);
|
|
694
|
+
if (session?.opens)
|
|
695
|
+
this.liveSessionKeys.add(session.key);
|
|
696
|
+
resolve(response);
|
|
697
|
+
}
|
|
698
|
+
else if (response.sessionLost) {
|
|
699
|
+
if (session)
|
|
700
|
+
this.liveSessionKeys.delete(session.key);
|
|
701
|
+
reject(new WrunLiveSessionLostError(response.error));
|
|
702
|
+
}
|
|
703
|
+
else if (response.code === 'live-order')
|
|
704
|
+
reject(new WrunLiveOrderError(response.error));
|
|
705
|
+
else {
|
|
706
|
+
// A failed tick drops its session in the worker; a failed start
|
|
707
|
+
// never replaces the session already open under its key.
|
|
708
|
+
if (session && !session.opens)
|
|
709
|
+
this.liveSessionKeys.delete(session.key);
|
|
710
|
+
reject(new Error(response.error));
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
ensureWorker() {
|
|
714
|
+
if (this.worker)
|
|
715
|
+
return this.worker;
|
|
716
|
+
// A spawn after a death is a respawn: it opens the window a second
|
|
717
|
+
// death must stay out of.
|
|
718
|
+
if (this.lastDeath !== null)
|
|
719
|
+
this.lastRespawnAt = Date.now();
|
|
720
|
+
// The host's engine port spawns the sandbox worker (web: the worker factory, with the worker script's URL and
|
|
721
|
+
// the factory's failure source, both the app's), synchronously, as the host's own call did.
|
|
722
|
+
this.worker = wrunChartHostEnv().engine.spawnWorker({
|
|
723
|
+
// The sandbox worker posts no handshake: any message proves it up. No ready deadline: the requests' clocks,
|
|
724
|
+
// the quarantine and the respawn window own this worker's liveness.
|
|
725
|
+
readiness: { mode: 'first-message' },
|
|
726
|
+
onMessage: (event) => this.receive(event.data),
|
|
727
|
+
// A worker-level error (a script or module chunk that would not load, an
|
|
728
|
+
// uncaught throw in the worker script) leaves the Worker unable to answer
|
|
729
|
+
// anything: keep it installed and every later run would post into a void
|
|
730
|
+
// and only settle at the 20s timeout. The factory already terminated it
|
|
731
|
+
// (and beaconed a script that would not load, naming the worker file);
|
|
732
|
+
// mirror the timeout path: poison it now so the next run respawns a clean
|
|
733
|
+
// worker and this failure fails fast. A replaced or terminated
|
|
734
|
+
// incarnation's late events reach nobody, so a late one is never another
|
|
735
|
+
// death.
|
|
736
|
+
onDead: (death) => this.poisonWorker('worker-error', death.message || 'WRUN worker error'),
|
|
737
|
+
});
|
|
738
|
+
return this.worker;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* The shared worker died: quarantine the package that was running (the
|
|
742
|
+
* culprit, `culpritOf`), terminate the worker, remember the death for the
|
|
743
|
+
* respawn window, and reject every pending request (loads included) with
|
|
744
|
+
* the poison error naming the live sessions lost with the worker. Nothing
|
|
745
|
+
* in flight means nothing to quarantine (a worker that dies idle is only a
|
|
746
|
+
* death for the window). `message` is what every casualty reads; the
|
|
747
|
+
* culprit of a timeout keeps its own deadline sentence. The death's
|
|
748
|
+
* context (cause, the culprit's package, session and phase, the budget a
|
|
749
|
+
* timeout used up) is recorded here once, frozen, and rides every
|
|
750
|
+
* rejection of this death, the respawn hold's included, so a casualty can
|
|
751
|
+
* name who held the sandbox.
|
|
752
|
+
*/
|
|
753
|
+
poisonWorker(reason, message, expiredId) {
|
|
754
|
+
const now = Date.now();
|
|
755
|
+
const culprit = this.culpritOf(expiredId);
|
|
756
|
+
if (culprit !== undefined)
|
|
757
|
+
this.quarantine(culprit.quarantineKey, reason, now);
|
|
758
|
+
const casualties = new Set(this.liveSessionKeys);
|
|
759
|
+
for (const entry of this.pending.values())
|
|
760
|
+
if (entry.session)
|
|
761
|
+
casualties.add(entry.session.key);
|
|
762
|
+
const casualtySessionKeys = [...casualties];
|
|
763
|
+
this.liveSessionKeys.clear();
|
|
764
|
+
this.worker?.terminate();
|
|
765
|
+
this.worker = null;
|
|
766
|
+
const kind = reason === 'timeout' || reason === 'worker-error' ? reason : 'unknown';
|
|
767
|
+
const context = Object.freeze({
|
|
768
|
+
kind,
|
|
769
|
+
...(culprit !== undefined ? { quarantineKey: culprit.quarantineKey } : {}),
|
|
770
|
+
...(culprit?.session !== undefined ? { sessionKey: culprit.session.key } : {}),
|
|
771
|
+
...(culprit !== undefined ? { phase: culprit.phase } : {}),
|
|
772
|
+
// A phase's clock (from the post for `start`, from `running` for `run`): the budget bounds the hold, not the
|
|
773
|
+
// execution.
|
|
774
|
+
...(kind === 'timeout' ? { heldMs: WRUN_RUN_TIMEOUT_MS } : {}),
|
|
775
|
+
at: now,
|
|
776
|
+
});
|
|
777
|
+
const death = { reason, casualtySessionKeys, message, context };
|
|
778
|
+
this.lastDeath = death;
|
|
779
|
+
if (this.lastRespawnAt !== null && now - this.lastRespawnAt < WRUN_WORKER_RESPAWN_WINDOW_MS) {
|
|
780
|
+
this.respawnHeldUntil = this.lastRespawnAt + WRUN_WORKER_RESPAWN_WINDOW_MS;
|
|
781
|
+
}
|
|
782
|
+
for (const [id, entry] of this.pending) {
|
|
783
|
+
clearTimeout(entry.timer);
|
|
784
|
+
const own = reason === 'timeout' && entry === culprit
|
|
785
|
+
? `WRUN ${entry.kind === 'load' ? 'module load' : 'run'} ${id} timed out after ${WRUN_RUN_TIMEOUT_MS}ms`
|
|
786
|
+
: message;
|
|
787
|
+
entry.reject(wrunWorkerPoisonError(death, own));
|
|
788
|
+
}
|
|
789
|
+
this.pending.clear();
|
|
790
|
+
}
|
|
791
|
+
/** Who held the worker when it died: the request in the `run` phase, the hog holding the worker's synchronous turn
|
|
792
|
+
* (the expired request itself when it was running, else the first that started running), else the expired
|
|
793
|
+
* request (nothing ran: its own wait and compile used its ceiling up), else, for an error event, the oldest
|
|
794
|
+
* request in flight. */
|
|
795
|
+
culpritOf(expiredId) {
|
|
796
|
+
const expired = expiredId !== undefined ? this.pending.get(expiredId) : undefined;
|
|
797
|
+
if (expired?.phase === 'run')
|
|
798
|
+
return expired;
|
|
799
|
+
let hog;
|
|
800
|
+
for (const entry of this.pending.values()) {
|
|
801
|
+
if (entry.phase === 'run' && (hog === undefined || entry.runOrder < hog.runOrder))
|
|
802
|
+
hog = entry;
|
|
803
|
+
}
|
|
804
|
+
if (hog !== undefined)
|
|
805
|
+
return hog;
|
|
806
|
+
return expiredId !== undefined ? expired : this.pending.values().next().value;
|
|
807
|
+
}
|
|
808
|
+
/** Put (or keep) a package on the ladder: a death while its previous hold
|
|
809
|
+
* runs, or inside the reset grace after it, is a repeat and doubles the
|
|
810
|
+
* hold (capped); a later death starts over at the base hold. Records past
|
|
811
|
+
* the grace are forgotten here. */
|
|
812
|
+
quarantine(key, reason, now) {
|
|
813
|
+
for (const [staleKey, record] of this.quarantines) {
|
|
814
|
+
if (now - record.until >= LOCAL_ENGINE_SELF_HEAL_RESET_GRACE_MS)
|
|
815
|
+
this.quarantines.delete(staleKey);
|
|
816
|
+
}
|
|
817
|
+
const strikes = (this.quarantines.get(key)?.strikes ?? 0) + 1;
|
|
818
|
+
this.quarantines.set(key, { key, until: now + localEngineSelfHealDelayMs(strikes), reason, strikes });
|
|
819
|
+
}
|
|
820
|
+
/** The rejection a request gets while the respawn is held: the last death's
|
|
821
|
+
* poison error (its casualties are still unrebuilt, no worker ran since,
|
|
822
|
+
* and it carries that death's context), marked as held. Null when a worker
|
|
823
|
+
* runs or the window has closed. */
|
|
824
|
+
respawnHold() {
|
|
825
|
+
if (this.worker !== null || this.lastDeath === null || Date.now() >= this.respawnHeldUntil)
|
|
826
|
+
return null;
|
|
827
|
+
return wrunWorkerPoisonError(this.lastDeath, `${this.lastDeath.message} (respawn held)`);
|
|
828
|
+
}
|
|
829
|
+
failAllPending(error) {
|
|
830
|
+
for (const pending of this.pending.values()) {
|
|
831
|
+
clearTimeout(pending.timer);
|
|
832
|
+
pending.reject(error);
|
|
833
|
+
}
|
|
834
|
+
this.pending.clear();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
let sharedHost = null;
|
|
838
|
+
export function getWrunBrowserHost() {
|
|
839
|
+
sharedHost ??= new WrunBrowserHost();
|
|
840
|
+
return sharedHost;
|
|
841
|
+
}
|
|
842
|
+
// The overlay teardown ends a live series through this (wrun-overlay-drivers.util keeps no import
|
|
843
|
+
// of the host): bound as the host evaluates, before its worker can open a session. A spec that
|
|
844
|
+
// mocks the drivers util partially has no binder (reading a missing export of a mocked module
|
|
845
|
+
// throws at access time), so the bind is skipped there rather than failing the import.
|
|
846
|
+
try {
|
|
847
|
+
bindWrunHostLiveSeriesEnd((sessionKey) => getWrunBrowserHost().endLiveSeries(sessionKey));
|
|
848
|
+
}
|
|
849
|
+
catch {
|
|
850
|
+
// partial module mock (specs): no teardown door to bind
|
|
851
|
+
}
|
|
852
|
+
/** Clear the shared host's quarantines and respawn window between specs. */
|
|
853
|
+
export function __resetWrunBrowserHostGuardsForTests() {
|
|
854
|
+
sharedHost?.resetGuardsForTests();
|
|
855
|
+
}
|