@waffle-os/runtime 0.0.145 → 0.0.146
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 +32 -0
- package/browser/command-input.ts +86 -0
- package/browser/command-owner.ts +5 -0
- package/browser/display/guest.ts +2 -18
- package/browser/display/surface-info.ts +19 -0
- package/browser/operations/cells.ts +90 -0
- package/browser/operations/guest.ts +94 -0
- package/browser/operations/owner.ts +201 -0
- package/browser/operations/protocol.ts +16 -0
- package/browser/operations/types.ts +41 -0
- package/browser/operations/writer.ts +106 -0
- package/browser/preview1-worker.ts +8 -1
- package/browser/process-broker.ts +372 -22
- package/browser/process-start.ts +5 -2
- package/browser/run-command.ts +388 -0
- package/browser/shared-fs.ts +20 -3
- package/browser/worker-memory.ts +6 -0
- package/browser/worker.ts +121 -27
- package/dist/browser/command-input.js +82 -0
- package/dist/browser/command-owner.js +2 -0
- package/dist/browser/display/guest.js +2 -18
- package/dist/browser/display/surface-info.js +18 -0
- package/dist/browser/operations/cells.js +80 -0
- package/dist/browser/operations/guest.js +67 -0
- package/dist/browser/operations/owner.js +175 -0
- package/dist/browser/operations/protocol.js +0 -0
- package/dist/browser/operations/types.js +0 -0
- package/dist/browser/operations/writer.js +98 -0
- package/dist/browser/preview1-worker.js +4 -0
- package/dist/browser/process-broker.js +317 -18
- package/dist/browser/process-start.js +3 -0
- package/dist/browser/run-command.js +377 -0
- package/dist/browser/shared-fs.js +8 -3
- package/dist/browser/worker-memory.js +10 -1
- package/dist/browser/worker.js +83 -28
- package/dist/fs/client.js +81 -18
- package/dist/fs/resolve-observation.js +11 -0
- package/dist/fs/service.js +51 -4
- package/dist/proc/command-transfer.js +72 -0
- package/dist/proc/directory.js +9 -1
- package/dist/proc/intrinsics/host.js +4 -1
- package/dist/proc/intrinsics.js +1 -0
- package/dist/proc/pipes.js +37 -4
- package/dist/proc/registry.js +25 -14
- package/dist/proc/start-command.js +101 -0
- package/dist/proc/supervisor.js +34 -10
- package/dist/proc/worker-broker.js +86 -31
- package/dist/proc/worker-client.js +67 -31
- package/dist/programs/collection.js +2 -0
- package/dist/runtime.js +14 -1
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/client.ts +113 -17
- package/fs/resolve-observation.ts +25 -0
- package/fs/service.ts +63 -4
- package/index.ts +5 -0
- package/package.json +9 -1
- package/proc/command-transfer.ts +96 -0
- package/proc/directory.ts +10 -1
- package/proc/intrinsics/host.ts +5 -1
- package/proc/intrinsics.ts +1 -0
- package/proc/pipes.ts +39 -6
- package/proc/registry.ts +52 -17
- package/proc/start-command.ts +157 -0
- package/proc/supervisor.ts +34 -9
- package/proc/worker-broker.ts +100 -38
- package/proc/worker-client.ts +84 -31
- package/programs/collection.ts +4 -0
- package/runtime.ts +44 -3
- package/scripts/test-browser.ts +49 -29
- package/tests/browser-controls-discovery.test.ts +2 -10
- package/tests/browser-matrix.test.ts +105 -59
- package/tests/browser-navigation.test.ts +1 -1
- package/tests/browser-runner-lifecycle.ts +23 -13
- package/tests/command-input.test.ts +40 -0
- package/tests/command-scope.test.ts +422 -0
- package/tests/filesystem-client-intrinsics.test.ts +2 -0
- package/tests/filesystem-refcount.test.ts +2 -0
- package/tests/filesystem-resolve-observation.test.ts +185 -0
- package/tests/fixtures/command-bounded-admission.ts +31 -0
- package/tests/fixtures/command-disposal.ts +47 -0
- package/tests/fixtures/command-guests.ts +123 -0
- package/tests/fixtures/operation-fs-worker.ts +114 -0
- package/tests/fixtures/operation-observer-worker.ts +41 -0
- package/tests/fixtures/operation-page.ts +522 -0
- package/tests/fixtures/process-start-worker.ts +32 -0
- package/tests/link-browser-runner.ts +95 -22
- package/tests/node-exports.test.ts +29 -0
- package/tests/operation-diagnostics-browser.ts +192 -0
- package/tests/operation-diagnostics.test.ts +291 -0
- package/tests/page-runner/browser-controls-process-fixture.ts +24 -0
- package/tests/page-runner/browser-controls-runner.test.ts +20 -0
- package/tests/page-runner/browser-controls-runner.ts +1 -0
- package/tests/page-runner/browser-controls-suite.ts +20 -3
- package/tests/page-runner/control-run.ts +9 -1
- package/tests/page-runner/driver.ts +2 -0
- package/tests/page-runner/playwright-driver.ts +1 -1
- package/tests/page-runner/suite-host.ts +26 -1
- package/tests/page-runner/suite-startup.test.ts +39 -0
- package/tests/page-runner/threads-runtime-browser.test.ts +4 -6
- package/tests/page-runner/threads-runtime-suite.test.ts +14 -5
- package/tests/page-runner/worker-capability-controls.ts +174 -15
- package/tests/pipe-reader-reuse-races.test.ts +44 -0
- package/tests/process-start-browser-runner.ts +12 -4
- package/tests/process-start-browser.ts +66 -5
- package/tests/program-build-tools.test.ts +1 -1
- package/tests/runtime-facade.test.ts +5 -0
- package/tests/start-command.test.ts +109 -0
- package/tests/threads-guest-fixture.ts +1 -1
- package/tests/threads-guest-module.ts +6 -3
- package/tests/threads-guest.test.ts +25 -0
- package/tests/threads-runtime-browser-runner.ts +36 -13
- package/tests/threads-runtime-browser.ts +231 -92
- package/tests/threads-runtime-cases.ts +18 -1
- package/tests/threads-runtime-cleanup.ts +5 -1
- package/tests/threads-runtime-fd-browser.ts +247 -0
- package/tests/threads-runtime-fd-control.ts +3 -385
- package/tests/threads-runtime-fd-descriptors.test.ts +15 -13
- package/tests/threads-runtime-fd-module.ts +13 -2
- package/tests/threads-runtime-fd-service.ts +23 -2
- package/tests/threads-runtime-growth-worker.ts +61 -0
- package/tests/threads-runtime-host.ts +17 -4
- package/tests/threads-runtime-modules.ts +23 -5
- package/tests/threads-runtime-regression-controls.ts +386 -0
- package/tests/threads-runtime-regression-modules.ts +242 -0
- package/tests/threads-runtime-service-barrier.ts +8 -1
- package/tests/webkit-diagnostics.ts +125 -0
- package/tests/webkit-error-output.test.ts +118 -0
- package/tests/worker-memory-bootstrap.test.ts +19 -1
- package/tests/worker-memory-broker.test.ts +16 -8
- package/tooling/ci-paths.test.ts +329 -61
- package/tooling/private-authority.ts +14 -0
- package/tooling/program/program-transformer.json +1 -1
- package/tooling/tarball-smoke.ts +3 -1
|
@@ -6,27 +6,33 @@ import {
|
|
|
6
6
|
WorkerProcessClient,
|
|
7
7
|
type WorkerProcessMessage,
|
|
8
8
|
} from "../proc/worker-client.js";
|
|
9
|
-
import { PipeController } from "../proc/pipes.js";
|
|
9
|
+
import { PipeController, type PipeEndpoint } from "../proc/pipes.js";
|
|
10
10
|
import { createWorkerPipeCodec } from "../proc/worker-pipes.js";
|
|
11
11
|
import { createThreadRuntime } from "./threads-runtime-host.js";
|
|
12
12
|
import { cleanupThreadRuntime, releaseThreadBarriers } from "./threads-runtime-cleanup.js";
|
|
13
13
|
import type { SharedGuestSnapshot } from "../memory/reservations.js";
|
|
14
|
-
import {
|
|
14
|
+
import type { ProcessExit } from "../proc/types.js";
|
|
15
|
+
import {
|
|
16
|
+
isRuntimeThreadRegression,
|
|
17
|
+
stockThreadCase,
|
|
18
|
+
type BrowserRuntimeThreadCase,
|
|
19
|
+
} from "./threads-runtime-cases.js";
|
|
20
|
+
import {
|
|
21
|
+
check,
|
|
22
|
+
checkFatalRetirement,
|
|
23
|
+
deadline,
|
|
24
|
+
observeThreadOwner,
|
|
25
|
+
releaseFatalThread,
|
|
26
|
+
runOverlappingWaits,
|
|
27
|
+
runReceivingGrowth,
|
|
28
|
+
runThreadAdmission,
|
|
29
|
+
runThreadIds,
|
|
30
|
+
ThreadRegressionObservations,
|
|
31
|
+
until,
|
|
32
|
+
} from "./threads-runtime-regression-controls.js";
|
|
33
|
+
import { RuntimeDescriptorCase } from "./threads-runtime-fd-browser.js";
|
|
15
34
|
export type { RuntimeThreadCase } from "./threads-runtime-cases.js";
|
|
16
35
|
|
|
17
|
-
function check(value: unknown, label: string): asserts value {
|
|
18
|
-
if (!value) throw new Error(label);
|
|
19
|
-
}
|
|
20
|
-
function deadline<T>(promise: Promise<T>, label: string): Promise<T> {
|
|
21
|
-
let timer: ReturnType<typeof setTimeout>;
|
|
22
|
-
return Promise.race([
|
|
23
|
-
promise,
|
|
24
|
-
new Promise<never>((_, reject) => {
|
|
25
|
-
timer = setTimeout(() => reject(new Error(label)), 15000);
|
|
26
|
-
}),
|
|
27
|
-
]).finally(() => clearTimeout(timer));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
36
|
function checkStockBackings(
|
|
31
37
|
observations: readonly (readonly SharedGuestSnapshot[])[],
|
|
32
38
|
retired: readonly SharedGuestSnapshot[],
|
|
@@ -59,8 +65,61 @@ function peakAliases(observations: readonly (readonly SharedGuestSnapshot[])[]):
|
|
|
59
65
|
0,
|
|
60
66
|
);
|
|
61
67
|
}
|
|
68
|
+
function expectedOutput(selected: BrowserRuntimeThreadCase): string {
|
|
69
|
+
if (stockThreadCase(selected))
|
|
70
|
+
return `threads-ok mode=${selected} main-static=1369948382 main-tls=901\n`;
|
|
71
|
+
switch (selected) {
|
|
72
|
+
case "join":
|
|
73
|
+
return "c";
|
|
74
|
+
case "fd-read":
|
|
75
|
+
case "fd-write":
|
|
76
|
+
return "PRM";
|
|
77
|
+
case "admission":
|
|
78
|
+
return "A";
|
|
79
|
+
case "growth":
|
|
80
|
+
return "AB";
|
|
81
|
+
case "overlapping-waits":
|
|
82
|
+
return "W";
|
|
83
|
+
default:
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function checkExit(
|
|
89
|
+
selected: BrowserRuntimeThreadCase,
|
|
90
|
+
exit: ProcessExit,
|
|
91
|
+
output: string,
|
|
92
|
+
errors: readonly string[],
|
|
93
|
+
): void {
|
|
94
|
+
const signaled = ["kill-start", "cpu", "wait32", "wait64"].includes(selected);
|
|
95
|
+
const code = signaled ? 9 : selected === "fatal-exit" ? 23 : 0;
|
|
96
|
+
check(
|
|
97
|
+
exit.kind === (signaled ? "signaled" : "exited") && exit.code === code,
|
|
98
|
+
`Runtime ${selected} outcome ${JSON.stringify(exit)}, output ${output}, errors ${errors}`,
|
|
99
|
+
);
|
|
100
|
+
check(output === expectedOutput(selected), `Runtime ${selected} stdout ${output}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function threadServiceUrl(
|
|
104
|
+
local: boolean,
|
|
105
|
+
fence: boolean,
|
|
106
|
+
descriptor: RuntimeDescriptorCase | undefined,
|
|
107
|
+
) {
|
|
108
|
+
if (descriptor)
|
|
109
|
+
return local
|
|
110
|
+
? new URL("./threads-runtime-fd-service.ts", import.meta.url).href
|
|
111
|
+
: "/thread-fd-service.js";
|
|
112
|
+
if (fence)
|
|
113
|
+
return local
|
|
114
|
+
? new URL("./threads-runtime-service-barrier.ts", import.meta.url).href
|
|
115
|
+
: "/thread-barrier.js";
|
|
116
|
+
return local
|
|
117
|
+
? new URL("../thread/service-worker.ts", import.meta.url).href
|
|
118
|
+
: "/thread-service.js";
|
|
119
|
+
}
|
|
120
|
+
|
|
62
121
|
export async function runThreadsRuntime(
|
|
63
|
-
selected:
|
|
122
|
+
selected: BrowserRuntimeThreadCase = "pair",
|
|
64
123
|
local = false,
|
|
65
124
|
expectedFixtureSha256?: string,
|
|
66
125
|
) {
|
|
@@ -71,7 +130,14 @@ export async function runThreadsRuntime(
|
|
|
71
130
|
let constructionKilled = false;
|
|
72
131
|
let killAtConstruction: (() => void) | undefined;
|
|
73
132
|
let guestReady = 0;
|
|
74
|
-
|
|
133
|
+
const stopped = new Set<Worker>();
|
|
134
|
+
const observations = new ThreadRegressionObservations(stopped);
|
|
135
|
+
const isRegression = isRuntimeThreadRegression(selected);
|
|
136
|
+
const allocator = selected === "tid-boundaries" ? await observeThreadOwner() : undefined;
|
|
137
|
+
const descriptor =
|
|
138
|
+
selected === "fd-read" || selected === "fd-write"
|
|
139
|
+
? new RuntimeDescriptorCase(selected === "fd-read" ? "read" : "write", local)
|
|
140
|
+
: undefined;
|
|
75
141
|
const barriers = new Set<Worker>();
|
|
76
142
|
let heldSections: Int32Array | undefined;
|
|
77
143
|
let drainRevoked = false;
|
|
@@ -105,6 +171,8 @@ export async function runThreadsRuntime(
|
|
|
105
171
|
workerTargets.set(this, target);
|
|
106
172
|
created.push(this);
|
|
107
173
|
urls.push(target);
|
|
174
|
+
if (isRegression) observations.attach(this, target);
|
|
175
|
+
descriptor?.observe(this, target);
|
|
108
176
|
if (
|
|
109
177
|
selected === "kill-start" &&
|
|
110
178
|
(String(url).includes("thread-guest") || String(url).includes("guest-bootstrap"))
|
|
@@ -140,6 +208,7 @@ export async function runThreadsRuntime(
|
|
|
140
208
|
message: unknown,
|
|
141
209
|
transfer?: Transferable[] | StructuredSerializeOptions,
|
|
142
210
|
): void {
|
|
211
|
+
descriptor?.observePost(message);
|
|
143
212
|
if (
|
|
144
213
|
message &&
|
|
145
214
|
typeof message === "object" &&
|
|
@@ -148,6 +217,7 @@ export async function runThreadsRuntime(
|
|
|
148
217
|
)
|
|
149
218
|
observeBacking(message.memory);
|
|
150
219
|
const target = workerTargets.get(this) ?? "unknown";
|
|
220
|
+
if (isRegression) observations.post(this, message);
|
|
151
221
|
recordCausal("worker-post", {
|
|
152
222
|
worker: target,
|
|
153
223
|
messageKind:
|
|
@@ -172,11 +242,12 @@ export async function runThreadsRuntime(
|
|
|
172
242
|
override terminate() {
|
|
173
243
|
if (barriers.has(this) && heldSections && Atomics.load(heldSections, 0) !== 0)
|
|
174
244
|
throw new Error("service terminated with a live filesystem section");
|
|
175
|
-
stopped
|
|
245
|
+
check(!stopped.has(this), "Worker received a duplicate native stop");
|
|
246
|
+
stopped.add(this);
|
|
176
247
|
return super.terminate();
|
|
177
248
|
}
|
|
178
249
|
};
|
|
179
|
-
const runtime = createThreadRuntime(local, errors);
|
|
250
|
+
const runtime = createThreadRuntime(local, errors, descriptor?.host);
|
|
180
251
|
const descriptors = new DescriptorTable();
|
|
181
252
|
const backingObservations: ReturnType<typeof runtime.sharedMemory.snapshot>["sharedGuests"][] =
|
|
182
253
|
[];
|
|
@@ -190,13 +261,86 @@ export async function runThreadsRuntime(
|
|
|
190
261
|
if (backings.length) backingObservations.push(backings);
|
|
191
262
|
};
|
|
192
263
|
const input = new PipeController({ relay: "manual" });
|
|
264
|
+
const threadInput = new PipeController({ relay: "manual" });
|
|
193
265
|
const pipe = new PipeController({ relay: "manual" });
|
|
194
266
|
let output = "";
|
|
195
267
|
let drainingOutput: ReturnType<typeof setInterval> | undefined;
|
|
268
|
+
let failure: unknown;
|
|
269
|
+
|
|
270
|
+
async function exerciseFence(pid: number, exited: () => boolean, terminate: () => Promise<void>) {
|
|
271
|
+
await until(() => !!heldSections, "real filesystem section was entered");
|
|
272
|
+
const before = runtime.sharedMemory.snapshot().sharedGuests;
|
|
273
|
+
check(
|
|
274
|
+
before.length === 1 && before[0]?.chargedBytes === 33554432,
|
|
275
|
+
"one admitted ceiling before kill",
|
|
276
|
+
);
|
|
277
|
+
await terminate();
|
|
278
|
+
await deadline(drainMarker.promise, "fixture drain marker deadline");
|
|
279
|
+
check(drainRevoked, "fixture drain started without real filesystem revocation");
|
|
280
|
+
recordCausal("drain-marker-observed", { pid, revoked: drainRevoked });
|
|
281
|
+
check(
|
|
282
|
+
heldSections && Atomics.load(heldSections, 0) === 1,
|
|
283
|
+
"real section disappeared before release",
|
|
284
|
+
);
|
|
285
|
+
check(!exited(), "process collected before filesystem safety");
|
|
286
|
+
fenceBlocked = true;
|
|
287
|
+
recordCausal("fixture-probe-post-before", { barriers: barriers.size });
|
|
288
|
+
for (const worker of barriers) worker.postMessage({ kind: "fixture-probe" });
|
|
289
|
+
recordCausal("fixture-probe-post-after", { barriers: barriers.size });
|
|
290
|
+
await deadline(fixtureProbe.promise, "fixture probe deadline");
|
|
291
|
+
check(fixtureProbeReceived, "same-process fixture probe did not return");
|
|
292
|
+
recordCausal("fixture-release-post-before", { barriers: barriers.size });
|
|
293
|
+
for (const worker of barriers) worker.postMessage({ kind: "fixture-release" });
|
|
294
|
+
recordCausal("fixture-release-post-after", { barriers: barriers.size });
|
|
295
|
+
await deadline(barrierRelease.promise, "fixture release deadline");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function runRegression(
|
|
299
|
+
selected: BrowserRuntimeThreadCase,
|
|
300
|
+
pid: number,
|
|
301
|
+
inputWriter: PipeEndpoint,
|
|
302
|
+
) {
|
|
303
|
+
if (descriptor) {
|
|
304
|
+
await until(() => !!backingMemory, "descriptor process backing");
|
|
305
|
+
check(backingMemory, "descriptor process backing");
|
|
306
|
+
return descriptor.run({
|
|
307
|
+
runtime,
|
|
308
|
+
memory: backingMemory,
|
|
309
|
+
pid,
|
|
310
|
+
inputWriter,
|
|
311
|
+
observations,
|
|
312
|
+
readOutput: () => output,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
if (selected === "overlapping-waits") return runOverlappingWaits(observations);
|
|
316
|
+
if (selected === "admission") return runThreadAdmission(observations);
|
|
317
|
+
if (selected === "growth") return runReceivingGrowth(observations);
|
|
318
|
+
if (allocator) return runThreadIds(observations, allocator);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function prepareThreadDescriptors(rootPid: number) {
|
|
322
|
+
const fds = [
|
|
323
|
+
{ parent: 1, child: 1 },
|
|
324
|
+
{ parent: 1, child: 2 },
|
|
325
|
+
];
|
|
326
|
+
const writer = threadInput.retain(rootPid, "write");
|
|
327
|
+
if (descriptor || selected === "fatal-exit") {
|
|
328
|
+
descriptors.openAt(6, threadInput.retain(rootPid, "read"), RIGHTS_ALL, RIGHTS_ALL);
|
|
329
|
+
fds.push({ parent: 6, child: 0 });
|
|
330
|
+
}
|
|
331
|
+
if (descriptor) {
|
|
332
|
+
fds.push({ parent: 4, child: 4 }, { parent: 5, child: 5 });
|
|
333
|
+
await descriptor.arm();
|
|
334
|
+
}
|
|
335
|
+
return { fds, writer };
|
|
336
|
+
}
|
|
337
|
+
|
|
196
338
|
try {
|
|
197
339
|
recordCausal("runtime-start", { selected });
|
|
198
340
|
const stock = stockThreadCase(selected);
|
|
199
341
|
const killed = ["kill-start", "cpu", "wait32", "wait64"].includes(selected);
|
|
342
|
+
const fatal = selected === "fatal-exit";
|
|
343
|
+
const needsFence = killed || fatal;
|
|
200
344
|
const source = stock
|
|
201
345
|
? new Uint8Array(await (await fetch("/threads.wasm")).arrayBuffer())
|
|
202
346
|
: generatedRuntimeThreadModule(selected);
|
|
@@ -214,16 +358,13 @@ export async function runThreadsRuntime(
|
|
|
214
358
|
? new URL("../browser/preview1-worker.ts", import.meta.url).href
|
|
215
359
|
: "/preview1-worker.js",
|
|
216
360
|
threaded: {
|
|
217
|
-
serviceWorkerUrl:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
guestWorkerUrl: local
|
|
225
|
-
? new URL("../thread/guest-bootstrap.ts", import.meta.url).href
|
|
226
|
-
: "/thread-guest.js",
|
|
361
|
+
serviceWorkerUrl: threadServiceUrl(local, needsFence, descriptor),
|
|
362
|
+
guestWorkerUrl:
|
|
363
|
+
selected === "growth"
|
|
364
|
+
? "/thread-growth.js"
|
|
365
|
+
: local
|
|
366
|
+
? new URL("../thread/guest-bootstrap.ts", import.meta.url).href
|
|
367
|
+
: "/thread-guest.js",
|
|
227
368
|
},
|
|
228
369
|
request: {
|
|
229
370
|
module: context.module,
|
|
@@ -243,7 +384,9 @@ export async function runThreadsRuntime(
|
|
|
243
384
|
identity: runtime.identities.buffer,
|
|
244
385
|
capacity: 8,
|
|
245
386
|
});
|
|
246
|
-
|
|
387
|
+
const rootIdentity = runtime.filesystem.createIdentity();
|
|
388
|
+
root.data = { filesystem: rootIdentity };
|
|
389
|
+
await descriptor?.setup(runtime, descriptors, rootIdentity);
|
|
247
390
|
const reader = pipe.retain(root.pid, "read");
|
|
248
391
|
const writer = pipe.retain(root.pid, "write");
|
|
249
392
|
descriptors.openAt(1, writer, RIGHTS_ALL, RIGHTS_ALL);
|
|
@@ -253,7 +396,13 @@ export async function runThreadsRuntime(
|
|
|
253
396
|
descriptors,
|
|
254
397
|
codec: createWorkerPipeCodec(),
|
|
255
398
|
postMessage: (message) => notices.push(message),
|
|
256
|
-
prepareSpawn: () =>
|
|
399
|
+
prepareSpawn: () => {
|
|
400
|
+
const filesystem = runtime.filesystem.createIdentity();
|
|
401
|
+
const data = { filesystem };
|
|
402
|
+
return descriptor
|
|
403
|
+
? { data, codec: createWorkerPipeCodec({ fallback: descriptor.codec(filesystem) }) }
|
|
404
|
+
: { data };
|
|
405
|
+
},
|
|
257
406
|
});
|
|
258
407
|
await service.adoptRuntimeRoot(root, { memory: [], stop: () => descriptors.dispose() });
|
|
259
408
|
await runtime.filesystem.writeFile("/survivor", "original");
|
|
@@ -281,21 +430,21 @@ export async function runThreadsRuntime(
|
|
|
281
430
|
(url) =>
|
|
282
431
|
!url.includes("thread-service") &&
|
|
283
432
|
!url.includes("thread-guest") &&
|
|
433
|
+
!url.includes("thread-fd-service") &&
|
|
434
|
+
!url.includes("thread-growth") &&
|
|
284
435
|
!url.includes("service-worker") &&
|
|
285
436
|
!url.includes("guest-bootstrap"),
|
|
286
437
|
) && runtime.sharedMemory.snapshot().sharedGuests.length === 0,
|
|
287
438
|
"ordinary launch eagerly created thread resources",
|
|
288
439
|
);
|
|
440
|
+
const threadDescriptors = await prepareThreadDescriptors(root.pid);
|
|
289
441
|
const pid = client.spawn(root.pid, {
|
|
290
442
|
executable: "/bin/threads",
|
|
291
443
|
argv: ["threads", selected],
|
|
292
444
|
env: {},
|
|
293
445
|
cwd: "/",
|
|
294
446
|
job: -1,
|
|
295
|
-
fds:
|
|
296
|
-
{ parent: 1, child: 1 },
|
|
297
|
-
{ parent: 1, child: 2 },
|
|
298
|
-
],
|
|
447
|
+
fds: threadDescriptors.fds,
|
|
299
448
|
});
|
|
300
449
|
killAtConstruction = () => {
|
|
301
450
|
constructionKilled = true;
|
|
@@ -308,41 +457,29 @@ export async function runThreadsRuntime(
|
|
|
308
457
|
const n = reader.tryRead([buffer]);
|
|
309
458
|
if (n > 0) output += new TextDecoder().decode(buffer.subarray(0, n));
|
|
310
459
|
}, 5));
|
|
311
|
-
if (
|
|
460
|
+
if (needsFence) {
|
|
312
461
|
if (selected === "kill-start") await until(() => constructionKilled);
|
|
313
|
-
if (selected !== "kill-start")
|
|
462
|
+
if (killed && selected !== "kill-start")
|
|
314
463
|
await until(
|
|
315
464
|
() =>
|
|
316
465
|
client.startStatus(root.pid, pid) === 0 &&
|
|
317
466
|
(selected === "cpu" ? guestReady > 0 : registered > 0),
|
|
318
467
|
);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
await deadline(drainMarker.promise, "fixture drain marker deadline");
|
|
328
|
-
check(drainRevoked, "fixture drain started without real filesystem revocation");
|
|
329
|
-
recordCausal("drain-marker-observed", { pid, revoked: drainRevoked });
|
|
330
|
-
check(
|
|
331
|
-
heldSections && Atomics.load(heldSections, 0) === 1,
|
|
332
|
-
"real section disappeared before release",
|
|
468
|
+
await exerciseFence(
|
|
469
|
+
pid,
|
|
470
|
+
() => client.childExited(root.pid, pid),
|
|
471
|
+
async () => {
|
|
472
|
+
if (fatal) return releaseFatalThread(observations, pid);
|
|
473
|
+
recordCausal("kill-request", { pid });
|
|
474
|
+
await service.kill(pid, 9);
|
|
475
|
+
},
|
|
333
476
|
);
|
|
334
|
-
check(!client.childExited(root.pid, pid), "process collected before filesystem safety");
|
|
335
|
-
fenceBlocked = true;
|
|
336
|
-
recordCausal("fixture-probe-post-before", { barriers: barriers.size });
|
|
337
|
-
for (const worker of barriers) worker.postMessage({ kind: "fixture-probe" });
|
|
338
|
-
recordCausal("fixture-probe-post-after", { barriers: barriers.size });
|
|
339
|
-
await deadline(fixtureProbe.promise, "fixture probe deadline");
|
|
340
|
-
check(fixtureProbeReceived, "same-process fixture probe did not return");
|
|
341
|
-
recordCausal("fixture-release-post-before", { barriers: barriers.size });
|
|
342
|
-
for (const worker of barriers) worker.postMessage({ kind: "fixture-release" });
|
|
343
|
-
recordCausal("fixture-release-post-after", { barriers: barriers.size });
|
|
344
|
-
await deadline(barrierRelease.promise, "fixture release deadline");
|
|
345
477
|
}
|
|
478
|
+
let regression: object | undefined = await runRegression(
|
|
479
|
+
selected,
|
|
480
|
+
pid,
|
|
481
|
+
threadDescriptors.writer,
|
|
482
|
+
);
|
|
346
483
|
let exit;
|
|
347
484
|
try {
|
|
348
485
|
exit = await deadline(supervisor.waitForExit(root.pid, pid), "Runtime pair deadline");
|
|
@@ -352,21 +489,8 @@ export async function runThreadsRuntime(
|
|
|
352
489
|
const buffer = new Uint8Array(4096);
|
|
353
490
|
const n = reader.tryRead([buffer]);
|
|
354
491
|
if (n > 0) output += new TextDecoder().decode(buffer.subarray(0, n));
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
? exit.kind === "exited" && exit.code === 0
|
|
358
|
-
: exit.kind === "signaled" && exit.code === 9,
|
|
359
|
-
`Runtime pair outcome ${JSON.stringify(exit)}, output ${output}, errors ${errors}`,
|
|
360
|
-
);
|
|
361
|
-
check(
|
|
362
|
-
output ===
|
|
363
|
-
(stock
|
|
364
|
-
? `threads-ok mode=${selected} main-static=1369948382 main-tls=901\n`
|
|
365
|
-
: selected === "join"
|
|
366
|
-
? "c"
|
|
367
|
-
: ""),
|
|
368
|
-
`Runtime pair stdout ${output}`,
|
|
369
|
-
);
|
|
492
|
+
checkExit(selected, exit, output, errors);
|
|
493
|
+
if (fatal) regression = await checkFatalRetirement(observations, pid);
|
|
370
494
|
check(
|
|
371
495
|
inputWriter.tryWrite([new Uint8Array([1])]) === 1,
|
|
372
496
|
"could not release ordinary sibling stdin",
|
|
@@ -390,6 +514,7 @@ export async function runThreadsRuntime(
|
|
|
390
514
|
"filesystem continued after thread terminal",
|
|
391
515
|
);
|
|
392
516
|
await deadline(runtime.dispose(), "Runtime disposal deadline");
|
|
517
|
+
if (descriptor) regression = { ...regression, ...descriptor.checkDisposal() };
|
|
393
518
|
check(errors.length === 0, errors.join("\n"));
|
|
394
519
|
const snapshot = runtime.sharedMemory.snapshot();
|
|
395
520
|
check(
|
|
@@ -420,7 +545,18 @@ export async function runThreadsRuntime(
|
|
|
420
545
|
controlDebts.reduce((sum, holder) => sum + holder.declaredBytes, 0) === snapshot.debtBytes,
|
|
421
546
|
"cleanup retained debt outside consumed controls",
|
|
422
547
|
);
|
|
423
|
-
|
|
548
|
+
if (descriptor) {
|
|
549
|
+
const sizes = controlDebts.map((holder) => holder.declaredBytes).sort((a, b) => a - b);
|
|
550
|
+
const debtSizes = sizes.join(",");
|
|
551
|
+
check(
|
|
552
|
+
debtSizes === "88,88" || debtSizes === "4,88,88",
|
|
553
|
+
`unexpected descriptor control debt: ${sizes}`,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
check(
|
|
557
|
+
stopped.size === created.length,
|
|
558
|
+
`Worker stop mismatch ${stopped.size}/${created.length}`,
|
|
559
|
+
);
|
|
424
560
|
return {
|
|
425
561
|
selected,
|
|
426
562
|
...hostInfo(),
|
|
@@ -428,7 +564,7 @@ export async function runThreadsRuntime(
|
|
|
428
564
|
fenceBlocked,
|
|
429
565
|
registered,
|
|
430
566
|
guestReady,
|
|
431
|
-
stopped,
|
|
567
|
+
stopped: stopped.size,
|
|
432
568
|
fixtureSha256,
|
|
433
569
|
exit,
|
|
434
570
|
output,
|
|
@@ -443,38 +579,41 @@ export async function runThreadsRuntime(
|
|
|
443
579
|
.filter((holder) => holder.label === "guest-control" && holder.state === "debt")
|
|
444
580
|
.map((holder) => holder.declaredBytes),
|
|
445
581
|
causalEvents,
|
|
582
|
+
regression,
|
|
446
583
|
};
|
|
584
|
+
} catch (error) {
|
|
585
|
+
failure = error;
|
|
586
|
+
throw error;
|
|
447
587
|
} finally {
|
|
448
588
|
await cleanupThreadRuntime({
|
|
449
589
|
release: [
|
|
450
590
|
() => releaseThreadBarriers(barriers, barrierReleased),
|
|
591
|
+
() => descriptor?.release(),
|
|
451
592
|
() => clearInterval(drainingOutput),
|
|
452
593
|
() => descriptors.dispose(),
|
|
594
|
+
() => descriptor?.dispose(),
|
|
453
595
|
() => pipe.dispose(),
|
|
454
596
|
() => input.dispose(),
|
|
597
|
+
() => threadInput.dispose(),
|
|
455
598
|
],
|
|
456
599
|
dispose: () => runtime.dispose(),
|
|
457
|
-
workers: created
|
|
600
|
+
workers: created.map((worker) => ({
|
|
601
|
+
terminate: () => {
|
|
602
|
+
if (!stopped.has(worker)) NativeWorker.prototype.terminate.call(worker);
|
|
603
|
+
},
|
|
604
|
+
})),
|
|
458
605
|
restore: () => {
|
|
459
606
|
backingMemory = undefined;
|
|
460
607
|
globalThis.Worker = NativeWorker;
|
|
608
|
+
allocator?.restore();
|
|
461
609
|
},
|
|
610
|
+
}).catch((cleanup: unknown) => {
|
|
611
|
+
if (!failure) throw cleanup;
|
|
612
|
+
throw new AggregateError([failure, cleanup], `${String(failure)}\n${String(cleanup)}`);
|
|
462
613
|
});
|
|
463
614
|
}
|
|
464
615
|
}
|
|
465
616
|
|
|
466
|
-
async function until(predicate: () => boolean): Promise<void> {
|
|
467
|
-
let timer: ReturnType<typeof setInterval>;
|
|
468
|
-
await deadline(
|
|
469
|
-
new Promise<void>((resolve) => {
|
|
470
|
-
timer = setInterval(() => {
|
|
471
|
-
if (predicate()) resolve();
|
|
472
|
-
}, 5);
|
|
473
|
-
}),
|
|
474
|
-
"thread entry observation deadline",
|
|
475
|
-
).finally(() => clearInterval(timer));
|
|
476
|
-
}
|
|
477
|
-
|
|
478
617
|
function hostInfo() {
|
|
479
618
|
return {
|
|
480
619
|
userAgent: globalThis.navigator?.userAgent ?? "Bun",
|
|
@@ -12,10 +12,27 @@ export const runtimeThreadCases = [
|
|
|
12
12
|
|
|
13
13
|
export type RuntimeThreadCase = (typeof runtimeThreadCases)[number];
|
|
14
14
|
|
|
15
|
+
export const runtimeThreadRegressions = [
|
|
16
|
+
"fd-read",
|
|
17
|
+
"fd-write",
|
|
18
|
+
"fatal-exit",
|
|
19
|
+
"admission",
|
|
20
|
+
"tid-boundaries",
|
|
21
|
+
"growth",
|
|
22
|
+
"overlapping-waits",
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
export type RuntimeThreadRegression = (typeof runtimeThreadRegressions)[number];
|
|
26
|
+
export type BrowserRuntimeThreadCase = RuntimeThreadCase | RuntimeThreadRegression;
|
|
27
|
+
|
|
15
28
|
export function isRuntimeThreadCase(value: unknown): value is RuntimeThreadCase {
|
|
16
29
|
return runtimeThreadCases.some((selected) => selected === value);
|
|
17
30
|
}
|
|
18
31
|
|
|
19
|
-
export function
|
|
32
|
+
export function isRuntimeThreadRegression(value: unknown): value is RuntimeThreadRegression {
|
|
33
|
+
return runtimeThreadRegressions.some((selected) => selected === value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function stockThreadCase(selected: BrowserRuntimeThreadCase): boolean {
|
|
20
37
|
return selected === "pair" || selected === "repeat" || selected === "nested";
|
|
21
38
|
}
|
|
@@ -30,7 +30,11 @@ export async function cleanupThreadRuntime(resources: ThreadRuntimeCleanup): Pro
|
|
|
30
30
|
} finally {
|
|
31
31
|
resources.restore();
|
|
32
32
|
}
|
|
33
|
-
if (errors.length)
|
|
33
|
+
if (errors.length)
|
|
34
|
+
throw new AggregateError(
|
|
35
|
+
errors,
|
|
36
|
+
`Runtime thread cleanup failed: ${errors.map(String).join(", ")}`,
|
|
37
|
+
);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
export function releaseThreadBarriers(barriers: Iterable<Worker>, released: boolean): void {
|