Skip to content

P0-S1a: Implement VfsInputStream & VfsOutputStream (wasmtime-wasi-io) #80

@mconcat

Description

@mconcat

P0-S1a: Implement VfsInputStream & VfsOutputStream (wasmtime-wasi-io)

Background

We are integrating a Virtual Filesystem (VFS) with WASI Preview 2 so contracts perform std::fs operations that persist to a Merkle KV store. Current state (per internal status and PR #78):

  • Our host exports wasi:filesystem/* and non-FS subsystems; components instantiate successfully.
  • Descriptors, preopens, open_at (files/dirs), directory iteration, mkdir/unlink/rename/rmdir(empty), and set_size are implemented.
  • Streams (wasi:io/streams, io:poll) are not implemented; read_via_stream/write_via_stream return Unsupported.

This sub-issue delivers the concrete stream types to back file I/O over the VFS.

Goal

Implement VFS-backed InputStream and OutputStream types that satisfy wasmtime-wasi-io traits and operate on our file descriptors, enabling buffered read/write semantics with an internal offset.

Design

  • Define host-side types:
    • VfsInputStream { fd: u32, offset: u64, ctx: Weak<VfsCtx> }
    • VfsOutputStream { fd: u32, offset: u64, ctx: Weak<VfsCtx>, append: bool }
  • Implement wasmtime_wasi_io::streams::InputStream and OutputStream:
    • Input: read(size) -> Bytes, copy from file contents at offset, advance offset; EOF => empty bytes.
    • Output: write(bytes), apply to the per-execution overlay at offset (or end if append), advance offset. flush() no-op for P0.
  • Error mapping: surface I/O errors as StreamError; descriptor validation errors bubble via the binding call sites.
  • Determinism: do not read external time/random; deterministic overlay updates only.

Constraints

  • WASI Preview 2, wasmtime 34.x.
  • Do not fork wasmtime-wasi; use public wasmtime-wasi-io traits.
  • These objects will later be boxed into the resource table by binding fns (see S1b).

Acceptance Criteria

  • Stream types compile and can be constructed in tests with a stubbed context.
  • Input returns bytes and empty on EOF; Output writes bytes and advances offset.
  • Unit tests cover offset behavior and basic error flows.

Non-Goals (P0)

  • Poll/readiness beyond always-ready (handled in S1c).
  • Direct preview2 read/write syscalls (we keep them Unsupported).

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions