Stream playground runs with a Stop button, dropping the 5 s hard kill - #33
Merged
Conversation
The playground and tour capped every run at a 5 s timeout that `terminate()`d the Web Worker and respawned it — a blunt runaway guard that also killed legitimately long-running, constant-space programs and discarded any output already produced (stdout was buffered and only posted back after completion). Drive the new bounded-step WASM entry point (kaappi#2283) instead: the worker pumps `kaappi_step_run(budget)` in a loop, flushing streamed stdout/stderr to the page between chunks, honoring a cooperative Stop button, and enforcing a generous 30 s wall-clock backstop rather than a hard kill. Output is batched per chunk (per-line postMessage floods the main thread on a fast print loop) and capped per stream so an unbounded loop can't balloon the DOM; the program itself keeps running. The worker feature-detects the step exports and falls back to the classic blocking `_start` batch path when they're absent, so the site stays deployable against the current released WASM (v0.22.3, no step exports) and upgrades to streaming automatically once `update-wasm` syncs a release that ships them. Fixes #32 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #32.
What
Replaces the playground/tour's blunt 5 s hard-timeout (which
terminate()d the Web Worker, killing legitimately long-running constant-space programs and discarding any output already produced) with cooperative, streaming execution built on the new bounded-step WASM entry point (kaappi#2283, merged in kaappi#2284).playground-worker.jsrunskaappi_step_run(budget)a chunk at a time, yielding to the event loop between chunks.postMessagefloods the main thread on a fast print loop) and are capped per stream so an unbounded loop can't balloon the DOM. The program keeps running regardless.kaappi_step_stop()→ the VM unwinds at its safepoint, runningdynamic-windafter-thunks), replacing terminate-and-respawn. Output already produced is preserved.kp-runner.mjskeeps a hard-kill timer only as a last resort for a wedged/blocking worker.Safe to merge before a core release
The released WASM the site currently fetches (v0.22.3) does not yet export the step entry point. The worker feature-detects the exports:
_start, identical to today's behavior.So this deploys safely against the current WASM (batch) and upgrades to streaming automatically once
update-wasmsyncs a kaappi release that ships the exports. No coordination window.Testing
Verified in-browser (
mkdocs serve) against azig build wasmbinary from coremain(step exports present):(display …)/ result echo / error-to-stderr all match the batch output;0…999loop streams and completes (Done);(let loop ((i 0)) (display i)(newline)(loop (+ i 1)))streamsticks live and stops cleanly on the Stop button (no hang, output capped with a truncation notice, buttons reset);Batch fallback verified against the released v0.22.3 WASM (no step exports): feature-detect correctly selects batch and output is identical.
mkdocs build --strictpasses.🤖 Generated with Claude Code