Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: resource types are not the same when composing components #149

Open
mschuwalow opened this issue Jan 16, 2025 · 0 comments
Open

Error: resource types are not the same when composing components #149

mschuwalow opened this issue Jan 16, 2025 · 0 comments

Comments

@mschuwalow
Copy link

mschuwalow commented Jan 16, 2025

I'm trying to wrap a component that implments wasi:http/incoming-handler into a different api. The way I'm trying to accomplish this is by having two different components that will be composed with it.

  1. Exports the wasi:http/types interface + some extensions. This will be composed with (2) and (3) and has otherwise no imports (except other wasi interfaces)
  2. The wrapped component. This imports wasi:http/types and exports wasi:http/incoming-handler.
  3. A component providing the new api. This imports wasi:http/types, wasi:http/incoming-handler, the extensions from (1) and exports the new api.

Problem is that when I try composing the wasm, it errors with:

❯ wac plug adapter.wasm --plug types.wasm -o adapter-plugged.wasm
error: encoding produced a component that failed validation

Caused by:
    type mismatch for import `wasi:http/[email protected]`
    type mismatch in instance export `incoming-request`
    resource types are not the same (ResourceId { globally_unique_id: 2, contextually_unique_id: 8 } vs. ResourceId { globally_unique_id: 2, contextually_unique_id: 57 }) (at offset 0x4e0399)

This error shows up both for wac plug and wac compose.


Wits look as follows:
Component 1:

package poc:types;

interface extensions {
    use wasi:http/[email protected].{method, scheme, status-code, incoming-request, response-outparam};

    type fields = list<tuple<string, list<u8>>>;

    type body = list<u8>;

    record body-and-trailers {
        body: body,
        trailers: option<fields>
    }

    record request {
        method: method,
        path-with-query: string,
        scheme: scheme,
        authority: string,
        headers: fields,
        body-and-trailers: option<body-and-trailers>
    }

    record response {
        status: status-code,
        body: option<body-and-trailers>
    }

    resource response-outparam-proxy {
        constructor();

        new-outparam: func() -> response-outparam;
        get-response: func() -> response;
    }

    new-wasi-http-request: func(request: request) -> incoming-request;
}

world api {
    export wasi:http/[email protected];
    export extensions
}

Component 2:

package poc:handler;

world api {
  import wasi:http/[email protected];
  export wasi:http/[email protected];
}

Component 3:

package poc:adapter;

interface adapted-api {
    use poc:types/extensions.{request, response};

    handle: func(request: request) -> response;
}

world api {
    import wasi:http/[email protected];
    import wasi:http/[email protected];
    import poc:types/extensions;

    export adapted-api;
}

I suspect this is a similiar error to bytecodealliance/wasm-tools#1565. This comment provided a reproduction that fails with the same error.

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

No branches or pull requests

1 participant