HTTP router response body: a guest-created schema-value-stream in a returned value tree is never delivered (empty body, no error)
Upstream report: a guest-created schema-value-stream in a returned value tree is never delivered
This is the ready-to-file report for the one thing the dynamic HTTP router handler
cannot do on Golem 1.6.0 (parity item 1 in docs/golem-1.6-parity.md). The
measurements behind it are in docs/router-handler-status.md; this file is the
short, self-contained version for the Golem issue tracker.
Summary
A guest component that returns a value tree containing a stream it created itself
(golem:core/[email protected] schema-value-stream.wrap) — the documented way to put
a native stream into a schema-value-tree, and what an HTTP router's response
body is — gets no error and no delivery: the guest's write into that stream
completes, the runtime registers an output stream for it, and the items never
reach the invocation session. The client sees the response head with an empty
body. The official Rust SDK's router delivers bodies, so the runtime can do this;
the difference is in how the stream gets into the value tree.
Environment
- Golem 1.6.0 GA (
v1.6.0), local server (golem server run), single component deployed through an HTTP API,http-routerkind, mount/static. - Roc platform component (
roc-golem) built with Golem'swit-bindgenfork (wit-bindgen-golem-1.6, rev3e7d6bd6e79809b2d64a151515d51800448fab2a,wit-bindgen 0.59.0) and the component model async ABI ([task-return]invokeis present in the built component). - Control: the official Rust SDK probe (
golem-rust v3.0.0,#[http_router],AgentStream::<Vec<u8>>::new()plusspawn_localfor the write) deployed on the same server.
What happens
| SDK probe | this component | |
|---|---|---|
| client | 200, 35 bytes, clean chunked framing |
200, 0 bytes, curl reports a truncated transfer |
| oplog | StreamSession, StreamItems, StreamEnd |
StreamRegistered, StreamSession, StreamEnd — no StreamItems |
| guest write | blocks until the runtime reads | returns immediately ("0 bytes left over") |
So the chunk is accepted by something on the host side and then dropped: it never enters the durable session journal, so the gateway has nothing to relay.
What it is not
- Not timing. Queuing the write with
spawn_local, callingwit_bindgen::yield_async()before it, and blocking on a WASI clock for 300 ms before it (the oplog shows the output stream registering during that wait) all leave the body empty. - Not the response head or the value-tree shape. The same handler returns a
204correctly, and the same response record with a host-created stream in the body slot (the request's own body stream, which the runtime created for the session) delivers the client's upload back to it (POST /static/echo→200,echo me). The head, the slot, the relay and the framing are all fine. - Not the guest's item encoding. The item is a
schema-value-treewhose root is alist<u8>— the same shape the SDK'sAgentStream<Vec<u8>>produces.
Reproducer sketch
Any component whose exported golem:agent/[email protected] invoke returns a
schema-value-tree with a stream-value node in it, where the stream was created
by the guest:
// inside an async guest export (the router handler's method)
let (mut writer, reader) = wit_stream::new(); // stream<schema-value-tree>
let handle = golem::core::types::SchemaValueStream::wrap(reader).await; // host takes the read end
// ... return the response record with `StreamValue(handle)` in its body field ...
writer.write_all(vec![chunk]).await; // accepted, never delivered
drop(writer);
wrapis implemented by the executor asreader.pipe(&mut access, consumer)into anaccounted_output_stream_pair(golem-worker-executor/src/durable_host/schema_value_stream.rs, tagv1.6.0), and the handle pushed into the table wraps that live output stream.- Writing the same chunk from a task spawned after the export's
task.return(the SDK's shape) changes nothing, and writing it before the return deadlocks only in the SDK's case — in this component it is accepted immediately, which is the asymmetry that points at the pipe.
Two candidate causes, for whoever knows the code
- The
wrappipe is not driven outside the export call: the piped items sit in the live output stream and are never pulled into the session. - The transport stream id the returned value carries is not the one the session
publishes under, so the gateway's
output_step(which matchestransport_stream_idagainst the id parsed out of the response value) skips the items. The session mapping logged for this response is{ transport_stream_id: 2, source: Local((19)), role: Output }.
Requested API shape (optional)
The tool surface already has the shape that would sidestep this:
golem:tool/[email protected] gives the guest a writer and keeps the
read end host-side. A router body endpoint of the same kind — a host-created
output stream a handler can write into and return — would make the response body
host-owned, which this platform has demonstrated it can deliver. Failing that,
making the wrap path deliver would fix it for every guest language at once.
Thanks for reporting!
Sorry for the slow response, I somehow did not notice the issue earlier.
Checked the issue and your code with an agent and it seems like a problem of how you construct SchemaValueTrees here: https://github.com/thesparq/roc-golem/blob/e49166a8b93ee51bec1848bb7a546131dfe4e4e0/host/src/lib.rs#L755-L765
The code appends the body's byte nodes to the response tree, but sends a separate chunk tree containing only the list node. Each chunk's indices must refer to nodes within that chunk's own value_nodes array.
You should be constructing the list and its U8Value nodes together in the chunk's own array, rather than appending those bytes to the outer response tree.
For example
let chunk = SchemaValueTree {
value_nodes: vec![
SchemaValueNode::ListValue(vec![1, 2]),
SchemaValueNode::U8Value(72),
SchemaValueNode::U8Value(105),
],
root: 0,
};
A possible improvement on the golem side: make the structural stream error easier to find in normal diagnostics, rather than exposing only a generic HTTP body failure.
You were right, and thank you for reading the code — that is exactly the bug.
The chunk I sent carried only its ListValue, whose indices pointed into the response tree around it instead of into the chunk's own value_nodes. With self-contained chunks the body arrives:
fn body_chunks(text: &str) -> Vec<SchemaValueTree> {
const CHUNK_BYTES: usize = 16 * 1024;
text.as_bytes().chunks(CHUNK_BYTES).map(|chunk| {
let mut nodes = Vec::with_capacity(chunk.len() + 1);
nodes.push(SchemaValueNode::ListValue((0..chunk.len()).map(|i| (i + 1) as i32).collect()));
for byte in chunk { nodes.push(SchemaValueNode::U8Value(*byte)); }
SchemaValueTree { value_nodes: nodes, root: 0 }
}).collect()
}
Verified against a local 1.6.0 server, router handler answering from a value tree with StreamValue(wrapped) in the body slot: a small body (50 bytes), a POST whose request body is echoed back, and a 100 KB body written as three 16 KiB chunks all reach the client with clean framing. A unit test now pins the invariant (every index a chunk's list carries must be valid inside that chunk), so the shape can't regress.
So: not a runtime bug, and my report was wrong about wrap, the pipe, the session relay and the framing — those were all fine, and the "not the head, not timing" findings were symptoms of the malformed chunk rather than independent evidence.
The one thing from the report I would still ask for is your own suggestion: making the structural stream error visible in normal diagnostics. From the guest side the only symptom was a 200 with an empty body and no log line, and it took a side-by-side comparison against the Rust SDK's router plus oplog inspection to even locate where the item disappeared — a validation error surfaced as a warn/error (with the offending value-tree shape, or at least "stream item failed to decode") would have pointed straight at it.
Closing since there is nothing to fix on your side.
Closing: the cause was in my chunk encoding, fixed and verified. The diagnostics suggestion is the only ask left, and it is tracked in the platform's notes.