Skip to content

feat(wasm): add killable threaded-sketch worker containment #28

Closed

Description

@zackees

Context

Final implementation child of #15, following #25, #26, and #27, and required by #13/#14. Threaded Wasm shutdown cannot be considered safe until a timeout, trap, or host shutdown can terminate every guest thread even when an in-process atomic wait cannot be interrupted reliably.

Depends on

Proposal

Run untrusted threaded sketches behind a private killable worker-process boundary on Windows, Linux, and macOS. The parent owns process launch, lifecycle, deadline/cancellation authority, crash/trap observation, and final cleanup. The worker owns one logical sketch execution; it is not a second guest-visible kernel runtime.

Use existing facade-owned process/lifecycle mechanisms where applicable, keep raw process/IPC/backend types private, and design the host-worker control protocol only around lifecycle commands/events needed for this proof. A normal in-process fast path may be considered later only after blocked atomic-wait interruption is demonstrably reliable; it is not part of this issue.

Invariants

  • Killing the worker terminates every guest thread and releases worker-owned memory/resources.
  • The parent retains one facade-owned kernel runtime; worker thread startup must not create an additional runtime per guest thread.
  • Cancellation, deadline, trap, host shutdown, and parent death have deterministic terminal handling.
  • Process, IPC, engine, Store, and platform backend types remain private. No ambient filesystem/network/process authority is added to the guest.
  • default = [] neither resolves nor compiles worker/engine dependencies.

Non-goals

  • Async resource ABI, streams/blobs/output, Tauri, screenshots, or application policy.
  • General remote worker/daemon architecture, durable broker protocol, or a public worker API.
  • Claiming in-process atomic-wait interruption is solved.

Acceptance criteria

  • RED: a regression fixture proves an in-process blocked/looping threaded guest cannot yet be trusted to release every thread/resource solely through normal cancellation.
  • RED: fixtures show current host teardown lacks a cross-platform killable containment proof.
  • GREEN: feature-gated worker launch runs the feat(wasm): add threaded Rust guest and owned thread bootstrap #26 threaded sketch on Windows, Linux, and macOS through private facade-owned lifecycle plumbing.
  • GREEN: parent cancellation, deadline, guest trap, and host shutdown terminate the worker and every guest thread within a documented bounded interval.
  • GREEN: parent/worker death paths leave no orphan worker, guest thread, temporary control artifact, accounted memory, or registered host resource.
  • GREEN: worker exit yields facade-owned typed terminal diagnostics distinguishing normal exit, cancellation, deadline, trap, and forced containment.
  • GREEN: feat(wasm): add scheduling limits and teardown instrumentation #27 instrumentation proves the final live resource/accounting counters are zero after every terminal path.
  • GREEN: a repeated stress regression covers normal completion, blocked atomic-wait/loop fixture, trap, timeout, and cancellation without leaking descendants.
  • GREEN: focused build/test coverage exists for Linux, macOS, and Windows x86-64/ARM64; native runtime evidence identifies actual executed architecture.
  • GREEN: soldr cargo test --locked --no-default-features remains free of worker/engine dependencies.

Deliverables

  • Private cross-platform worker containment implementation.
  • Lifecycle control/event protocol limited to the containment proof.
  • Trap/cancel/deadline/parent-death cleanup tests and instrumentation.
  • Focused Soldr documentation and platform coverage record.

Decisions

  • Worker containment is required before untrusted threaded sketches are treated as teardown-safe.
  • This is deliberately private and minimal: it does not hoist a generic broker-daemon pattern or change application payloads.

Related issues

Activity

  1. added
    enhancement
    on Aug 27, 2026
  2. zackees commented on Aug 27, 2026

    @zackees
    CollaboratorAuthor

    #28 v1 worker-boundary decision\n\nUse an explicitly configured kernal-wasm-worker executable path in v1. The worker is feature-gated as wasm-sketch-worker -> wasm-sketch-host; default = [] and ull remain free of it.\n\nThe first PR is deliberately narrow:\n\n- private, versioned, bounded stdin/stdout framing; one request per worker and one logical sketch (all guest threads) entirely inside that worker;\n- no capability proxies, streams, worker cache, sibling/extracted discovery, or release-install policy yet; those are follow-ups with #16/#17;\n- parent selects cancellation/deadline winner, sends cooperative cancel, waits a bounded grace period, then terminates the worker tree and reaps it; forced blocked execution remains the existing facade ContainmentRequired;\n- #44 remains the characterization evidence for host-block/atomic-wait containment; #28 supplies production supervisor/reap behavior.\n\nLater release assets should mirror kernal-symbolize for Linux/macOS/Windows on x86-64 and ARM64. Before Windows implementation, confirm Job Object assignment occurs before the worker can run/spawn descendants (assign-before-resume or equivalent). On macOS, validate the existing owner-death supervisor semantics and its failure/acknowledgement caveat before treating it as tree-containment proof.\n\nThis issue stays open pending those prerequisites and the worker protocol/supervisor implementation.

  3. zackees commented on Aug 27, 2026

    @zackees
    CollaboratorAuthor

    Foundation landed in #52 (squash f745dcff4e2874170b779c510c698258aee90055). #28 remains open for the exact Cargo-built #26 Rust std::thread/DashMap guest through the worker and native macOS runtime evidence; this PR only established the worker containment/protocol foundation.

  4. zackees commented on Sep 13, 2026

    @zackees
    CollaboratorAuthor

    Progress on the parent-death acceptance gap: commits 1ad7bbb and 26850c2 add a macOS-only external worker proof and make the shared smoke scripts run it on every native host. The proof launches the real worker through the inner-parent harness, validates identity with proc_pidinfo start timestamps, registers an EVFILT_PROC/NOTE_EXIT kqueue watch, revalidates identity after registration, then releases the parent and requires that retained lifecycle watch to fire. It does not use a bare PID cleanup signal.

    The initial current-head run 34788940497 passed the exact external gate on native Linux x86-64 and Windows x86-64, but both Apple lanes exposed a test-only hand-written proc_bsdinfo ABI mismatch before worker marker publication. Commit d4ff920 replaces it with libc’s canonical ABI definitions. Replacement run 34789618582 then passed screenshot/admission and exact containment on Linux x86-64/ARM64, macOS ARM64, and Windows x86-64/ARM64. Intel macOS passed all 16 screenshot/admission tests but its real Cargo artifact completed in about 12.7 seconds against an 8-second smoke deadline, so the smoke misclassified normal execution as DeadlineExceeded before the external proof. Commit 0b96bb9 raises only that real-artifact smoke to a 20-second execution deadline inside a 30-second outer bound; ordinary containment tests retain their strict 10-second bound. Replacement run 34790621949 is validating that narrow correction. The shared script verifies the one test is registered, then requires one passed and zero ignored. Cross-target checks pass for both Apple targets, with strict Clippy for Apple ARM64.

  5. zackees commented on Sep 13, 2026

    @zackees
    CollaboratorAuthor

    Follow-up evidence: the narrow artifact-startup adjustment in 0b96bb9 is validated by run 34790621949, whose Native screenshot (x86_64-apple-darwin) job completed successfully. It passed native-host identity, actual Rust screenshot-guest build, offline admission/screenshot proof, and native parent-death containment.

    The 20-second worker deadline and 30-second outer bound apply only to the real artifact case that had measured roughly 12.7 seconds of Intel macOS startup; ordinary containment cases retain their original 10-second outer bound.

  6. zackees commented on Sep 14, 2026

    @zackees
    CollaboratorAuthor

    The same run 34790621949 also completed Native screenshot (x86_64-pc-windows-msvc) successfully, including actual Windows guest build, offline admission/screenshot proof, and Windows parent-death containment. The separate rust-native (windows-latest) failure is limited to the already-tracked compiler-session PermissionDenied job-object behavior in running-process#1207; it occurs after the screenshot proof and is not a containment-test failure.

  7. zackees commented on Sep 14, 2026

    @zackees
    CollaboratorAuthor

    Final status for run 34790621949: every native screenshot/containment and archive lane completed successfully, including Windows ARM archive. The run’s sole failed job was rust-native (windows-latest), limited to the two compiler-session spawn rejections already tracked in running-process#1207. No containment or archive proof failed.

  8. zackees commented on Sep 14, 2026

    @zackees
    CollaboratorAuthor

    Completed by PR #153 (merge fddd176). The private cross-platform worker containment protocol, typed terminal outcomes, trap/cancel/deadline/parent-death cleanup coverage, and six-target native proof lanes landed. Run 34801708129 passed every containment lane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions