Skip to content

fix(wasmtime): correctly handle input-stream - #1568

Merged
rvolosatovs merged 9 commits into
mainfrom
fix/wasi-input-stream
Oct 23, 2026
Merged

rvolosatovs merged 9 commits into
mainfrom
fix/wasi-input-stream

Conversation

@rvolosatovs

Copy link
Copy Markdown
Member

No description provided.

@rvolosatovs
rvolosatovs force-pushed the fix/wasi-input-stream branch 2 times, most recently from a3f3f9e to 56067c5 Compare October 23, 2026 11:09
Data received after the end of a pending future or stream value is a
protocol violation by the peer rather than a closed pipe.

Assisted-by: claude:claude-opus-5-5
`copy_io_error` and `receiver_closed` are not specific to framing and are
used by the value codec as well, while `encode_ready_bytes_header` is
shared by the value codec and the packer. Prefix the error constructors
with `error_` to make their purpose apparent at call sites.

Assisted-by: claude:claude-opus-5-5
Report the outcome of receiving a pending `stream<u8>` decoded by
`StreamDecoderRead` to the reader once all chunks are read, so that e.g.
a truncated stream, or one whose receiving future was dropped, is no
longer observed as a clean end of stream. The outcome is sent on a
dedicated channel, so reporting it never waits for the reader.

Assisted-by: claude:claude-opus-5-5
Add a `MAX_READY` const generic parameter (`usize::MAX` by default)
limiting the number of bytes read from the stream when encoding, any
remaining bytes are then transmitted asynchronously. Make
`READ_CHUNK_SIZE` public.

Assisted-by: claude:claude-opus-5-5
@rvolosatovs
rvolosatovs force-pushed the fix/wasi-input-stream branch 3 times, most recently from 406f786 to 1216f05 Compare October 23, 2026 11:29
@rvolosatovs
rvolosatovs enabled auto-merge October 23, 2026 11:30
`wasi:io/input-stream` resources are transmitted as `stream<u8>`, which
is encoded as `variant { pending, ready(list<u8>) }`, but the codec
neither wrote nor read the status byte.

Since the Rust encoder inlines streams that are already finished as
`ready`, the decoder read nothing from the async sub-stream and left the
inlined bytes unprocessed, e.g. the `streams-io` example counted 0 bytes.
The encoder omitted the `pending` byte, so other implementations failed
to decode `input-stream` results.

Encode `input-stream`s via `wrpc-transport`'s `StreamEncoderRead`, which
inlines at most `READ_CHUNK_SIZE` bytes of finished streams as `ready`,
and back decoded `ready` streams by a `MemoryInputPipe`.

Assisted-by: claude:claude-opus-5-5
A pending `input-stream` whose sub-stream ended before the empty
end-of-stream chunk was reported to the guest as a cleanly closed
stream, silently truncating the data, and data received after the
end-of-stream chunk was silently dropped. Fail the read in both cases,
matching the `wrpc-transport` stream decoders.

Decode the chunks with `CoreVecDecoderBytes` and `StreamReader`,
avoiding a copy per chunk and the `futures` compat layer.

Assisted-by: claude:claude-opus-5-5
Compute the async paths of polyfilled function results, so that pending
`input-stream`s and other asynchronous values returned by the remote are
received.

Assisted-by: claude:claude-opus-5-5
Byte streams were read in chunks of 8096 bytes, likely a typo of 8192,
which is the chunk size used by `wrpc-transport`. Export it as
`ReadChunkSize` and use it in the runtime and generated bindings.

Assisted-by: claude:claude-opus-5-5
`go run` executes the built server as a child process, so killing it
left the server running and holding the test's stdout and stderr open,
which made `cargo test` hang when its output was piped.

Build the servers into a temporary directory instead, accounting for
the platform executable suffix.

Assisted-by: claude:claude-opus-5-5
@rvolosatovs
rvolosatovs force-pushed the fix/wasi-input-stream branch from 1216f05 to 5eba7f4 Compare October 23, 2026 11:39
@rvolosatovs
rvolosatovs added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 6ae8f8e Oct 23, 2026
41 checks passed
@rvolosatovs
rvolosatovs deleted the fix/wasi-input-stream branch October 23, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant