Skip to content

feat(wasm): bootstrap real threaded guest instances over shared memory #32

Closed

Description

@zackees

Child of #26 and #15; depends on #31's real artifact/admission profile; required by #13/#14.\n\n## Scope\n\nImplement private feature-gated execution for the exact #31 artifact. Compile/prelink once. Allocate one engine-owned SharedMemory and link it as env.memory. Build a store-independent Linker and one InstancePre. Root and every guest child receive distinct Store, Instance, native stack/TLS, and execution state while sharing compiled code, same SharedMemory/heap, capability/resource registry, and one facade-owned kernel RuntimeHandle identity. No backend types become public.\n\nImplement synchronous owned wasi.thread-spawn (i32)->i32. Reserve a valid nonzero TID under a short registry lock, reject configured max/closing state with deterministic negative result and semantic diagnostic, then spawn one native worker with a fresh Store/Instance and call exported wasi_thread_start(tid,start_arg). The host treats start_arg as opaque and never holds the registry lock across instance construction, Wasm execution, or join.\n\nThe checked-in guest uses ordinary std::thread, Arc, atomics, Mutex, channel, and a deterministic DashMap-class concurrent-map proof. It exports kernal-api-run. The host reads a bounded shared-memory result and proves all child instances saw the same allocation and expected synchronization results.\n\n## RED to GREEN\n\nRED: after #31 admission succeeds, there is no host allocation/link/prelink/thread path and no evidence of shared versus per-thread state. GREEN: one compilation/prelink; root plus two real std::thread children; same memory/runtime/module identities, distinct Store/Instance/TLS identities; expected Arc/atomic/mutex/channel/map result; max-thread rejection leaks no slot; normal completion joins guest and host workers and leaves zero live registrations.\n\n## Cleanup boundary\n\nThis issue handles cooperative normal completion and bounded join only. Trap, cancellation, timeout, quotas/fuel/epoch, memory accounting, and hostile blocked atomic waits are not solved in-process here: resource/scheduling policy belongs to #27 and worker-process containment to #28.\n\n## Non-goals\n\nNo async guest resources/streams/blobs/output, filesystem/network/process capability, Tauri, screenshot orchestration, broad WASI, pooling allocator, public engine traits, or second Tokio runtime.\n\n## Decisions\n\nClone facade-owned shared references and the one RuntimeHandle into Store state; never create a Tokio/runtime per guest thread. Wasmtime InstancePre/SharedMemory API compatibility is verified against exactly pinned 45.0.0.\n\nRelated: parent #26; prerequisite #15; depends on #31; contributes to #13 and #14. WASI thread lifecycle: https://github.com/WebAssembly/wasi-threads ; Wasmtime shared memory: https://docs.rs/wasmtime/45.0.0/wasmtime/struct.SharedMemory.html

Activity

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

    @zackees
    CollaboratorAuthor

    Implemented; closing with the evidence, checked against the artifacts rather than the issue's own status.

    kernal-api — guests/threaded-smoke/src/main.rs is the ordinary-threaded-Rust guest this issue specifies: std::thread, Arc, Mutex, mpsc::channel, AtomicU32 and a dashmap::DashMap concurrent-map proof, writing a bounded 48-byte result record (REPORT_MAGIC/REPORT_VERSION/REPORT_BYTES) into the imported shared linear memory rather than exporting it, so the threaded command ABI stays closed.

    The RED→GREEN cases are cargo_built_threaded_guest_runs_inside_killable_worker, ..._commits_parent_owned_output, ..._forced_output_cleanup, ..._deadline_stops_and_releases_parent_state and real_worker_sequential_stress_leaves_no_parent_state in tests/wasm_worker_containment.rs — the last covering this issue's "zero live registrations" requirement.

    These four are a dependency chain (#15 → #26 → #32, with #14 as the end-to-end proof), and the chain is present end to end, which is why they close together rather than one at a time.

    🤖 Generated with Claude Code

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