eutaxy 0.17.0 → 0.17.1

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.
@@ -1491,9 +1491,11 @@ var Frame = class {
1491
1491
  mayPark;
1492
1492
  /** The hosting effect this one was made inside of and waited for a turn under, if any. */
1493
1493
  parent;
1494
- /** Effects the hosted code made that are parked or running now. */
1494
+ /** Effects the hosted code made as turns, parked or running now, and invocations hosted inside it. */
1495
1495
  children = 0;
1496
- /** Effects nested in this one (made inside its perform, not as turns) being performed now. */
1496
+ /** Of those, the ones given their turn that have not started performing yet: on their way. */
1497
+ arriving = 0;
1498
+ /** Effects made inside this one's perform being performed now, its children that run included. */
1497
1499
  performing = 0;
1498
1500
  /** A host's effect whose call the host's code has started (`Frames.claimHost`). */
1499
1501
  claimed = false;
@@ -1508,9 +1510,31 @@ var Frame = class {
1508
1510
  * the effect hosts is that attempt's code too, late once the attempt is.
1509
1511
  */
1510
1512
  attempt;
1511
- /** Of those, the ones parked, or running but only waiting on parked effects of their own. */
1512
- waitingChildren = 0;
1513
+ /**
1514
+ * The host whose code made this effect, when a host's did. What awaits
1515
+ * the effect runs in that host's context and goes with it when the host
1516
+ * is reset (the runtime tears the context down), so the run ends the
1517
+ * effect itself then (`Run.hostAbandoned`).
1518
+ */
1519
+ issuer;
1520
+ /**
1521
+ * Its issuer was reset while the code it hosts was running: that code
1522
+ * goes on in its own object, so the effect stays until the code answers
1523
+ * or crashes, and is ended there.
1524
+ */
1525
+ orphaned = false;
1526
+ /**
1527
+ * The instance of its host whose code this call entered was reset: that
1528
+ * code is gone and will not answer, whatever it left outstanding died
1529
+ * with it, and nothing of it is the new instance's work.
1530
+ */
1531
+ codeGone = false;
1532
+ /** End the effect's bookkeeping; set by the run, and safe to call again. */
1533
+ end = () => {};
1534
+ /** Stop the deadline its perform is awaited under; set by the run, which times an orphan itself. */
1535
+ untime = () => {};
1513
1536
  abandoned = false;
1537
+ struck = false;
1514
1538
  wake = () => {};
1515
1539
  crashed = new Promise((resolve) => {
1516
1540
  this.wake = () => resolve("nested_crash");
@@ -1525,27 +1549,46 @@ var Frame = class {
1525
1549
  this.mayPark = options.mayPark ?? (() => true);
1526
1550
  }
1527
1551
  /**
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.
1552
+ * Its hosted code is only waiting on effects of its own, and each of
1553
+ * those is accounted for: parked for a turn, or being performed and so
1554
+ * counted itself (a call into another object the code awaits, whose own
1555
+ * code may be idle, waiting or busy in its turn). One given its turn and
1556
+ * not yet performing is on its way, so the code is not covered then. A
1557
+ * call into a host (an object) is covered only once its code is running
1558
+ * there: one whose constructor left an effect parked and whose method has
1559
+ * not started is still on its way in, and taking it for covered would let
1560
+ * another call enter the host's code ahead of it. Only an effect that
1561
+ * hosts code is ever covered: another effect's own perform is real I/O
1562
+ * whatever it makes meanwhile.
1533
1563
  */
1534
- isWaiting() {
1535
- return (this.host === void 0 || this.entered || this.entering > 0) && this.children > 0 && this.waitingChildren === this.children;
1564
+ isCovered() {
1565
+ const inside = this.host === void 0 || this.entered || this.entering > 0;
1566
+ const outstanding = this.children > 0 || this.hosts && this.performing > 0;
1567
+ return inside && outstanding && this.arriving === 0 && !this.codeGone;
1536
1568
  }
1537
1569
  /**
1538
- * Whether it counts as real I/O pending: unless its hosted code is only
1539
- * waiting on parked effects of its own; once that code has answered, the
1540
- * answer is on its way whatever it left parked, so the effect counts again
1541
- * until it ends.
1570
+ * Whether it counts as real I/O pending: unless its hosted code is covered;
1571
+ * once that code has answered, the answer is on its way whatever it left
1572
+ * outstanding, so the effect counts again until it ends.
1542
1573
  */
1543
1574
  inFlight() {
1544
- return this.answered || !this.isWaiting();
1575
+ return this.answered || !this.isCovered();
1576
+ }
1577
+ /**
1578
+ * Whether a crash inside it was signalled (`crash`). Read after the
1579
+ * perform settles, not only raced against it: the signal is raised where
1580
+ * the crash happened, which may be another object's context, and what
1581
+ * then wakes the code awaiting the effect may be the runtime's own
1582
+ * rejection of a call into the object the crash reset.
1583
+ */
1584
+ get wasCrashed() {
1585
+ return this.struck;
1545
1586
  }
1546
1587
  crash() {
1588
+ this.struck = true;
1547
1589
  this.wake();
1548
1590
  this.abandon();
1591
+ if (this.orphaned) this.end();
1549
1592
  }
1550
1593
  /** Whether the effect was abandoned: a crash in its hosted code, or its I/O past the budget; the host was reset. */
1551
1594
  get isAbandoned() {
@@ -1585,6 +1628,14 @@ var Frames = class {
1585
1628
  liveHost(host) {
1586
1629
  return this.byHost.get(host)?.at(-1);
1587
1630
  }
1631
+ /** The effects being performed now that are calls into `host`, oldest first. */
1632
+ into(host) {
1633
+ return [...this.byHost.get(host) ?? []];
1634
+ }
1635
+ /** The effects `host`'s code made that are being performed now, innermost first. */
1636
+ issuedBy(host) {
1637
+ return this.stack.filter((f) => f.issuer === host).reverse();
1638
+ }
1588
1639
  /** The effects of `invocation`'s being performed now that host an object's code (`EffectOptions.host`). */
1589
1640
  hostingOf(invocation) {
1590
1641
  return this.stack.filter((f) => f.invocation === invocation && f.host !== void 0);
@@ -1616,19 +1667,22 @@ var Frames = class {
1616
1667
  * on its way), with no effect of it performing or waiting for a turn,
1617
1668
  * nothing hosted inside it and no real work tracked. Such code can only
1618
1669
  * be awaiting a timer of its own (an object sleeping before it answers),
1619
- * which the run may fire for it. Null while anything else is in flight,
1620
- * or nothing is: a call still crossing into its object is on its way, and
1621
- * waiting for it keeps the order in which calls enter the object the
1622
- * schedule's, not real time's (two timers due together fire by the order
1623
- * they were set).
1670
+ * which the run may fire for it. An effect whose code is covered (an
1671
+ * object awaiting its call into another) is not in flight and has no say:
1672
+ * what it awaits is judged in its own right, so the object asleep at the
1673
+ * end of a chain of calls is found however long the chain. Null while
1674
+ * anything else is in flight, or nothing is: a call still crossing into
1675
+ * its object is on its way, and waiting for it keeps the order in which
1676
+ * calls enter the object the schedule's, not real time's (two timers due
1677
+ * together fire by the order they were set).
1624
1678
  */
1625
1679
  idleHosts() {
1626
1680
  let counted = 0;
1627
1681
  const hosts = /* @__PURE__ */ new Set();
1628
1682
  for (const frame of this.stack) {
1629
- if (frame.isWaiting()) continue;
1683
+ if (!frame.inFlight()) continue;
1630
1684
  counted++;
1631
- if (frame.host === void 0 || !(frame.entered || frame.entering > 0) || frame.answered || frame.performing > 0 || frame.children > 0) return null;
1685
+ if (frame.host === void 0 || !(frame.entered || frame.entering > 0) || frame.answered || frame.codeGone || frame.performing > 0 || frame.children > 0) return null;
1632
1686
  hosts.add(frame.host);
1633
1687
  }
1634
1688
  return counted > 0 && counted === this.inFlight ? hosts : null;
@@ -1707,27 +1761,19 @@ var Frames = class {
1707
1761
  frames?.splice(frames.lastIndexOf(frame), 1);
1708
1762
  }
1709
1763
  if (frame.inFlight()) this.inFlight--;
1710
- if (frame.isWaiting() && frame.parent) {
1711
- const parent = frame.parent;
1712
- this.adjust(parent, () => parent.waitingChildren--);
1713
- }
1714
1764
  frame.active = false;
1715
1765
  frame.parent = void 0;
1716
1766
  }
1717
1767
  /**
1718
- * Change a hosting frame's children and keep `inFlight` in step: a frame
1719
- * counts in flight unless it is only waiting on parked effects of its own,
1720
- * and a frame that starts or stops waiting does so for its parent too.
1768
+ * Change what a frame's hosted code has outstanding (or where its call
1769
+ * is) and keep `inFlight` in step: a frame counts in flight unless its
1770
+ * code is covered.
1721
1771
  */
1722
1772
  adjust(frame, change) {
1723
- const waitingBefore = frame.isWaiting();
1724
- const inFlightBefore = frame.inFlight();
1773
+ const before = frame.inFlight();
1725
1774
  change();
1726
- const waiting = frame.isWaiting();
1727
- if (frame.active && inFlightBefore !== frame.inFlight()) this.inFlight += waiting ? -1 : 1;
1728
- if (waitingBefore === waiting) return;
1729
- const parent = frame.parent;
1730
- if (frame.active && parent) this.adjust(parent, () => parent.waitingChildren += waiting ? 1 : -1);
1775
+ const now = frame.inFlight();
1776
+ if (frame.active && before !== now) this.inFlight += now ? 1 : -1;
1731
1777
  }
1732
1778
  hostingFrames(invocation) {
1733
1779
  let frames = this.hosting.get(invocation);
@@ -1803,7 +1849,7 @@ var Turns = class {
1803
1849
  });
1804
1850
  }
1805
1851
  /** Park an invocation at an effect until `takeTurn` releases it with `go`. */
1806
- park(inv, target, go, host, attempt) {
1852
+ park(inv, target, go, host, attempt, gone) {
1807
1853
  const option = {
1808
1854
  label: `${inv.id}@${inv.parks++}`,
1809
1855
  invocation: inv.id,
@@ -1815,7 +1861,8 @@ var Turns = class {
1815
1861
  go,
1816
1862
  option,
1817
1863
  attempt,
1818
- ...host ? { host } : {}
1864
+ ...host ? { host } : {},
1865
+ ...gone ? { gone } : {}
1819
1866
  });
1820
1867
  this.rested();
1821
1868
  }
@@ -1928,7 +1975,7 @@ var Turns = class {
1928
1975
  */
1929
1976
  takeTurn(canStart, timer, canWait = false) {
1930
1977
  const order = (inv) => this.startOrder.get(inv.id) ?? 0;
1931
- this.parked = this.parked.filter((p) => !p.inv.isCrashed()).sort((a, b) => order(a.inv) - order(b.inv) || a.seq - b.seq);
1978
+ this.parked = this.parked.filter((p) => !p.inv.isCrashed() && !p.gone?.()).sort((a, b) => order(a.inv) - order(b.inv) || a.seq - b.seq);
1932
1979
  const waiting = canWait && !canStart && !timer && this.waits < 100 && this.parked.length > 0 && this.parked.every((p) => p.attempt?.late === true);
1933
1980
  const offered = this.turnOptions(canStart, timer, waiting);
1934
1981
  const options = offered.length;
@@ -1955,7 +2002,7 @@ var Turns = class {
1955
2002
  this.turnTarget = chosen.option.target ?? null;
1956
2003
  this.runAs(chosen.inv.id);
1957
2004
  const host = chosen.host;
1958
- if (host) this.frames.adjust(host, () => host.waitingChildren--);
2005
+ if (host) this.frames.adjust(host, () => host.arriving++);
1959
2006
  chosen.go();
1960
2007
  return "turn";
1961
2008
  }
@@ -2112,6 +2159,21 @@ var Run = class {
2112
2159
  /** Per hosted invocation, the object (host) whose code it was hosted from, directly or through another: see `hosted`. */
2113
2160
  hostedWithin = /* @__PURE__ */ new Map();
2114
2161
  /**
2162
+ * Per host, how many times it was reset. Code belongs to the instance it
2163
+ * entered (`HostContext.instance`); once the host is reset that instance
2164
+ * is gone, and with it everything that ran in its context: its code makes
2165
+ * no further effect and takes no turn, a Worker it called dies with it,
2166
+ * what it awaited ends or goes on as another object's own work, and the
2167
+ * calls that were inside it will not be answered (`hostAbandoned`).
2168
+ */
2169
+ resetCounts = /* @__PURE__ */ new Map();
2170
+ /**
2171
+ * Calls whose caller was reset while the called object's code was running
2172
+ * (`Frame.orphaned`), each with the deadline the run timed it under once
2173
+ * one of its loops came by (`watchOrphans`).
2174
+ */
2175
+ orphans = /* @__PURE__ */ new Map();
2176
+ /**
2115
2177
  * Per host, its poller (concurrent runs; see `pollHost`): the waits its
2116
2178
  * ticks wake, and the turns released to the host's code since its last
2117
2179
  * tick (`releasedTo`).
@@ -2225,6 +2287,8 @@ var Run = class {
2225
2287
  }
2226
2288
  uninstall() {
2227
2289
  if (installed === this) installed = null;
2290
+ for (const deadline of this.orphans.values()) deadline?.cancel();
2291
+ this.orphans.clear();
2228
2292
  this.restoreFetch?.();
2229
2293
  this.restoreFetch = null;
2230
2294
  this.patched?.restore();
@@ -2269,9 +2333,11 @@ var Run = class {
2269
2333
  if (this.concurrent) this.pollHost(host);
2270
2334
  const frame = this.frames.enteringHost(host);
2271
2335
  const run = () => this.patched ? this.patched.handlerCode(code) : code();
2336
+ const instance = this.instanceOf(host);
2272
2337
  if (!frame) return hostScope ? hostScope.run({
2273
2338
  host,
2274
- frame
2339
+ frame,
2340
+ instance
2275
2341
  }, run) : run();
2276
2342
  this.frames.adjust(frame, () => {
2277
2343
  frame.entering++;
@@ -2283,7 +2349,8 @@ var Run = class {
2283
2349
  try {
2284
2350
  result = hostScope ? hostScope.run({
2285
2351
  host,
2286
- frame
2352
+ frame,
2353
+ instance
2287
2354
  }, run) : run();
2288
2355
  } catch (err) {
2289
2356
  left();
@@ -2302,12 +2369,17 @@ var Run = class {
2302
2369
  frame.entered = true;
2303
2370
  });
2304
2371
  const run = () => this.patched ? this.patched.handlerCode(code) : code();
2372
+ const instance = this.instanceOf(host);
2305
2373
  const result = hostScope ? hostScope.run({
2306
2374
  host,
2307
- frame
2375
+ frame,
2376
+ instance
2308
2377
  }, run) : run();
2309
2378
  if (frame) {
2310
- const answered = () => this.frames.answered(frame);
2379
+ const answered = () => {
2380
+ this.frames.answered(frame);
2381
+ if (frame.orphaned) frame.end();
2382
+ };
2311
2383
  if (isThenable(result)) Promise.resolve(result).then(answered, answered);
2312
2384
  else answered();
2313
2385
  }
@@ -2412,6 +2484,13 @@ var Run = class {
2412
2484
  hostReset(host) {
2413
2485
  this.hostAbandoned(host);
2414
2486
  }
2487
+ instanceOf(host) {
2488
+ return this.resetCounts.get(host) ?? 0;
2489
+ }
2490
+ /** Whether the instance is gone: its host was reset since it began. */
2491
+ isGone(instance) {
2492
+ return instance !== void 0 && this.instanceOf(instance.host) !== instance.instance;
2493
+ }
2415
2494
  /**
2416
2495
  * The host was reset (`onAbandon` ran: a crash inside its code, an effect
2417
2496
  * of its that hung; or the platform dropped the instance, `hostReset`): its
@@ -2420,6 +2499,31 @@ var Run = class {
2420
2499
  */
2421
2500
  hostAbandoned(host) {
2422
2501
  this.hostPollers.delete(host);
2502
+ const old = this.instanceOf(host);
2503
+ this.resetCounts.set(host, old + 1);
2504
+ for (const [id, within] of [...this.hostedWithin]) {
2505
+ if (within.host !== host || within.instance !== old) continue;
2506
+ this.invocations.get(id)?.crash();
2507
+ this.hosts.delete(id);
2508
+ this.hostedWithin.delete(id);
2509
+ }
2510
+ for (const frame of this.frames.into(host)) {
2511
+ if (!(frame.entered || frame.entering > 0)) continue;
2512
+ this.frames.adjust(frame, () => {
2513
+ frame.codeGone = true;
2514
+ });
2515
+ if (frame.orphaned) frame.end();
2516
+ }
2517
+ for (const frame of this.frames.issuedBy(host)) if (frame.host !== void 0 && frame.host !== host && frame.entered && !frame.answered && !frame.codeGone) {
2518
+ frame.orphaned = true;
2519
+ frame.untime();
2520
+ if (!this.orphans.has(frame)) this.orphans.set(frame, null);
2521
+ if (frame.host !== void 0 && !this.adopted.has(frame)) {
2522
+ const work = this.continuationOf(frame.host);
2523
+ this.adopted.set(frame, work);
2524
+ if (this.concurrent) this.turns.adopt(frame, work);
2525
+ }
2526
+ } else frame.end();
2423
2527
  const cont = this.continuations.get(host);
2424
2528
  if (!cont) return;
2425
2529
  this.continuations.delete(host);
@@ -2427,6 +2531,31 @@ var Run = class {
2427
2531
  cont.crash();
2428
2532
  }
2429
2533
  /**
2534
+ * Put the orphaned calls not yet timed under the real-time budget. What
2535
+ * timed such a call was awaiting it in its caller's context, which went
2536
+ * with the caller, so the run times it instead, from here: its own loops
2537
+ * ask whose timers may fire on every tick while anything is in flight,
2538
+ * in a context no reset tears down. A call whose code never answers ends
2539
+ * as any effect past the budget does: the run is UNSUPPORTED and the
2540
+ * called object is reset.
2541
+ */
2542
+ watchOrphans() {
2543
+ for (const [frame, watched] of this.orphans) {
2544
+ if (watched) continue;
2545
+ const budgetMs = this.options.bounds.budgetMs;
2546
+ const deadline = realDeadline(budgetMs);
2547
+ this.orphans.set(frame, deadline);
2548
+ deadline.expired.then(() => {
2549
+ if (!frame.active || this.orphans.get(frame) !== deadline) return;
2550
+ this.unsupported(`${frame.target} ${frame.op} did not complete within ${budgetMs} ms of real time`);
2551
+ this.adopted.get(frame)?.crash();
2552
+ frame.abandon();
2553
+ frame.end();
2554
+ if (this.concurrent) this.progressed();
2555
+ });
2556
+ }
2557
+ }
2558
+ /**
2430
2559
  * A host's effect ended: work its code left outstanding (effects parked or
2431
2560
  * performing, timers pending, real work tracked) is the host's own now,
2432
2561
  * its continuation's, which owns the outstanding effects from here on
@@ -2434,7 +2563,7 @@ var Run = class {
2434
2563
  * them is the object's.
2435
2564
  */
2436
2565
  leftHost(frame) {
2437
- if (frame.host === void 0 || frame.isAbandoned) return;
2566
+ if (frame.host === void 0 || frame.isAbandoned || frame.codeGone) return;
2438
2567
  this.hostFrames.set(frame.host, frame);
2439
2568
  const effects = frame.children > 0 || frame.performing > 0;
2440
2569
  if (!effects && !this.patched?.clock.hasTimerIn(frame.host) && (this.hostIo.get(frame.host) ?? 0) === 0) {
@@ -2545,6 +2674,7 @@ var Run = class {
2545
2674
  * crossing into the object, storage I/O).
2546
2675
  */
2547
2676
  timersAllowed() {
2677
+ if (this.orphans.size > 0) this.watchOrphans();
2548
2678
  const clock = this.patched?.clock;
2549
2679
  if (!clock || this.firedPending() > 0) return null;
2550
2680
  if (this.frames.inFlight === 0) return () => true;
@@ -2688,6 +2818,9 @@ var Run = class {
2688
2818
  }
2689
2819
  async effect(point, perform, summarize, options = {}) {
2690
2820
  const ctx = hostScope?.getStore();
2821
+ const inside = ctx ?? this.hostedWithin.get(point.invocation);
2822
+ const gone = () => this.isGone(inside);
2823
+ if (gone()) return hang();
2691
2824
  /** A host's code inside a call of its: that call. */
2692
2825
  let call;
2693
2826
  if (ctx !== void 0) {
@@ -2726,9 +2859,9 @@ var Run = class {
2726
2859
  if (this.concurrent && !nested) {
2727
2860
  const host = this.hosts.get(point.invocation);
2728
2861
  if (host?.active) {
2729
- const within = this.hostedWithin.get(point.invocation);
2862
+ const within = this.hostedWithin.get(point.invocation)?.host;
2730
2863
  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) => {
2864
+ return this.hostedTurn(point, perform, summarize, options, inv, void 0, host, gone, within === void 0 ? (park) => new Promise((go) => park(() => go(true))) : async (park, crashed) => {
2732
2865
  let released = false;
2733
2866
  park(() => {
2734
2867
  released = true;
@@ -2740,7 +2873,7 @@ var Run = class {
2740
2873
  }
2741
2874
  await new Promise((go) => this.turns.park(inv, point.target, go, void 0, this.attemptNow()));
2742
2875
  if (inv.isCrashed()) return hang();
2743
- } else if (this.concurrent && enclosing?.hosts && enclosing.mayPark()) return this.hostedTurn(point, perform, summarize, options, inv, enclosing, enclosing, async (park, crashed) => {
2876
+ } else if (this.concurrent && enclosing?.hosts && enclosing.mayPark()) return this.hostedTurn(point, perform, summarize, options, inv, enclosing, enclosing, gone, async (park, crashed) => {
2744
2877
  let released = false;
2745
2878
  const host = enclosing.host;
2746
2879
  park(() => {
@@ -2758,34 +2891,39 @@ var Run = class {
2758
2891
  * again while it performs. `wait` parks the effect through `park` and answers whether the turn
2759
2892
  * came; when it did not (the invocation crashed meanwhile) the effect hangs.
2760
2893
  */
2761
- async hostedTurn(point, perform, summarize, options, inv, enclosing, host, wait) {
2762
- this.childWaits(host);
2894
+ async hostedTurn(point, perform, summarize, options, inv, enclosing, host, gone, wait) {
2895
+ this.childStarts(host);
2763
2896
  const owner = this.ownerOf(inv, enclosing);
2764
- const crashed = () => this.ownerOf(inv, enclosing).isCrashed();
2897
+ const crashed = () => gone() || this.ownerOf(inv, enclosing).isCrashed();
2765
2898
  const attempt = this.attemptNow(enclosing, host);
2766
- if (!await wait((go) => this.turns.park(owner, point.target, go, host, attempt), crashed)) {
2767
- this.childLeaves(host, true);
2899
+ let given = false;
2900
+ let over = false;
2901
+ const arrived = () => this.frames.adjust(host, () => host.arriving--);
2902
+ const came = await wait((go) => this.turns.park(owner, point.target, () => {
2903
+ given = true;
2904
+ if (over) arrived();
2905
+ go();
2906
+ }, host, attempt, gone), crashed);
2907
+ over = true;
2908
+ if (given) arrived();
2909
+ if (gone()) return hang();
2910
+ if (!came) {
2911
+ this.childEnds(host);
2768
2912
  return hang();
2769
2913
  }
2770
2914
  try {
2771
2915
  return await this.performEffect(point, perform, summarize, options, inv, enclosing, host);
2772
2916
  } finally {
2773
- this.childLeaves(host, false);
2917
+ this.childEnds(host);
2774
2918
  }
2775
2919
  }
2776
- /** A child of `host` started and waits for its turn (the scheduler clears the wait when it comes). */
2777
- childWaits(host) {
2778
- this.frames.adjust(host, () => {
2779
- host.children++;
2780
- host.waitingChildren++;
2781
- });
2920
+ /** A child of `host` started: an effect waiting for its turn under it, or an invocation hosted inside it. */
2921
+ childStarts(host) {
2922
+ this.frames.adjust(host, () => host.children++);
2782
2923
  }
2783
- /** A child of `host` ended; `stillWaiting` when its turn never came. */
2784
- childLeaves(host, stillWaiting) {
2785
- this.frames.adjust(host, () => {
2786
- host.children--;
2787
- if (stillWaiting) host.waitingChildren--;
2788
- });
2924
+ /** A child of `host` ended. */
2925
+ childEnds(host) {
2926
+ this.frames.adjust(host, () => host.children--);
2789
2927
  }
2790
2928
  /** The effect once it has its turn: the fault, the perform under its deadline, the record. */
2791
2929
  async performEffect(made, perform, summarize, options, inv, enclosing, host) {
@@ -2809,8 +2947,21 @@ var Run = class {
2809
2947
  frame.onHostAbandoned = (h) => this.hostAbandoned(h);
2810
2948
  frame.parent = host;
2811
2949
  frame.attempt = this.attemptNow(enclosing, host);
2950
+ frame.issuer = (hostScope?.getStore() ?? this.hostedWithin.get(made.invocation))?.host;
2812
2951
  this.frames.enter(frame);
2813
- if (enclosing) enclosing.performing++;
2952
+ if (enclosing) this.frames.adjust(enclosing, () => enclosing.performing++);
2953
+ let ended = false;
2954
+ frame.untime = () => deadline.cancel();
2955
+ frame.end = () => {
2956
+ if (ended) return;
2957
+ ended = true;
2958
+ deadline.cancel();
2959
+ this.orphans.get(frame)?.cancel();
2960
+ this.orphans.delete(frame);
2961
+ if (enclosing) this.frames.adjust(enclosing, () => enclosing.performing--);
2962
+ this.frames.leave(frame);
2963
+ this.leftHost(frame);
2964
+ };
2814
2965
  try {
2815
2966
  const inside = () => effectScope ? effectScope.run(frame, perform) : perform();
2816
2967
  const io = this.patched ? this.patched.libraryIo(inside) : inside();
@@ -2831,13 +2982,12 @@ var Run = class {
2831
2982
  error: err
2832
2983
  };
2833
2984
  } finally {
2834
- deadline.cancel();
2835
- if (enclosing) enclosing.performing--;
2836
- this.frames.leave(frame);
2837
- this.leftHost(frame);
2985
+ frame.end();
2838
2986
  this.patched?.clock.advance(1);
2839
2987
  if (this.concurrent) this.progressed();
2840
2988
  }
2989
+ if (frame.wasCrashed) settled = "nested_crash";
2990
+ if (frame.orphaned) return hang();
2841
2991
  if (settled === "expired") {
2842
2992
  this.unsupported(`${point.target} ${point.op} did not complete within ${this.options.bounds.budgetMs} ms of real time`);
2843
2993
  owner().crash();
@@ -3002,17 +3152,21 @@ var Run = class {
3002
3152
  const frame = this.frames.current();
3003
3153
  if (!frame) throw new Error(`invocation ${id} can only be hosted inside an effect being performed`);
3004
3154
  if (!deliveryScope) throw new Error("hosting an invocation needs AsyncLocalStorage (node:async_hooks)");
3005
- const within = hostScope?.getStore()?.host ?? this.hostedWithin.get(frame.invocation);
3155
+ const here = hostScope?.getStore();
3156
+ const within = here ? {
3157
+ host: here.host,
3158
+ instance: here.instance
3159
+ } : this.hostedWithin.get(frame.invocation);
3006
3160
  const run = async () => {
3007
3161
  const inv = this.track(id);
3008
3162
  if (this.concurrent) this.turns.started(id);
3009
3163
  this.hosts.set(id, frame);
3010
3164
  if (within !== void 0) this.hostedWithin.set(id, within);
3011
- this.childWaits(frame);
3165
+ this.childStarts(frame);
3012
3166
  try {
3013
3167
  return await work(inv);
3014
3168
  } finally {
3015
- this.childLeaves(frame, true);
3169
+ this.childEnds(frame);
3016
3170
  this.hosts.delete(id);
3017
3171
  this.hostedWithin.delete(id);
3018
3172
  }
@@ -3160,21 +3314,22 @@ var Run = class {
3160
3314
  }
3161
3315
  /**
3162
3316
  * Concurrent runs: nothing can make progress; abandon these invocations so
3163
- * the run can end. Returns how many were still alive, or whose delivery
3164
- * ends now: one that crashed inside an object (the object's reset tears
3165
- * down the task the crash settled its promise in, so the delivery never
3166
- * saw it) has its settle released here, on the run's own step.
3317
+ * the run can end. Returns how many were still alive, or how many crashes
3318
+ * were passed on first: an invocation that crashed inside an object (the
3319
+ * object's reset tears down the task the crash settled its promise in, so
3320
+ * what waited on it never saw it) has its settle released here, on the
3321
+ * run's own step. A crash released here is on its way to whatever waited
3322
+ * on it, which may be one of `ids` (an invocation waiting on a Worker it
3323
+ * called, which crashed inside an object): none of them is stuck until
3324
+ * that has landed, so nothing is abandoned in the same step.
3167
3325
  */
3168
3326
  abandon(ids) {
3169
- let abandoned = 0;
3170
3327
  const released = this.releaseCrashed();
3328
+ if (released.size > 0) return released.size;
3329
+ let abandoned = 0;
3171
3330
  for (const id of ids) {
3172
3331
  const inv = this.invocations.get(id);
3173
- if (!inv) continue;
3174
- if (inv.isCrashed()) {
3175
- if (released.has(id)) abandoned++;
3176
- continue;
3177
- }
3332
+ if (!inv || inv.isCrashed()) continue;
3178
3333
  this.unsupported(waitingUnseen(id));
3179
3334
  inv.crash();
3180
3335
  abandoned++;
@@ -3762,11 +3917,13 @@ async function explore(scenario, platform, options) {
3762
3917
  ...done(),
3763
3918
  ...exhaustive ? { exhaustive: exhaustive.reached } : {}
3764
3919
  });
3765
- const unsupported = (cause, reason) => ({
3920
+ /** `schedule`: the run's that reached it, when a run did. */
3921
+ const unsupported = (cause, reason, schedule) => ({
3766
3922
  ...base,
3767
3923
  kind: "UNSUPPORTED",
3768
3924
  cause,
3769
3925
  reason,
3926
+ ...schedule === void 0 ? {} : { schedule },
3770
3927
  reached: doneNow()
3771
3928
  });
3772
3929
  if (spec.bounds.maxConcurrentInvocations > 1 && !concurrencySupported) return unsupported("unsupported_bounds", "maxConcurrentInvocations above 1 needs AsyncLocalStorage (Node, or workerd with nodejs_compat or nodejs_als)");
@@ -3796,7 +3953,7 @@ async function explore(scenario, platform, options) {
3796
3953
  if (run.faultsInjected === 0) baseline = Math.max(baseline, run.eligiblePoints);
3797
3954
  longest = Math.max(longest, run.eligiblePoints);
3798
3955
  if (exhaustive) {
3799
- if (exhaustive.mismatch) return unsupported("not_replayable", `exhaustive exploration needs deterministic runs: ${exhaustive.mismatch}`);
3956
+ if (exhaustive.mismatch) return unsupported("not_replayable", `exhaustive exploration needs deterministic runs: ${exhaustive.mismatch}`, run.schedule);
3800
3957
  if (!exhaustive.ran(() => run.turnsMayNotCommute)) continue;
3801
3958
  }
3802
3959
  reached.effectPoints += run.effectPoints;
@@ -3805,16 +3962,16 @@ async function explore(scenario, platform, options) {
3805
3962
  schedule: run.schedule,
3806
3963
  log
3807
3964
  });
3808
- if (run.unsupportedReasons.length > 0) return unsupported("unsupported_api", run.unsupportedReasons.join("; "));
3965
+ if (run.unsupportedReasons.length > 0) return unsupported("unsupported_api", run.unsupportedReasons.join("; "), run.schedule);
3809
3966
  const violation = checkInvariants(log, spec.invariants)[0];
3810
3967
  if (violation) {
3811
3968
  const schedule = run.schedule;
3812
3969
  const replayedRun = await replayRun(spec, platform, schedule);
3813
3970
  const replayed = replayedRun.log;
3814
3971
  reached.runs++;
3815
- if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "));
3972
+ if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "), schedule);
3816
3973
  const differed = whatDiffered(log, replayed);
3817
- if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}`);
3974
+ if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}`, schedule);
3818
3975
  const shrunk = await shrink(spec, platform, schedule, violation, replayed, {
3819
3976
  maxRuns: options.maxShrinkRuns ?? 200,
3820
3977
  deadline: now() + spec.bounds.budgetMs,
@@ -3841,9 +3998,9 @@ async function explore(scenario, platform, options) {
3841
3998
  for (const witness of [...witnesses].reverse()) {
3842
3999
  const again = await replayRun(spec, platform, witness.schedule);
3843
4000
  reached.runs++;
3844
- if (again.unsupportedReasons.length > 0) return unsupported("unsupported_api", again.unsupportedReasons.join("; "));
4001
+ if (again.unsupportedReasons.length > 0) return unsupported("unsupported_api", again.unsupportedReasons.join("; "), witness.schedule);
3845
4002
  const differed = whatDiffered(witness.log, again.log);
3846
- if (differed) return unsupported("module_state_leak", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: state is leaking between runs (module-level variables, or a binding Eutaxy does not reset); ${differed}`);
4003
+ if (differed) return unsupported("module_state_leak", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: state is leaking between runs (module-level variables, or a binding Eutaxy does not reset); ${differed}`, witness.schedule);
3847
4004
  }
3848
4005
  return {
3849
4006
  ...base,
@@ -4072,4 +4229,4 @@ function observeCore(namespace, functions) {
4072
4229
  }
4073
4230
  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 };
4074
4231
 
4075
- //# sourceMappingURL=src-BiX530QY.mjs.map
4232
+ //# sourceMappingURL=src-D_hHC_-3.mjs.map