lthibault requested pchickey for a review on PR #15167.
lthibault opened PR #15167 from wetware:lthibault/pasted-text-file-v2 to bytecodealliance:main:
Why: embedders need to bound active filesystem work and retain its backing
content. A native worker can outlive its initiating future, descriptor, or Store.
An idle handle can still access backing content after active work ends. Existing
filesystem APIs do not let embedders attach owners to these independent lifetimes.This adds two opaque owners:
FilesystemOperationretains an admission value through native execution and
resource-result installation or disposal. P3 streams share one admission per
session.WasiFilesystemCtx::set_operation_hookand
WasiCtxBuilder::filesystem_operation_hookconfigure admission;
WasiFilesystemCtx::push_descriptorapplies the hook to custom descriptors.
FilesystemHandleretains backing ownership through shared handles, native
duplicates made withtry_clone, child opens, and directory iterators.
Native state drops before its owner. Idle handles do not retain admission.Both are needed for
is_same_object(A, B): A admits the operation, while the
worker must retain B's backing owner after B's descriptor disappears.link_at
andrename_athave the same requirement.Prior discussion: filesystem operation and native handle lifecycle hooks.
Compatibility
File.fileandDir.dirchange fromArc<std::fs::File>to
Arc<FilesystemHandle>. Typed raw-Arcuses and native-file trait bounds can
require changes. Borrowed methods remain available throughDeref;try_clone
now returns the owner-preserving wrapper. Constructors accept raw files, though
explicit.into()calls can need type annotations.RELEASES.mdrecords the
break. Guest WIT interfaces do not change.A descriptor sidecar cannot follow escaped raw-
Arcclones. An admission hook
cannot retain idle handles or B's independent owner. Private fields would also
break callers; a registry would add tracking machinery. Explicit raw-file or
OS-handle duplication remains the embedder's responsibility.Validation
Tests cover cancellation, native worker unwinding, child/result handoff,
secondary descriptors, idle duplicates, directory iterators, and terminal P3
streams while the Store remains alive. Native-worker gates establish ordering;
tests do not infer completion from sleeps.On macOS arm64 with Rust 1.99.1,
cargo test -p wasmtime-wasi --locked
passed 171 unit, 227 integration, and 54 documentation tests. Three existing
tests were ignored. P1 and P3-only filesystem suites passed 136 and 145 tests.
WASI all-target Clippy passed with warnings denied; changed tests pass Rustfmt.All nine negative controls made their targeted test fail. The passing suites ran
after restoring those mutations. Linux, Windows, the full repository CI matrix,
and performance overhead remain unvalidated.
lthibault removed the review request for wasmtime-wasi-reviewers from PR #15167.
lthibault requested wasmtime-wasi-reviewers for a review on PR #15167.
lthibault requested wasmtime-core-reviewers for a review on PR #15167.
lthibault removed the review request for wasmtime-default-reviewers from PR #15167.
lthibault requested alexcrichton for a review on PR #15167.
lthibault requested wasmtime-default-reviewers for a review on PR #15167.
pchickey commented on PR #15167:
This PR doesn't appear to comply with our policy on tool-generated content, and requires additional justification for why it is valuable enough to the project for us to review it. Please see our developer policy on AI-generated contributions: https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.md
lthibault commented on PR #15167:
Thanks, Patrick. I appreciate the concern about review cost, and have previously familiarized myself with the policy.
Before opening this PR, I looked into the existing filesystem lifecycle mechanisms and prior discussions, then raised the proposed API on Zulip to get design feedback. I didn't receive a response, so I opened the PR hoping to make the proposal concrete.
The motivating problem is that an embedder (Wetware) needs to account for native filesystem work (wetware/ww#713) and backing resources (wetware/ww#266) independently of guest lifetimes:
- Operation lifetime: Native work can continue after the initiating guest future or Store is gone. The embedder needs to retain an admission/ownership token until that work actually completes.
- Handle lifetime: Native file and directory handles, including duplicates and handles retained by workers, can outlive their originating descriptors. The backing-resource owner must survive with the actual native handle.
These are distinct lifetimes. In particular, operations involving multiple descriptors (e.g.
is_same_object,rename_at) demonstrate why tracking only the initiating operation or descriptor is insufficient.The patch implements both contracts and includes regression tests for the relevant cancellation and ownership boundaries.
I recognize this is a substantial diff, and I'm happy to narrow or split it if that would make review more manageable. I'm also open to taking a different approach if there's a better fit for Wasmtime's embedder API.
Ultimately, I'm just trying to move the discussion forward and would welcome your thoughts on the right design. If I've overlooked or under-delivered on any part of the AI tool policy, I'm ofc happy to correct that! :)
lthibault deleted a comment on PR #15167:
Thanks, Patrick. I appreciate the concern about review cost, and have previously familiarized myself with the policy.
Before opening this PR, I looked into the existing filesystem lifecycle mechanisms and prior discussions, then raised the proposed API on Zulip to get design feedback. I didn't receive a response, so I opened the PR hoping to make the proposal concrete.
The motivating problem is that an embedder (Wetware) needs to account for native filesystem work (wetware/ww#713) and backing resources (wetware/ww#266) independently of guest lifetimes:
- Operation lifetime: Native work can continue after the initiating guest future or Store is gone. The embedder needs to retain an admission/ownership token until that work actually completes.
- Handle lifetime: Native file and directory handles, including duplicates and handles retained by workers, can outlive their originating descriptors. The backing-resource owner must survive with the actual native handle.
These are distinct lifetimes. In particular, operations involving multiple descriptors (e.g.
is_same_object,rename_at) demonstrate why tracking only the initiating operation or descriptor is insufficient.The patch implements both contracts and includes regression tests for the relevant cancellation and ownership boundaries.
I recognize this is a substantial diff, and I'm happy to narrow or split it if that would make review more manageable. I'm also open to taking a different approach if there's a better fit for Wasmtime's embedder API.
Ultimately, I'm just trying to move the discussion forward and would welcome your thoughts on the right design. If I've overlooked or under-delivered on any part of the AI tool policy, I'm ofc happy to correct that! :)
lthibault commented on PR #15167:
Thanks, @pchickey. I appreciate the concern about review cost, and have previously familiarized myself with the policy.
Before opening this PR, I looked into the existing filesystem lifecycle mechanisms and prior discussions, then raised the proposed API on Zulip to get design feedback. I didn't receive a response, so I opened the PR hoping to make the proposal concrete.
The motivating problem is that an embedder (Wetware) needs to account for native filesystem work (wetware/ww#713) and backing resources (wetware/ww#266) independently of guest lifetimes:
- Operation lifetime: Native work can continue after the initiating guest future or Store is gone. The embedder needs to retain an admission/ownership token until that work actually completes.
- Handle lifetime: Native file and directory handles, including duplicates and handles retained by workers, can outlive their originating descriptors. The backing-resource owner must survive with the actual native handle.
These are distinct lifetimes. In particular, operations involving multiple descriptors (e.g.
is_same_object,rename_at) demonstrate why tracking only the initiating operation or descriptor is insufficient.The patch implements both contracts and includes regression tests for the relevant cancellation and ownership boundaries.
I recognize this is a substantial diff, and I'm happy to narrow or split it if that would make review more manageable. I'm also open to taking a different approach if there's a better fit for Wasmtime's embedder API.
Ultimately, I'm just trying to move the discussion forward and would welcome your thoughts on the right design. If I've overlooked or under-delivered on any part of the AI tool policy, I'm ofc happy to correct that! :)
pchickey commented on PR #15167:
Thanks, your comment is a much better description and I can understand this PR a lot better from it. I missed that discussion on Zulip, sorry about that. I will review this PR this week and also I want to tag in @dicej because I know he is working on some issues related to these.
lthibault commented on PR #15167:
No worries at all -- I imagine you guys have to deal with quite a few drive-by PRs these days!
Sounds good. Looking forward to discussing in the coming days!
github-actions[bot] added the label wasi on PR #15167.
github-actions[bot] added the label wasmtime:docs on PR #15167.
pchickey commented on PR #15167:
So I've looked at this, and also asked two other colleagues who know this code well to look at this to see if I was missing something.
The first issue, an operation on a host resource outliving the store, is a known systemic problem throughout wasmtime-wasi{-http} and broadly speaking we are exploring solutions to it, though it isnt at the top of anyones priority queue right now.
The second issue, I think means that guest resources pointing at some host file descriptor outlives the file descriptor? If there is a specific case this is a bug, we need a minimal reproducable case showing this, to help us understand what exactly the problem is here.
This is 2500 lines of code that nobody on the maintainer team is enthusiastic about reviewing deeper and maintaining based on this PR so far. So, we'd like to ask you to please file an issue with a reproducer about issue number 2, and if you'd like to collaborate with the maintainers on PRs to solve these issues, please submit an agenda item and attend one of our wasmtime project calls to discuss it with us further.
lthibault updated PR #15167.
lthibault edited PR #15167:
Embedders that manage external filesystem content need to retain that content while guest descriptors or native operations still depend on it. They also need to track admitted native work until it finishes, including work that outlives its initiating future or Store. These lifetimes differ: an idle descriptor can still need backing content after an operation releases admission.
This PR proposes optional filesystem operation hooks to support both lifetimes. Descriptors retain hook factories that can own backing content. Admitted operations retain values supplied by those factories until the required native work and resource handoff finish.
Public
File.fileandDir.dirhave typeArc<std::fs::File>.File::newandDir::newacceptstd::fs::File. The proposal preserves these upstream types and guest WIT signatures.Factories can retain backing content while descriptors are idle. On admission, a factory returns a
FilesystemOperationcontaining the embedder's admission token and any required backing owner. Wasmtime retains that value through native execution, even after the initiating future or Store is destroyed. Secondary operands retain their own factories without a second admission.Ownership continues through child-result installation or disposal and P3 iterator use. Cancellation does not release ownership required by a running native worker. Terminal file streams release admission while their descriptors retain their factories.
Naked native
Arcclones and OS-handle duplicates do not automatically retain backing owners. Embedders must pair extracted native state with an attached descriptor or explicit backing owner. Embedders must dispose of the native state before releasing that owner.Wetware uses the corresponding Wasmtime 48.0.1 backport at
96e45d8b025aac7a5aea5aa505bd73826996919d. Its consumer migration uses factories that own content generations, prepared descriptor results, and explicit pairs of native state and backing owners. The migration passed 156 selected local tests. The proposal supplies a missing embedder ownership capability. The investigation did not demonstrate premature native-descriptor closure in unmodified upstream Wasmtime.
lthibault commented on PR #15167:
@pchickey Thanks for taking a look, and for checking with your colleagues.
Regarding the second issue, I went back through my reproducers and confirmed that the failures were in the ownership machinery I'd added to my fork, not in upstream Wasmtime. Sorry for the confusion; please disregard that part.
As for the main feature request, I've since simplified the public API changes. In particular, I've eliminated
FilesystemHandleand restored the original native file types. The overall diff is still large, mostly because of the tests, so I understand this likely doesn't change your decision. I've pushed the changes anyway, just in case it becomes useful for discussion later.At any rate, I'm happy to discuss the design at a project meeting before making further changes. I'll look into submitting an agenda item and joining a call.
Thanks again for your consideration, and I look forward to speaking with you and the rest of the team soon!
lthibault updated PR #15167.
Last updated: Nov 19 2026 at 20:05 UTC