Skip to content

Conversation

@sancyx
Copy link
Contributor

@sancyx sancyx commented Dec 8, 2025

Description

Slimrpc code ported from python to Rust.
Related issue: #1005

Type of Change

  • Bugfix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@sancyx sancyx changed the title Slimrpc rust feat: port slimrpc code to rust lang Jan 9, 2026
@sancyx sancyx marked this pull request as ready for review January 9, 2026 09:23
@sancyx sancyx requested a review from a team as a code owner January 9, 2026 09:23
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJan 22, 2026, 12:35 PM

@sancyx sancyx requested a review from msardara January 10, 2026 16:22
@sancyx sancyx force-pushed the slimrpc-rust branch 3 times, most recently from 6b8f05b to 15c60c1 Compare January 16, 2026 17:02
sancyx added 10 commits January 21, 2026 12:55
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
responses.push(response?);
}

Ok(responses)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right, what will happen here is that the stream will get drained into responses, and then returned to handle_session, which will then drain it into the SLIM channel.

Instead call_handler should return the stream itself to handle_session, and as items are drained from the stream they should be sent on the SLIM channel.

In python we handled this by having call_handler return a generator of responses regardless of stream or not stream.

Immediate thought is that call_handler should create a channel, and a background task to do the handling, then return the channel to session_handler or perhaps we can use a futures:Stream.

Honestly I would revisit this whole logic as we're in a different language for example:

session_handler can create two different channels one for inputs and one for responses, these are passed to call_handler:

For UnaryUnary:

  • session_handler reads one message and push it down the input channel
  • call_hander reads one message from the input channel
  • calls the handler
  • sends the response down the output channel then closes it

For UnaryStream:

  • session_handler reads one message and push it down the input channel
  • call_hander reads one message from the input channel
  • calls the handler
  • drains the response stream down the output channel then closes it

For StreamUnary:

  • session_handler creates a routine/task which continuously reads messages and pushes them down the input channel
  • call_handler passes the stream to the handler
  • waits for one response from the call_handler function
  • sends the response down the output channel then closes it

For StreamStream:

  • session_handler creates a routine/task which continuously reads messages and pushes them down the input channel
  • call_handler passes the stream to the handler
  • drains the response stream down the output channel then closes it

session_handler's main "thread" will drain the output channel, forwarding each message, and then when the channel closes / ends it will send the channel end response to the client.

msg_ctx: MessageContext,
session_ctx: SessionContext,
) -> Result<Res>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for this to work with uniffi, we need to make sure that we enable the trait to be implemented by the foreign/binding language explictly: https://mozilla.github.io/uniffi-rs/latest/foreign_traits.html

msg_ctx: MessageContext,
session_ctx: SessionContext,
) -> Result<ResponseStream<Res>>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that the function declaration here is correct, in python we had call implement a "generator" essentially the function gets wrapped by the runtime into an iterator class which isn't a concept that exists in rust. This current declaration would require the call function to create and return a stream and trigger downstream a background task to populate the stream.

It would be better for Stream handlers to receive an output stream channel rx from the session handler, so that they can simply call output_stream.try_send(...) or add we function on the session_ctx to send responses which then pushes responses onto the channel internally (this is how gRPC implements it BTW).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference this is the gRPC interface for the session context:
https://github.com/grpc/grpc/blob/master/src/python/grpcio/grpc/aio/_base_server.py#L154

read is used to read messages for "Stream****" channels and write is used to response to "***Stream" channels.

Signed-off-by: Magyari Sandor Szilard <[email protected]>
Signed-off-by: Magyari Sandor Szilard <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants