@zakkster/lite-signal 1.7.0-preview.0 → 1.7.0-preview.2

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
@@ -4,6 +4,267 @@ All notable changes to `@zakkster/lite-signal` are documented here.
4
4
  Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
  This project follows [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [1.7.0-preview] -- 2026-07-XX
8
+
9
+ The **flush-strategy minor**, shipping on the `preview` dist-tag while it settles.
10
+ Two additions on top of 1.6.0-preview:
11
+
12
+ - **`flushStrategy` registry option + `r.flush()`** -- the primary 1.7 lever, a
13
+ per-registry choice of when effects auto-deliver (`"eager"` default | `"sab"` |
14
+ `"manual"`) plus an explicit `flush()` method on every registry. Resolved once at
15
+ registry init by binding to a pre-built closure reference; the "eager" inlined
16
+ body is byte-identical to 1.6's `if (batchDepth === 0) flushEffects()` so
17
+ existing users see zero behavioral or performance regression.
18
+ - **`getOwner` / `runWithOwner` port** -- carried forward from 1.5.0-beta.2 into
19
+ this line. The 1.7.0-preview `Signal.js` was branched from a pre-1.5.0-beta.2
20
+ base and the two async-gap primitives (`getOwner()` capture, `runWithOwner()`
21
+ restore) were missing. Ported unchanged: the same safe `describeNode` +
22
+ `liveNode` gen-guard machinery that landed in 1.5.0-beta.2 and carried into 1.6
23
+ is now present here too, so any consumer using the ownership escape hatch (e.g.
24
+ `lite-query`'s query-watcher across an `await`) gets the same guarantees on the
25
+ 1.7 line.
26
+
27
+ The two hot-path changes 1.6 -> 1.7 are localised to `signal` / `computed` /
28
+ `effect` / `signalBox` / `computedBox` (their `.set` sites) and `batch` (their
29
+ exit sites) -- specifically the resolved-once binding to `flushAfterWrite` /
30
+ `flushAfterBatch`. **Every other hot-path body is byte-identical to 1.6.0**
31
+ (sha256-verified over `pullComputed`, `markDownstream`, `executeEffect`,
32
+ `flushEffects`, `allocateLink`, `severTail`, `createNode`, `runCleanup`,
33
+ `disposeNode`, `createRoot`, `createScope`). The two ownership primitives added
34
+ by this port only add new user-API functions -- they do not touch any of the
35
+ above; the sha256 check confirms it.
36
+
37
+ Drop-in over 1.6.0-preview. The default is unchanged.
38
+
39
+ ### Added -- `flushStrategy` registry option
40
+
41
+ Selects when effects auto-deliver, chosen once at `createRegistry` time:
42
+
43
+ - **`"eager"`** (default, byte-identical to 1.6.0): `.set` outside batch
44
+ auto-flushes; batch exit auto-flushes.
45
+ - **`"sab"`** (**stable-after-batch**, matches Reflex semantics): `.set` outside
46
+ batch enqueues effects via the existing `FLAG_SCHEDULED` dedup but does NOT
47
+ auto-flush; batch exit DOES auto-flush. This is the apples-to-apples mode for
48
+ the `js-reactivity-benchmark` `update*` group -- on shapes with observers but
49
+ no effects, the eager `flushEffects` empty-path `try/finally` was the dominant
50
+ per-write overhead.
51
+ - **`"manual"`**: neither `.set` nor batch exit auto-flush; only explicit
52
+ `r.flush()` drains the queue. For hard-real-time loops that need frame-aligned
53
+ settle points (Hueforge, Gradient Studio).
54
+
55
+ ### Added -- `r.flush()` explicit flush API
56
+
57
+ Explicit flush method on every registry. Re-entrant safe (the existing
58
+ `isFlushing` guard applies unchanged); empty queue exits immediately. The three
59
+ strategies use it as follows: `"eager"` never needs it (auto-flushes cover
60
+ everything); `"sab"` needs it if you `.set` outside batch and want the effects
61
+ to run without waiting for the next batch exit; `"manual"` needs it to run any
62
+ effects at all.
63
+
64
+ ### Added -- `getOwner` / `runWithOwner` (carried forward from 1.5.0-beta.2)
65
+
66
+ The capture-and-restore companion to `createRoot`. `getOwner()` returns the
67
+ current lifecycle owner as an opaque, gen-stamped handle (`undefined` outside
68
+ any effect/computed body); `runWithOwner(handle, fn)` runs `fn` with that owner
69
+ reinstated so effects/computeds created directly in `fn` are adopted by it (and
70
+ cascade-dispose when the owner re-runs). Nulls the tracking observer for `fn`'s
71
+ direct body -- same pairing as `createRoot`, so accidental cross-async
72
+ dependency edges cannot form.
73
+
74
+ **Handles are gen-stamped.** They use the `describeNode` + `liveNode` ABA-guard
75
+ machinery (`NODE_GEN` stamp checked against the pool slot's current gen), same as
76
+ `describe` / `nodeId` / `forEachOwned` / `ownerOf` since 1.2.1. Safe to hold
77
+ across async boundaries: if the captured owner is disposed and the pool slot is
78
+ recycled by an unrelated effect via the LIFO free list, the handle's gen no
79
+ longer matches and `runWithOwner` degrades to **rooted execution** rather than
80
+ adopting the continuation into the recycled slot's new resident. Two hazards on
81
+ the raw-pointer alternative pinned in `test/28-run-with-owner.test.mjs` and
82
+ empirically reproduced against a patched engine via
83
+ `harness/owner-hazard-repro.mjs`:
84
+
85
+ - **Recycled-slot cascade death** -- capture, dispose owner, allocate a stranger
86
+ effect that reuses the slot; a raw-pointer `runWithOwner(captured)` silently
87
+ adopts the continuation into the stranger; the stranger's next re-run
88
+ cascade-disposes it.
89
+ - **Corpse adoption = engine crash** -- capture, dispose owner but not-yet-
90
+ recycled; a raw-pointer `runWithOwner(captured, () => effect(...))` splices a
91
+ child into a disposed owner's `firstOwned`; the next disposal walk recurses
92
+ without termination (`RangeError: Maximum call stack size exceeded`). Not a
93
+ leak; a crash.
94
+
95
+ Both fail on the raw-pointer sketch; both pass on the shipped `describeNode` /
96
+ `liveNode` implementation. Verified against 1.7.0-preview's engine directly --
97
+ `harness/owner-hazard-repro.mjs ./Signal.js` reports `VERDICT: SAFE` on the
98
+ recycled-slot case (continuation runs 2 times before stranger disposal, 3
99
+ times after) and completes the corpse case without stack overflow.
100
+
101
+ Exported as registry methods AND top-level helpers bound to `defaultRegistry`,
102
+ mirroring `createRoot` and `createScope`. Top-level exports added right before
103
+ the top-level `createScope` binding for stable ordering.
104
+
105
+ ### Hot-path safety
106
+
107
+ The `flushStrategy` lever is resolved ONCE at registry init by binding
108
+ `flushAfterWrite` and `flushAfterBatch` to one of two pre-built closure
109
+ references (`eagerFlushHook | noopFlush`). Every `.set` / `boxSet` / `batch`
110
+ call site captures a constant function reference for its lifetime; V8 sees
111
+ monomorphic targets and inlines the body. In "eager" mode the inlined body is
112
+ byte-identical to the 1.6.0 inline check `if (batchDepth === 0) flushEffects()`
113
+ -- **zero behavioral or performance regression** for any existing user.
114
+
115
+ This is NOT ledger §0b #6 (per-call closure-var load of a primitive). It is a
116
+ hoisted function reference resolved once at registry build time and is a NEW
117
+ mechanism by the v1 roadmap §0b line 100 definition.
118
+
119
+ The `getOwner` / `runWithOwner` port adds new user-API functions but touches no
120
+ hot path. sha256 over the extracted function bodies of `pullComputed`,
121
+ `markDownstream`, `executeEffect`, `flushEffects`, `allocateLink`, `severTail`,
122
+ `createNode`, `runCleanup`, `disposeNode`, `createRoot`, `createScope` matches
123
+ pristine 1.7.0-preview byte-for-byte; the two new functions are inserted between
124
+ `createRoot` and `createScope` without disturbing either.
125
+
126
+ ### Test coverage
127
+
128
+ - **Full suite green** on 1.7.0-preview with the getOwner/runWithOwner port
129
+ merged in: **451 total**, 440 pass, 0 fail, 1 skip (only the
130
+ architecturally-N/A SSR case in `17-reactivity`), 10 cancelled (the
131
+ `25-devtools-real-boot` cases that need `@zakkster/lite-devtools` installed as
132
+ a peer -- pre-existing, unrelated). Default-mode behavior is unchanged
133
+ byte-for-byte from 1.6.0.
134
+ - **+16 tests in `test/28-run-with-owner.test.mjs`** (carried forward from
135
+ 1.5.0-beta.2 / 1.6.0-alpha): 7 basic-shape tests, 3 degradation tests
136
+ (`null` / `undefined` / signal-handle all fall through to rooted execution),
137
+ and 3 **hazard pins** with allocation pressure applied so the ABA guard is
138
+ actually exercised (recycled-slot cascade, corpse adoption, composed).
139
+ - **`test/03-pool` "stats() shape" test** bumped from the 11-key 1.4.0 shape to
140
+ the 12-key 1.6+ shape (adds `flushPasses`). This was flagged already in the
141
+ 1.6.0 line; the 1.7 line inherits it.
142
+ - **New behavioral coverage to add** (per the drafted 1.7 notes, deferred to
143
+ 1.7.0-preview.1): `sab` batch-exit flush, `sab` dedup across many writes,
144
+ `manual` flush gating, lazy-pull correctness across all three modes, invalid
145
+ `flushStrategy` validation.
146
+
147
+ ### Bench impact (sandbox VM medians, 7 samples)
148
+
149
+ `update*` group with observers-but-no-effects, apples-to-apples in `sab` mode:
150
+
151
+ | Shape (n=writes) | eager | sab | speedup |
152
+ |------------------|-------:|-------:|--------:|
153
+ | 1to1 (400k) | 14.15 | 12.04 | 1.18x |
154
+ | 1to2 (400k) | 11.68 | 10.25 | 1.14x |
155
+ | 1to4 (400k) | 11.36 | 11.01 | 1.03x |
156
+ | 1to8 (400k) | 11.47 | 10.09 | 1.14x |
157
+ | 1to1000 (4k) | 1.59 | 1.55 | 1.03x |
158
+ | 1000to1 (1k) | 0.07 | 0.03 | 2.31x |
159
+
160
+ Real wins, but smaller than the gap to Reflex on the same shapes. The residual
161
+ gap is structural (per-write `gen` check, batch-revert epoch tracking, global
162
+ version bumping) -- design decisions accepted by §0b and not in scope here.
163
+ Modern V8's `try/finally` elision varies; expect higher absolute speedups on
164
+ production V8 than on this sandbox.
165
+
166
+ ### Migration
167
+
168
+ - **Every existing user**: zero work needed. The default is unchanged; every
169
+ registry created without a `flushStrategy` argument runs the same code as on
170
+ 1.6.0.
171
+ - **Bench adapters wanting apples-to-apples with Reflex-style flush semantics**:
172
+ pass `flushStrategy: "sab"` to `createRegistry` (see `liteSignal.ts` example
173
+ in the changeset).
174
+ - **Frame-aligned real-time loops**: pass `flushStrategy: "manual"` and call
175
+ `r.flush()` at the settle point.
176
+ - **Users of `createRoot` who want the capture-and-restore idiom across
177
+ async boundaries**: `getOwner()` + `runWithOwner()` are now available on
178
+ the 1.7 line (they were absent from pre-1.5.0-beta.2 branches and needed the
179
+ forward-port to reach 1.7 through the flushStrategy branch).
180
+
181
+ ### Verified
182
+
183
+ - **Full engine test suite** green on the merged engine (451 total, 440 pass,
184
+ 0 fail, 1 skip, 10 cancelled).
185
+ - **`harness/owner-hazard-repro.mjs ./Signal.js`** reports
186
+ `VERDICT: SAFE` on the recycled-slot case AND completes the corpse case
187
+ without stack overflow -- the ABA guard degrades both hazards to rooted
188
+ execution as designed.
189
+ - **sha256 over 11 hot-path function bodies** (`pullComputed`, `markDownstream`,
190
+ `executeEffect`, `flushEffects`, `allocateLink`, `severTail`, `createNode`,
191
+ `runCleanup`, `disposeNode`, `createRoot`, `createScope`) byte-identical
192
+ between pristine 1.7.0-preview (as uploaded) and the merged-with-getOwner
193
+ engine. The port literally only adds new code between `createRoot` and
194
+ `createScope` plus updates the return object and adds two top-level exports;
195
+ zero touch on any pre-existing function.
196
+
197
+ ### Tooling -- harness wiring, and a benchmark that was measuring nothing
198
+
199
+ **`bench/benchmark.mjs` was producing invalid numbers and is fixed.** Every
200
+ lite-signal adapter in it constructed its registry with `flushStrategy: "sab"`
201
+ while driving un-batched `.set` calls. In SAB mode a `.set` outside `batch()`
202
+ *enqueues* effects but does not flush them, and the harness never called
203
+ `batch()` or `r.flush()` anywhere -- so the effect ran exactly **once** (its
204
+ creation-time run) and never again inside the timed loop. The loop was timing a
205
+ bare mark-dirty against dead-code-eliminated downstream work.
206
+
207
+ The symptom was visible in the reports and went unread: nine of eleven rows
208
+ printed `sink=[ ]` and `BENCH_SINK_SUM (anti-DCE): 0.00`. MUX reported
209
+ **22,032K ops/s** against a real **~219K** -- a ~100x fiction. Measured on the
210
+ same host: as-written `sab`-no-flush = 1 effect run, sink 0; `sab` + explicit
211
+ `r.flush()` = 20,000 runs, 191K ops/s; `eager` = 20,000 runs, 219K ops/s (which
212
+ matches the long-published ~223K MUX figure).
213
+
214
+ - The nine adapters now run **eager**, which is byte-identical to 1.6.0 and the
215
+ only mode comparable to the reference libraries -- alien-signals, preact,
216
+ vue-reactivity and solid all deliver eagerly. SAB is the right mode for
217
+ Andrii's `update*` group (observers but no effects), which is what
218
+ `harness/perf-probe.mjs` and `harness/toe-to-toe/` are for, not this harness.
219
+ - A **VALIDITY GUARD** was added: any scenario finishing with a dead sink now
220
+ prints an `INVALID RUN` block naming the offending rows and sets a non-zero
221
+ exit code. The old code computed the `sink=[x]` / `[ ]` column and then ignored
222
+ it. Silence was the bug.
223
+ - **Every number in `results.txt` and `bench/bench-runs/` predating this fix is
224
+ invalid and must be regenerated.** `bench/benchmarkReactive.mjs` is
225
+ **unaffected**: it also sets `"sab"`, but it drives every write through
226
+ `withBatch(...)`, and batch exit *does* auto-flush in SAB mode -- verified
227
+ clean against 1.7.0 (cellx vectors matched, all internal assertions pass).
228
+
229
+ **Harness wiring restored and extended.** `profile:burst` / `profile:pull`
230
+ pointed at `burst-dag.mjs` / `pull-stress.mjs` in the repo root, where neither
231
+ file has lived since 1.6; both now resolve into `harness/`. The dispatcher
232
+ (`harness/run.mjs`) gained `smoke`, `perf`, `burst`, `pull` and `toe`, and the
233
+ `harness:*` scripts plus `gate` / `prepublishOnly` (VersionMatrix) and
234
+ `test:harness` (ProfilerTools) are wired in `package.json` again. `harness:smoke`
235
+ now leads `harness:all` and `npm run verify`, because it is the only probe that
236
+ **asserts** -- a `flushStrategy` regression fails in a second instead of after
237
+ twenty minutes of timed probes.
238
+
239
+ **Scratch directories folded in.** `tmp/`, `tmp2/` and `tmp3/` are gone:
240
+
241
+ - `tmp3/toe-to-toe.mjs` + `runner.mjs` -> `harness/toe-to-toe/`. This is the
242
+ corrected cross-version sweep and it supersedes the sbench driver: it replaces
243
+ sequential ordering with round-robin (the old loop ran the newest engine last,
244
+ on the hottest chassis, which is why three sha256-**identical** propagation
245
+ bodies appeared to trend across 1.9 -> 1.11), adds a `1.6.0-sentinel` drift
246
+ column, and fixes the **silent corrupter** -- `if (mode === "sab" && engineDir
247
+ === "v17")` meant only v17 ever received `flushStrategy: "sab"`, while every
248
+ later engine was *labelled* sab and batch-wrapped but built **eager**. Its
249
+ `engines/` dir is gitignored: several snapshots are unreleased, so the sweep
250
+ script is public and the engine source is not.
251
+ - `tmp/sbench-driver.mjs` + `sbench-runner.mjs` -> `harness/attic/` (superseded).
252
+ Their output stands, though: in that sweep v17 was the only `sab` combo, so the
253
+ corrupter was accidentally correct there. Preserved as
254
+ `harness/toe-to-toe/sbench-results-1.7.0.txt`.
255
+ - `tmp2/TESTING-SAB-METHODOLOGY.md` -> `harness/`; `tmp2/sink-check.mjs` ->
256
+ `harness/attic/` (redundant -- `harness/smoke.mjs` covers eager/sab/manual and
257
+ asserts). `tmp/Signal.js` (a stale 1.7.0-WIP snapshot) and the duplicated
258
+ `CHANGELOG-1.7.0.md` / `ROADMAP` copies are dropped.
259
+ - Root loose files cleaned: `owner-hazard-repro.mjs` (a formatting-only duplicate
260
+ of the `harness/` copy) removed; `retracking.difftest.mjs` moved into
261
+ `harness/` and **fixed** -- it imported a hard-coded `./1.1.6.js` that does not
262
+ exist in this tree, so it could not run at all; it now takes
263
+ `<reference.js> [candidate.js]` on the command line.
264
+
265
+ `Signal.js` and the published `files[]` whitelist are untouched by any of the
266
+ above; installed tarballs are byte-identical.
267
+
7
268
  ## [1.6.0] -- 2026-06-26 (preview)
8
269
 
9
270
  The observability-and-lifecycle minor, shipping on the `preview` dist-tag while it
package/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@zakkster/lite-signal?style=for-the-badge)](https://bundlephobia.com/result?p=@zakkster/lite-signal)
10
10
  [![npm downloads](https://img.shields.io/npm/dm/@zakkster/lite-signal?style=for-the-badge&color=blue)](https://www.npmjs.com/package/@zakkster/lite-signal)
11
11
  [![npm total downloads](https://img.shields.io/npm/dt/@zakkster/lite-signal?style=for-the-badge&color=blue)](https://www.npmjs.com/package/@zakkster/lite-signal)
12
+ ![Tree-Shakeable](https://img.shields.io/badge/tree--shakeable-yes-brightgreen)
12
13
  ![TypeScript](https://img.shields.io/badge/TypeScript-Types-informational)
13
14
  ![Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
14
15
  [![license](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](./LICENSE)
@@ -485,7 +486,7 @@ A registry-level (and top-level) debug hook for push-based tooling -- the connec
485
486
 
486
487
  **1.6.0 -- flush-profiling opcodes.** Opcodes `6` (flush pass) and `7` (effect run in pass) extend the surface to cover the flush dimension lite-devtools 1.2 / lite-studio 1.2 read through `watchAllocations`. The matching `stats().flushPasses` counter (the 12th `stats()` key) advances once per drain pass. Both the counter bump and the opcode dispatch sit behind the same `mutationHook !== null` gate, so when no listener is attached they are inert and `flushPasses` is frozen -- the flush loop is byte-identical to 1.5.0.
487
488
 
488
- **Characterization harnesses (`burst-dag.mjs`, `pull-stress.mjs`).** Two root-level standalone harnesses that exercise the 1.6.0 instrumentation against the engine's two main hot paths. `burst-dag.mjs` (`npm run profile:burst`) reconstructs the layered DAG burst shape (sources -> width x layers, fanIn 8, burst 16) and uses opcodes 5/6/7 to characterize a single steady-state burst: flush passes, recomputes per node, effects enqueued vs short-circuited. Exports `burstDagScenario` for a steady-state allocation gate, and `multiPassProbe` for a controlled two-effect write-back that forces a `passes > 1` case so the opcode dispatch can be smoke-tested where multi-pass actually occurs. `pull-stress.mjs` (`npm run profile:pull`) is the pull-path companion: binary-searches the exact recursive-pull depth limit (the ~5,000-computed bound named in the roadmap, pinned to a number for the current engine), sweeps cold cost per level across depths to flag any superlinear bookkeeping, and confirms cached reads are O(1) regardless of depth (the 1.1.4 `markEpoch` short-circuit holds). Exports `pullStressScenario` for steady-state gates and `probeOverflow` for the bisection alone; supports both `--kind=callable` and `--kind=box`, which surface a real engine difference (box pulls overflow earlier because `box.get()` adds a prototype-method frame per level). Both import only `./Signal.js` + the public `onGraphMutation` hook, so the same files run against any engine build (point `Signal.js` at 1.5.x to compare without the counters). Neither is part of `npm test` or the published tarball -- they ship in source for reproducibility.
489
+ **Characterization harnesses (`harness/burst-dag.mjs`, `harness/pull-stress.mjs`).** Two standalone harnesses in `harness/` that exercise the 1.6.0 instrumentation against the engine's two main hot paths. `burst-dag.mjs` (`npm run profile:burst`) reproduces Andrii's verbatim strided burst generator (`base = (node*13 + layer*17) % prevW`, `staticFraction = 1`, per-batch pull reads -- his real *layered burst flush warm* shape) and runs it head-to-head against the earlier contiguous-window guess it embeds, using opcodes 5/6/7 plus `stats().flushPasses` to report flush passes, recomputes per node, and per-burst us. The strided topology recomputes ~2x the nodes at ~26% higher us/burst, both single-pass -- so the burst gap is **locality, not redundancy** (ROADMAP S5 closed). It takes the engine path as an argument; the contiguous guess it replaced, with its `burstDagScenario` / `multiPassProbe` exports, is archived in `harness/attic/`. `pull-stress.mjs` (`npm run profile:pull`) is the pull-path companion: binary-searches the exact recursive-pull depth limit (the ~5,000-computed bound named in the roadmap, pinned to a number for the current engine -- **4096** on this one, overflow at 4097), sweeps cold cost per level across depths to flag any superlinear bookkeeping, and confirms cached reads are O(1) regardless of depth (the 1.1.4 `markEpoch` short-circuit holds). Exports `pullStressScenario` for steady-state gates and `probeOverflow` for the bisection alone; supports both `--kind=callable` and `--kind=box`, which surface a real engine difference (box pulls overflow earlier because `box.get()` adds a prototype-method frame per level). `pull-stress` imports only `../Signal.js` + the public `onGraphMutation` hook and `burst-dag` takes an engine path, so both run against any engine build. Neither is part of `npm test` or the published tarball -- they ship in source for reproducibility.
489
490
 
490
491
  ### onCleanup
491
492
 
@@ -1156,14 +1157,91 @@ Yes, if your computeFn reads its deps in the same order each invocation. The `cu
1156
1157
 
1157
1158
  ---
1158
1159
 
1160
+ ## Test harnesses
1161
+
1162
+ Everything under `harness/` is a measurement instrument or a gate. None of it is
1163
+ in `npm test` and none of it is in the published tarball -- it ships in source so
1164
+ every number in this README can be reproduced or falsified.
1165
+
1166
+ ### `harness/` -- run-on-demand probes
1167
+
1168
+ One dispatcher (`harness/run.mjs`) routes them; each keeps its own node flags, and
1169
+ paths resolve from the dispatcher so the working directory never matters.
1170
+
1171
+ ```bash
1172
+ npm run harness:smoke # 1.7 flushStrategy semantics (eager/sab/manual) -- ASSERTS
1173
+ npm run harness:field # verify + cold-child A/B bench (fieldkit)
1174
+ npm run harness:dispose # creation cost: signal() vs signalBox() vs alien
1175
+ npm run harness:churn # topology-churn-per-recompute (1.11 cone-cache gate)
1176
+ npm run harness:owner # async-gap owner-recycling hazard verdict
1177
+ npm run harness:creation # per-framework createComputations matrix
1178
+ npm run harness:perf # sBench update-group shape: eager vs sab
1179
+ npm run harness:toe # cross-version sweep (needs the private engines/ dir)
1180
+ npm run harness:all # smoke + field + dispose + churn, in sequence
1181
+ npm run profile:burst # burst shape: Andrii strided vs contiguous guess
1182
+ npm run profile:pull # pull depth: per-level cost + exact overflow point
1183
+ ```
1184
+
1185
+ `harness:smoke` runs first in `harness:all` and in `npm run verify` because it is
1186
+ the only probe that **asserts**: it fails loudly if `eager` / `sab` / `manual`
1187
+ stop behaving as specified, so a broken engine is caught before the long timed
1188
+ probes spend twenty minutes measuring it.
1189
+
1190
+ `owner-hazard-repro.mjs` is the reproducer cited in the `getOwner` / `runWithOwner`
1191
+ notes (`VERDICT: SAFE` on the shipping engine, `VERDICT: CORRUPTED` on a raw-pointer
1192
+ sketch). `churnprobe.mjs` reads link churn off `onGraphMutation` (opcodes `3`/`4`),
1193
+ not `stats()`, so it reports gross retracking that a net `activeLinks` gauge would
1194
+ hide. `retracking.difftest.mjs` is a differential fuzzer: point it at a previously
1195
+ shipped engine and it asserts both builds agree on every write across thousands of
1196
+ value-dependent topology flips. `dispose` and `creation` compare against
1197
+ `alien-signals`, which is **not** a declared dependency -- without it, `dispose`
1198
+ runs the two lite columns only (`npm i -D alien-signals` unlocks the rest).
1199
+ Settled one-off probes are parked in `harness/attic/`, wired into nothing.
1200
+
1201
+ ### `harness/toe-to-toe/` -- cross-version sweep
1202
+
1203
+ Every shipped and in-flight engine measured against every other, in cold
1204
+ processes, on one host -- the tool that separates "1.N got faster" from "the
1205
+ machine got hotter". It fixes three defects in its predecessor: sequential
1206
+ ordering (which made three sha256-*identical* propagation bodies appear to trend
1207
+ across 1.9 -> 1.11 -- a pure thermal artifact) is now round-robin; a `1.6.0-sentinel`
1208
+ column detects mid-run drift; and the silent corrupter -- where only `v17` actually
1209
+ received `flushStrategy: "sab"` while later engines were *labelled* sab and
1210
+ batch-wrapped but built **eager** -- is fixed so the mode decides.
1211
+
1212
+ Its `engines/` directory is **gitignored**: several snapshots are unreleased, so the
1213
+ sweep *script* is public and versioned while the engine source is not. A fresh clone
1214
+ cannot run `harness:toe` until the snapshots are restored. See
1215
+ `harness/toe-to-toe/README.md`.
1216
+
1217
+ ### `harness/VersionMatrix/` -- the publish gate
1218
+
1219
+ Cold-process-per-version performance regression gate, wired as `prepublishOnly`.
1220
+ Refuses to render a verdict at all when a capture's rep-to-rep spread exceeds
1221
+ `maxSpreadPct` (**NO EVIDENCE -- RECAPTURE**) rather than mistaking host noise for
1222
+ a regression. Run `npm run calibrate` inside it to measure self-noise before
1223
+ touching any tolerance; tolerances must sit above measured noise, and a hot or
1224
+ thermally-throttling laptop will blow the spread guard long before it blows a
1225
+ tolerance.
1226
+
1227
+ ### `harness/ProfilerTools/` -- version-portable hardening suite
1228
+
1229
+ Wired as `npm run test:harness`.
1230
+
1231
+ ---
1232
+
1159
1233
  ## npm scripts
1160
1234
 
1161
1235
  ```bash
1162
1236
  npm test # behavior suite, ~1.3s
1163
1237
  npm run test:gc # zero-gc suite, requires --expose-gc, ~3s
1238
+ npm run test:harness # profiler-tools hardening suite
1164
1239
  npm run bench # comparative benchmark vs alien-signals (results.txt), ~5min
1165
1240
  npm run bench-reactive # 5-framework reactivity suite (resultsReactive.txt)
1166
- npm run verify # test + test:gc + sanity bench; gate for publish
1241
+ npm run harness:smoke # flushStrategy semantics -- asserts
1242
+ npm run harness:all # smoke + field + dispose + churn probes
1243
+ npm run gate # cold-process version-matrix regression gate (also runs on prepublish)
1244
+ npm run verify # test + harness:smoke + bench; gate for publish
1167
1245
  ```
1168
1246
 
1169
1247
  ---
package/Signal.js CHANGED
@@ -1610,6 +1610,67 @@ export function createRegistry(config) {
1610
1610
  }
1611
1611
  }
1612
1612
 
1613
+ /**
1614
+ * Capture the currently-active owner as an opaque, gen-stamped handle
1615
+ * (`undefined` if called outside any effect/computed body). Companion to
1616
+ * `runWithOwner`: capture the lifecycle scope now, restore it later --
1617
+ * typically across an async boundary. Shipped in 1.5.0-beta.2, carried
1618
+ * forward unchanged into 1.6 and 1.7.
1619
+ *
1620
+ * The handle is a `describeNode` descriptor stamped with the pool slot's
1621
+ * generation counter. It is safe to hold across async boundaries: if the
1622
+ * captured owner is disposed and its slot is subsequently recycled by an
1623
+ * unrelated effect/computed, the gen no longer matches and `runWithOwner`
1624
+ * treats the handle as stale (degrades to rooted execution). Same ABA guard
1625
+ * used by `describe` / `nodeId` / `forEachOwned` / `ownerOf`.
1626
+ *
1627
+ * The handle does NOT keep the owner alive -- it is a snapshot, not a
1628
+ * reference. Node lifetime is controlled by the owner tree, not by
1629
+ * outstanding handles.
1630
+ */
1631
+ function getOwner() {
1632
+ return currentOwner !== null ? describeNode(currentOwner) : undefined;
1633
+ }
1634
+
1635
+ /**
1636
+ * Run `fn` with `ownerHandle` as the current lifecycle owner. Effects
1637
+ * or computeds created directly in `fn` are adopted by that owner and
1638
+ * cascade-dispose when the owner re-runs or is disposed. Shipped in
1639
+ * 1.5.0-beta.2, carried forward unchanged into 1.6 and 1.7.
1640
+ *
1641
+ * Degradation semantics for handles that cannot be re-attached:
1642
+ * - `null` / `undefined` -> rooted execution (createRoot semantics for the
1643
+ * ownership axis; created children survive, caller disposes them).
1644
+ * - stale handle (owner disposed, slot recycled) -> rooted execution. Never
1645
+ * adopts into the unrelated new resident of the recycled slot; never
1646
+ * adopts into a corpse (a disposed owner whose slot is not yet recycled).
1647
+ * - handle for a live signal (not an effect/computed) -> rooted execution
1648
+ * (signals cannot own).
1649
+ *
1650
+ * Nulls the tracking observer for the duration of `fn` (the same pairing
1651
+ * as `createRoot`): reads directly inside `fn` do NOT link into any
1652
+ * enclosing observer. Inner effect/computed bodies still establish their
1653
+ * own owner + observer scopes.
1654
+ *
1655
+ * Returns whatever `fn` returns.
1656
+ */
1657
+ function runWithOwner(ownerHandle, fn) {
1658
+ const node = liveNode(ownerHandle);
1659
+ const prevOwner = currentOwner;
1660
+ const prevObserver = currentObserver;
1661
+ const prevTracking = isTrackingDeps;
1662
+ currentOwner = (node !== undefined && (node.flags & (FLAG_COMPUTED | FLAG_EFFECT)) !== 0) ? node : null;
1663
+ currentObserver = null;
1664
+ isTrackingDeps = false;
1665
+ try {
1666
+ return fn();
1667
+ } finally {
1668
+ currentOwner = prevOwner;
1669
+ currentObserver = prevObserver;
1670
+ isTrackingDeps = prevTracking;
1671
+ }
1672
+ }
1673
+
1613
1674
  /**
1614
1675
  * Create a DISPOSABLE reactive scope: an owner that ADOPTS the effects and
1615
1676
  * computeds created inside `fn`, so a single returned `dispose` tears the
@@ -1898,7 +1959,7 @@ export function createRegistry(config) {
1898
1959
  while (l !== null) { const nx = l.nextDep; fn(describeNode(l.source)); l = nx; }
1899
1960
  }
1900
1961
 
1901
- return {signal, computed, effect, signalBox, computedBox, dispose, batch, flush, untrack, createRoot, createScope, onCleanup, stats, destroy, isTracking, hasObservers, observeObservers, forEachObserver, forEachSource, forEachOwned, ownerOf, nodeId, describe, onGraphMutation};
1962
+ return {signal, computed, effect, signalBox, computedBox, dispose, batch, flush, untrack, createRoot, getOwner, runWithOwner, createScope, onCleanup, stats, destroy, isTracking, hasObservers, observeObservers, forEachObserver, forEachSource, forEachOwned, ownerOf, nodeId, describe, onGraphMutation};
1902
1963
  }
1903
1964
 
1904
1965
  // -----------------------------------------------------------------
@@ -1950,6 +2011,24 @@ export function createRoot(fn) {
1950
2011
  return defaultRegistry.createRoot(fn);
1951
2012
  }
1952
2013
 
2014
+ /**
2015
+ * Capture the currently-active owner as an opaque, gen-stamped handle
2016
+ * (undefined outside any effect/computed body). Companion to
2017
+ * {@link runWithOwner}; safe to hold across async boundaries via the
2018
+ * NODE_GEN ABA guard.
2019
+ */
2020
+ export function getOwner() {
2021
+ return defaultRegistry.getOwner();
2022
+ }
2023
+
2024
+ /**
2025
+ * Run `fn` with `ownerHandle` as the current lifecycle owner. Stale, null,
2026
+ * undefined, or non-tracker handles degrade to rooted execution.
2027
+ */
2028
+ export function runWithOwner(ownerHandle, fn) {
2029
+ return defaultRegistry.runWithOwner(ownerHandle, fn);
2030
+ }
2031
+
1953
2032
  export function createScope(fn) {
1954
2033
  return defaultRegistry.createScope(fn);
1955
2034
  }
package/llms.txt CHANGED
@@ -661,6 +661,19 @@ function dumpOwnerTree(handle, depth = 0) {
661
661
  - `bench/dispose-recycle.mjs` -- 1.2.2 targeted microbench: create/dispose/recreate cycle (the free-list invariant audit target).
662
662
  - `bench/torture/` -- crash-detection soaks: `graph-fuzzer`, `scheduler-bench`, `torture-soak`. Exit 0 iff zero errors AND post-teardown pool clean.
663
663
  - `bench/run-all.sh` + `bench/aggregate.mjs` -- cold-process-per-engine protocol + per-scenario aggregation.
664
+ - `harness/run.mjs` -- dispatcher for the run-on-demand probes (smoke, field, dispose, churn, owner, creation, perf, burst, pull, toe, all).
665
+ - `harness/smoke.mjs` -- 1.7 flushStrategy semantics (eager/sab/manual) + `flush()`; ASSERTS, so it fails loudly on a regression. First in `harness:all` and `verify`.
666
+ - `harness/perf-probe.mjs` -- sBench update-group shape, eager vs sab, per scenario.
667
+ - `harness/fieldkit.mjs` -- single-file portable verify + cold-child A/B bench across six shapes.
668
+ - `harness/churnprobe.mjs` -- topology-churn-per-recompute via onGraphMutation opcodes 3/4 (link add/sever); the 1.11 cone-cache gate.
669
+ - `harness/burst-dag.mjs` -- burst-shape characterization: Andrii's verbatim strided topology vs the contiguous guess it embeds (ROADMAP S5 closed); takes engine-path arg.
670
+ - `harness/pull-stress.mjs` -- pull-mode depth characterization: per-level cost, exact overflow depth (4096 on 1.7.0), O(1) cached-read; exports pullStressScenario/probeOverflow.
671
+ - `harness/owner-hazard-repro.mjs` -- async-gap owner-recycling hazard verdict (cited by getOwner/runWithOwner).
672
+ - `harness/retracking.difftest.mjs` -- differential retracking fuzzer; takes <reference.js> [candidate.js] and asserts both builds agree under thousands of value-dependent topology flips.
673
+ - `harness/toe-to-toe/` -- cross-version sweep (round-robin ordering, drift sentinel, capability columns). Its `engines/` dir is PRIVATE/gitignored: several snapshots are unreleased.
674
+ - `harness/VersionMatrix/` -- cold-process-per-version regression gate (wired as prepublishOnly); refuses a verdict on unstable captures (NO EVIDENCE) rather than misreading host noise as a regression.
675
+ - `harness/ProfilerTools/` -- profiler-signal x devtools composition harness (wired as test:harness).
676
+ - `harness/attic/` -- parked probes (1.2.0->1.2.1 shape hunt, the superseded contiguous burst-dag, the superseded sbench sweep); wired into nothing.
664
677
  - `demo/index.html` -- interactive visualization of the reactive graph.
665
678
 
666
679
  ## Install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.7.0-preview.0",
3
+ "version": "1.7.0-preview.2",
4
4
  "description": "Zero-GC reactive graph. Monomorphic object pool, versioned push-pull propagation, 32-bit modular versioning. Built for hot paths and long-running processes.",
5
5
  "author": "Zahary Shinikchiev <shinikchiev@yahoo.com>",
6
6
  "license": "MIT",
@@ -29,11 +29,24 @@
29
29
  "test": "node --test --test-reporter=spec",
30
30
  "test:gc": "node --expose-gc --test --test-reporter=spec",
31
31
  "test:coverage": "c8 node --test --test-reporter=spec",
32
+ "test:harness": "node --test --test-reporter=spec harness/ProfilerTools/",
32
33
  "bench": "node --expose-gc bench/benchmark.mjs",
33
34
  "bench-reactive": "node --expose-gc bench/benchmarkReactive.mjs",
34
- "profile:burst": "node --expose-gc burst-dag.mjs",
35
- "profile:pull": "node --expose-gc pull-stress.mjs",
36
- "verify": "npm test && npm run bench"
35
+ "harness": "node harness/run.mjs",
36
+ "harness:smoke": "node harness/run.mjs smoke",
37
+ "harness:field": "node harness/run.mjs field",
38
+ "harness:dispose": "node harness/run.mjs dispose",
39
+ "harness:churn": "node harness/run.mjs churn",
40
+ "harness:owner": "node harness/run.mjs owner",
41
+ "harness:creation": "node harness/run.mjs creation",
42
+ "harness:perf": "node harness/run.mjs perf",
43
+ "harness:toe": "node harness/run.mjs toe",
44
+ "harness:all": "node harness/run.mjs all",
45
+ "profile:burst": "node --expose-gc harness/burst-dag.mjs ./Signal.js",
46
+ "profile:pull": "node --expose-gc harness/pull-stress.mjs",
47
+ "gate": "node harness/VersionMatrix/pre-publish.mjs",
48
+ "prepublishOnly": "node harness/VersionMatrix/pre-publish.mjs",
49
+ "verify": "npm test && npm run harness:smoke && npm run bench"
37
50
  },
38
51
  "keywords": [
39
52
  "signal",
@@ -71,6 +84,17 @@
71
84
  "sideEffects": false,
72
85
  "devDependencies": {
73
86
  "c8": "^11.0.0",
74
- "@zakkster/lite-devtools": "^1.1.0"
87
+ "@zakkster/lite-devtools": "^1.1.0",
88
+ "@zakkster/lite-signal": "^1.3.0 || >=1.4.0-beta.0 || >=1.6.0-preview.0",
89
+ "@zakkster/lite-profiler": "^1.1.0",
90
+ "@zakkster/lite-profiler-signal": "^1.2.0"
91
+ },
92
+ "overrides": {
93
+ "@zakkster/lite-time": {
94
+ "@zakkster/lite-signal": "$@zakkster/lite-signal"
95
+ },
96
+ "@zakkster/lite-devtools": {
97
+ "@zakkster/lite-signal": "$@zakkster/lite-signal"
98
+ }
75
99
  }
76
100
  }