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

feat(sdks/actor): add http api for calling rpcs #1950

Conversation

NathanFlurry
Copy link
Member

Changes

This was referenced Jan 28, 2025
Copy link
Member Author

NathanFlurry commented Jan 28, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds HTTP RPC support to the Rivet actor system, enabling RPC calls over HTTP alongside existing WebSocket connections, with improved development workflows.

  • Added HTTP RPC endpoint /rpc/:name in sdks/actor/runtime/src/actor.ts with proper request validation and error handling
  • Introduced Zod schemas in sdks/actor/protocol/src/http/rpc.ts for runtime validation of HTTP RPC requests/responses
  • Modified Connection class in sdks/actor/runtime/src/connection.ts to support optional WebSocket connections for HTTP-only RPCs
  • Changed WebSocket connection URL format from /connect?version=1&format=... to /v1/connect?format=... in sdks/actor/client/src/handle.ts
  • Added dev scripts with watch mode across multiple packages for improved development workflow

8 file(s) reviewed, 7 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -31,6 +31,7 @@
"sideEffects": false,
"scripts": {
"build": "tsup src/mod.ts src/query.ts",
"dev": "yarn build --watch",
Copy link

Choose a reason for hiding this comment

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

style: consider using 'tsup --watch' directly instead of 'yarn build --watch' to avoid potential yarn command resolution issues

@@ -22,6 +22,7 @@
"sideEffects": false,
"scripts": {
"build": "tsup src/mod.ts",
"dev": "yarn build --watch",
Copy link

Choose a reason for hiding this comment

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

style: consider using tsup src/mod.ts --watch directly instead of yarn build --watch to avoid potential issues with yarn command resolution

}
export const RequestSchema = z.object({
// Args
a: z.array(z.unknown()),
Copy link

Choose a reason for hiding this comment

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

style: consider adding validation for empty arrays since they likely indicate invalid RPC calls

}
export const ResponseOkSchema = z.object({
// Output
o: z.unknown(),
Copy link

Choose a reason for hiding this comment

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

style: consider adding validation for null/undefined output values which could indicate bugs in RPC handlers

// Message
m: z.string(),
// Metadata
md: z.unknown().optional(),
Copy link

Choose a reason for hiding this comment

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

logic: metadata should be z.record() instead of z.unknown() to ensure object type

@@ -64,6 +64,7 @@
"sideEffects": false,
"scripts": {
"build": "tsup src/http/rpc.ts src/http/inspect.ts src/ws/mod.ts src/ws/to_client.ts src/ws/to_server.ts",
"dev": "yarn build --watch",
Copy link

Choose a reason for hiding this comment

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

style: consider using 'tsup --watch' directly instead of 'yarn build --watch' for better cross-platform compatibility

Comment on lines +468 to +470
const contentLength = Number(c.req.header("content-length") || "0");
if (contentLength > this.#config.protocol.maxIncomingMessageSize) {
throw new errors.MessageTooLong();
Copy link

Choose a reason for hiding this comment

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

logic: Content-Length validation happens after parsing the body. Move this check before c.req.json() to prevent potential DoS attacks.

Copy link

Deploying rivet with  Cloudflare Pages  Cloudflare Pages

Latest commit: b8aefc8
Status: ✅  Deploy successful!
Preview URL: https://036625ae.rivet.pages.dev
Branch Preview URL: https://01-23-feat-sdks-actor-add-ht.rivet.pages.dev

View logs

Copy link
Contributor

graphite-app bot commented Jan 30, 2025

Merge activity

  • Jan 30, 3:38 AM EST: A user added this pull request to the Graphite merge queue.
  • Jan 30, 3:43 AM EST: CI is running for this PR on a draft PR: #1974
  • Jan 30, 3:45 AM EST: A user merged this pull request with the Graphite merge queue via draft PR: #1974.

NathanFlurry added a commit that referenced this pull request Jan 30, 2025
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
@graphite-app graphite-app bot closed this Jan 30, 2025
@graphite-app graphite-app bot deleted the 01-23-feat_sdks_actor_add_http_api_for_calling_rpcs branch January 30, 2025 08:45
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.

1 participant