@ai-ecoverse/slicc-kernel 1.186.1 → 1.187.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 +9 -1
- package/dist/async-process.js +23 -8
- package/dist/async-process.js.map +2 -2
- package/dist/cloudflare-sources.js +2 -2
- package/dist/cloudflare.js +53 -34
- package/dist/cloudflare.js.map +3 -3
- package/dist/kernel-worker.js +1 -1
- package/dist/node-process-worker.cjs +4 -4
- package/dist/node-process-worker.cjs.map +2 -2
- package/dist/node-process-worker.js +4 -4
- package/dist/node-process-worker.js.map +2 -2
- package/dist/node.js +10116 -10072
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +4 -4
- package/dist/process-worker.js.map +2 -2
- package/dist/types/async/node-host.d.ts +1 -0
- package/dist/types/cloudflare/loader.d.ts +4 -2
- package/dist/types/process/wasi/wasi-imports.d.ts +111 -0
- package/dist/types/process/wasi/wasi-threads.d.ts +23 -0
- package/dist/types/process/wasi/wasix-process.d.ts +39 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -317,7 +317,9 @@ The Worker needs a Worker Loader binding (`worker_loaders`) and a SQLite-backed
|
|
|
317
317
|
|
|
318
318
|
**Limits.**
|
|
319
319
|
- **Programs linked with pthreads run on one thread.** An Emscripten program built with `-pthread` imports a shared memory and Emscripten's thread functions, even when it never starts a thread (jq does, for its thread-local storage). The kernel gives it that memory and sets up its main thread, so it runs as any other program does. A Dynamic Worker has no second thread to give, so `pthread_create` fails with `EAGAIN`. `createNodeKernel({ emscripten: 'kernel' })` does the same.
|
|
320
|
-
- **Not supported:** threads (`pthread_create` fails with `EAGAIN`), `dlopen` and anything else that compiles wasm at run time, JS programs (`"abi": "js"`), and
|
|
320
|
+
- **Not supported:** threads (`pthread_create` fails with `EAGAIN`), `dlopen` and anything else that compiles wasm at run time, JS programs (`"abi": "js"`), and an imports module without `createAsyncImports` (126, `the imports module exports no createAsyncImports function, which the async process host calls`). Each fails with an errno or a message, never a hang.
|
|
321
|
+
- **Imports modules:** a WASI command's [imports module](#program-imports) is one of its Dynamic Worker's modules, beside the wasm, so it is loaded without `import()` and without the embedder. The Dynamic Worker is the program's and that module's: a command whose module differs (another package, or the file changed) gets a Dynamic Worker of its own. The module is evaluated when the Dynamic Worker starts and shared by the processes in it, so it must be one self-contained file (no `import`), and state at its top level is seen by all of them. Its HTTP and its commands go through the process's system calls, so through the kernel's transport; a Dynamic Worker has no network of its own (`globalOutbound: null`). The kernel calls `createAsyncImports(ctx)`, not `createImports`: see [Program imports](#program-imports).
|
|
322
|
+
- **Program size:** a Dynamic Worker's code (the program's wasm, its imports module, and the 0.5 MB process host) must be under 64 MiB. A larger program fails with status 70 and `Dynamic Worker code size (78982007 bytes) exceeds the maximum allowed size of 67108864 bytes.`, as `gh.wasm` of `@ai-ecoverse/wasi-gh` 2.102.0-2 (78 MB) does, in `wrangler dev` and deployed alike. The Durable Object also reads the whole wasm and keeps a copy of it while the kernel runs.
|
|
321
323
|
- **Memory:** a Dynamic Worker has 128 MB. A program whose wasm memory starts above that cannot run (`python.wasm` declares 160 MiB). Processes of one program share a Dynamic Worker up to the budget and then spill into another; at most 8 Dynamic Workers run at once, and a spawn beyond that waits, then fails with `EAGAIN`, which bash retries. A Dynamic Worker that outgrows its limit is ended by Cloudflare: its processes exit with status 70 and the kernel carries on.
|
|
322
324
|
- **CPU and signals:** a process that computes for 30 s without a system call is ended by Cloudflare. Nothing can interrupt it sooner: a signal, `SIGKILL` included, is seen at the process's next system call.
|
|
323
325
|
- **Clocks:** inside a Workers request the clock stands still while code computes. `time` and CPU accounting are wrong, and a timed wait that follows a long computation in the same process can end early by that computation's length.
|
|
@@ -557,6 +559,8 @@ A WASI command can name an ES module of its package that provides imports of its
|
|
|
557
559
|
- `errno(err)`: the WASI errno of an error;
|
|
558
560
|
- `uid` and `gid`, with `users: 'report'` or `'enforce'`: the process's effective uid and gid, read again at each use, so they follow a `setresuid`. `fstat` then shows a file's real owner, and the process's ids for a descriptor with no path. With `users: 'off'`, `ctx` has no `uid` or `gid`, and `fstat` answers 1000 for both, as before.
|
|
559
561
|
|
|
562
|
+
**On the async process host** (a [Durable Object](#in-a-cloudflare-durable-object)'s Dynamic Workers, and `createNodeKernel({ blocking: 'async' })`), nothing in a process can block, so the kernel calls the module's `createAsyncImports(ctx)` instead, with the same `ctx` except that every function of it that reaches the kernel returns a promise: `cwd()`, `fs.*`, `fds.*`, `syscall`, `net.*`, `spawn`, `wait`, `kill` and `async.*` (and `uid` and `gid` are promises). `memory()`, `instance()`, `tid`, `argv`, `env` and `errno` stay synchronous. An import that is an `async function` suspends the program with JSPI until its promise settles, so it can `await` those calls and return a number to the wasm as a synchronous import does; any other function is called as it is and must not return a promise (the process fails, naming the import). A module without `createAsyncImports` is refused there (126); `createImports` is still what a page and Node call. One source can serve both: write each operation as a generator that yields every `ctx` call, and drive it synchronously in `createImports` and with `await` in `createAsyncImports`, as the `hostcall` fixture (`test/integration/fixtures/hostcall`) does. Measured with gh (a 50 MB build) in a deployed Durable Object: `gh api repos/cli/cli --jq .full_name` takes 3.7 s the first time (reading the wasm from an R2 mount, and starting its Dynamic Worker) and 0.3 s after that.
|
|
563
|
+
|
|
560
564
|
### JS programs
|
|
561
565
|
|
|
562
566
|
A command can be an ES module instead of a wasm program: `"abi": "js"` and `module` name the module in the package, which must be one self-contained file (no relative or bare imports), and `args`, `argv0` and `env` work as for other commands. An entry with `"abi": "js"` but no `module` (or one outside the package) is not a command, like a wasm entry without its module, so running it fails with 127. Every run gets its own process worker, so each process evaluates the module afresh: module-level state never carries over from one run to the next. The kernel keeps an importable URL per module source (a `blob:` URL in the browser; under Node a short `slicc-module:<sha-256>` id that the process worker is handed together with the source, so no base64 is made or decoded, [#1596](https://github.com/ai-ecoverse/slicc-kernel/issues/1596)) for the 16 sources it ran last, so a command run in a loop doesn't encode its module again each time ([#846](https://github.com/ai-ecoverse/slicc-kernel/issues/846)). A changed file is a new source and gets a new URL. An evicted URL is revoked once every run it was handed to has exited, so a run that is still loading its module never loses it.
|
|
@@ -1696,6 +1700,10 @@ The Biome, TypeScript, lefthook, Renovate and CI configuration comes from [slicc
|
|
|
1696
1700
|
|
|
1697
1701
|
## Test fixtures
|
|
1698
1702
|
|
|
1703
|
+
### `hostcall`
|
|
1704
|
+
|
|
1705
|
+
A WASI program in WebAssembly text (`hostcall.wat`, built with `node build.mjs` and `wabt`), the fixture of `test/integration/cf/async-wasi-imports.test.mjs` and `cloudflare-imports.test.mjs`. `hostcall REQUEST` hands `REQUEST` (a JSON object) to its imports module through `host_call.call(pointer, length)`, takes the answer with `host_call.take(pointer)` and prints it, as `gh.wasm` talks to `gh_host`. `host/hostcall-host.mjs` answers `echo` (its argv and directory), `exists` (`fs.exists` of a `path`), `http` (a `net-request` of a `url` with `headers`, and its body) and `run` (spawns `argv` and returns its status and output), from one set of generators that `createImports` and `createAsyncImports` both drive. The `hostcall-sync` command is the same wasm with `host/sync-only.mjs`, which has no `createAsyncImports`.
|
|
1706
|
+
|
|
1699
1707
|
The WASIX fixtures of `test/integration/epoll.test.mjs` (#674), under `test/integration/fixtures/`, are committed with their sources, build scripts and built wasm.
|
|
1700
1708
|
|
|
1701
1709
|
### `dnstest`
|
package/dist/async-process.js
CHANGED
|
@@ -1337,7 +1337,7 @@ function createParentRefreshCount() {
|
|
|
1337
1337
|
}
|
|
1338
1338
|
|
|
1339
1339
|
// src/version.ts
|
|
1340
|
-
var KERNEL_VERSION = true ? "1.
|
|
1340
|
+
var KERNEL_VERSION = true ? "1.187.0" : "0.0.0-dev";
|
|
1341
1341
|
var OS_RELEASE = "6.0.0-slicc";
|
|
1342
1342
|
function procVersion() {
|
|
1343
1343
|
return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
|
|
@@ -10273,7 +10273,7 @@ async function runWasiProcess(init, port, given = {}) {
|
|
|
10273
10273
|
if (!host.fds.isShared) await host.fds.share(threads.ids, false);
|
|
10274
10274
|
};
|
|
10275
10275
|
}
|
|
10276
|
-
const program = await programImports(init.program, host, transport, MAIN_TID);
|
|
10276
|
+
const program = await programImports(init.program, host, transport, MAIN_TID, given.imports);
|
|
10277
10277
|
const { instance, driver, linkedStack } = await instantiate(host, module, memory, threads, {
|
|
10278
10278
|
...fork ? { forked: fork } : {},
|
|
10279
10279
|
stats,
|
|
@@ -10348,9 +10348,9 @@ function programNames(host, program, warned) {
|
|
|
10348
10348
|
warn: (line) => warned.push(line)
|
|
10349
10349
|
});
|
|
10350
10350
|
}
|
|
10351
|
-
async function programImports(program, host, transport, tid) {
|
|
10351
|
+
async function programImports(program, host, transport, tid, given) {
|
|
10352
10352
|
if (program.imports === void 0) return void 0;
|
|
10353
|
-
const create = await loadImports(program.imports);
|
|
10353
|
+
const create = given ?? await loadImports(program.imports);
|
|
10354
10354
|
const raw = async (req) => await transport.call(req, Number.POSITIVE_INFINITY, req.op);
|
|
10355
10355
|
return async (memory, instance) => await create(importsContext({ host, raw, tid, memory, instance }));
|
|
10356
10356
|
}
|
|
@@ -14104,14 +14104,24 @@ var ASYNC_NO_JSPI = "the async process host needs WebAssembly JSPI (Suspending,
|
|
|
14104
14104
|
var ASYNC_NO_JS = "the async process host runs no JavaScript programs";
|
|
14105
14105
|
var ASYNC_NO_EMSCRIPTEN = "the async process host runs Emscripten programs only on the kernel's personality (emscripten: 'kernel')";
|
|
14106
14106
|
var ASYNC_NO_IMPORTS = "the async process host loads no JavaScript imports modules";
|
|
14107
|
-
function
|
|
14107
|
+
var ASYNC_NO_CREATE = "the imports module exports no createAsyncImports function, which the async process host calls";
|
|
14108
|
+
function refusal(init, deps) {
|
|
14108
14109
|
const program = init.program;
|
|
14109
14110
|
if (program.abi === "js") return ASYNC_NO_JS;
|
|
14110
14111
|
if (program.abi !== "wasi" && program.emscripten !== "kernel") return ASYNC_NO_EMSCRIPTEN;
|
|
14111
|
-
if (program.imports !== void 0) return ASYNC_NO_IMPORTS;
|
|
14112
|
+
if (program.imports !== void 0 && !deps.imports) return ASYNC_NO_IMPORTS;
|
|
14112
14113
|
if (!jspiAvailable()) return ASYNC_NO_JSPI;
|
|
14113
14114
|
return void 0;
|
|
14114
14115
|
}
|
|
14116
|
+
var NotRunnable = class extends Error {
|
|
14117
|
+
};
|
|
14118
|
+
async function importsOf(init, deps) {
|
|
14119
|
+
const source = init.program.imports;
|
|
14120
|
+
if (source === void 0 || !deps.imports) return void 0;
|
|
14121
|
+
const create = (await deps.imports(source)).createAsyncImports;
|
|
14122
|
+
if (typeof create !== "function") throw new NotRunnable(ASYNC_NO_CREATE);
|
|
14123
|
+
return create;
|
|
14124
|
+
}
|
|
14115
14125
|
var KernelGone = class extends Error {
|
|
14116
14126
|
constructor() {
|
|
14117
14127
|
super("the kernel link closed");
|
|
@@ -14158,6 +14168,7 @@ function localInit(init, transport, module) {
|
|
|
14158
14168
|
};
|
|
14159
14169
|
}
|
|
14160
14170
|
async function started(init, transport, deps, size) {
|
|
14171
|
+
const create = await importsOf(init, deps);
|
|
14161
14172
|
const module = await deps.module(init.program.image);
|
|
14162
14173
|
const kernel = guarded(transport);
|
|
14163
14174
|
const mirrored2 = kernelWaiter(transport, kernel, true);
|
|
@@ -14180,6 +14191,7 @@ async function started(init, transport, deps, size) {
|
|
|
14180
14191
|
return await runWasiProcess(local2, port, {
|
|
14181
14192
|
transport: transports,
|
|
14182
14193
|
threadCap: 1,
|
|
14194
|
+
...create ? { imports: create } : {},
|
|
14183
14195
|
bound: (memory) => {
|
|
14184
14196
|
forget();
|
|
14185
14197
|
forget = registerMemoryWaiter(memory, kernelWaiter(transport, kernel, false));
|
|
@@ -14204,12 +14216,14 @@ function asyncProcessEntry(link, deps) {
|
|
|
14204
14216
|
});
|
|
14205
14217
|
transport.init.then(
|
|
14206
14218
|
(init) => {
|
|
14207
|
-
const refused3 = refusal(init);
|
|
14219
|
+
const refused3 = refusal(init, deps);
|
|
14208
14220
|
if (refused3) return failed2(refused3, NOT_RUNNABLE2);
|
|
14209
14221
|
started(init, transport, deps, size).then(
|
|
14210
14222
|
(code2) => transport.post({ type: WASM_PROCESS_EXIT, code: code2 }),
|
|
14211
14223
|
(err) => {
|
|
14212
|
-
if (
|
|
14224
|
+
if (transport.closed) return;
|
|
14225
|
+
if (err instanceof NotRunnable) failed2(err.message, NOT_RUNNABLE2);
|
|
14226
|
+
else failed2(err);
|
|
14213
14227
|
}
|
|
14214
14228
|
);
|
|
14215
14229
|
},
|
|
@@ -14217,6 +14231,7 @@ function asyncProcessEntry(link, deps) {
|
|
|
14217
14231
|
);
|
|
14218
14232
|
}
|
|
14219
14233
|
export {
|
|
14234
|
+
ASYNC_NO_CREATE,
|
|
14220
14235
|
ASYNC_NO_EMSCRIPTEN,
|
|
14221
14236
|
ASYNC_NO_IMPORTS,
|
|
14222
14237
|
ASYNC_NO_JS,
|