jspi: fix the dead-tools ownership bug, emscripten-6 fallout, and green the full suite on Playwright 1.62

Live-app fix (Place Footprints / routing dead in Chrome): submodule
bumps carry the coroutine ownership fix (kicad 012d95ecb4) and the
handler-exception survival fix (wxwidgets 1b5f0e31f4).

Emscripten-6 fallout:
- occ/ngspice worker wrappers: mainScriptUrlOrBlob was removed
  upstream; pthread children re-run the wrapper blob, so an em-pthread
  realm now importScripts the glue and gets out of the way (before:
  recursive service boots, pool never fills, silent 180s boot hangs —
  every occ spec and ngspice bg_run).
- Makefile.wasm: -sASYNCIFY frankenlinks on the no-wx coroutine repro
  targets ported to -sJSPI (the JSPI-only libcontext crashed at first
  yield under them); mainloop/gl repro pages drive their tick through a
  promising export (emscripten_set_main_loop callbacks cannot suspend);
  retired inject-dyncall-shims lines removed (targets were unbuildable
  since Phase 8); $stringToNewUTF8 force-included (the EM_ASM value
  bridge aborted the runtime on the first decoded exception).
- fiber-park levers: neither embind shape can drive suspending levers
  (plain throws on strict-JSPI Firefox; emscripten::async() re-executes
  its invoker on settle) — kept sync for manual Chromium probing, spec
  coverage moved to the jspi-coroutine harness (18 cases).

Suite work:
- Playwright 1.61.1 -> 1.62.1 (Firefox 153: JSPI on by default).
- fiber-resume-park.spec retired -> coroutine-lifecycle.spec: census
  gate over boot / board load / chooser open / cancel (deterministically
  red on the pre-fix build).
- Blind asyncify-era pins re-keyed: quasimodal-strand + wait-beacons
  beacon regexes, footprint-chooser-close liveness -> wx parking-timer
  heartbeat (scheduler counters idle flat on Firefox).
- occ/ngspice test providers: 60s boot timeout + worker error
  surfacing (a worker death used to be a silent 180s timeout).
- Harness pages: stale 9.99 config dir -> 10.0 (library_manager wxCHECK
  noise, chooser had no libraries).
- gal-webgl harness: missing artifacts rebuilt (boost/glm extracted to
  the host sysroot), PgmOrNull stub added for the rebased GAL.
- jspi-scheduler: clean-shutdown console line restored (app-quit
  contract), quarantine never yanks SP from a live window.

Gates: test:e2e 699 passed / 0 failed (wx-chromium, kicad-firefox,
kicad-chromium, jspi-firefox, coroutine-firefox); web ff/cr/mobile 71
passed; lint:ci-coverage 166, lint:determinism 163, screenshots
manifest 492 current, corpus 7/7, tools:contract green. Offline
screenshot baselines show expected mass drift from the engine bump —
re-baseline (screenshots:noise -> promote) is a follow-up.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016X9eh1s5sTx1o9Em9KBuwR
This commit is contained in:
Viktor Vaczi 2026-08-13 17:41:28 +02:00
commit db819850ee
31 changed files with 577 additions and 359 deletions

View file

@ -69,9 +69,14 @@ WX_JSPI_EXPORTS = main,wx_dom_event,wx_dom_mouse,wx_window_close,wx_window_move,
# deliberately stay plain.
RACES_EXTRA_LDFLAGS = -sJSPI_EXPORTS=$(WX_JSPI_EXPORTS),races_swap_once,races_park_token2,races_wdt_park_b
JSPI_SHIM = $(abspath ../../scripts/common/shims/jspi-scheduler.js)
# $stringToNewUTF8: the JSPI rejection path decodes a thrown C++ exception
# through it; without forced inclusion the reference resolves to emscripten's
# throwing stub and the FIRST throwing wx handler aborts the whole runtime
# ("native code called abort()" -> pthread mutex deadlock storm).
ASYNC_LDFLAGS = -sJSPI \
-sJSPI_EXPORTS=$(WX_JSPI_EXPORTS) \
-s "EXPORTED_RUNTIME_METHODS=['HEAPU8','HEAP8','HEAP32','ccall','stackSave','stackRestore']" \
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$$stringToNewUTF8' \
--pre-js $(JSPI_SHIM)
ASYNC_CORO_LDFLAGS = $(ASYNC_LDFLAGS)
CXXFLAGS += $(EH_FLAGS)
@ -708,7 +713,6 @@ $(S)/async-preload/async_preload_test.o: $(S)/async-preload/async_preload_test.c
$(S)/async-preload/async_preload_test.html: $(S)/async-preload/async_preload_test.o $(WX_CORE_LIB) $(JS_FILES)
$(CXX) $< $(LDFLAGS_RAYTRACE) --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
async-preload: $(S)/async-preload/async_preload_test.html
.PHONY: async-preload
@ -723,7 +727,6 @@ $(S)/raytrace-modal/raytrace_modal_test.o: $(S)/raytrace-modal/raytrace_modal_te
$(S)/raytrace-modal/raytrace_modal_test.html: $(S)/raytrace-modal/raytrace_modal_test.o $(WX_CORE_LIB) $(JS_FILES)
$(CXX) $< $(LDFLAGS_RAYTRACE) --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
raytrace-modal: $(S)/raytrace-modal/raytrace_modal_test.html
.PHONY: raytrace-modal
@ -746,7 +749,6 @@ $(S)/coroutine/libcontext.o: $(KICAD_ROOT)/thirdparty/libcontext/libcontext.cpp
$(S)/coroutine/coroutine_test.html: $(S)/coroutine/coroutine_test.o $(S)/coroutine/libcontext.o $(WX_CORE_LIB) $(JS_FILES)
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE) --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
# Nested coroutine+modal interaction harness - reproduces Asyncify rewind corruption
# when fiber swaps happen inside a wxDialog::ShowModal event loop (Issue #9153).
@ -755,9 +757,7 @@ $(S)/coroutine-nested/nested_test.o: $(S)/coroutine-nested/nested_test.cpp $(S)/
$(S)/coroutine-nested/nested_test.html: $(S)/coroutine-nested/nested_test.o $(S)/coroutine/libcontext.o $(WX_CORE_LIB) $(JS_FILES)
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE) --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
# (The trampoline-heal / handleSleep ablation variants — races_test_noheal /
# races_test_nosleepfix — were retired at doc 20 D-1 together with the legacy
@ -767,7 +767,6 @@ $(S)/asyncify-races/races_test.o: $(S)/asyncify-races/races_test.cpp $(S)/corout
$(S)/asyncify-races/races_test.html: $(S)/asyncify-races/races_test.o $(S)/coroutine/libcontext.o $(WX_CORE_LIB)
$(CXX) $^ $(LDFLAGS_RACES) $(RACES_EXTRA_LDFLAGS) --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
# Convenience targets
@ -870,15 +869,18 @@ $(S)/coroutine-pthread/libcontext_pt.o: $(KICAD_ROOT)/thirdparty/libcontext/libc
$(S)/coroutine-pthread/coroutine_test.html: $(S)/coroutine-pthread/coroutine_test_pt.o $(S)/coroutine-pthread/libcontext_pt.o $(WX_CORE_LIB) $(JS_FILES)
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD) --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread: $(S)/coroutine-pthread/coroutine_test.html
.PHONY: coroutine-pthread
# === No-wx pthread main() reproduction: fiber pattern in main + pthreads, no wxWidgets ===
# === No-wx pthread main() reproduction: coroutine pattern in main + pthreads, no wx ===
# JSPI since 2026-08-13: these pages compile the JSPI-only libcontext, so they must
# link the JSPI suspension engine (the old -sASYNCIFY/-sDYNCALLS link produced a
# frankenbuild matching no shipped configuration — instant stack overflow at the
# first yield).
LDFLAGS_COROUTINE_PTHREAD_NOWX = $(EH_FLAGS) $(DEBUG_LDFLAGS) -sALLOW_MEMORY_GROWTH -sERROR_ON_UNDEFINED_SYMBOLS=0 \
-sASYNCIFY=1 -sASYNCIFY_STACK_SIZE=65536 -sASYNCIFY_IMPORTS=['emscripten_fiber_swap'] \
-sDYNCALLS=1 -pthread -sPTHREAD_POOL_SIZE='navigator.hardwareConcurrency' \
-sJSPI -sJSPI_EXPORTS=main,pcbjam_libctx_entry \
-pthread -sPTHREAD_POOL_SIZE='navigator.hardwareConcurrency' \
-sPTHREAD_POOL_SIZE_STRICT=0 -sEXPORTED_RUNTIME_METHODS=['ccall']
$(S)/coroutine-pthread/main_repro.o: $(S)/coroutine-pthread/main_repro.cpp $(S)/coroutine/kicad_coroutine_harness.h
@ -887,7 +889,6 @@ $(S)/coroutine-pthread/main_repro.o: $(S)/coroutine-pthread/main_repro.cpp $(S)/
$(S)/coroutine-pthread/main_repro.html: $(S)/coroutine-pthread/main_repro.o $(S)/coroutine-pthread/libcontext_pt.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD_NOWX) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread-main: $(S)/coroutine-pthread/main_repro.html
.PHONY: coroutine-pthread-main
@ -899,16 +900,15 @@ $(S)/coroutine-pthread/nested_repro.o: $(S)/coroutine-pthread/nested_repro.cpp $
$(S)/coroutine-pthread/nested_repro.html: $(S)/coroutine-pthread/nested_repro.o $(S)/coroutine-pthread/libcontext_pt.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD_NOWX) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread-nested: $(S)/coroutine-pthread/nested_repro.html
.PHONY: coroutine-pthread-nested
# Nested invoke_/dynCall reproduction WITH exceptions (invoke_* boundaries, asyncify-unwindable)
# Nested invoke_/dynCall reproduction WITH exceptions (invoke_* boundaries).
# JSPI since 2026-08-13 — see the NOWX comment above.
LDFLAGS_COROUTINE_INVOKE = $(EH_FLAGS) $(DEBUG_LDFLAGS) -sALLOW_MEMORY_GROWTH -sERROR_ON_UNDEFINED_SYMBOLS=0 \
-sASYNCIFY=1 -sASYNCIFY_STACK_SIZE=65536 \
-sASYNCIFY_IMPORTS=['invoke_vi','invoke_v','invoke_ii','invoke_iii','emscripten_fiber_swap'] \
-sDYNCALLS=1 -pthread -sPTHREAD_POOL_SIZE='navigator.hardwareConcurrency' \
-sJSPI -sJSPI_EXPORTS=main,pcbjam_libctx_entry \
-pthread -sPTHREAD_POOL_SIZE='navigator.hardwareConcurrency' \
-sPTHREAD_POOL_SIZE_STRICT=0 -sEXPORTED_RUNTIME_METHODS=['ccall']
$(S)/coroutine-pthread/nested_repro_ex.o: $(S)/coroutine-pthread/nested_repro.cpp $(S)/coroutine/kicad_coroutine_harness.h
@ -921,7 +921,6 @@ $(S)/coroutine-pthread/libcontext_ex.o: $(KICAD_ROOT)/thirdparty/libcontext/libc
$(S)/coroutine-pthread/nested_repro_ex.html: $(S)/coroutine-pthread/nested_repro_ex.o $(S)/coroutine-pthread/libcontext_ex.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_INVOKE) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread-nested-ex: $(S)/coroutine-pthread/nested_repro_ex.html
.PHONY: coroutine-pthread-nested-ex
@ -930,7 +929,6 @@ coroutine-pthread-nested-ex: $(S)/coroutine-pthread/nested_repro_ex.html
# pthread workers don't crash on wx's module-eval document access.
$(S)/coroutine-pthread/coroutine_test_wxpt.html: $(S)/coroutine-pthread/coroutine_test_pt.o $(S)/coroutine-pthread/libcontext_pt.o $(WX_CORE_LIB) $(JS_FILES)
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD) --pre-js $(S)/coroutine-pthread/worker_dom_stub.js --pre-js $(JS) --shell-file $(HTML) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread-wx: $(S)/coroutine-pthread/coroutine_test_wxpt.html
.PHONY: coroutine-pthread-wx
@ -944,7 +942,6 @@ $(S)/coroutine-pthread/embind_repro.o: $(S)/coroutine-pthread/embind_repro.cpp $
$(S)/coroutine-pthread/embind_repro.html: $(S)/coroutine-pthread/embind_repro.o $(S)/coroutine-pthread/libcontext_ex.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_EMBIND) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread-embind: $(S)/coroutine-pthread/embind_repro.html
.PHONY: coroutine-pthread-embind
@ -954,25 +951,25 @@ $(S)/coroutine-pthread/mainloop_repro.o: $(S)/coroutine-pthread/mainloop_repro.c
@mkdir -p $(S)/coroutine-pthread
$(CXX) -c $(CXXFLAGS) -pthread -I$(KICAD_ROOT)/thirdparty/libcontext -I$(S)/coroutine $< -o $@
# repro_tick is the promising rAF tick export (see mainloop_repro.cpp); a LAST
# -sJSPI_EXPORTS overrides the base list.
$(S)/coroutine-pthread/mainloop_repro.html: $(S)/coroutine-pthread/mainloop_repro.o $(S)/coroutine-pthread/libcontext_pt.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD_NOWX) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD_NOWX) -sJSPI_EXPORTS=main,pcbjam_libctx_entry,repro_tick -o $@
coroutine-pthread-mainloop: $(S)/coroutine-pthread/mainloop_repro.html
.PHONY: coroutine-pthread-mainloop
# WebGL2 + coroutine reproduction (no wx, no pthreads, default shell with #canvas)
LDFLAGS_COROUTINE_GL = $(EH_FLAGS) $(DEBUG_LDFLAGS) -sALLOW_MEMORY_GROWTH -sERROR_ON_UNDEFINED_SYMBOLS=0 \
-sASYNCIFY=1 -sASYNCIFY_STACK_SIZE=65536 -sASYNCIFY_IMPORTS=['emscripten_fiber_swap'] \
-sDYNCALLS=1 -sMAX_WEBGL_VERSION=2 -sMIN_WEBGL_VERSION=2 -sEXPORTED_RUNTIME_METHODS=['ccall']
-sJSPI -sJSPI_EXPORTS=main,pcbjam_libctx_entry \
-sMAX_WEBGL_VERSION=2 -sMIN_WEBGL_VERSION=2 -sEXPORTED_RUNTIME_METHODS=['ccall']
$(S)/coroutine-pthread/gl_repro.o: $(S)/coroutine-pthread/gl_repro.cpp $(S)/coroutine/kicad_coroutine_harness.h
@mkdir -p $(S)/coroutine-pthread
$(CXX) -c $(CXXFLAGS) -I$(KICAD_ROOT)/thirdparty/libcontext -I$(S)/coroutine $< -o $@
$(S)/coroutine-pthread/gl_repro.html: $(S)/coroutine-pthread/gl_repro.o $(S)/coroutine/libcontext.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_GL) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_GL) -sJSPI_EXPORTS=main,pcbjam_libctx_entry,repro_tick -o $@
coroutine-pthread-gl: $(S)/coroutine-pthread/gl_repro.html
.PHONY: coroutine-pthread-gl
@ -986,8 +983,7 @@ $(S)/coroutine-pthread/gl_repro_pt.o: $(S)/coroutine-pthread/gl_repro.cpp $(S)/c
$(CXX) -c $(CXXFLAGS) -pthread -I$(KICAD_ROOT)/thirdparty/libcontext -I$(S)/coroutine $< -o $@
$(S)/coroutine-pthread/gl_repro_pt.html: $(S)/coroutine-pthread/gl_repro_pt.o $(S)/coroutine-pthread/libcontext_pt.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_GL_PTHREAD) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_GL_PTHREAD) -sJSPI_EXPORTS=main,pcbjam_libctx_entry,repro_tick -o $@
coroutine-pthread-gl-pt: $(S)/coroutine-pthread/gl_repro_pt.html
.PHONY: coroutine-pthread-gl-pt
@ -998,7 +994,6 @@ $(S)/coroutine-pthread/vcall_repro.o: $(S)/coroutine-pthread/vcall_repro.cpp $(S
$(S)/coroutine-pthread/vcall_repro.html: $(S)/coroutine-pthread/vcall_repro.o $(S)/coroutine-pthread/libcontext_pt.o
$(CXX) $(filter %.o %.a,$^) $(LDFLAGS_COROUTINE_PTHREAD_NOWX) -o $@
../../scripts/common/inject-dyncall-shims.sh $(basename $@).js
coroutine-pthread-vcall: $(S)/coroutine-pthread/vcall_repro.html
.PHONY: coroutine-pthread-vcall

View file

@ -135,7 +135,7 @@
// NeedsUserInput()==false and the wizard never opens — same as eeschema.html
// and pl_editor.html.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {

View file

@ -129,7 +129,7 @@
// wizard's "use defaults" path — and it never opens. Settings dir matches
// PATHS::GetUserSettingsPath() for this build.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {

View file

@ -62,7 +62,7 @@
};
// KiCad config dir baked into the WASM build (see boot.js / constants.ts).
var KICAD_CONFIG_DIR = '/home/kicad/.config/kicad/kicad/9.99';
var KICAD_CONFIG_DIR = '/home/kicad/.config/kicad/kicad/10.0';
// A lightweight subset of the tiny_tapeout demo board: enough layers/drill
// files to enable the Print action and populate the dialog's layer list,

View file

@ -127,7 +127,7 @@
// NeedsUserInput()==false and the first-run setup wizard never opens —
// same as eeschema.html / pl_editor.html.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {

View file

@ -133,7 +133,7 @@
// pcbnew.spec.ts explicitly exercises the wizard; the collab tests instead
// need a clean, wizard-free boot (like eeschema.html), hence this variant.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {

View file

@ -132,7 +132,7 @@
// NeedsUserInput()==false and the first-run setup wizard never opens —
// same as eeschema.html / pl_editor.html.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {

View file

@ -130,7 +130,7 @@
// before main() so every provider reports NeedsUserInput()==false and the
// wizard never opens — same as eeschema.html and the web app's boot.ts.
var seedKicadConfig = function() {
var cfgDir = '/home/kicad/.config/kicad/kicad/9.99';
var cfgDir = '/home/kicad/.config/kicad/kicad/10.0';
FS.mkdirTree(cfgDir);
var writeIfAbsent = function(path, contents) {

View file

@ -3,8 +3,10 @@
// KiCad's GAL renders via WebGL 2.0 in the rAF refresh, and tool coroutines activate
// during the same refresh — so the Asyncify unwind/rewind happens MID-RENDER-FRAME with
// the GL context current. This probe creates a real WebGL-2.0 context and activates the
// coroutine between GL draw calls inside an emscripten_set_main_loop(rAF) frame, then the
// coroutine yields back -> main rewinds the render frame.
// coroutine between GL draw calls inside the rAF-driven frame, then the coroutine
// yields back and the frame's promising activation suspends/resumes. (JSPI 2026-08-13:
// emscripten_set_main_loop callbacks are plain calls and cannot suspend — the frame is
// driven like the shipped app drives ticks, a JS rAF loop over a promising export.)
//
// No-wx (single-threaded first; GL+pthreads needs OFFSCREEN proxying — add later if this
// passes). Firefox should reach "[REPRO] DONE"; if system Chrome crashes before DONE, the
@ -13,6 +15,7 @@
#include "kicad_coroutine_harness.h"
#include <emscripten.h>
#include <emscripten/em_js.h>
#include <emscripten/html5.h>
#include <GLES3/gl3.h>
@ -41,8 +44,13 @@ static void run_coroutine()
std::fflush( stdout );
}
static void render_frame()
static bool g_done = false;
extern "C" EMSCRIPTEN_KEEPALIVE void repro_tick()
{
if( g_done )
return;
++g_frame;
glClearColor( 0.1f, 0.2f, 0.3f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT ); // a real WebGL2 draw call before the coroutine
@ -52,16 +60,24 @@ static void render_frame()
std::printf( "[REPRO] frame %d: activating coroutine mid-GL-frame\n", g_frame );
std::fflush( stdout );
run_coroutine(); // coroutine yields -> Asyncify rewinds the render frame
run_coroutine(); // coroutine yields -> the frame activation suspends + resumes
glClearColor( 0.3f, 0.2f, 0.1f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT ); // another GL call after the coroutine resumes
std::printf( "[REPRO] DONE\n" );
std::fflush( stdout );
emscripten_cancel_main_loop();
g_done = true;
}
}
// rAF driver over the promising tick export (each tick may suspend mid-frame).
EM_JS( void, install_raf_driver, (), {
const tick = () => {
Promise.resolve( _repro_tick() ).then( () => requestAnimationFrame( tick ) );
};
requestAnimationFrame( tick );
} );
int main()
{
EmscriptenWebGLContextAttributes attrs;
@ -73,6 +89,7 @@ int main()
std::printf( "[REPRO] start; WebGL2 context=%d\n", (int) g_ctx );
std::fflush( stdout );
emscripten_set_main_loop( render_frame, 0, 0 );
install_raf_driver();
emscripten_exit_with_live_runtime(); // main returns; rAF drives repro_tick
return 0;
}

View file

@ -1,22 +1,26 @@
// Reproduction probe #4: activate the coroutine from inside an emscripten_set_main_loop
// (requestAnimationFrame) callback — the SINGLE JS->wasm boundary KiCad actually uses
// (rAF -> callUserCallback -> iterFunc -> dynCall_v -> wasm refresh -> tool coroutine).
// The crash trace's "main-refresh ctx=#2" is exactly this. Unlike the EM_JS/embind probes,
// there is NO synchronous JS frame sitting above the coroutine — the coroutine runs in a
// wasm chain below dynCall_v, so the Asyncify rewind re-enters via dynCall_v (like KiCad).
// Reproduction probe #4: activate the coroutine from inside the rAF-driven tick —
// the SINGLE JS->wasm boundary KiCad actually uses. Asyncify-era shape: rAF ->
// callUserCallback -> iterFunc -> dynCall_v -> wasm refresh -> tool coroutine, via
// emscripten_set_main_loop. JSPI (2026-08-13): a plain main-loop callback cannot
// suspend ("SuspendError: trying to suspend without WebAssembly.promising"), and the
// shipped app doesn't use emscripten_set_main_loop anymore — wx drives rAF ticks
// through PROMISING exports (wxWasmTopLevelTick et al). This probe mirrors that: a JS
// rAF driver calls the exported repro_tick(), which is on the target's JSPI_EXPORTS
// list, so the coroutine suspends mid-tick exactly like a tool coroutine mid-refresh.
//
// No-wx + pthreads. Firefox should reach "[REPRO] DONE"; if system Chrome crashes before
// DONE, the main-loop/rAF activation is the missing factor.
// No-wx + pthreads. Both engines should reach "[REPRO] DONE".
#include "kicad_coroutine_harness.h"
#include <emscripten.h>
#include <emscripten/em_js.h>
#include <cstdio>
using coroutine_test::TestCoroutine;
static int g_frame = 0;
static bool g_done = false;
static void run_coroutine()
{
@ -26,7 +30,7 @@ static void run_coroutine()
self.Yield( 42 );
} );
bool running = co.Call( 1 ); // unwinds the main-loop callback back to dynCall_v; yields back
bool running = co.Call( 1 ); // suspends the tick's promising activation; yields back
std::printf( "[REPRO] after Call: running=%d lastValue=%ld\n",
(int) running, (long) co.LastReturnValue() );
std::fflush( stdout );
@ -36,8 +40,11 @@ static void run_coroutine()
std::fflush( stdout );
}
static void main_loop_iter()
extern "C" EMSCRIPTEN_KEEPALIVE void repro_tick()
{
if( g_done )
return;
++g_frame;
std::printf( "[REPRO] main-loop frame %d\n", g_frame );
std::fflush( stdout );
@ -49,14 +56,27 @@ static void main_loop_iter()
run_coroutine();
std::printf( "[REPRO] DONE\n" );
std::fflush( stdout );
emscripten_cancel_main_loop();
g_done = true;
}
}
// rAF driver calling the PROMISING tick export (the glue wraps every
// JSPI_EXPORTS entry with WebAssembly.promising, so each tick may suspend).
EM_JS( void, install_raf_driver, (), {
const tick = () => {
Promise.resolve( _repro_tick() ).then( () => {
if( !Module.__reproDone )
requestAnimationFrame( tick );
} );
};
requestAnimationFrame( tick );
} );
int main()
{
std::printf( "[REPRO] start; installing emscripten_set_main_loop (rAF)\n" );
std::printf( "[REPRO] start; installing rAF driver over the promising tick export\n" );
std::fflush( stdout );
emscripten_set_main_loop( main_loop_iter, 0, 0 ); // main returns; rAF drives main_loop_iter
install_raf_driver();
emscripten_exit_with_live_runtime(); // main returns; rAF drives repro_tick
return 0;
}

