Skip to content

[stats] use the Native runtime weak-reference hierarchy - #1949

Merged
fwbrasil merged 1 commit into
mainfrom
fix/native-weak-references
Sep 18, 2026
Merged

fwbrasil merged 1 commit into
mainfrom
fix/native-weak-references

Conversation

@DamianReeves

@DamianReeves DamianReeves commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The JavaScript WeakReference shim was also compiled for Scala Native, shadowing its runtime implementation. That broke reference casts and inherited thread-local copying, including the runtime stack-unwinding buffers.

Solution

Restrict the shim to JS and Wasm. Add regressions for clearing references, replacing cleared registry entries, and child-local inheritance. Enable Native machine-metric readback tests and remove the scheduler tests' exception suppression.

Notes

Validated on this standalone branch: 282 registry tests across JVM, Native, JS, and Wasm; three machine-metric tests each on JVM and Native; both README doctests; and serial scalafmtCheckAll. The three Native weak-reference regressions reproduced the original defects before the fix.

Extracted from #1868 so the filesystem stack can be reviewed independently.

Rebased onto 6d50eecae on September 17. Revalidated all 282 registry tests across JVM, Native, JS, and Wasm, plus six machine-metric tests across JVM and Native. The previous Linux JVM CI failures are addressed separately in #1953 and #1954.

@@ -10,35 +10,20 @@ import kyo.scheduler.util.Threads
* same process. The returned executors ignore shutdown calls to prevent accidental closure by test cleanup code.
*/
object TestExecutors {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the workaround for the Native bug fixed here. Our JS WeakReference shim was being compiled into Native without extending Reference, so Native’s inherited-thread-local copy skipped childValue. Its stack-trace implementation uses that hook to allocate separate unwind buffers for each child thread; skipping it left threads sharing those buffers and could crash in libunwind.

Using Native’s real weak-reference hierarchy restores that copy. StatsRegistryWeakReferenceTest reproduces the broken hierarchy and missing childValue call before the fix. With the suppression removed, the scheduler suites pass (215 JVM tests and 213 Native tests). Keeping the handlers would continue swallowing uncaught test exceptions, including globally on JVM.

Restrict the strong-reference shim to JS and Wasm. Native needs its
runtime Reference hierarchy for registry reads and inherited thread-local
copies. Restore Native readback tests and uncaught exception reporting.
@DamianReeves

Copy link
Copy Markdown
Collaborator Author

Rebased onto main at 6d50eecae. #1950 and #1951 were restacked in the same atomic push, with their patches unchanged.

The two previous Linux JVM failures led to separate fixes:

  • [ui] synchronize teardown subscription assertions #1953 corrects the UI test's synchronization. Its render counter advances before the observer registers its next waiter; a gated reproduction consistently observed zero where the old check expected one.
  • [core] retain resource cleanup across acquisition interrupts #1954 fixes a resource leak in Scope.acquireRelease, which also backs Fiber.init. Interrupting the final acquisition step could leave one acquired resource with zero releases. This independently reproduces a defect consistent with the SQL cancellation failure; the CI log alone cannot establish the exact interleaving.

Both fixes pass their focused tests on JVM, JS, Native, and Wasm. The core fix also passes all 1,756 active JVM core tests, 681 JVM kernel tests, and 21 SQL cancellation tests.

On this PR's rebased head, all 282 registry tests and six machine-metric tests passed locally. GitHub checks and the release probe have passed; the build matrix is still running.

fwbrasil pushed a commit that referenced this pull request Sep 18, 2026
The UI teardown test could observe the second render before its callback
returned and before `Signal.observe` registered its next waiter. That
made the exact one-waiter assertion race with valid observer progress,
as seen in [#1949's Linux x64 JVM
job](https://github.com/getkyo/kyo/actions/runs/35183452786/job/105080376925).

Gate the second callback with promises and assert that no next waiter
exists while it is blocked. After releasing it, wait for registration
before asserting exactly two renders and one waiter. Freeze the observer
clock so periodic repair passes cannot change the waiter count during
this check.

Validation: the gated reproduction failed with exactly zero waiters
where the original check expected one. The corrected
ReactiveUITeardownTest passes on JVM, JS, Native, and Wasm, eight tests
on each target. One existing ignored test remains unchanged. The
subscription fiber is scoped so a failed assertion also cleans it up.
@fwbrasil
fwbrasil merged commit 0742023 into main Sep 18, 2026
10 of 14 checks passed
@fwbrasil
fwbrasil deleted the fix/native-weak-references branch September 18, 2026 16:55
fwbrasil added a commit that referenced this pull request Sep 18, 2026
Main's #1949 and this branch fixed the Native WeakReference stand-in the same way and each added a test for it.
Main's file is kept; the one leaf it lacked, ThreadLocal entries surviving the thread's table growth (the symptom
the stand-in produced), moves into it, and the branch's duplicate file goes.

Unverified: kyo-stats-registry tests on JVM and Native after this change, run with the post-merge validation.
fwbrasil added a commit that referenced this pull request Sep 20, 2026
29 commits from main, 74 conflicted paths. Every conflict was resolved against the
merge base rather than by taking a side: 68 of the 134 hunks had one side changed
only by a reformat, which the base makes checkable; the other 66 were decided by
reading what each side actually did.

The decisions worth recording:

- The Wasm platform stays retired. main added six modules (kyo-sql-dolt-api,
  kyo-sql-dolt, kyo-sql-sqlite-driver, kyo-sql-sqlite, kyo-sql-doltlite,
  kyo-system-doltfs) with a WasmPlatform leg and a kyoWasm aggregate entry. Each
  leg folds into the JS project: main states Node's environment once per platform,
  this branch states it once as kyoNodeEnv and both rows build their jsEnv from it.
  All six also get an explicit browser-row decision, which they had never been
  through: every one of them reaches an engine through koffi or a socket, so none
  runs in a page.

- kyo-stats-registry's WeakReference shim moves to js/. main's #1949 restricted it
  from js-native-wasm to js-wasm because compiling the JS shim for Native shadowed
  the runtime's own, breaking reference casts and thread-local inheritance. With
  the Wasm twins retired, js/ is the root that means exactly "JS and its Wasm row",
  so that fix is preserved rather than reverted by the rename.

- kyo-pod's runtime detection: main's version wins whole. Both branches fixed the
  same bug (a podman machine installs /var/run/docker.sock as a symlink, so the
  path heuristic answered "docker" against a podman daemon); main's carries the
  container-leak evidence for why the answer is recorded on the same instance.

- main's availableProcessors reaches the JS side through PlatformJs.nodeBuiltin and
  PlatformJs.jsGlobal instead of a bare `require`/`navigator` read, and its suite's
  static @jsimport("node:os") becomes a call-time lookup. kyo-system runs a browser
  row, where a hoisted node: import fails the bundle before any gate is consulted.

- kyo-sql's type table keeps main's SQLite column and this branch's Currency row:
  java.util.Currency no longer has a Column instance, kyo's Currency does.

- The README keeps this branch's six platform columns and gains main's four new
  module rows, with no Browser mark, matching their kyoBrowserRow above.

Verified with a loss audit over all 74 paths: every line either side added that is
absent from the result was re-read and is a deliberate supersession.

Unverified at commit time: nothing has been compiled or run yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants