Skip to content

Node-target WebSocket upgrade returns 500 due to dual-instance Symbol mismatch #198

@astrobot-houston

Description

@astrobot-houston

Originally reported by @k161196 in #197.

All community-submitted pull requests are automatically converted to issues (bugs) & discussions (feature requests, enhancements) where they can be triaged and prioritized. Once prioritized, a PR implementation is created automatically.

Describe the Bug

Node-target builds (@flue/cli) return HTTP 500 on every WebSocket upgrade request to /agents/:name/:id. The root cause is a dual-instance Symbol mismatch: @flue/cli bundles @hono/node-server into the generated dist/server.mjs, while the generated entry also imports createNodeWebSocketTransport from @flue/runtime/node (kept external), which re-imports upgradeWebSocket from a separate disk copy of @hono/node-server. The two module instances produce two distinct WAIT_FOR_WEBSOCKET_SYMBOL identities — injectWebSocket writes symbol A onto env, but upgradeWebSocket reads symbol B, finds undefined, and returns new Response(null, { status: 500 }). The same dual-copy problem applies to the ws package.

Expected Behavior

WebSocket upgrade requests to /agents/:name/:id on node-target builds should complete successfully with a 101 Switching Protocols response, allowing the SDK client to stream events over the connection.

Steps to Reproduce

  1. Build a Flue project targeting Node (e.g., starting from examples/hello-world/ with the node target configured).
  2. Start the built server from dist/server.mjs.
  3. Attempt a WebSocket connection to /agents/:name/:id (e.g., via the SDK client or a WebSocket tool).
  4. Observe that the server responds with HTTP 500 instead of upgrading the connection.

Original implementation from #197 by @k161196

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions