design-b D3: fix the doc-19 hang — quasi-modals off the coroutine stack

THE BUG IS FIXED. tests/kicad/quasimodal-strand.spec.ts flips from a
test.fail() pin to a plain green regression test: 3/3 runs
closed=true dialogs=0 refused-resumes=0 (was closed=false dialogs=1
refused-resumes=1 on every run).

Mechanism: a quasi-modal's nested event loop parked on the TOOL
COROUTINE's stack, which suspends the fiber's body where the fiber layer
cannot see it — so the stale-fiber guard quarantined the fiber and then
refused its own resume, the dispatch guard was never released, and every
click after that was deferred forever. Bouncing the nested loop onto the
main stack leaves the coroutine suspended the legitimate way (a recorded
fiber swap), so nothing is quarantined and nothing is refused.

Layering, so this is not a pile of WASM ifdefs in KiCad:
- wx (3d37db3bf1) owns the POLICY and the hook; it must not know what a
  coroutine is.
- wasm/bindings/main_stack_runner.h is the only place that may know both
  sides: it finds the frame's TOOL_MANAGER and bounces via RunMainStack.
  Header-only and self-installing, so no build-script change; included by
  every editor's binding TU.
- KiCad gets ONE ifdef-free method (2c777efede), needed only because
  TOOL_STATE is opaque outside TOOL_MANAGER. libcontext and dialog_shim
  are untouched — an earlier draft edited both and was reverted.

This also reframes the remaining plan: the doc-19 class is closed WITHOUT
migrating tool coroutines onto scheduler contexts. Note it does not make
the wait a context yield — waits still park in place, just never on a
coroutine stack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TEHGiiXMShNXbBr7gSJ7iz
This commit is contained in:
Gergő Törcsvári 2026-08-06 12:22:21 +02:00
commit 48da418f34
No known key found for this signature in database
GPG key ID: 8E75F2CDE64E5322
10 changed files with 108 additions and 17 deletions

View file

@ -310,15 +310,16 @@ test.describe("quasi-modal strand (doc 19)", () => {
).toBeGreaterThan(0);
});
test("doc-19 red: OK resolves the quasi-modal wait and the dialog closes", async ({
test("doc-19: OK resolves the quasi-modal wait and the dialog closes", async ({
page,
testLogger,
}) => {
// RED today by the doc-19 strand (aliased wake → quarantined fiber →
// refused resume → dialog never closes). Goes GREEN at D3 (waits become
// scheduler-context yields); Playwright then reports "expected to fail
// but passed" and this marker comes off.
test.fail();
// WAS RED (aliased wake → quarantined fiber → refused resume → the dialog
// could never be closed by a click). GREEN since the quasi-modal's nested
// event loop stopped running on the tool coroutine's stack: it is bounced
// onto the main stack, so the coroutine is suspended the legitimate way —
// a recorded fiber swap — instead of parking its body where the fiber
// layer cannot see it. This test is now the regression pin for that.
test.setTimeout(240000);
await bootAndOpen(page);
const { timer } = await openDialogAndEngageWindow(page);