fix(js-component-bindgen): treat undefined as none when lowering options#1722
Merged
vados-cosmonic merged 1 commit intoJul 4, 2026
Merged
Conversation
vados-cosmonic
approved these changes
Jul 4, 2026
Collaborator
There was a problem hiding this comment.
LGTM 🚀
Thanks for this fix @GamePad64 !
I really think that we should be leaning towards null here other than undefined, but the current type representation documentation it looks like we really do use undefined.
This is probably something left for a breaking change in Jco for the future -- null is an explicit value (that is none-ish) whereas undefined overlaps with a completely missing option, which makes null seem like the better representation here (there are some benefits like when making objects for record values)... That's a conversation for a different time, I guess.
`_lowerFlatOption` mapped only JS `null` to the option `none` case, but jco's own generated TypeScript types model `option<T>` none as `T | undefined`. A value of `undefined` was therefore lowered as `some(undefined)`; when `T` contains an `own<resource>`, `_lowerFlatOwn` then throws `missing resource` and aborts the task.
This surfaced with wasi:http p3 `response.consume-body`, whose trailers future is typed `Result<Trailers | undefined, ErrorCode>`: an empty-trailers `Ok(None)` (`{ tag: 'ok', val: undefined }`) crashed lowering at body completion, leaving the enclosing streaming result's `.next()` unresolved.
Widen the none check to accept `undefined`, consistent with the generated types.
Signed-off-by: Alexander Shishenko <alex@shishenko.com>
2c2dd76 to
f779305
Compare
GamePad64
added a commit
to actcore/host-browser
that referenced
this pull request
Jul 5, 2026
Two stacked bugs made any browser component doing a real wasi:http call inside a streaming tool-result hang indefinitely (ACT-153):
- jco's `_lowerFlatOption` treats only JS `null` as option `none`, but jco's generated types model option-none as `T | undefined`. The empty trailers future (`Ok(None)` = `{tag:'ok', val: undefined}`) was mis-lowered as `some(undefined)`, throwing `missing resource` at body completion and killing the call-tool task. Fixed via a one-line post-transpile patch in patches.ts (upstream: bytecodealliance/jco#1722; drop the patch once it ships).
- `consumeBody` enqueued the body one byte per chunk (~95 B/s); jco batches array-like stream values via appendReadValue, so enqueue the whole Uint8Array in one chunk.
A 43 KB body went from an effective hang (projected ~7.5 min) to ~70 ms, byte-for-byte identical. Updated the consumeBody test to the batched contract.
GamePad64
added a commit
to actcore/actcore.dev
that referenced
this pull request
Jul 5, 2026
ACT-153 (jco browser wasi:http hang) is fixed in @actcore/host, so restore the `install` example (`await _pip.install("humanize")`) to the playground picker and refresh the vendored wasi:http shim (public/host/shims) with the batch-enqueue body drain.
The jco `_lowerFlatOption` undefined-as-none crash fix rides in via @actcore/host's patches.ts (upstream: bytecodealliance/jco#1722). Verified end-to-end: a 43 KB body drains in ~70 ms, byte-for-byte identical (was an effective hang).
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.
_lowerFlatOptionmapped only JSnullto the optionnonecase, but jco's own generated TypeScript types modeloption<T>none asT | undefined. A value ofundefinedwas therefore lowered assome(undefined); whenTcontains anown<resource>,_lowerFlatOwnthen throwsmissing resourceand aborts the task.This surfaced with wasi:http p3
response.consume-body, whose trailers future is typedResult<Trailers | undefined, ErrorCode>: an empty-trailersOk(None)({ tag: 'ok', val: undefined }) crashed lowering at body completion, leaving the enclosing streaming result's.next()unresolved.Widen the none check to accept
undefined, consistent with the generated types.