Skip to content

feat(wasm-abi): dispatch generated async operations through poll, yield, and cancellation #37

Closed

Description

@zackees

Parent: #16. Depends on #36's versioned generated core-ABI contract and consumes #15's private threaded-root execution substrate.

Scope

Implement the generated Wasmtime async-operation lifecycle for the v1 ABI using exactly one caller-provided kernal_api::async_engine::RuntimeHandle. Replace any ambient Tokio use and fp-bindgen's former AsyncValue callback model: generated imports submit/poll/yield/cancel through the explicit kernal-api runtime handle and private dispatcher only. Add only one synthetic semantic operation: clock/yield completion. It proves request creation, guest suspension, native completion, generated poll/resume, cancellation, and one terminal result without granting clock, filesystem, network, process, or platform authority.

The guest facade exposes an idiomatic semantic future/result surface. It may yield or be polled; it does not expose packet pointers, Wasmtime futures, Tokio tasks, callbacks, or runtime handles. The host dispatch maps generated operation IDs to private native work and resumes only the Store/Instance that owns the request. It must not construct a runtime or re-enter a Store concurrently.

Define one terminal-winner state machine for completion, cancellation, timeout, trap, close, thread exit, and sketch teardown. Late native completions are ignored/reclaimed deterministically.

Safety and identity invariants

  • Every operation ID is generation-tagged and scoped to one logical sketch plus its authorized capability context. A stale/raw/forged ID cannot address a reused operation slot.
  • No Store, Instance, Caller, guest pointer/reference, resource-table borrow, mutex guard, or DashMap guard may survive an await, yield, native completion handoff, cancellation callback, or guest re-entry.
  • Native completion never moves a Store/Instance across a native thread and never executes guest code while that Store is active.
  • Bounded pending-operation quota is enforced before scheduling.
  • The exact generated ABI is the only operation path; no direct test-only host call, ambient Tokio callback, old AsyncValue, or handwritten guest import.
  • Public result/error types are semantic and bounded; private dispatcher/backend errors never leak.

Non-goals

No resource handles, blobs, streams, raw clocks, real timers, Tauri, filesystem, output capability, broad WASI, worker containment, or blocking std adapters.

RED → GREEN

  • RED: a generated guest fixture has no operation capable of suspending/resuming through the host and no typed terminal-race behavior.
  • RED: fixtures characterize forbidden direct/re-entrant Store execution, retained pointer/guard across yield, stale operation ID, and duplicate terminal completion.
  • GREEN: a generated root guest invokes synthetic yield/clock, returns Pending, resumes from native completion, and completes through the generated facade and explicit RuntimeHandle.
  • GREEN: cancellation wins against completion in both orderings; exactly one typed terminal result is observed and late completion cannot re-enter guest code.
  • GREEN: timeout/trap/thread-exit/sketch teardown cancel outstanding operations and return pending-operation counters to zero.
  • GREEN: quota exhaustion rejects before scheduling with a facade-owned error.
  • GREEN: instrumentation records operation ID, logical sketch scope, generation, suspend/resume count, terminal reason, and pending count without backend leaks.
  • GREEN: root-only execution proves no illegal Store re-entry, deadlock, ambient callback/runtime, or second kernel runtime. Do not substitute a native/mock child-thread test: a separate-guest-thread proof is deferred until feat(wasm): bootstrap owned threaded guest instances #35 is complete.
  • GREEN: default-feature isolation remains intact.

Platform and deliverables

Compile Linux/macOS/Windows x86-64/ARM64; run native focused root proof where supported. Deliver private dispatcher/state machine, generated synthetic-operation facade, race fixtures, teardown/instrumentation tests, and Soldr-only commands.

Dependencies and closure

Activity

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

    @zackees
    CollaboratorAuthor

    Closed as completed. Main now has the single RuntimeHandle-backed generated submit/poll/yield/cancel lifecycle with generation-scoped ownership, quotas, terminal cleanup, and real threaded guest coverage. PR #151 fixed the scheduler-first deferred-close race and its cancellation winner rule; focused hub and real artifact proofs pass.

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