@systemfsoftware/effect-sim-kernel 2.0.6 → 2.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @systemfsoftware/effect-sim-kernel
2
2
 
3
- # @systemfsoftware/effect-sim-kernel@2.0.6
3
+ # @systemfsoftware/effect-sim-kernel@2.1.0
4
4
 
5
- Requires Effect ^4.1.4.
5
+ Dev dependency bump (@types/node) only; the packed tarball is unchanged.
6
+
7
+ No consumer-visible package changes.
8
+
9
+ On Node 26 a run that waited on a file read as a deadlock: Node 26 leaves pending file requests out of `process.getActiveResourcesInfo()`, the list the kernel read its host waits from. `Kernel.run` takes a `host` option naming where it reads them, and `Kernel.fileRequestHooks(createHook)` follows file requests through `async_hooks` while keeping the process list for sockets, DNS lookups and timers. The kernel still imports no Node module: the caller passes `createHook`. `Conformance.released` reads the source from `Kernel.HostResourcesService` when it is provided.
10
+
11
+ Rebuilt with tsdown 0.23.7 against the updated dev dependencies: the bundled `dist/` files carry a different hashed runtime chunk name and comment markers, and the declared devDependency ranges move. The public API and runtime behaviour are unchanged.
package/README.md CHANGED
@@ -61,6 +61,16 @@ await Kernel.run(program, { external: 'await' })
61
61
 
62
62
  A real-timer wait still fails (`Escape`) under `'await'` — timers go through the controlled clock instead. `'await'` beside `path` or `choose` is refused, since an awaited host wait cannot take an explored schedule. For checks that run one ordered program against the real system, use `'await'` with no exploration options.
63
63
 
64
+ A run reads the host's pending waits from `process.getActiveResourcesInfo()` unless it is given another source. Node 26 leaves pending file reads and writes out of that list, so on Node 26 a file wait reads as a deadlock. Pass the `host` option there; the kernel imports no Node module, so the caller hands in `createHook`:
65
+
66
+ ```ts
67
+ import { createHook } from 'node:async_hooks'
68
+
69
+ await Kernel.run(program, { external: 'await', host: Kernel.fileRequestHooks(createHook) })
70
+ ```
71
+
72
+ `Kernel.fileRequestHooks` keeps the process list for sockets, DNS lookups and timers, and follows each file request through `async_hooks` from the moment it is issued until its callback runs. An Effect caller that runs the kernel for its own callers reads the source from `Kernel.HostResourcesService` and passes it on, as `Conformance.released` does. `Kernel.search`, `Kernel.shrink` and `Kernel.pick` take no `host` and read the process list, so on Node 26 a file stall under them is named a deadlock rather than a file wait; they explore schedules and fail on any host wait either way.
73
+
64
74
  ## One kernel at a time
65
75
 
66
76
  The global hooks (Effect's `Scheduler`, the fiber resume methods, `Ref`/`Deferred` field observation) are installed for the lifetime of one run and restored at its release. A second `Kernel.run` started while one is active queues behind it, in arrival order, instead of sharing the hooks — one kernel owns the process at a time, so two runs never interleave and a scenario never sees another run's decisions. `Kernel.search`, `Kernel.shrink` and `Kernel.pick` reach the kernel through the same queue, one run at a time.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Clock, Config, Duration, Effect, Exit, Fiber, Layer, Scheduler, Schema } from "effect";
2
- //#region src/Kernel/Bound.d.ts
1
+ import * as Context from "effect/Context";
2
+ import { Clock, Config, Duration, Effect, Exit, Fiber, Layer, Schema } from "effect";
3
3
  type UnobservedPrimitive = 'Queue' | 'PubSub' | 'Semaphore' | 'Latch' | 'Scope finalizer';
4
4
  interface Pruning {
5
5
  readonly enabled: boolean;
@@ -15,8 +15,33 @@ interface Bound {
15
15
  }
16
16
  declare const pruned: Pruning;
17
17
  declare const unpruned: (disabledBy: ReadonlyArray<UnobservedPrimitive>) => Pruning;
18
- //#endregion
19
- //#region src/Kernel/Pct.schema.d.ts
18
+ /** @internal */
19
+ interface HostResourceWatch {
20
+ readonly names: () => ReadonlyArray<string>;
21
+ readonly end: () => void;
22
+ }
23
+ /** @internal */
24
+ interface HostResources {
25
+ readonly begin: () => HostResourceWatch;
26
+ }
27
+ declare const HostResourcesService_base: Context.ServiceClass<HostResourcesService, "@systemfsoftware/effect-sim-kernel/internal/hostResources/HostResourcesService", HostResources>;
28
+ /** @internal */
29
+ declare class HostResourcesService extends HostResourcesService_base {}
30
+ /** @internal */
31
+ declare const processResources: HostResources;
32
+ interface HookCallbacks {
33
+ readonly init: (asyncId: number, type: string) => void;
34
+ readonly before: (asyncId: number) => void;
35
+ readonly destroy: (asyncId: number) => void;
36
+ }
37
+ interface Hook {
38
+ readonly enable: () => void;
39
+ readonly disable: () => void;
40
+ }
41
+ /** @internal */
42
+ type CreateHook = (callbacks: HookCallbacks) => Hook;
43
+ /** @internal */
44
+ declare const fileRequestHooks: (createHook: CreateHook) => HostResources;
20
45
  declare const PctDepth: Schema.brand<Schema.Int, "PctDepth">;
21
46
  type PctDepth = typeof PctDepth.Type;
22
47
  declare const PctSeedCount: Schema.brand<Schema.Int, "PctSeedCount">;
@@ -50,8 +75,6 @@ interface TestClock extends Clock.Clock {
50
75
  declare const make: Effect.Effect<TestClock>;
51
76
  /** The layer a harness provides in place of `TestClock.layer()`. */
52
77
  declare const layer: Layer.Layer<Clock.Clock>;
53
- //#endregion
54
- //#region src/internal/deadlock.d.ts
55
78
  /** The process resources that can call back into the program from outside. */
56
79
  /** @internal */
57
80
  type WaitKind = 'RealTimer' | 'File' | 'Socket' | 'Other';
@@ -62,8 +85,6 @@ interface SuspendedFiber {
62
85
  }
63
86
  /** @internal */
64
87
  type AnyFiber<A = unknown, E = unknown> = Fiber.Fiber<A, E>;
65
- //#endregion
66
- //#region src/internal/escapeRecorder.d.ts
67
88
  /** @internal */
68
89
  type TimerName = 'setTimeout' | 'setInterval' | 'setImmediate';
69
90
  /** @internal */
@@ -71,8 +92,6 @@ interface Escape {
71
92
  readonly timer: TimerName;
72
93
  readonly site: string;
73
94
  }
74
- //#endregion
75
- //#region src/internal/kernel.d.ts
76
95
  /** An index into the kernel's pending task list: the schedule's unit of choice. */
77
96
  /** @internal */
78
97
  type Decision = number;
@@ -154,8 +173,6 @@ declare const isStepping: () => boolean;
154
173
  */
155
174
  /** @internal */
156
175
  declare const beginExploration: Effect.Effect<void>;
157
- //#endregion
158
- //#region src/internal/stepLoop.d.ts
159
176
  /**
160
177
  * The discriminant tags of the run outcome; the variants inherit them because
161
178
  * an `Exit` cannot travel through a schema.
@@ -261,6 +278,11 @@ interface RunOptions {
261
278
  * or `choose` is rejected, so it cannot silently weaken an exploring run.
262
279
  */
263
280
  readonly external?: 'fail' | 'await';
281
+ /**
282
+ * Where the run reads the host resources alive while it stalls. The default reads the process's own list,
283
+ * which Node 26 leaves pending file requests out of; pass `fileRequestHooks(createHook)` there.
284
+ */
285
+ readonly host?: HostResources;
264
286
  /**
265
287
  * `'body'` keeps every decision before `beginExploration` on Effect's order,
266
288
  * so a harness's own setup is never explored (R15).
@@ -292,8 +314,6 @@ declare const run: {
292
314
  <A, E>(program: Effect.Effect<A, E>, options?: RunOptions): Promise<RunResult<A, E>>;
293
315
  (options?: RunOptions): <A, E>(program: Effect.Effect<A, E>) => Promise<RunResult<A, E>>;
294
316
  };
295
- //#endregion
296
- //#region src/Kernel/Pct.d.ts
297
317
  interface PickOptions {
298
318
  readonly seed: number;
299
319
  readonly depth?: PctDepth;
@@ -319,8 +339,6 @@ declare const pct: {
319
339
  <A, E>(program: Effect.Effect<A, E>, options?: PctOptions<A, E>): Promise<PctOutcome<A, E>>;
320
340
  <A, E>(options?: PctOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<PctOutcome<A, E>>;
321
341
  };
322
- //#endregion
323
- //#region src/Kernel/Profile.d.ts
324
342
  /**
325
343
  * How much schedule exploration a run buys. `per-change` is the budget a pull
326
344
  * request is judged on; `local` is a developer's own machine, which caps the
@@ -343,8 +361,6 @@ declare const preemptionsFor: {
343
361
  (profile: ProfileName): (requested: number | undefined) => number | undefined;
344
362
  };
345
363
  declare const currentPreemptionsFor: (requested: number | undefined) => Effect.Effect<number | undefined, Config.ConfigError>;
346
- //#endregion
347
- //#region src/Kernel/Search.d.ts
348
364
  declare const CompletedTag: {
349
365
  readonly _tag: 'Completed';
350
366
  };
@@ -386,8 +402,6 @@ declare const search: {
386
402
  <A, E>(program: Effect.Effect<A, E>, options?: SearchOptions<A, E>): Promise<SearchReport<A, E>>;
387
403
  <A, E>(options?: SearchOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<SearchReport<A, E>>;
388
404
  };
389
- //#endregion
390
- //#region src/Kernel/Shrink.d.ts
391
405
  interface ShrinkOptions<A, E> {
392
406
  readonly path: ReadonlyArray<Decision>;
393
407
  readonly isFailure?: (result: RunResult<A, E>) => boolean;
@@ -407,7 +421,6 @@ declare const shrinkCommands: {
407
421
  <C>(stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): (commands: ReadonlyArray<C>) => Promise<ReadonlyArray<C>>;
408
422
  };
409
423
  declare namespace mod_d_exports {
410
- export { AnyFiber, BlockedFailure, Bound, BoundaryKind, BoundaryRecord, Choice, ChoiceOption, DeadlockFailure, Decision, Escape, EscapeFailure, FiberTarget, Interruption, OverBudgetOutcome, PctDepth, PctFailure, PctOptions, PctOutcome, PctSeedCount, PctStepCount, PickOptions, ProfileName, Pruning, ReplayTraceDivergedFailure, RunCompleted, RunFailed, RunFailure, RunHistory, RunOptions, RunResult, RunawayFailure, SearchFailure, SearchOptions, SearchOutcome, SearchReport, ShrinkOptions, ShrinkOutcome, StepRecord, SuspendedFiber, TestClock_d_exports as TestClock, TimerName, TraceDivergence, TraceSnapshot, UnobservedPrimitive, WaitKind, beginExploration, currentPreemptionsFor, currentProfile, currentSeedsFor, isStepping, localPreemptions, localSeeds, runOutcomeTags as outcomeTags, pct, pctDepth, perChangeSeeds, pick, preemptionsFor, pruned, run, search, searchTags, seedsFor, shrink, shrinkCommands, unpruned };
424
+ export { AnyFiber, BlockedFailure, Bound, BoundaryKind, BoundaryRecord, Choice, ChoiceOption, CreateHook, DeadlockFailure, Decision, Escape, EscapeFailure, FiberTarget, HostResourceWatch, HostResources, HostResourcesService, Interruption, OverBudgetOutcome, PctDepth, PctFailure, PctOptions, PctOutcome, PctSeedCount, PctStepCount, PickOptions, ProfileName, Pruning, ReplayTraceDivergedFailure, RunCompleted, RunFailed, RunFailure, RunHistory, RunOptions, RunResult, RunawayFailure, SearchFailure, SearchOptions, SearchOutcome, SearchReport, ShrinkOptions, ShrinkOutcome, StepRecord, SuspendedFiber, TestClock_d_exports as TestClock, TimerName, TraceDivergence, TraceSnapshot, UnobservedPrimitive, WaitKind, beginExploration, currentPreemptionsFor, currentProfile, currentSeedsFor, fileRequestHooks, isStepping, localPreemptions, localSeeds, runOutcomeTags as outcomeTags, pct, pctDepth, perChangeSeeds, pick, preemptionsFor, processResources, pruned, run, search, searchTags, seedsFor, shrink, shrinkCommands, unpruned };
411
425
  }
412
- //#endregion
413
426
  export { mod_d_exports as Kernel };
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { Clock, Config, Context, Deferred, Duration, Effect, Latch, Layer, Match, Option, Order, PubSub, Queue, Ref, Scheduler, Schema, Scope, Semaphore } from "effect";
1
+ import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
2
+ import * as Context from "effect/Context";
3
+ import { Clock, Config, Context as Context$1, Deferred, Duration, Effect, Latch, Layer, Match, Option, Order, PubSub, Queue, Ref, Scheduler, Schema, Scope, Semaphore } from "effect";
3
4
  import { dual } from "effect/Function";
4
- //#region src/Kernel/Bound.ts
5
+ // src/Kernel/Bound.ts
5
6
  const pruned = {
6
7
  enabled: true,
7
8
  disabledBy: []
@@ -10,8 +11,51 @@ const unpruned = (disabledBy) => ({
10
11
  enabled: false,
11
12
  disabledBy
12
13
  });
13
- //#endregion
14
- //#region src/Kernel/Pct.schema.ts
14
+ // src/internal/hostResources.ts
15
+ /** @internal */
16
+ var HostResourcesService = class extends Context.Service()("@systemfsoftware/effect-sim-kernel/internal/hostResources/HostResourcesService") {};
17
+ const NO_RESOURCES = [];
18
+ const isHostObject$4 = (candidate) => typeof candidate === "object" && candidate !== null;
19
+ const listsActiveResources = (candidate) => typeof Reflect.get(candidate, "getActiveResourcesInfo") === "function";
20
+ const isHostProcess = (candidate) => isHostObject$4(candidate) && listsActiveResources(candidate);
21
+ const activeResourceNames = () => {
22
+ const host = Reflect.get(globalThis, "process");
23
+ return isHostProcess(host) ? host.getActiveResourcesInfo() : NO_RESOURCES;
24
+ };
25
+ const endNothing = () => void 0;
26
+ /** @internal */
27
+ const processResources = { begin: () => ({
28
+ names: activeResourceNames,
29
+ end: endNothing
30
+ }) };
31
+ const FILE_REQUEST_KINDS = ["FSREQCALLBACK", "FSREQPROMISE"];
32
+ const LISTED_FILE_REQUEST = /^FSReq/u;
33
+ const isListedFileRequest = (name) => LISTED_FILE_REQUEST.test(name);
34
+ const listedWithoutFileRequests = () => activeResourceNames().filter((name) => !isListedFileRequest(name));
35
+ const watchFileRequests = (createHook) => {
36
+ const pending = /* @__PURE__ */ new Map();
37
+ const settle = (asyncId) => {
38
+ pending.delete(asyncId);
39
+ };
40
+ const hook = createHook({
41
+ init: (asyncId, type) => {
42
+ if (FILE_REQUEST_KINDS.includes(type)) pending.set(asyncId, type);
43
+ },
44
+ before: settle,
45
+ destroy: settle
46
+ });
47
+ hook.enable();
48
+ return {
49
+ names: () => [...listedWithoutFileRequests(), ...pending.values()],
50
+ end: () => {
51
+ hook.disable();
52
+ pending.clear();
53
+ }
54
+ };
55
+ };
56
+ /** @internal */
57
+ const fileRequestHooks = (createHook) => ({ begin: () => watchFileRequests(createHook) });
58
+ // src/Kernel/Pct.schema.ts
15
59
  const generatedBetween = (minimum, maximum) => Schema.makeFilter(() => void 0, { arbitraryConstraint: {
16
60
  order: Order.Number,
17
61
  minimum,
@@ -29,12 +73,10 @@ const PctStepCount = Schema.Int.pipe(Schema.check(Schema.isBetween({
29
73
  minimum: 0,
30
74
  maximum: Number.MAX_SAFE_INTEGER
31
75
  }, { message: "a PCT step count is a whole number of explored decisions, at least 0" })), Schema.check(generatedBetween(0, 1e4)), Schema.brand("PctStepCount"));
32
- //#endregion
33
- //#region src/internal/profile.schema.ts
76
+ // src/internal/profile.schema.ts
34
77
  /** @internal */
35
78
  const ProfileNames = Schema.Literals(["local", "per-change"]);
36
- //#endregion
37
- //#region src/internal/clocks.ts
79
+ // src/internal/clocks.ts
38
80
  /**
39
81
  * The kernel's clocks (R2, R37). The root clock is virtual time the run owns:
40
82
  * every sleep registers here, no host timer is ever created, and `advance`
@@ -176,8 +218,7 @@ const makeRunClocks = () => ({
176
218
  */
177
219
  /** @internal */
178
220
  const stepClocks = (clocks) => clocks.testClocks.some((testClock) => testClock.stepTowardRequest()) || clocks.clock.advance();
179
- //#endregion
180
- //#region src/internal/kernel.ts
221
+ // src/internal/kernel.ts
181
222
  /**
182
223
  * The kernel instance (KTD2): it supplies Effect's `Scheduler`, wraps the fiber
183
224
  * resume methods, and observes `Ref` and `Deferred` field access. The hooks are
@@ -332,7 +373,7 @@ const interceptFields$1 = (proto, fields, guard) => {
332
373
  const DEFAULT_VALUE = "~effect/Context/defaultValue";
333
374
  const FIBER_CACHE = "_fiberCache";
334
375
  const emptyContextRoot = () => {
335
- const root = Reflect.get(Context.empty(), "cacheRoot");
376
+ const root = Reflect.get(Context$1.empty(), "cacheRoot");
336
377
  if (!isHostObject$3(root)) throw new Error("effect-sim-kernel: Context no longer has a cache root on the pinned Effect version");
337
378
  return root;
338
379
  };
@@ -346,7 +387,7 @@ const restoreFiberCache = (root, captured) => {
346
387
  else Reflect.defineProperty(root, FIBER_CACHE, captured);
347
388
  };
348
389
  const cachedDefaultOf = (reference) => {
349
- Context.getOption(Context.empty(), reference);
390
+ Context$1.getOption(Context$1.empty(), reference);
350
391
  const descriptor = captureDescriptor(reference, DEFAULT_VALUE);
351
392
  if (descriptor === void 0) throw new Error("effect-sim-kernel: Context no longer caches reference defaults on the pinned Effect version");
352
393
  return descriptor;
@@ -854,26 +895,18 @@ const makeKernel = (options) => {
854
895
  restoreHooks = acquireHooks(kernel);
855
896
  return kernel;
856
897
  };
857
- //#endregion
858
- //#region src/internal/deadlock.ts
898
+ // src/internal/deadlock.ts
859
899
  const NO_FRAMES = [];
860
- const NO_RESOURCES = [];
861
900
  const isHostObject$2 = (candidate) => typeof candidate === "object";
862
901
  const isFrameList = (candidate) => Array.isArray(candidate);
863
- const isHostProcess = (candidate) => isHostObject$2(candidate);
864
- const hostProcess = () => Reflect.get(globalThis, "process");
865
- const resourceNames = () => {
866
- const host = hostProcess();
867
- return isHostProcess(host) ? host.getActiveResourcesInfo() : NO_RESOURCES;
868
- };
869
902
  const bump = (counts, resource) => {
870
903
  counts.set(resource, (counts.get(resource) ?? 0) + 1);
871
904
  };
872
905
  /** A snapshot of the process resources alive right now, by resource kind. */
873
906
  /** @internal */
874
- const resourceCounts = () => {
907
+ const resourceCounts = (names) => {
875
908
  const counts = /* @__PURE__ */ new Map();
876
- for (const resource of resourceNames()) bump(counts, resource);
909
+ for (const resource of names) bump(counts, resource);
877
910
  return counts;
878
911
  };
879
912
  const extraOf = (before, entry) => entry[1] - (before.get(entry[0]) ?? 0);
@@ -883,11 +916,11 @@ const appendExtra = (appeared, before, entry) => {
883
916
  };
884
917
  /** Resource kinds that appeared since `before`, as `"<kind> x<count>"` entries. */
885
918
  /** @internal */
886
- const newResources = (before) => {
919
+ const newResources = dual(2, (before, now) => {
887
920
  const appeared = [];
888
- for (const entry of resourceCounts()) appendExtra(appeared, before, entry);
921
+ for (const entry of now) appendExtra(appeared, before, entry);
889
922
  return appeared;
890
- };
923
+ });
891
924
  const FAMILY_PATTERNS = [
892
925
  [/Socket|TCP|UDP|Pipe|GetAddrInfo/u, "Socket"],
893
926
  [/FS|File/u, "File"],
@@ -961,8 +994,7 @@ const describeSuspended = (fibers) => {
961
994
  for (const fiber of fibers) collectSuspended(suspended, fiber);
962
995
  return suspended;
963
996
  };
964
- //#endregion
965
- //#region src/internal/escapeRecorder.ts
997
+ // src/internal/escapeRecorder.ts
966
998
  const TIMER_NAMES = [
967
999
  "setTimeout",
968
1000
  "setInterval",
@@ -1020,8 +1052,7 @@ const hostImmediateOf = (originals) => {
1020
1052
  return immediate === void 0 ? syncImmediate : immediate;
1021
1053
  };
1022
1054
  const syncImmediate = (handler) => handler();
1023
- //#endregion
1024
- //#region src/internal/runQueue.ts
1055
+ // src/internal/runQueue.ts
1025
1056
  let tail = Promise.resolve();
1026
1057
  /** @internal */
1027
1058
  const acquireRun = () => {
@@ -1030,8 +1061,7 @@ const acquireRun = () => {
1030
1061
  tail = turn.promise;
1031
1062
  return previous.then(() => turn.resolve);
1032
1063
  };
1033
- //#endregion
1034
- //#region src/internal/stepLoop.ts
1064
+ // src/internal/stepLoop.ts
1035
1065
  /**
1036
1066
  * The async step loop (R1, R4, R5, R36). It picks one pending task per step —
1037
1067
  * by a caller-supplied decision path, a `choose` callback, or Effect's own
@@ -1118,8 +1148,9 @@ const runawayOf = (kernel, options, guard) => {
1118
1148
  pending: kernel.pending.length
1119
1149
  };
1120
1150
  };
1121
- const quiescenceFailure = (kernel, before) => {
1122
- const resources = newResources(before);
1151
+ const countsNow = (watch) => resourceCounts(watch.names());
1152
+ const quiescenceFailure = (kernel, before, watch) => {
1153
+ const resources = newResources(before, countsNow(watch));
1123
1154
  if (resources.length === 0) return {
1124
1155
  ...runOutcomeTags.deadlock,
1125
1156
  suspended: describeSuspended(kernel.fibers)
@@ -1141,22 +1172,22 @@ const hostCheckYield = (state) => {
1141
1172
  return promise;
1142
1173
  };
1143
1174
  const hostYield = (state) => hostCheckYield(state).then(() => drain(DEFAULT_STEP_TURNS)).then(() => drain(DEFAULT_QUIESCENCE_TURNS));
1144
- const awaitedResources = (state) => newResources(state.before);
1175
+ const awaitedResources = (state) => newResources(state.before, countsNow(state.watch));
1145
1176
  const waitsRemain = (resources) => resources.some((resource) => waitKindOf([resource]) === "File" || waitKindOf([resource]) === "Socket");
1146
1177
  const loweredBaseline = (before, now) => new Map([...before].map(([name, count]) => [name, Math.min(count, now.get(name) ?? 0)]));
1147
1178
  const revivedDrive = (state) => drive({
1148
1179
  ...state,
1149
- before: loweredBaseline(state.before, resourceCounts())
1180
+ before: loweredBaseline(state.before, countsNow(state.watch))
1150
1181
  });
1151
1182
  const waitedOutcome = (state) => revivedAfterHost(state, 0);
1152
1183
  const revivedAfterHost = (state, waited) => hostYield(state).then(() => revivedAfterYield(state, waited));
1153
1184
  const revivedAfterYield = (state, waited) => tasksPending(state) ? revivedDrive(state) : revivedByResources(state, waited);
1154
1185
  const revivedByResources = (state, waited) => waitsRemain(awaitedResources(state)) ? revivedAfterLimit(state, waited) : revivedAfterHost(state, waited + 1);
1155
- const revivedAfterLimit = (state, waited) => waited > MAX_HOST_WAITS ? Promise.resolve(failedOn(state.kernel, quiescenceFailure(state.kernel, state.before))) : revivedAfterHost(state, waited + 1);
1186
+ const revivedAfterLimit = (state, waited) => waited > MAX_HOST_WAITS ? Promise.resolve(failedOn(state.kernel, quiescenceFailure(state.kernel, state.before, state.watch))) : revivedAfterHost(state, waited + 1);
1156
1187
  const waitForExternal = (state, _excuse) => drain(quiescenceTurnsOf(state.options)).then(() => waitedOutcome(state));
1157
1188
  const awaitedStall = (state, excuse) => awaitsStall(state.options, excuse) ? waitForExternal(state, excuse) : Promise.resolve(failedOn(state.kernel, excuse));
1158
1189
  const stallByExternal = (state, excuse) => awaitedStall(state, excuse);
1159
- const classifyStall = (state) => seamOffersProgress(state.options.onQuiescent) ? Promise.resolve(void 0) : stallByExternal(state, quiescenceFailure(state.kernel, state.before));
1190
+ const classifyStall = (state) => seamOffersProgress(state.options.onQuiescent) ? Promise.resolve(void 0) : stallByExternal(state, quiescenceFailure(state.kernel, state.before, state.watch));
1160
1191
  const seamOrFailure = (state) => classifyStall(state);
1161
1192
  const completedOn = (kernel, exit) => ({
1162
1193
  ...runOutcomeTags.completed,
@@ -1260,6 +1291,7 @@ const RUN_OPTION_KEYS = [
1260
1291
  "expectTrace",
1261
1292
  "explore",
1262
1293
  "external",
1294
+ "host",
1263
1295
  "interrupt",
1264
1296
  "maxSteps",
1265
1297
  "onQuiescent",
@@ -1279,6 +1311,14 @@ const isProgram = (candidate) => !isRunOptions(candidate);
1279
1311
  * taken, and a per-step record of which fiber ran. A run started while one is
1280
1312
  * active queues behind it, so two runs never share the global hooks.
1281
1313
  */
1314
+ const endingRun = (started, end) => {
1315
+ try {
1316
+ return started().finally(end);
1317
+ } catch (error) {
1318
+ end();
1319
+ return Promise.reject(error);
1320
+ }
1321
+ };
1282
1322
  const lockedRun = (program, options, release) => {
1283
1323
  const kernel = makeKernel({
1284
1324
  exploring: options.explore !== "body",
@@ -1288,19 +1328,24 @@ const lockedRun = (program, options, release) => {
1288
1328
  kernel.escapes.push(escape);
1289
1329
  });
1290
1330
  const userSeam = options.onQuiescent;
1291
- const root = Effect.runFork(Effect.provideService(program, Clock.Clock, kernel.clocks.clock), { scheduler: kernel.scheduler });
1292
- kernel.start(root);
1293
- return drive({
1294
- kernel,
1295
- root,
1296
- options: {
1297
- ...options,
1298
- onQuiescent: () => stepClocks(kernel.clocks) || seamOffersProgress(userSeam)
1299
- },
1300
- before: resourceCounts(),
1301
- guard: 0,
1302
- hostImmediate: recorder.hostImmediate
1303
- }).finally(() => {
1331
+ const watch = (options.host ?? processResources).begin();
1332
+ return endingRun(() => {
1333
+ const root = Effect.runFork(Effect.provideService(program, Clock.Clock, kernel.clocks.clock), { scheduler: kernel.scheduler });
1334
+ kernel.start(root);
1335
+ return drive({
1336
+ kernel,
1337
+ root,
1338
+ options: {
1339
+ ...options,
1340
+ onQuiescent: () => stepClocks(kernel.clocks) || seamOffersProgress(userSeam)
1341
+ },
1342
+ before: countsNow(watch),
1343
+ watch,
1344
+ guard: 0,
1345
+ hostImmediate: recorder.hostImmediate
1346
+ });
1347
+ }, () => {
1348
+ watch.end();
1304
1349
  recorder.restore();
1305
1350
  kernel.release();
1306
1351
  release();
@@ -1328,8 +1373,7 @@ const runImpl = (program, options = {}) => {
1328
1373
  */
1329
1374
  /** @internal */
1330
1375
  const run = dual((args) => args.length > 0 && isProgram(args[0]), runImpl);
1331
- //#endregion
1332
- //#region src/Kernel/Profile.ts
1376
+ // src/Kernel/Profile.ts
1333
1377
  const pctDepth = PctDepth.make(3);
1334
1378
  const isProfileName = Schema.is(ProfileNames);
1335
1379
  const profileOf = (name) => isProfileName(name) ? name : "per-change";
@@ -1364,8 +1408,7 @@ const localBoundOf = (requested) => Math.min(requested ?? 1, 1);
1364
1408
  const boundImpl = (requested, profile) => profile === "local" ? localBoundOf(requested) : requested;
1365
1409
  const preemptionsFor = dual(2, boundImpl);
1366
1410
  const currentPreemptionsFor = (requested) => Effect.map(currentProfile, (profile) => preemptionsFor(requested, profile));
1367
- //#endregion
1368
- //#region src/Kernel/Pct.ts
1411
+ // src/Kernel/Pct.ts
1369
1412
  /**
1370
1413
  * Seeded PCT (Burckhardt, Kothari & Musuvathi): each fiber gets a random
1371
1414
  * priority, the highest-priority runnable task runs, and `depth - 1` change
@@ -1535,8 +1578,7 @@ const pctImpl = (program, options = {}) => {
1535
1578
  });
1536
1579
  };
1537
1580
  const pct = dual((args) => args.length === 2 || Effect.isEffect(args[0]), pctImpl);
1538
- //#endregion
1539
- //#region src/internal/Unobserved.ts
1581
+ // src/internal/Unobserved.ts
1540
1582
  /**
1541
1583
  * Unobserved shared-primitive detection (R35, AE12). The kernel observes `Ref`
1542
1584
  * and `Deferred` only, so a run that touches `Queue`, `PubSub`, `Semaphore`,
@@ -1683,7 +1725,7 @@ const scopedContext = (fiber) => {
1683
1725
  };
1684
1726
  const heldScope = (fiber) => {
1685
1727
  const context = scopedContext(fiber);
1686
- return context === void 0 ? void 0 : Option.getOrUndefined(Context.getOption(context, Scope.Scope));
1728
+ return context === void 0 ? void 0 : Option.getOrUndefined(Context$1.getOption(context, Scope.Scope));
1687
1729
  };
1688
1730
  const holdIn = (scope, holder) => {
1689
1731
  currentKernel()?.holdScope(scope, holder);
@@ -1909,8 +1951,7 @@ const searchImpl = (program, options = {}) => {
1909
1951
  return driveSearch(state);
1910
1952
  };
1911
1953
  const search = dual((args) => args.length === 2 || Effect.isEffect(args[0]), searchImpl);
1912
- //#endregion
1913
- //#region src/Kernel/Shrink.ts
1954
+ // src/Kernel/Shrink.ts
1914
1955
  const failKept = (result) => "failure" in result;
1915
1956
  const withoutSteps = (state) => {
1916
1957
  const maxSteps = state.maxSteps;
@@ -2059,8 +2100,7 @@ const shrinkCommandsImpl = (commands, stillFails) => commandsPass({
2059
2100
  passes: 0
2060
2101
  });
2061
2102
  const shrinkCommands = dual((args) => Array.isArray(args[0]), shrinkCommandsImpl);
2062
- //#endregion
2063
- //#region src/Kernel/TestClock.ts
2103
+ // src/Kernel/TestClock.ts
2064
2104
  /**
2065
2105
  * The kernel's controllable test clock (R37): what a harness provides in place
2066
2106
  * of `TestClock.layer()`. Programs keep calling Effect's `TestClock` API —
@@ -2085,12 +2125,12 @@ const make = Effect.sync(() => {
2085
2125
  kernel.clocks.testClocks.push(testClock);
2086
2126
  return testClock;
2087
2127
  });
2088
- const contextOf = (testClock) => Context.makeUnsafe(/* @__PURE__ */ new Map([[Clock.Clock.key, testClock]]));
2128
+ const contextOf = (testClock) => Context$1.makeUnsafe(/* @__PURE__ */ new Map([[Clock.Clock.key, testClock]]));
2089
2129
  /** The layer a harness provides in place of `TestClock.layer()`. */
2090
2130
  const layer = Layer.effectContext(Effect.map(make, contextOf));
2091
- //#endregion
2092
- //#region src/Kernel/mod.ts
2131
+ // src/Kernel/mod.ts
2093
2132
  var Kernel_exports = /* @__PURE__ */ __exportAll({
2133
+ HostResourcesService: () => HostResourcesService,
2094
2134
  PctDepth: () => PctDepth,
2095
2135
  PctSeedCount: () => PctSeedCount,
2096
2136
  PctStepCount: () => PctStepCount,
@@ -2099,6 +2139,7 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
2099
2139
  currentPreemptionsFor: () => currentPreemptionsFor,
2100
2140
  currentProfile: () => currentProfile,
2101
2141
  currentSeedsFor: () => currentSeedsFor,
2142
+ fileRequestHooks: () => fileRequestHooks,
2102
2143
  isStepping: () => isStepping,
2103
2144
  localPreemptions: () => 1,
2104
2145
  localSeeds: () => 25,
@@ -2108,6 +2149,7 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
2108
2149
  perChangeSeeds: () => 250,
2109
2150
  pick: () => pick,
2110
2151
  preemptionsFor: () => preemptionsFor,
2152
+ processResources: () => processResources,
2111
2153
  pruned: () => pruned,
2112
2154
  run: () => run,
2113
2155
  search: () => search,
@@ -2117,5 +2159,4 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
2117
2159
  shrinkCommands: () => shrinkCommands,
2118
2160
  unpruned: () => unpruned
2119
2161
  });
2120
- //#endregion
2121
2162
  export { Kernel_exports as Kernel };
@@ -0,0 +1,12 @@
1
+ // \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, flags) => {
4
+ let target = Object.setPrototypeOf({}, null);
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return flags & 2 ? target : Object.preventExtensions(target);
11
+ };
12
+ export { __exportAll as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@systemfsoftware/effect-sim-kernel",
3
- "version": "2.0.6",
3
+ "version": "2.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
6
  "repository": {
@@ -32,17 +32,17 @@
32
32
  "./package.json": "./package.json"
33
33
  },
34
34
  "devDependencies": {
35
- "@microsoft/api-extractor": "^7.59.4",
36
- "@systemfsoftware/oxlint-config-recommended": "^8.0.3",
35
+ "@microsoft/api-extractor": "^7.60.1",
36
+ "@systemfsoftware/oxlint-config-recommended": "^8.0.4",
37
37
  "@systemfsoftware/tsconfig": "^2.1.0",
38
- "@systemfsoftware/tsdown-config": "^0.1.2",
39
- "@systemfsoftware/vitest": "^4.1.3",
40
- "@systemfsoftware/vitest-config": "^0.1.3",
41
- "@types/node": "^26.6.5",
38
+ "@systemfsoftware/tsdown-config": "^0.1.3",
39
+ "@systemfsoftware/vitest": "^4.2.0",
40
+ "@systemfsoftware/vitest-config": "^0.1.4",
41
+ "@types/node": "^26.6.6",
42
42
  "effect": "^4.1.4",
43
43
  "oxlint": "~1.93.0",
44
- "rimraf": "^6.1.3",
45
- "tsdown": "^0.23.0",
44
+ "rimraf": "^6.1.4",
45
+ "tsdown": "^0.23.7",
46
46
  "typescript": "^7.0.2",
47
47
  "vitest": "^5.1.0"
48
48
  },
@@ -1,13 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __defProp = Object.defineProperty;
3
- var __exportAll = (all, no_symbols) => {
4
- let target = {};
5
- for (var name in all) __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true
8
- });
9
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
- return target;
11
- };
12
- //#endregion
13
- export { __exportAll as t };