View file

@ -50,8 +50,11 @@ struct MiniCoro
~MiniCoro()
{
if( m_caller.ctx )
libcontext::release_fcontext( m_caller.ctx );
// Mirror of coroutine.h's ownership rule: m_callee.ctx is the one
// record we own. m_caller.ctx is BORROWED (the enterer's record or
// the root, written by jump_fcontext's symmetric protocol) — the old
// release here was the phantom-release bug the JSPI backend turned
// into a live-coroutine kill.
if( m_callee.ctx )
libcontext::release_fcontext( m_callee.ctx );
}
@ -168,6 +171,10 @@ EM_JS( int, js_dead_parked, (), {
const L = globalThis.__libctxJspi;
return L ? L.deadParked : -1;
} );
EM_JS( int, js_ghost_count, (), {
const L = globalThis.__libctxJspi;
return L ? L.ghosts : -1;
} );
EM_JS( void, js_schedule_resume_marker, (), {
globalThis.__timerFired = 0;
setTimeout( () => { globalThis.__timerFired = 1; }, 10 );
@ -325,10 +332,20 @@ int main()
c.Call();
c.Resume(); // finishes
bool resumed = c.Resume( 99 ); // must refuse: m_running false short-circuits
// force a backend-level ghost jump too:
// force a backend-level ghost jump too. Contract update: the ghost
// refusal must return the SENTINEL, never raw -1 — coroutine.h
// dereferences the return unconditionally, and a live COROUTINE CAN
// reach this path (a nested-dispatch partner's record dying
// mid-flight). The old "coroutine.h can't reach the raw -1" premise
// was disproven by the boot-time jumpOut OOB.
intptr_t r = libcontext::jump_fcontext( &c.m_caller.ctx, c.m_callee.ctx, 0 );
auto* sent = reinterpret_cast<INVOCATION_ARGS*>( r );
bool sentinelShaped = r != -1 && r != 0
&& sent->type == INVOCATION_ARGS::FROM_ROUTINE
&& sent->context == nullptr;
report( "resume_after_finish_does_not_reenter",
!resumed && entries == 1 && r == -1 );
!resumed && entries == 1 && sentinelShaped,
"r=" + std::to_string( (long long) r ) );
}
// 9. interleaving multiple coroutines
@ -429,6 +446,95 @@ int main()
+ " dead=" + std::to_string( deadAfter ) );
}
// 16. release of the RUNNING record is refused (legacy ~CALL_CONTEXT
// phantom-release shape): the coroutine keeps working afterwards
{
int deadBefore = js_dead_parked();
std::string order;
MiniCoro c( [&]( MiniCoro& me ) {
order += "a";
// what the old ~CALL_CONTEXT did: release the borrowed handle of
// the coroutine that is executing RIGHT NOW
libcontext::release_fcontext( me.m_callee.ctx );
order += "b";
me.Yield( 5 ); // must still park normally
order += "c";
} );
c.Call();
bool parked = c.Running() && c.YieldValue() == 5;
c.Resume(); // must still be resumable (record not killed)
report( "release_of_running_record_refused",
parked && !c.Running() && order == "abc"
&& js_dead_parked() == deadBefore,
order + " dead=" + std::to_string( js_dead_parked() ) );
}
// 17. release of a record on the ENTERER CHAIN is refused: a child body
// releasing its (running) parent must not kill the parent
{
int deadBefore = js_dead_parked();
std::string order;
MiniCoro* parentPtr = nullptr;
MiniCoro child( [&]( MiniCoro& me ) {
order += "c1";
// parent is mid-slice on the enterer chain right now
libcontext::release_fcontext( parentPtr->m_callee.ctx );
me.Yield();
order += "c2";
} );
MiniCoro parent( [&]( MiniCoro& me ) {
order += "p1";
child.Call();
order += "p2";
me.Yield(); // parent must still park fine
order += "p3";
child.Resume();
} );
parentPtr = &parent;
parent.Call();
bool mid = order == "p1c1p2" && parent.Running();
parent.Resume(); // parent record must still be alive
report( "release_of_enterer_chain_refused",
mid && order == "p1c1p2p3c2" && !parent.Running()
&& !child.Running() && js_dead_parked() == deadBefore,
order + " dead=" + std::to_string( js_dead_parked() ) );
}
// 18. destroy-while-parked quarantines WITHOUT poisoning the world:
// census +1 exactly once (double release idempotent), later jumps at
// the corpse return the sentinel, and fresh coroutines run clean
{
int deadBefore = js_dead_parked();
int stepsAfterPark = 0;
auto* victim = new MiniCoro( [&]( MiniCoro& me ) {
me.Yield();
stepsAfterPark++; // must NEVER run
} );
victim->Call();
libcontext::fcontext_t corpse = victim->m_callee.ctx;
delete victim; // release while parked mid-body -> quarantine
int deadMid = js_dead_parked();
libcontext::release_fcontext( corpse ); // idempotent second release
bool alive = libcontext::context_alive( corpse );
// a stray jump at the corpse must refuse with the sentinel
libcontext::fcontext_t from = nullptr;
intptr_t r = libcontext::jump_fcontext( &from, corpse, 0 );
auto* sent = reinterpret_cast<INVOCATION_ARGS*>( r );
bool sentinelShaped = r != -1 && r != 0
&& sent->type == INVOCATION_ARGS::FROM_ROUTINE;
// the scheduler keeps working: a fresh coroutine full lifecycle
std::string order;
MiniCoro after( [&]( MiniCoro& me ) { order += "x"; me.Yield(); order += "y"; } );
after.Call();
after.Resume();
report( "destroy_while_parked_is_contained",
deadMid == deadBefore + 1 && js_dead_parked() == deadBefore + 1
&& stepsAfterPark == 0 && !alive && sentinelShaped
&& order == "xy" && !after.Running(),
"dead=" + std::to_string( js_dead_parked() )
+ " steps=" + std::to_string( stepsAfterPark ) );
}
std::printf( "[JSPI_CORO] SUMMARY passed=%d failed=%d\n", g_passed, g_failed );
return g_failed == 0 ? 0 : 1;
}