Skip to content

Sending binary via a typescript websocket client call fails #3387

Description

@rbackhouse

Golem Version 1.5.1

import { agent, BaseAgent } from "@golemcloud/golem-ts-sdk";

@agent()
class WebSocketTest extends BaseAgent {
    constructor(name: string) {
        super();
    }
    async binary(url: string): Promise<string> {
        return new Promise((resolve, reject) => {
            const ws = new WebSocket(url);
            ws.onopen = () => {
                const buffer = new ArrayBuffer(10);
                const view = new Uint8Array(buffer);
                for (let i = 0; i < view.length; i++) {
                    view[i] = 255;
                }
                ws.send(buffer);
            }
            ws.onmessage = (event) => { ws.close();
                console.log(event);
                resolve("Done"); 
            };
            ws.onerror = (event) => reject(new Error(event.message));
        });
    }
}
golem agent invoke 'WebSocketTest("t1")' 'binary' '"ws://localhost:9090"'

Results in

JavaScript error: Error converting from js 'object' into type 'array'

[2026-05-12T14:02:18.004Z] [INVOKE  ] STARTED  binary (6758a2af-0d62-40fd-8bad-63937f9cbc54)
{"context":"","level":"STDERR","message":"","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"thread '<unnamed>' (1) panicked at src/internal.rs:188441:","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"Exception during awaiting call result for guest.invoke:","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"JavaScript error: Error converting from js 'object' into type 'array'","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"Stack:","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at <anonymous> (user:125:48)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at call (native)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at _dispatch (__wasm_rquickjs_builtin/websocket:365:32)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at send (__wasm_rquickjs_builtin/websocket:293:72)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at <anonymous> (user:118:25)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at call (native)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at _dispatch (__wasm_rquickjs_builtin/websocket:365:32)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at <anonymous> (__wasm_rquickjs_builtin/websocket:154:22)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at apply (native)","timestamp":"2026-05-12T14:02:18.010Z"}
{"context":"","level":"STDERR","message":"    at call (native)","timestamp":"2026-05-12T14:02:18.010Z"}
error: Agent Service - Error: 500 Internal Server Error, Invocation Failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions