Document concurrent instance reuse in wasi:http/service#920
Open
alexcrichton wants to merge 2 commits into
Open
Document concurrent instance reuse in wasi:http/service#920alexcrichton wants to merge 2 commits into
wasi:http/service#920alexcrichton wants to merge 2 commits into
Conversation
This commit adds a documentation block to the `wasi:http/service` world that's the result of discussions in today's WASI subgroup meeting, WebAssembly#918, and WebAssembly#919. The documentation here indicates a few properties around concurrent instance reuse, namely: * Guests should expect to be concurrently reused. If this is not acceptable then guests should disable reuse through backpressure mechanisms. * Guests should ensure that outgoing HTTP requests are done within the context of the original root task, or the original invocation of `handler`. If guests can't implement this then they're expected to use backpressure mechanisms instead. The overall conclusion of the various discussions that have happened over the past week or so is that it's not possible to provide the attribute behavior some hosts require exclusively through either in-guest interactions or pure-host interactions. Instead being able to reliably provide accurate attribution requires specifically outlining guidelines for both guests and hosts. The mechanism intended to be used for attribution is then: * For hosts such as Wasmtime calls to imports will be able to reflect on the current async call stack, notably the root export task. Hosts can then use this to correlate an identifier provided when a root task is created, providing a strong link from the import call to whatever export initiated it. This is expected to work as-is for some guest languages, such as Rust, but this is also not a bulletproof solution. Guests can always internally call imports from any currently-running task, and additionally languages such as JS and Go at this time are structured in such a way where imports are not always naturally called from the originating export task. * To enable languages like JS and Go to be able to leverage concurrent reuse while providing accurate attribution of outgoing requests to incoming requests, the plan is to eventually add and specify intrinsics on the component model level to, in a scoped fashion, mutate the async call stack. For example a guest would be able to say "I'm about to do some work for this component model task". When Wasmtime reflects on the async call graph at that time it'd see this and understand that the attribution needs to be slightly adjusted to what it would otherwise by default be. The goal with these addition is to enable hosts to be able to reliably expect to attribute outgoing requests to incoming requests (via async call graph inspection), provide guests the ability to work today (either naturally or disabling concurrent reuse via backpressure), and ensure that well-behaved and idiomatic guests can work reliably with concurrent reuse in the long-run (via component model intrinsics to massage the async backtrace that hosts operate with). When this is all combined it's expected to resolve the concerns of WebAssembly#918 and WebAssembly#919 with idiomatic bindings in guests and hosts alike. Closes WebAssembly#918 Closes WebAssembly#919
This was referenced May 28, 2026
lukewagner
previously approved these changes
May 28, 2026
Member
lukewagner
left a comment
There was a problem hiding this comment.
Looks good from my perspective
Member
tschneidereit
left a comment
There was a problem hiding this comment.
I added suggestions for fairly meaningful changes to the comments, which I hope make things a bit clearer.
tschneidereit
approved these changes
Jun 1, 2026
alexcrichton
added a commit
to alexcrichton/wasmtime
that referenced
this pull request
Jun 3, 2026
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
pull Bot
pushed a commit
to Haofei/wasmtime
that referenced
this pull request
Jun 4, 2026
…odealliance#13510) * Enable reflection on component async call stacks 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 * Thread request IDs through `wasi:http` handling 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. * Update expansion tests * Update crates/wasmtime/src/runtime/component/concurrent/func.rs Co-authored-by: Joel Dice <joel.dice@akamai.com> * Fix doc links --------- Co-authored-by: Joel Dice <joel.dice@akamai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds a documentation block to the
wasi:http/serviceworld that's the result of discussions in today's WASI subgroup meeting, #918, and #919. The documentation here indicates a few properties around concurrent instance reuse, namely:Guests should expect to be concurrently reused. If this is not acceptable then guests should disable reuse through backpressure mechanisms.
Guests should ensure that outgoing HTTP requests are done within the context of the original root task, or the original invocation of
handler. If guests can't implement this then they're expected to use backpressure mechanisms instead.The overall conclusion of the various discussions that have happened over the past week or so is that it's not possible to provide the attribute behavior some hosts require exclusively through either in-guest interactions or pure-host interactions. Instead being able to reliably provide accurate attribution requires specifically outlining guidelines for both guests and hosts. The mechanism intended to be used for attribution is then:
For hosts such as Wasmtime calls to imports will be able to reflect on the current async call stack, notably the root export task. Hosts can then use this to correlate an identifier provided when a root task is created, providing a strong link from the import call to whatever export initiated it. This is expected to work as-is for some guest languages, such as Rust, but this is also not a bulletproof solution. Guests can always internally call imports from any currently-running task, and additionally languages such as JS and Go at this time are structured in such a way where imports are not always naturally called from the originating export task.
To enable languages like JS and Go to be able to leverage concurrent reuse while providing accurate attribution of outgoing requests to incoming requests, the plan is to eventually add and specify intrinsics on the component model level to, in a scoped fashion, mutate the async call stack. For example a guest would be able to say "I'm about to do some work for this component model task". When Wasmtime reflects on the async call graph at that time it'd see this and understand that the attribution needs to be slightly adjusted to what it would otherwise by default be.
The goal with these addition is to enable hosts to be able to reliably expect to attribute outgoing requests to incoming requests (via async call graph inspection), provide guests the ability to work today (either naturally or disabling concurrent reuse via backpressure), and ensure that well-behaved and idiomatic guests can work reliably with concurrent reuse in the long-run (via component model intrinsics to massage the async backtrace that hosts operate with). When this is all combined it's expected to resolve the concerns of #918 and #919 with idiomatic bindings in guests and hosts alike.
Closes #918
Closes #919