Skip to content

Stream playground runs with a Stop button, dropping the 5 s hard kill - #33

Merged
baijum merged 1 commit into
mainfrom
claude/github-issue-32-pr-658876
Aug 23, 2026
Merged

Stream playground runs with a Stop button, dropping the 5 s hard kill#33
baijum merged 1 commit into
mainfrom
claude/github-issue-32-pr-658876

Conversation

@baijum

@baijum baijum commented Aug 23, 2026

Copy link
Copy Markdown
Member

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).

  • Pump loopplayground-worker.js runs kaappi_step_run(budget) a chunk at a time, yielding to the event loop between chunks.
  • Streaming output — stdout/stderr flush to the page as produced (batched per chunk; per-line postMessage floods 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.
  • Stop button — a real cooperative stop (kaappi_step_stop() → the VM unwinds at its safepoint, running dynamic-wind after-thunks), replacing terminate-and-respawn. Output already produced is preserved.
  • Wall-clock backstop — a generous 30 s cooperative limit instead of a 5 s kill; kp-runner.mjs keeps 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:

  • exports present → stepped path (streaming + Stop, above);
  • exports absent → batch path — the classic blocking WASI _start, identical to today's behavior.

So this deploys safely against the current WASM (batch) and upgrades to streaming automatically once update-wasm syncs a kaappi release that ships the exports. No coordination window.

Testing

Verified in-browser (mkdocs serve) against a zig build wasm binary from core main (step exports present):

  • (display …) / result echo / error-to-stderr all match the batch output;
  • a finite 0…999 loop streams and completes (Done);
  • the classic constant-space non-terminator (let loop ((i 0)) (display i)(newline)(loop (+ i 1))) streams ticks live and stops cleanly on the Stop button (no hang, output capped with a truncation notice, buttons reset);
  • same on the tour page.

Batch fallback verified against the released v0.22.3 WASM (no step exports): feature-detect correctly selects batch and output is identical.

mkdocs build --strict passes.

🤖 Generated with Claude Code

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>
@baijum
baijum merged commit d906a55 into main Aug 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Playground: chunked/streaming execution with a Stop button (replace the hard 5 s timeout)

1 participant