eutaxy 0.16.0 → 0.17.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 +6 -6
- package/dist/aws.d.mts +2 -2
- package/dist/aws.mjs +2 -2
- package/dist/bin.mjs +1 -1
- package/dist/{cli-DbLlYHTY.mjs → cli-dK6w25AU.mjs} +39 -16
- package/dist/{cli-DbLlYHTY.mjs.map → cli-dK6w25AU.mjs.map} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cloudflare.d.mts +16 -3
- package/dist/cloudflare.d.mts.map +1 -1
- package/dist/cloudflare.mjs +2 -2
- package/dist/{delivery-invariants-90c5xBcd.mjs → delivery-invariants-BXCuv43L.mjs} +2 -2
- package/dist/{delivery-invariants-90c5xBcd.mjs.map → delivery-invariants-BXCuv43L.mjs.map} +1 -1
- package/dist/{delivery-invariants-B8ZZnCZg.d.mts → delivery-invariants-D7DI7i8x.d.mts} +2 -2
- package/dist/{delivery-invariants-B8ZZnCZg.d.mts.map → delivery-invariants-D7DI7i8x.d.mts.map} +1 -1
- package/dist/{explore-DlwIUowm.d.mts → explore-Ci-xVeKU.d.mts} +2 -2
- package/dist/{explore-DlwIUowm.d.mts.map → explore-Ci-xVeKU.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{platform-DPJTjpSr.d.mts → platform-D4hlJjm3.d.mts} +26 -1
- package/dist/{platform-DPJTjpSr.d.mts.map → platform-D4hlJjm3.d.mts.map} +1 -1
- package/dist/{src-CmHdPsZy.mjs → src-BiX530QY.mjs} +235 -24
- package/dist/src-BiX530QY.mjs.map +1 -0
- package/dist/{src-Dz9Wn2vL.mjs → src-DVqL5Rk_.mjs} +2 -2
- package/dist/{src-Dz9Wn2vL.mjs.map → src-DVqL5Rk_.mjs.map} +1 -1
- package/dist/{workerd-D9cUGjYv.mjs → workerd-b1sqOnVc.mjs} +3786 -3218
- package/dist/workerd-b1sqOnVc.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/src-CmHdPsZy.mjs.map +0 -1
- package/dist/workerd-D9cUGjYv.mjs.map +0 -1
|
@@ -1499,6 +1499,8 @@ var Frame = class {
|
|
|
1499
1499
|
claimed = false;
|
|
1500
1500
|
/** The host's code this effect is the call of has started running (`Run.hostedCode`); until then the call is in transit. */
|
|
1501
1501
|
entered = false;
|
|
1502
|
+
/** Code the host runs on the call's way in (`Run.hostEntering`: its constructor's) is running now, this many times over. */
|
|
1503
|
+
entering = 0;
|
|
1502
1504
|
/** The host's code this effect is the call of has returned (`Frames.answered`): its answer is in transit. */
|
|
1503
1505
|
answered = false;
|
|
1504
1506
|
/**
|
|
@@ -1522,9 +1524,15 @@ var Frame = class {
|
|
|
1522
1524
|
this.onAbandon = options.onAbandon;
|
|
1523
1525
|
this.mayPark = options.mayPark ?? (() => true);
|
|
1524
1526
|
}
|
|
1525
|
-
/**
|
|
1527
|
+
/**
|
|
1528
|
+
* Its hosted code is only waiting on effects of its own that are parked
|
|
1529
|
+
* (however deep). A call into a host (an object) waits only once its code
|
|
1530
|
+
* is running there: one whose constructor left an effect parked and whose
|
|
1531
|
+
* method has not started is still on its way in, and taking it for
|
|
1532
|
+
* waiting would let another call enter the host's code ahead of it.
|
|
1533
|
+
*/
|
|
1526
1534
|
isWaiting() {
|
|
1527
|
-
return this.children > 0 && this.waitingChildren === this.children;
|
|
1535
|
+
return (this.host === void 0 || this.entered || this.entering > 0) && this.children > 0 && this.waitingChildren === this.children;
|
|
1528
1536
|
}
|
|
1529
1537
|
/**
|
|
1530
1538
|
* Whether it counts as real I/O pending: unless its hosted code is only
|
|
@@ -1587,6 +1595,15 @@ var Frames = class {
|
|
|
1587
1595
|
* gate delivers calls in the order they arrived, which is the order their
|
|
1588
1596
|
* effects entered. Without one of that op, the oldest unclaimed of any.
|
|
1589
1597
|
*/
|
|
1598
|
+
/**
|
|
1599
|
+
* The effect of `host`'s being performed whose call is on its way in: the
|
|
1600
|
+
* oldest the host's code has not started, else the newest of its effects.
|
|
1601
|
+
* Not claimed: the call's own code claims it when it starts.
|
|
1602
|
+
*/
|
|
1603
|
+
enteringHost(host) {
|
|
1604
|
+
const live = this.byHost.get(host) ?? [];
|
|
1605
|
+
return live.find((f) => !f.claimed) ?? live.at(-1);
|
|
1606
|
+
}
|
|
1590
1607
|
claimHost(host, op) {
|
|
1591
1608
|
const live = this.byHost.get(host) ?? [];
|
|
1592
1609
|
const frame = (op === void 0 ? void 0 : live.find((f) => !f.claimed && f.op === op)) ?? live.find((f) => !f.claimed);
|
|
@@ -1611,7 +1628,7 @@ var Frames = class {
|
|
|
1611
1628
|
for (const frame of this.stack) {
|
|
1612
1629
|
if (frame.isWaiting()) continue;
|
|
1613
1630
|
counted++;
|
|
1614
|
-
if (frame.host === void 0 || !frame.entered || frame.answered || frame.performing > 0 || frame.children > 0) return null;
|
|
1631
|
+
if (frame.host === void 0 || !(frame.entered || frame.entering > 0) || frame.answered || frame.performing > 0 || frame.children > 0) return null;
|
|
1615
1632
|
hosts.add(frame.host);
|
|
1616
1633
|
}
|
|
1617
1634
|
return counted > 0 && counted === this.inFlight ? hosts : null;
|
|
@@ -1624,17 +1641,21 @@ var Frames = class {
|
|
|
1624
1641
|
* resumed in the context of an effect that has ended, as an object's code
|
|
1625
1642
|
* may run in the context it was built in) or absent (workerd carries none
|
|
1626
1643
|
* into an object's code): trust only a live frame of the same invocation
|
|
1627
|
-
* (the innermost); else, for code
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1644
|
+
* (the innermost); else, for hosted code (`hosted`: an object's, entered
|
|
1645
|
+
* by the platform), the call that code is (`call`, when the platform
|
|
1646
|
+
* knows it: an invocation may have calls into several objects in flight
|
|
1647
|
+
* at once, and the one that started last is not the one every object's
|
|
1648
|
+
* code is inside); else, for hosted code or code in a stale context, the
|
|
1649
|
+
* invocation's own innermost hosting effect. Code in no context at all that is not hosted is
|
|
1630
1650
|
* outside every effect: a second strand of the invocation (a step
|
|
1631
1651
|
* attempt the engine gave up on, see `Run.attempt`) running while a call
|
|
1632
1652
|
* of the first strand is in flight.
|
|
1633
1653
|
*/
|
|
1634
|
-
enclosing(invocation, hosted = true) {
|
|
1654
|
+
enclosing(invocation, hosted = true, call) {
|
|
1635
1655
|
if (!effectScope) return this.stack.at(-1);
|
|
1636
1656
|
const store = effectScope.getStore();
|
|
1637
1657
|
if (store?.active && store.invocation === invocation) return store;
|
|
1658
|
+
if (call?.active && call.invocation === invocation) return call;
|
|
1638
1659
|
return hosted || store !== void 0 ? this.hosting.get(invocation)?.at(-1) : void 0;
|
|
1639
1660
|
}
|
|
1640
1661
|
/**
|
|
@@ -1769,6 +1790,18 @@ var Turns = class {
|
|
|
1769
1790
|
started(id) {
|
|
1770
1791
|
this.startOrder.set(id, this.startOrder.size);
|
|
1771
1792
|
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Whether a turn is parked that belongs to one of these hosts: an effect
|
|
1795
|
+
* made by code a call into the host hosts, or by the host's work after an
|
|
1796
|
+
* answer (its continuation, `<host>/after`).
|
|
1797
|
+
*/
|
|
1798
|
+
parkedFor(hosts) {
|
|
1799
|
+
return this.parked.some((p) => {
|
|
1800
|
+
if (p.host?.host !== void 0 && hosts.has(p.host.host)) return true;
|
|
1801
|
+
const continuation = /^(.*)\/after(?:#\d+)?$/.exec(p.inv.id);
|
|
1802
|
+
return continuation !== null && hosts.has(continuation[1]);
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1772
1805
|
/** Park an invocation at an effect until `takeTurn` releases it with `go`. */
|
|
1773
1806
|
park(inv, target, go, host, attempt) {
|
|
1774
1807
|
const option = {
|
|
@@ -2076,7 +2109,13 @@ var Run = class {
|
|
|
2076
2109
|
* those effects from then on; see `ownerOf`.
|
|
2077
2110
|
*/
|
|
2078
2111
|
adopted = /* @__PURE__ */ new WeakMap();
|
|
2079
|
-
/** Per
|
|
2112
|
+
/** Per hosted invocation, the object (host) whose code it was hosted from, directly or through another: see `hosted`. */
|
|
2113
|
+
hostedWithin = /* @__PURE__ */ new Map();
|
|
2114
|
+
/**
|
|
2115
|
+
* Per host, its poller (concurrent runs; see `pollHost`): the waits its
|
|
2116
|
+
* ticks wake, and the turns released to the host's code since its last
|
|
2117
|
+
* tick (`releasedTo`).
|
|
2118
|
+
*/
|
|
2080
2119
|
hostPollers = /* @__PURE__ */ new Map();
|
|
2081
2120
|
/** Concurrent runs: settles waiting on invocations, released with a `CrashSignal` once theirs crashed; see `settle`. */
|
|
2082
2121
|
crashWatch = [];
|
|
@@ -2093,7 +2132,7 @@ var Run = class {
|
|
|
2093
2132
|
options;
|
|
2094
2133
|
constructor(options) {
|
|
2095
2134
|
this.options = options;
|
|
2096
|
-
this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads, () => this.firedPending(), () => this.hasAfterWork(), () => this.timersAllowed() !== null);
|
|
2135
|
+
this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads, () => this.firedPending() + this.releasedUnseen(), () => this.hasAfterWork(), () => this.timersAllowed() !== null || this.idleBehindParked());
|
|
2097
2136
|
this.concurrent = options.bounds.maxConcurrentInvocations > 1;
|
|
2098
2137
|
}
|
|
2099
2138
|
get log() {
|
|
@@ -2225,12 +2264,43 @@ var Run = class {
|
|
|
2225
2264
|
if (host !== void 0) return this.continuationOf(host).id;
|
|
2226
2265
|
return deliveryScope?.getStore()?.id ?? this.current;
|
|
2227
2266
|
}
|
|
2267
|
+
hostEntering(host, code) {
|
|
2268
|
+
if (hostScope?.getStore()?.host === host) return code();
|
|
2269
|
+
if (this.concurrent) this.pollHost(host);
|
|
2270
|
+
const frame = this.frames.enteringHost(host);
|
|
2271
|
+
const run = () => this.patched ? this.patched.handlerCode(code) : code();
|
|
2272
|
+
if (!frame) return hostScope ? hostScope.run({
|
|
2273
|
+
host,
|
|
2274
|
+
frame
|
|
2275
|
+
}, run) : run();
|
|
2276
|
+
this.frames.adjust(frame, () => {
|
|
2277
|
+
frame.entering++;
|
|
2278
|
+
});
|
|
2279
|
+
const left = () => this.frames.adjust(frame, () => {
|
|
2280
|
+
frame.entering--;
|
|
2281
|
+
});
|
|
2282
|
+
let result;
|
|
2283
|
+
try {
|
|
2284
|
+
result = hostScope ? hostScope.run({
|
|
2285
|
+
host,
|
|
2286
|
+
frame
|
|
2287
|
+
}, run) : run();
|
|
2288
|
+
} catch (err) {
|
|
2289
|
+
left();
|
|
2290
|
+
throw err;
|
|
2291
|
+
}
|
|
2292
|
+
if (isThenable(result)) Promise.resolve(result).then(left, left);
|
|
2293
|
+
else left();
|
|
2294
|
+
return result;
|
|
2295
|
+
}
|
|
2228
2296
|
hostedCode(host, code, op) {
|
|
2229
2297
|
if (hostScope?.getStore()?.host === host) return code();
|
|
2230
2298
|
if (this.concurrent) this.pollHost(host);
|
|
2231
2299
|
const current = this.frames.current();
|
|
2232
2300
|
const frame = current?.host === host && current.active ? current : this.frames.claimHost(host, op);
|
|
2233
|
-
if (frame) frame
|
|
2301
|
+
if (frame) this.frames.adjust(frame, () => {
|
|
2302
|
+
frame.entered = true;
|
|
2303
|
+
});
|
|
2234
2304
|
const run = () => this.patched ? this.patched.handlerCode(code) : code();
|
|
2235
2305
|
const result = hostScope ? hostScope.run({
|
|
2236
2306
|
host,
|
|
@@ -2254,17 +2324,43 @@ var Run = class {
|
|
|
2254
2324
|
*/
|
|
2255
2325
|
pollHost(host) {
|
|
2256
2326
|
if (this.hostPollers.has(host)) return;
|
|
2257
|
-
const poller = {
|
|
2327
|
+
const poller = {
|
|
2328
|
+
waiters: [],
|
|
2329
|
+
unseen: 0
|
|
2330
|
+
};
|
|
2258
2331
|
this.hostPollers.set(host, poller);
|
|
2259
2332
|
const tick = () => {
|
|
2260
2333
|
const waiters = poller.waiters;
|
|
2261
2334
|
poller.waiters = [];
|
|
2335
|
+
const released = poller.unseen;
|
|
2262
2336
|
for (const wake of waiters) wake();
|
|
2337
|
+
if (released > 0) Promise.resolve().then(() => {
|
|
2338
|
+
poller.unseen -= released;
|
|
2339
|
+
});
|
|
2263
2340
|
if (poller.waiters.length > 0 || this.hostMayMove(host)) realSetTimeout(tick, 0);
|
|
2264
2341
|
else this.hostPollers.delete(host);
|
|
2265
2342
|
};
|
|
2266
2343
|
realSetTimeout(tick, 0);
|
|
2267
2344
|
}
|
|
2345
|
+
/**
|
|
2346
|
+
* A turn was released to code that waits for it by polling from inside
|
|
2347
|
+
* `host` (an object's effect during a call, or in its work after an
|
|
2348
|
+
* answer). Until the host's poller ticks, the effect is neither parked
|
|
2349
|
+
* nor in flight, and the scheduler must not take the run for at rest: it
|
|
2350
|
+
* would decide with that code's next effect missing from its options on
|
|
2351
|
+
* a slow tick and present on a fast one. Counted against the poller, so
|
|
2352
|
+
* a host that was reset, whose poller is gone, is not waited for.
|
|
2353
|
+
*/
|
|
2354
|
+
releasedTo(host) {
|
|
2355
|
+
const poller = host === void 0 ? void 0 : this.hostPollers.get(host);
|
|
2356
|
+
if (poller) poller.unseen++;
|
|
2357
|
+
}
|
|
2358
|
+
/** Turns released to hosts' code and not yet seen by it (see `releasedTo`): work on its way. */
|
|
2359
|
+
releasedUnseen() {
|
|
2360
|
+
let n = 0;
|
|
2361
|
+
for (const poller of this.hostPollers.values()) n += poller.unseen;
|
|
2362
|
+
return n;
|
|
2363
|
+
}
|
|
2268
2364
|
hostMayMove(host) {
|
|
2269
2365
|
const cont = this.continuations.get(host);
|
|
2270
2366
|
return cont !== void 0 && !cont.isCrashed() && this.afterWork.has(cont) || this.frames.liveHost(host) !== void 0;
|
|
@@ -2592,9 +2688,12 @@ var Run = class {
|
|
|
2592
2688
|
}
|
|
2593
2689
|
async effect(point, perform, summarize, options = {}) {
|
|
2594
2690
|
const ctx = hostScope?.getStore();
|
|
2691
|
+
/** A host's code inside a call of its: that call. */
|
|
2692
|
+
let call;
|
|
2595
2693
|
if (ctx !== void 0) {
|
|
2596
2694
|
const { host } = ctx;
|
|
2597
2695
|
const live = ctx.frame ? ctx.frame.active ? ctx.frame : void 0 : this.frames.liveHost(host);
|
|
2696
|
+
call = live;
|
|
2598
2697
|
if (live) {
|
|
2599
2698
|
if (live.invocation !== point.invocation) return this.effect({
|
|
2600
2699
|
...point,
|
|
@@ -2612,6 +2711,7 @@ var Run = class {
|
|
|
2612
2711
|
let released = false;
|
|
2613
2712
|
this.turns.park(cont, own.target, () => {
|
|
2614
2713
|
released = true;
|
|
2714
|
+
this.releasedTo(host);
|
|
2615
2715
|
});
|
|
2616
2716
|
while (!released && !cont.isCrashed()) await this.hostTick(host);
|
|
2617
2717
|
if (!released) return hang();
|
|
@@ -2620,18 +2720,33 @@ var Run = class {
|
|
|
2620
2720
|
}
|
|
2621
2721
|
}
|
|
2622
2722
|
const inv = this.invocation(point.invocation);
|
|
2623
|
-
const enclosing = this.frames.enclosing(point.invocation,
|
|
2723
|
+
const enclosing = this.frames.enclosing(point.invocation, ctx !== void 0, call);
|
|
2624
2724
|
if (this.ownerOf(inv, enclosing).isCrashed()) return hang();
|
|
2625
2725
|
const nested = enclosing !== void 0;
|
|
2626
2726
|
if (this.concurrent && !nested) {
|
|
2627
2727
|
const host = this.hosts.get(point.invocation);
|
|
2628
|
-
if (host?.active)
|
|
2728
|
+
if (host?.active) {
|
|
2729
|
+
const within = this.hostedWithin.get(point.invocation);
|
|
2730
|
+
if (within !== void 0) this.pollHost(within);
|
|
2731
|
+
return this.hostedTurn(point, perform, summarize, options, inv, void 0, host, within === void 0 ? (park) => new Promise((go) => park(() => go(true))) : async (park, crashed) => {
|
|
2732
|
+
let released = false;
|
|
2733
|
+
park(() => {
|
|
2734
|
+
released = true;
|
|
2735
|
+
this.releasedTo(within);
|
|
2736
|
+
});
|
|
2737
|
+
while (!released && !crashed()) await this.hostTick(within);
|
|
2738
|
+
return released;
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2629
2741
|
await new Promise((go) => this.turns.park(inv, point.target, go, void 0, this.attemptNow()));
|
|
2630
2742
|
if (inv.isCrashed()) return hang();
|
|
2631
2743
|
} else if (this.concurrent && enclosing?.hosts && enclosing.mayPark()) return this.hostedTurn(point, perform, summarize, options, inv, enclosing, enclosing, async (park, crashed) => {
|
|
2632
2744
|
let released = false;
|
|
2633
|
-
park(() => released = true);
|
|
2634
2745
|
const host = enclosing.host;
|
|
2746
|
+
park(() => {
|
|
2747
|
+
released = true;
|
|
2748
|
+
this.releasedTo(host);
|
|
2749
|
+
});
|
|
2635
2750
|
while (!released && !crashed()) await (host === void 0 ? realTick() : this.hostTick(host));
|
|
2636
2751
|
return released;
|
|
2637
2752
|
});
|
|
@@ -2887,16 +3002,19 @@ var Run = class {
|
|
|
2887
3002
|
const frame = this.frames.current();
|
|
2888
3003
|
if (!frame) throw new Error(`invocation ${id} can only be hosted inside an effect being performed`);
|
|
2889
3004
|
if (!deliveryScope) throw new Error("hosting an invocation needs AsyncLocalStorage (node:async_hooks)");
|
|
3005
|
+
const within = hostScope?.getStore()?.host ?? this.hostedWithin.get(frame.invocation);
|
|
2890
3006
|
const run = async () => {
|
|
2891
3007
|
const inv = this.track(id);
|
|
2892
3008
|
if (this.concurrent) this.turns.started(id);
|
|
2893
3009
|
this.hosts.set(id, frame);
|
|
3010
|
+
if (within !== void 0) this.hostedWithin.set(id, within);
|
|
2894
3011
|
this.childWaits(frame);
|
|
2895
3012
|
try {
|
|
2896
3013
|
return await work(inv);
|
|
2897
3014
|
} finally {
|
|
2898
3015
|
this.childLeaves(frame, true);
|
|
2899
3016
|
this.hosts.delete(id);
|
|
3017
|
+
this.hostedWithin.delete(id);
|
|
2900
3018
|
}
|
|
2901
3019
|
};
|
|
2902
3020
|
const asHandler = () => this.patched ? this.patched.handlerCode(run) : run();
|
|
@@ -3063,6 +3181,40 @@ var Run = class {
|
|
|
3063
3181
|
}
|
|
3064
3182
|
return abandoned;
|
|
3065
3183
|
}
|
|
3184
|
+
timersPending(invocation) {
|
|
3185
|
+
return this.patched?.clock.nextDueOwned((owner) => owner === invocation, false) !== void 0;
|
|
3186
|
+
}
|
|
3187
|
+
/**
|
|
3188
|
+
* Whether everything in flight is idle code of hosts (see
|
|
3189
|
+
* `Frames.idleHosts`) one of which has an effect parked: a call that
|
|
3190
|
+
* awaits what another call of the same object started (a load the object
|
|
3191
|
+
* dedupes) is waiting on that call's effect, though it parked none of its
|
|
3192
|
+
* own. The run is at rest then, for the scheduler to give that effect its
|
|
3193
|
+
* turn; taken for busy, the call would wait for a turn nothing could give.
|
|
3194
|
+
*/
|
|
3195
|
+
idleBehindParked() {
|
|
3196
|
+
const hosts = this.frames.idleHosts();
|
|
3197
|
+
return hosts !== null && this.turns.parkedFor(hosts);
|
|
3198
|
+
}
|
|
3199
|
+
/** Whether the invocation of this id has crashed; one never started has not. */
|
|
3200
|
+
hasCrashed(id) {
|
|
3201
|
+
return id !== null && (this.invocations.get(id)?.isCrashed() ?? false);
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Concurrent runs: wait in real time until one of these deliveries ends,
|
|
3205
|
+
* within the scenario's budget. False when there is none to wait for or
|
|
3206
|
+
* none ended in time.
|
|
3207
|
+
*/
|
|
3208
|
+
async ended(deliveries) {
|
|
3209
|
+
if (deliveries.length === 0) return false;
|
|
3210
|
+
const deadline = realDeadline(this.options.bounds.budgetMs);
|
|
3211
|
+
const over = () => "ended";
|
|
3212
|
+
try {
|
|
3213
|
+
return await Promise.race([...deliveries.map((d) => d.then(over, over)), deadline.expired]) === "ended";
|
|
3214
|
+
} finally {
|
|
3215
|
+
deadline.cancel();
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3066
3218
|
/** A call of a pure core function, recorded as a decision of the invocation running now (see `observeCore`). */
|
|
3067
3219
|
decision(fn, payload) {
|
|
3068
3220
|
this.append({
|
|
@@ -3389,17 +3541,67 @@ function concurrencyAssumption(bounds) {
|
|
|
3389
3541
|
if (bounds.maxConcurrentInvocations === 1) return "one invocation at a time (maxConcurrentInvocations = 1)";
|
|
3390
3542
|
return `up to ${bounds.maxConcurrentInvocations} invocations in flight, interleaved only at asynchronous effects (proxied bindings, fetch): code between two such effects runs without interruption (except continuations of a promise it settles for another invocation, which run then and are still attributed to their own invocation), Web Crypto calls are waited for like I/O, other non-effect awaits (body reads included) settle within one turn of the event loop, synchronous effects are not interleaving points, an effect made by code another effect hosts (an object calling out during a call) is a turn of its own unless that code cannot be interrupted (an object inside blockConcurrencyWhile), when it runs within the hosting effect's turn, the next turn is a seeded pick among parked invocations, starting a new event while a slot is free, and firing the earliest timer already due (at or before the virtual now, which effects advance), timers firing in due order among themselves, and a timer not yet due fires (virtual time passing to it) only when nothing else can move`;
|
|
3391
3543
|
}
|
|
3392
|
-
/**
|
|
3544
|
+
/** Where two JSON values first differ, as a path into them (`.tables.audit[0].at`), with the two values there. */
|
|
3545
|
+
function firstDifference(a, b, path = "") {
|
|
3546
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
3547
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
3548
|
+
const d = firstDifference(a[i], b[i], `${path}[${i}]`);
|
|
3549
|
+
if (d) return d;
|
|
3550
|
+
}
|
|
3551
|
+
return null;
|
|
3552
|
+
}
|
|
3553
|
+
const record = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3554
|
+
if (record(a) && record(b)) {
|
|
3555
|
+
for (const key of [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].sort()) {
|
|
3556
|
+
const d = firstDifference(a[key], b[key], `${path}.${key}`);
|
|
3557
|
+
if (d) return d;
|
|
3558
|
+
}
|
|
3559
|
+
return null;
|
|
3560
|
+
}
|
|
3561
|
+
return (a === void 0 || b === void 0 ? a === b : canonicalJson(a) === canonicalJson(b)) ? null : {
|
|
3562
|
+
path,
|
|
3563
|
+
a,
|
|
3564
|
+
b
|
|
3565
|
+
};
|
|
3566
|
+
}
|
|
3567
|
+
/**
|
|
3568
|
+
* The first record a replay recorded differently from the run, or how their
|
|
3569
|
+
* lengths differ; null when the logs match. Two records of the same effect
|
|
3570
|
+
* are told apart by the first value in their payloads that differs, with its
|
|
3571
|
+
* path: a snapshot of many tables that differs in one column says which.
|
|
3572
|
+
*/
|
|
3393
3573
|
function whatDiffered(run, replay) {
|
|
3394
|
-
const
|
|
3395
|
-
|
|
3396
|
-
const
|
|
3397
|
-
return
|
|
3574
|
+
const short = (v) => {
|
|
3575
|
+
if (v === void 0) return "nothing";
|
|
3576
|
+
const text = canonicalJson(v);
|
|
3577
|
+
return text.length > 120 ? `${text.slice(0, 117)}...` : text;
|
|
3398
3578
|
};
|
|
3579
|
+
/** Two differing values, each cut to the stretch around where their texts part, so the excerpts differ too. */
|
|
3580
|
+
const apart = (x, y) => {
|
|
3581
|
+
if (x === void 0 || y === void 0) return [short(x), short(y)];
|
|
3582
|
+
const [s, t] = [canonicalJson(x), canonicalJson(y)];
|
|
3583
|
+
if (s.length <= 120 && t.length <= 120) return [s, t];
|
|
3584
|
+
let at = 0;
|
|
3585
|
+
while (at < s.length && at < t.length && s[at] === t[at]) at++;
|
|
3586
|
+
const from = Math.max(0, at - 40);
|
|
3587
|
+
const cut = (text) => `${from > 0 ? "..." : ""}${text.slice(from, from + 110)}${from + 110 < text.length ? "..." : ""}`;
|
|
3588
|
+
return [cut(s), cut(t)];
|
|
3589
|
+
};
|
|
3590
|
+
const head = (e) => `${e.kind} ${e.target} ${e.op} in ${e.invocation}`;
|
|
3399
3591
|
const a = serializeLog(run).split("\n");
|
|
3400
3592
|
const b = serializeLog(replay).split("\n");
|
|
3401
3593
|
const n = Math.min(run.entries.length, replay.entries.length);
|
|
3402
|
-
for (let i = 0; i < n; i++)
|
|
3594
|
+
for (let i = 0; i < n; i++) {
|
|
3595
|
+
if (a[i] === b[i]) continue;
|
|
3596
|
+
const ran = run.entries[i];
|
|
3597
|
+
const replayed = replay.entries[i];
|
|
3598
|
+
const within = head(ran) === head(replayed) && firstDifference(ran.payload, replayed.payload);
|
|
3599
|
+
if (within) {
|
|
3600
|
+
const [was, is] = apart(within.a, within.b);
|
|
3601
|
+
return `at seq ${i} the run recorded ${head(ran)} with ${was} at payload${within.path} and the replay with ${is}`;
|
|
3602
|
+
}
|
|
3603
|
+
return `at seq ${i} the run recorded ${head(ran)} ${short(ran.payload)} and the replay ${head(replayed)} ${short(replayed.payload)}`;
|
|
3604
|
+
}
|
|
3403
3605
|
if (run.entries.length === replay.entries.length) return null;
|
|
3404
3606
|
return `the run recorded ${run.entries.length} entries and the replay ${replay.entries.length}`;
|
|
3405
3607
|
}
|
|
@@ -3415,7 +3617,9 @@ function explorationAssumption(options) {
|
|
|
3415
3617
|
/** Deliver events one at a time, each to completion; time passes until a delayed one is due. */
|
|
3416
3618
|
async function deliverInOrder(spec, platform, run) {
|
|
3417
3619
|
const pending = [...platform.initialEvents(spec)];
|
|
3418
|
-
|
|
3620
|
+
for (;;) {
|
|
3621
|
+
if (pending.length === 0) pending.push(...platform.closingEvents?.(spec) ?? []);
|
|
3622
|
+
if (pending.length === 0) return;
|
|
3419
3623
|
const [event] = pending.splice(earliestEvent(pending), 1);
|
|
3420
3624
|
if (event.at !== void 0) await run.advanceTo(event.at);
|
|
3421
3625
|
const result = await platform.deliver(event, run, spec);
|
|
@@ -3444,7 +3648,11 @@ async function deliverConcurrently(spec, platform, run) {
|
|
|
3444
3648
|
active = active.filter((d) => !d.outcome);
|
|
3445
3649
|
pending.push(...run.takeQueued());
|
|
3446
3650
|
if (pending.length > queuedBefore) run.queuedEvents();
|
|
3447
|
-
if (active.length === 0 && pending.length === 0 && !run.hasAfterWork())
|
|
3651
|
+
if (active.length === 0 && pending.length === 0 && !run.hasAfterWork()) {
|
|
3652
|
+
pending.push(...platform.closingEvents?.(spec) ?? []);
|
|
3653
|
+
if (pending.length === 0) return;
|
|
3654
|
+
run.queuedEvents();
|
|
3655
|
+
}
|
|
3448
3656
|
const next = pending.length > 0 ? earliestEvent(pending) : -1;
|
|
3449
3657
|
const eventAt = pending[next]?.at ?? 0;
|
|
3450
3658
|
const due = next >= 0 && eventAt <= run.now();
|
|
@@ -3471,7 +3679,10 @@ async function deliverConcurrently(spec, platform, run) {
|
|
|
3471
3679
|
if (!await run.advanceTo(eventAt)) continue;
|
|
3472
3680
|
} else if (turn === "none" && !(active.length > 0 || !run.hasAfterWork() ? run.fireTimer() : run.fireAfterWorkTimer()) && run.settleAfterWork() === 0) {
|
|
3473
3681
|
const stuck = active.flatMap((d) => d.started.invocation() ?? []);
|
|
3474
|
-
if (run.abandon(stuck) === 0)
|
|
3682
|
+
if (run.abandon(stuck) === 0) {
|
|
3683
|
+
const ending = active.filter((d) => run.hasCrashed(d.started.invocation()));
|
|
3684
|
+
if (!await run.ended(ending.map((d) => d.started.promise))) throw new Error(`the ${platform.name} platform's delivery made no progress and cannot be abandoned`);
|
|
3685
|
+
}
|
|
3475
3686
|
}
|
|
3476
3687
|
await run.quiesce();
|
|
3477
3688
|
}
|
|
@@ -3861,4 +4072,4 @@ function observeCore(namespace, functions) {
|
|
|
3861
4072
|
}
|
|
3862
4073
|
export { writeFaults as A, toJson as C, checkInvariants as D, checkInvariant as E, getPath as F, invocationOf as I, redelivery as L, nextInt as M, nextU32 as N, decisionFaults as O, seedPrng as P, canonicalJson as R, patchProperty as S, validateScenario as T, replyOf as _, explore as a, realTick as b, decide as c, runInvocation as d, CrashSignal as f, parseBody as g, isRedirect as h, rawRun as i, nextFloat as j, readFaults as k, hostInvocation as l, findResponse as m, compareSides as n, replay as o, InjectedEffectError as p, proxiedSide as r, restrictSpec as s, observeCore as t, note as u, toResponse as v, defaultBounds as w, virtualEpoch as x, withoutNetwork as y };
|
|
3863
4074
|
|
|
3864
|
-
//# sourceMappingURL=src-
|
|
4075
|
+
//# sourceMappingURL=src-BiX530QY.mjs.map
|