-
Notifications
You must be signed in to change notification settings - Fork 129
fix(rivetkit): ack ws messages #3329
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
fix(rivetkit): ack ws messages #3329
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Code Review for PR #3329: fix(rivetkit): ack ws messagesSummaryThis PR adds WebSocket message acknowledgment to the engine actor driver. The change ensures that WebSocket messages received by actors are properly acknowledged back to the engine runner. Code Quality: ✅ GoodPositives:
Code location context:
Potential Issues:
|
a0d58a1 to
9fbbebe
Compare
f1efe27 to
7b1fd28
Compare
Pull Request ReviewSummaryThis PR adds WebSocket message acknowledgment (ACK) functionality to the engine actor driver. The change ensures that each incoming WebSocket message is acknowledged back to the runner with its request ID and message index. Code Quality ✅Positive aspects:
Suggestions for improvement:
Potential Issues
|
PR Review: fix(rivetkit): ack ws messagesSummaryThis PR adds acknowledgment logic for WebSocket messages in the engine actor driver. The change sends an acknowledgment to the engine runner for each WebSocket message received, which is critical for hibernatable WebSocket support. Code Quality & Best Practices✅ Positive aspects:
1. Error Handling & RobustnessIssue: The invariant(event.rivetRequestId, "missing rivetRequestId");
invariant(event.rivetMessageIndex, "missing rivetMessageIndex");Context: According to the interface definition in Recommendation: Consider handling the case where these properties are missing more gracefully: // Option 1: Only ack if the fields are present (for backward compatibility)
if (event.rivetRequestId && event.rivetMessageIndex !== undefined) {
this.#runner.sendWebsocketMessageAck(
event.rivetRequestId,
event.rivetMessageIndex,
);
}
// Option 2: Log a warning instead of crashing
if (!event.rivetRequestId || event.rivetMessageIndex === undefined) {
logger().warn("websocket message missing hibernation metadata, skipping ack");
return;
}2. Timing & Race ConditionsIssue: The acknowledgment is sent after the user's wsHandlerPromise.then((x) => x.onMessage?.(event, wsContext)); // Async, may still be running
this.#runner.sendWebsocketMessageAck(...); // Called immediately afterQuestions to consider:
Current behavior: The code acks messages immediately, regardless of whether the user's handler completes successfully. This is probably correct for a message delivery guarantee system (ack receipt, not processing), but it should be documented. 3. Test CoverageRecommendation: Add tests to verify:
Test files that should be updated:
4. DocumentationMissing context:
Recommendation: Add a comment explaining the purpose: // Acknowledge receipt of hibernatable websocket messages to the engine runner.
// This is required for the experimental hibernation feature to track message delivery.
// See: https://docs.rs/... or internal docs
if (event.rivetRequestId && event.rivetMessageIndex !== undefined) {
this.#runner.sendWebsocketMessageAck(
event.rivetRequestId,
event.rivetMessageIndex,
);
}Performance Considerations✅ Good: The Security Concerns✅ No obvious security issues - The acknowledgment system appears to be internal to the engine runner communication and doesn't expose user data or create attack vectors. Recommendations SummaryHigh Priority:
Medium Priority: Low Priority: Would you like me to help implement any of these recommendations? |
9fbbebe to
d9e0eb8
Compare
7b1fd28 to
5f837ae
Compare
PR Review: fix(rivetkit): ack ws messagesSummaryThis PR adds acknowledgment (ack) functionality for WebSocket messages in the RivetKit engine actor driver. The change ensures that each incoming WebSocket message is acknowledged back to the engine runner, which is critical for the hibernatable WebSocket feature. Code Quality ✅Positives:
Potential Issues 🔍Minor Concerns:
Performance Considerations ✅No performance concerns. The ack operation is lightweight and properly placed after the async handler is queued, so it won't block message processing. Security Considerations ✅No security concerns identified. The invariants provide good protection against malformed events. Test Coverage
|
d9e0eb8 to
d2735a8
Compare
5f837ae to
9d011a4
Compare
PR Review: Fix WebSocket Message AcknowledgmentSummaryThis PR adds WebSocket message acknowledgment logic to the EngineActorDriver by calling ✅ Positive Observations
🔍 Potential Issues & Concerns1. Missing Error Handling Around sendWebsocketMessageAckThe call to try {
invariant(event.rivetRequestId, "missing rivetRequestId");
invariant(event.rivetMessageIndex, "missing rivetMessageIndex");
this.#runner.sendWebsocketMessageAck(
event.rivetRequestId,
event.rivetMessageIndex,
);
} catch (error) {
logger().error({ msg: "failed to ack websocket message", error });
// Consider whether to close the WebSocket here
}2. Invariant May Be Too StrictThe Recommendation: Check if the WebSocket is hibernatable before asserting these properties, or make the ack call conditional: websocket.addEventListener("message", (event: RivetMessageEvent) => {
wsHandlerPromise.then((x) => x.onMessage?.(event, wsContext));
// Only ack if this is a hibernatable WebSocket with tracking info
if (event.rivetRequestId && event.rivetMessageIndex !== undefined) {
this.#runner.sendWebsocketMessageAck(
event.rivetRequestId,
event.rivetMessageIndex,
);
}
});3. Race Condition ConcernThe 4. Ordering GuaranteeThe acknowledgment happens after calling the user's message handler. If the user handler is slow or async, multiple messages could queue up. Verify this is the intended behavior - typically acks should happen immediately on receipt, not after processing. 🧪 Test CoverageCritical Gap: There are no tests validating this acknowledgment logic in the driver test suite. Recommendations:
🔒 Security ConsiderationsNo major security concerns. The invariant checks prevent undefined values from being passed to the engine, which is good defensive programming. ⚡ Performance ConsiderationsMinimal performance impact. The ack is a simple method call. However, if 📝 DocumentationConsider adding a comment explaining why this acknowledgment is necessary: // Acknowledge message receipt for hibernatable WebSockets.
// The engine runner uses these acks to track message delivery state
// and properly resume hibernated connections.
invariant(event.rivetRequestId, "missing rivetRequestId");
invariant(event.rivetMessageIndex, "missing rivetMessageIndex");
this.#runner.sendWebsocketMessageAck(
event.rivetRequestId,
event.rivetMessageIndex,
);🎯 Final VerdictThis is an important bug fix, but the invariant checks may be too strict. The safest approach is to make the ack conditional on the presence of these properties rather than throwing if they're missing. Suggested Change: websocket.addEventListener("message", (event: RivetMessageEvent) => {
wsHandlerPromise.then((x) => x.onMessage?.(event, wsContext));
// Acknowledge message for hibernatable WebSockets
if (event.rivetRequestId && event.rivetMessageIndex !== undefined) {
this.#runner.sendWebsocketMessageAck(
event.rivetRequestId,
event.rivetMessageIndex,
);
}
});This maintains backward compatibility while adding the necessary hibernation support. |
Merge activity
|
d2735a8 to
a114914
Compare
9d011a4 to
0298a50
Compare
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/limits#rate-limits |
PR Review: fix(rivetkit): ack ws messagesSummaryThis PR adds WebSocket message acknowledgment functionality to the engine actor driver. The change ensures that each WebSocket message received is acknowledged back to the engine runner using Code Quality ✅Positives:
Concerns:
Test Coverage ❌Missing:
Recommendation: Add tests in
Performance Considerations ✅The change adds minimal overhead (one function call per message), which should be negligible. Security Concerns ✅No security issues identified. The acknowledgment data comes from the engine runner (trusted source). Architecture Fit
|

No description provided.