Skip to content

feat(rust): add WebSocket (WSS) support with typed channel clients#12429

Open
iamnamananand996 wants to merge 2 commits intomainfrom
devin/1771253722-rust-websocket-support
Open

feat(rust): add WebSocket (WSS) support with typed channel clients#12429
iamnamananand996 wants to merge 2 commits intomainfrom
devin/1771253722-rust-websocket-support

Conversation

@iamnamananand996
Copy link
Member

@iamnamananand996 iamnamananand996 commented Feb 16, 2026

Description

Refs #12338

POC for WebSocket/WSS support in the Rust SDK generator. Adds a tokio-tungstenite-based runtime and a code generator that reads ir.websocketChannels to emit typed per-channel Rust client structs with send/receive methods.

Link to Devin run: https://app.devin.ai/sessions/9a2809fa93d24d13be0c3c338e042e91
Requested by: @iamnamananand996

Changes Made

Runtime (websocket.rs — new as-is file)

  • WebSocketClient struct with async connect, send_json, send_raw, close
  • WebSocketOptions (headers, query params, reconnection config)
  • WebSocketState enum and parse_websocket_message<T> helper
  • Feature-gated behind #[cfg(feature = "websocket")], matching the SSE pattern

Generator (WebSocketChannelGenerator.ts — new)

  • Reads ir.websocketChannels and emits one Rust file per channel under src/api/websocket/
  • Generates typed ServerMessage enum (serde-tagged), client struct, connect, per-message send_*, recv, and close methods
  • Generates mod.rs with re-exports

Integration (modified files)

  • AbstractRustGeneratorContext.tshasWebSocketChannels(), optional deps (tokio-tungstenite, urlencoding), websocket Cargo feature
  • SdkGeneratorCli.ts — wires generator into pipeline, adds websocket module to API mod file
  • SdkGeneratorContext.ts — conditionally includes websocket.rs in core as-is files
  • ErrorGenerator.ts — adds WebSocketError variant
  • AsIs.ts / mod.rs — registers and exports the new as-is file

⚠️ Important Review Notes

This is a proof-of-concept — the following items are intentionally incomplete or need scrutiny:

  1. read_loop is stubbed: The read half of the split WebSocket stream is never stored or consumed. incoming_rx will never yield messages. The receive path is non-functional — this needs a real implementation before shipping.

  2. No seed fixtures: The generated Rust code has not been validated to compile or run against a real IR with WebSocket channels. Recommend adding a WebSocket test case to the exhaustive seed fixture.

  3. String-based code generation: WebSocketChannelGenerator builds Rust via string templates. Typos or incorrect type references won't be caught until Rust compile time. Needs validation.

  4. Path expression building: buildPathExpression uses IR property names directly in format strings — verify these match the snake_case parameter names in the generated connect() method.

  5. Channel wiring confusion: Two unbounded channels are created in connect() but only one is used. The outgoing_tx is stored but never consumed. The read half from ws_stream.split() is also unused.

  6. Missing explicit http crate dependency: websocket.rs references http::uri::InvalidUri but http isn't explicitly listed (may come transitively via tokio-tungstenite).

Human Review Checklist

  • Verify read half of split stream and channel wiring make sense before shipping
  • Confirm http crate is available transitively or add explicit dep
  • Validate generated Rust compiles with a real WebSocket channel IR fixture
  • Review buildPathExpression output against generated connect() parameter names

Updates since last revision

  • Updated 9 ErrorGenerator test snapshots to include the new WebSocketError variant (all tests now pass)

Testing

  • Lint checks pass (pnpm run check)
  • ErrorGenerator snapshots updated for WebSocketError variant
  • Seed test fixtures added — None added (POC)
  • Manual testing completed — Not tested (POC)

Next steps before production-ready:

  • Implement actual read_loop to consume WebSocket messages
  • Add seed test fixture with WebSocket channel definition
  • Verify generated code compiles and runs
  • Fix channel wiring and unused variables

Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Contributor

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments