Skip to content

Add async call stacks to the public API, use it in wasi:http#13510

Merged
alexcrichton merged 5 commits into
bytecodealliance:mainfrom
alexcrichton:wasi-http-changes
Jun 4, 2026
Merged

Add async call stacks to the public API, use it in wasi:http#13510
alexcrichton merged 5 commits into
bytecodealliance:mainfrom
alexcrichton:wasi-http-changes

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This PR is intended to be the Wasmtime-specific resolution of WebAssembly/WASI#918, WebAssembly/WASI#919, and WebAssembly/WASI#920. Two commits are included here, both of which have more details as to what they're doing. At a high level though the first commit is providing the primitives in the wasmtime crate's API to reflect on the async call stack as defined by the component model. The second commit then refactors our wasmtime serve handling to thread this through and provide the host with a strong guarantee of "this request is being served on this store with this task", which is intended to then enable the store to do whatever it likes in terms of handling.

@alexcrichton alexcrichton requested review from a team as code owners May 29, 2026 19:48
@alexcrichton alexcrichton requested review from dicej and removed request for a team May 29, 2026 19:48
This commit adds a few new APIs to the surface area of the `wasmtime`
crate as well as reorganizes some internals. Namely:

* `StoreContextMut::async_call_stack` - yields an `Iterator` of the call
  stack of async tasks in the component model to understand the current
  call graph.

* `{Typed,}Func::{start,finish}_call_concurrent` - these new APIs allow
  splitting apart the previous `call_concurrent` function into discrete
  steps to learn about the task being created, notably the
  `GuestTaskId`. The previous `call_concurrent` is reimplemented in
  terms of these functions.

* Methods requiring the `component-model-async` Cargo feature are now
  under the `concurrent` module in `wasmtime` to cut down on `#[cfg]`
  required.

This is all intended to address the concerns of WebAssembly/WASI#918,
WebAssembly/WASI#919, and WebAssembly/WASI#920. This isn't plumbed into
wasi-http yet, but that'll come as a
This commit uses the previous commit to connect a generic, host-defined,
request ID and provide a strong connection to the `GuestTaskId` that's
being used to serve that request. This can be used by `wasi:http`
handlers to provide a strong correlation between outgoing requests, for
example, and incoming requests.
/// An opaque unique identifier that hosts can assigned to requests which is
/// threaded from [`ProxyHandler::handle`] into
/// [`WorkerState::on_request_start`]
type RequestId: Send + Sync;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just note that Extensions is another way to attach arbitrary data to a Request. This is likely more efficient, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I had no idea about that! I'll try to stick to RequestId for now but if it becomes too onerous we can switch to that.

Comment thread crates/wasmtime/src/runtime/component/concurrent/func.rs Outdated
Co-authored-by: Joel Dice <joel.dice@akamai.com>
@alexcrichton alexcrichton enabled auto-merge June 4, 2026 14:28
@alexcrichton alexcrichton added this pull request to the merge queue Jun 4, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@alexcrichton alexcrichton enabled auto-merge June 4, 2026 15:04
@alexcrichton alexcrichton added this pull request to the merge queue Jun 4, 2026
Merged via the queue into bytecodealliance:main with commit 5ed2436 Jun 4, 2026
51 checks passed
@alexcrichton alexcrichton deleted the wasi-http-changes branch June 4, 2026 15:39
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.

2 participants